tests/ur/rt_state.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(RTState_V1_6__7, testRandomDataParsing)
26 {
27  RandomDataTest rdt(764);
28  BinParser bp = rdt.getParser(true);
29  RTState_V1_6__7 state;
30  EXPECT_TRUE(state.parseWith(bp)) << "parse() returned false";
31 
32  ASSERT_EQ(rdt.getNext<double>(), state.time);
33  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.q_target);
34  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.qd_target);
35  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.qdd_target);
36  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.i_target);
37  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.m_target);
38  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.q_actual);
39  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.qd_actual);
40  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.i_actual);
41  ASSERT_EQ(rdt.getNext<double3_t>(), state.tool_accelerometer_values);
42  rdt.skip(sizeof(double) * 15);
43  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.tcp_force);
44  ASSERT_EQ(rdt.getNext<cartesian_coord_t>(), state.tool_vector_actual);
45  ASSERT_EQ(rdt.getNext<cartesian_coord_t>(), state.tcp_speed_actual);
46  ASSERT_EQ(rdt.getNext<uint64_t>(), state.digital_inputs);
48  ASSERT_EQ(rdt.getNext<double>(), state.controller_time);
49  rdt.skip(sizeof(double)); // skip unused value
50  ASSERT_EQ(rdt.getNext<double>(), state.robot_mode);
51 
52  EXPECT_TRUE(bp.empty()) << "Did not consume all data";
53 }
54 
55 TEST(RTState_V1_8, testRandomDataParsing)
56 {
57  RandomDataTest rdt(812);
58  BinParser bp = rdt.getParser(true);
59  RTState_V1_8 state;
60  EXPECT_TRUE(state.parseWith(bp)) << "parse() returned false";
61 
62  ASSERT_EQ(rdt.getNext<double>(), state.time);
63  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.q_target);
64  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.qd_target);
65  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.qdd_target);
66  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.i_target);
67  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.m_target);
68  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.q_actual);
69  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.qd_actual);
70  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.i_actual);
71  ASSERT_EQ(rdt.getNext<double3_t>(), state.tool_accelerometer_values);
72  rdt.skip(sizeof(double) * 15);
73  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.tcp_force);
74  ASSERT_EQ(rdt.getNext<cartesian_coord_t>(), state.tool_vector_actual);
75  ASSERT_EQ(rdt.getNext<cartesian_coord_t>(), state.tcp_speed_actual);
76  ASSERT_EQ(rdt.getNext<uint64_t>(), state.digital_inputs);
78  ASSERT_EQ(rdt.getNext<double>(), state.controller_time);
79  rdt.skip(sizeof(double)); // skip unused value
80  ASSERT_EQ(rdt.getNext<double>(), state.robot_mode);
81  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.joint_modes);
82 
83  EXPECT_TRUE(bp.empty()) << "Did not consume all data";
84 }
85 
86 TEST(RTState_V3_0__1, testRandomDataParsing)
87 {
88  RandomDataTest rdt(1044);
89  BinParser bp = rdt.getParser(true);
90  RTState_V3_0__1 state;
91  EXPECT_TRUE(state.parseWith(bp)) << "parse() returned false";
92 
93  ASSERT_EQ(rdt.getNext<double>(), state.time);
94  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.q_target);
95  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.qd_target);
96  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.qdd_target);
97  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.i_target);
98  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.m_target);
99  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.q_actual);
100  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.qd_actual);
101  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.i_actual);
102 
103  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.i_control);
104  ASSERT_EQ(rdt.getNext<cartesian_coord_t>(), state.tool_vector_actual);
105  ASSERT_EQ(rdt.getNext<cartesian_coord_t>(), state.tcp_speed_actual);
106  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.tcp_force);
107  ASSERT_EQ(rdt.getNext<cartesian_coord_t>(), state.tool_vector_target);
108  ASSERT_EQ(rdt.getNext<cartesian_coord_t>(), state.tcp_speed_target);
109 
110  ASSERT_EQ(rdt.getNext<uint64_t>(), state.digital_inputs);
111  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.motor_temperatures);
112  ASSERT_EQ(rdt.getNext<double>(), state.controller_time);
113  rdt.skip(sizeof(double)); // skip unused value
114  ASSERT_EQ(rdt.getNext<double>(), state.robot_mode);
115  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.joint_modes);
116  ASSERT_EQ(rdt.getNext<double>(), state.safety_mode);
117  rdt.skip(sizeof(double) * 6);
118  ASSERT_EQ(rdt.getNext<double3_t>(), state.tool_accelerometer_values);
119  rdt.skip(sizeof(double) * 6);
120  ASSERT_EQ(rdt.getNext<double>(), state.speed_scaling);
121  ASSERT_EQ(rdt.getNext<double>(), state.linear_momentum_norm);
122  rdt.skip(sizeof(double) * 2);
123  ASSERT_EQ(rdt.getNext<double>(), state.v_main);
124  ASSERT_EQ(rdt.getNext<double>(), state.v_robot);
125  ASSERT_EQ(rdt.getNext<double>(), state.i_robot);
126  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.v_actual);
127 
128  EXPECT_TRUE(bp.empty()) << "Did not consume all data";
129 }
130 
131 TEST(RTState_V3_2__3, testRandomDataParsing)
132 {
133  RandomDataTest rdt(1060);
134  BinParser bp = rdt.getParser(true);
135  RTState_V3_2__3 state;
136  EXPECT_TRUE(state.parseWith(bp)) << "parse() returned false";
137 
138  ASSERT_EQ(rdt.getNext<double>(), state.time);
139  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.q_target);
140  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.qd_target);
141  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.qdd_target);
142  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.i_target);
143  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.m_target);
144  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.q_actual);
145  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.qd_actual);
146  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.i_actual);
147 
148  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.i_control);
149  ASSERT_EQ(rdt.getNext<cartesian_coord_t>(), state.tool_vector_actual);
150  ASSERT_EQ(rdt.getNext<cartesian_coord_t>(), state.tcp_speed_actual);
151  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.tcp_force);
152  ASSERT_EQ(rdt.getNext<cartesian_coord_t>(), state.tool_vector_target);
153  ASSERT_EQ(rdt.getNext<cartesian_coord_t>(), state.tcp_speed_target);
154 
155  ASSERT_EQ(rdt.getNext<uint64_t>(), state.digital_inputs);
156  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.motor_temperatures);
157  ASSERT_EQ(rdt.getNext<double>(), state.controller_time);
158  rdt.skip(sizeof(double)); // skip unused value
159  ASSERT_EQ(rdt.getNext<double>(), state.robot_mode);
160  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.joint_modes);
161  ASSERT_EQ(rdt.getNext<double>(), state.safety_mode);
162  rdt.skip(sizeof(double) * 6);
163  ASSERT_EQ(rdt.getNext<double3_t>(), state.tool_accelerometer_values);
164  rdt.skip(sizeof(double) * 6);
165  ASSERT_EQ(rdt.getNext<double>(), state.speed_scaling);
166  ASSERT_EQ(rdt.getNext<double>(), state.linear_momentum_norm);
167  rdt.skip(sizeof(double) * 2);
168  ASSERT_EQ(rdt.getNext<double>(), state.v_main);
169  ASSERT_EQ(rdt.getNext<double>(), state.v_robot);
170  ASSERT_EQ(rdt.getNext<double>(), state.i_robot);
171  ASSERT_DOUBLE_ARRAY_EQ(rdt.getNext<double>(), state.v_actual);
172  ASSERT_EQ(rdt.getNext<uint64_t>(), state.digital_outputs);
173  ASSERT_EQ(rdt.getNext<double>(), state.program_state);
174 
175  EXPECT_TRUE(bp.empty()) << "did not consume all data";
176 }
177 
178 TEST(RTState_V1_6__7, testTooSmallBuffer)
179 {
180  RandomDataTest rdt(10);
181  BinParser bp = rdt.getParser(true);
182  RTState_V1_6__7 state;
183  EXPECT_FALSE(state.parseWith(bp)) << "parse() should fail when buffer not big enough";
184 }
185 
186 TEST(RTState_V1_8, testTooSmallBuffer)
187 {
188  RandomDataTest rdt(10);
189  BinParser bp = rdt.getParser(true);
190  RTState_V1_8 state;
191  EXPECT_FALSE(state.parseWith(bp)) << "parse() should fail when buffer not big enough";
192 }
193 
194 TEST(RTState_V3_0__1, testTooSmallBuffer)
195 {
196  RandomDataTest rdt(10);
197  BinParser bp = rdt.getParser(true);
198  RTState_V3_0__1 state;
199  EXPECT_FALSE(state.parseWith(bp)) << "parse() should fail when buffer not big enough";
200 }
201 
202 TEST(RTState_V3_2__3, testTooSmallBuffer)
203 {
204  RandomDataTest rdt(10);
205  BinParser bp = rdt.getParser(true);
206  RTState_V3_2__3 state;
207  EXPECT_FALSE(state.parseWith(bp)) << "parse() should fail when buffer not big enough";
208 }
uint64_t digital_inputs
Definition: rt_state.h:64
double i_robot
Definition: rt_state.h:116
#define ASSERT_DOUBLE_ARRAY_EQ(fn, name)
Definition: utils.h:21
std::array< double, 6 > joint_modes
Definition: rt_state.h:92
std::array< double, 6 > qdd_target
Definition: rt_state.h:46
std::array< double, 6 > i_actual
Definition: rt_state.h:51
cartesian_coord_t tool_vector_target
Definition: rt_state.h:106
std::array< double, 6 > motor_temperatures
Definition: rt_state.h:65
cartesian_coord_t tcp_speed_actual
Definition: rt_state.h:60
bool parseWith(BinParser &bp)
BinParser getParser(bool skip=false)
Definition: random_data.h:49
double v_robot
Definition: rt_state.h:115
double linear_momentum_norm
Definition: rt_state.h:113
bool parseWith(BinParser &bp)
double safety_mode
Definition: rt_state.h:110
std::array< double, 6 > qd_actual
Definition: rt_state.h:50
std::array< double, 6 > qd_target
Definition: rt_state.h:45
std::array< double, 6 > joint_modes
Definition: rt_state.h:109
bool parseWith(BinParser &bp)
double3_t tool_accelerometer_values
Definition: rt_state.h:111
bool empty()
Definition: bin_parser.h:194
std::array< double, 6 > tcp_force
Definition: rt_state.h:55
double robot_mode
Definition: rt_state.h:67
double program_state
Definition: rt_state.h:132
std::array< double, 6 > q_actual
Definition: rt_state.h:49
double speed_scaling
Definition: rt_state.h:112
double v_main
Definition: rt_state.h:114
std::array< double, 6 > m_target
Definition: rt_state.h:48
bool parseWith(BinParser &bp)
cartesian_coord_t tool_vector_actual
Definition: rt_state.h:59
std::array< double, 6 > i_control
Definition: rt_state.h:105
std::array< double, 6 > v_actual
Definition: rt_state.h:117
uint64_t digital_outputs
Definition: rt_state.h:131
double time
Definition: rt_state.h:43
cartesian_coord_t tcp_speed_target
Definition: rt_state.h:107
TEST(RTState_V1_6__7, testRandomDataParsing)
double controller_time
Definition: rt_state.h:66
double3_t tool_accelerometer_values
Definition: rt_state.h:79
std::array< double, 6 > q_target
Definition: rt_state.h:44
void skip(size_t n)
Definition: random_data.h:76
std::array< double, 6 > i_target
Definition: rt_state.h:47


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