tests/ur/robot_mode.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017, 2018 Simon Rasmussen (refactor)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 #include <gtest/gtest.h>
20 #include "ur_modern_driver/log.h"
23 #include "ur_modern_driver/types.h"
24 
25 TEST(RobotModeData_V1_X, testRandomDataParsing)
26 {
27  RandomDataTest rdt(24);
28  BinParser bp = rdt.getParser();
29  RobotModeData_V1_X state;
30  ASSERT_TRUE(state.parseWith(bp)) << "parse() returned false";
31 
32  ASSERT_EQ(rdt.getNext<uint64_t>(), state.timestamp);
33  ASSERT_EQ(rdt.getNext<bool>(), state.physical_robot_connected);
34  ASSERT_EQ(rdt.getNext<bool>(), state.real_robot_enabled);
35  ASSERT_EQ(rdt.getNext<bool>(), state.robot_power_on);
36  ASSERT_EQ(rdt.getNext<bool>(), state.emergency_stopped);
37  ASSERT_EQ(rdt.getNext<bool>(), state.protective_stopped);
38  ASSERT_EQ(rdt.getNext<bool>(), state.program_running);
39  ASSERT_EQ(rdt.getNext<bool>(), state.program_paused);
40  ASSERT_EQ(rdt.getNext<robot_mode_V1_X>(), state.robot_mode);
41  ASSERT_EQ(rdt.getNext<double>(), state.speed_fraction);
42 
43  ASSERT_TRUE(bp.empty()) << "Did not consume all data";
44 }
45 
46 TEST(RobotModeData_V3_0__1, testRandomDataParsing)
47 {
48  RandomDataTest rdt(33);
49  BinParser bp = rdt.getParser();
51  ASSERT_TRUE(state.parseWith(bp)) << "parse() returned false";
52 
53  ASSERT_EQ(rdt.getNext<uint64_t>(), state.timestamp);
54  ASSERT_EQ(rdt.getNext<bool>(), state.physical_robot_connected);
55  ASSERT_EQ(rdt.getNext<bool>(), state.real_robot_enabled);
56  ASSERT_EQ(rdt.getNext<bool>(), state.robot_power_on);
57  ASSERT_EQ(rdt.getNext<bool>(), state.emergency_stopped);
58  ASSERT_EQ(rdt.getNext<bool>(), state.protective_stopped);
59  ASSERT_EQ(rdt.getNext<bool>(), state.program_running);
60  ASSERT_EQ(rdt.getNext<bool>(), state.program_paused);
61  ASSERT_EQ(rdt.getNext<robot_mode_V3_X>(), state.robot_mode);
62  ASSERT_EQ(rdt.getNext<robot_control_mode_V3_X>(), state.control_mode);
63  ASSERT_EQ(rdt.getNext<double>(), state.target_speed_fraction);
64  ASSERT_EQ(rdt.getNext<double>(), state.speed_scaling);
65 
66  ASSERT_TRUE(bp.empty()) << "Did not consume all data";
67 }
68 
69 TEST(RobotModeData_V3_2, testRandomDataParsing)
70 {
71  RandomDataTest rdt(41);
72  BinParser bp = rdt.getParser();
73  RobotModeData_V3_2 state;
74  ASSERT_TRUE(state.parseWith(bp)) << "parse() returned false";
75 
76  ASSERT_EQ(rdt.getNext<uint64_t>(), state.timestamp);
77  ASSERT_EQ(rdt.getNext<bool>(), state.physical_robot_connected);
78  ASSERT_EQ(rdt.getNext<bool>(), state.real_robot_enabled);
79  ASSERT_EQ(rdt.getNext<bool>(), state.robot_power_on);
80  ASSERT_EQ(rdt.getNext<bool>(), state.emergency_stopped);
81  ASSERT_EQ(rdt.getNext<bool>(), state.protective_stopped);
82  ASSERT_EQ(rdt.getNext<bool>(), state.program_running);
83  ASSERT_EQ(rdt.getNext<bool>(), state.program_paused);
84  ASSERT_EQ(rdt.getNext<robot_mode_V3_X>(), state.robot_mode);
85  ASSERT_EQ(rdt.getNext<robot_control_mode_V3_X>(), state.control_mode);
86  ASSERT_EQ(rdt.getNext<double>(), state.target_speed_fraction);
87  ASSERT_EQ(rdt.getNext<double>(), state.speed_scaling);
88  ASSERT_EQ(rdt.getNext<double>(), state.target_speed_fraction_limit);
89 
90  ASSERT_TRUE(bp.empty()) << "Did not consume all data";
91 }
92 
93 TEST(RobotModeData_V1_X, testTooSmallBuffer)
94 {
95  RandomDataTest rdt(10);
96  BinParser bp = rdt.getParser();
97  RobotModeData_V1_X state;
98  EXPECT_FALSE(state.parseWith(bp)) << "parse() should fail when buffer not big enough";
99 }
100 
101 TEST(RobotModeData_V3_0__1, testTooSmallBuffer)
102 {
103  RandomDataTest rdt(10);
104  BinParser bp = rdt.getParser();
105  RobotModeData_V3_0__1 state;
106  EXPECT_FALSE(state.parseWith(bp)) << "parse() should fail when buffer not big enough";
107 }
108 
109 TEST(RobotModeData_V3_2, testTooSmallBuffer)
110 {
111  RandomDataTest rdt(10);
112  BinParser bp = rdt.getParser();
113  RobotModeData_V3_2 state;
114  EXPECT_FALSE(state.parseWith(bp)) << "parse() should fail when buffer not big enough";
115 }
double speed_fraction
Definition: robot_mode.h:66
virtual bool parseWith(BinParser &bp)
uint64_t timestamp
Definition: robot_mode.h:32
double target_speed_fraction
Definition: robot_mode.h:103
robot_mode_V3_X robot_mode
Definition: robot_mode.h:100
BinParser getParser(bool skip=false)
Definition: random_data.h:49
bool empty()
Definition: bin_parser.h:194
robot_control_mode_V3_X control_mode
Definition: robot_mode.h:101
double target_speed_fraction_limit
Definition: robot_mode.h:118
robot_mode_V1_X robot_mode
Definition: robot_mode.h:65
TEST(RobotModeData_V1_X, testRandomDataParsing)
robot_mode_V3_X
Definition: robot_mode.h:73
robot_mode_V1_X
Definition: robot_mode.h:44
virtual bool parseWith(BinParser &bp)
bool physical_robot_connected
Definition: robot_mode.h:33
robot_control_mode_V3_X
Definition: robot_mode.h:86
virtual bool parseWith(BinParser &bp)


ur_modern_driver
Author(s): Thomas Timm Andersen, Simon Rasmussen
autogenerated on Fri Jun 26 2020 03:37:00