test_rtde_parser.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // Copyright 2020 FZI Forschungszentrum Informatik
5 // Created on behalf of Universal Robots A/S
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // -- END LICENSE BLOCK ------------------------------------------------
19 
20 //----------------------------------------------------------------------
27 //----------------------------------------------------------------------
28 
29 #include <gtest/gtest.h>
30 
33 
34 using namespace urcl;
35 
36 TEST(rtde_parser, request_protocol_version)
37 {
38  // Accepted request protocol version
39  unsigned char raw_data[] = { 0x00, 0x04, 0x56, 0x01 };
40  comm::BinParser bp(raw_data, sizeof(raw_data));
41 
42  std::vector<std::unique_ptr<rtde_interface::RTDEPackage>> products;
43  rtde_interface::RTDEParser parser({ "" });
44  parser.parse(bp, products);
45 
46  EXPECT_EQ(products.size(), 1);
47 
49  dynamic_cast<rtde_interface::RequestProtocolVersion*>(products[0].get()))
50  {
51  EXPECT_EQ(data->accepted_, true);
52  }
53  else
54  {
55  std::cout << "Failed to get request protocol version data" << std::endl;
56  GTEST_FAIL();
57  }
58 }
59 
60 TEST(rtde_parser, get_urcontrol_version)
61 {
62  // URControl version 5.8.0-0
63  unsigned char raw_data[] = { 0x00, 0x13, 0x76, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
64  0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
65  comm::BinParser bp(raw_data, sizeof(raw_data));
66 
67  std::vector<std::unique_ptr<rtde_interface::RTDEPackage>> products;
68  rtde_interface::RTDEParser parser({ "" });
69  parser.parse(bp, products);
70 
71  EXPECT_EQ(products.size(), 1);
72 
73  if (rtde_interface::GetUrcontrolVersion* data = dynamic_cast<rtde_interface::GetUrcontrolVersion*>(products[0].get()))
74  {
75  EXPECT_EQ(data->version_information_.major, 5);
76  EXPECT_EQ(data->version_information_.minor, 8);
77  EXPECT_EQ(data->version_information_.bugfix, 0);
78  EXPECT_EQ(data->version_information_.build, 0);
79  }
80  else
81  {
82  std::cout << "Failed to get urcontrol version data" << std::endl;
83  GTEST_FAIL();
84  }
85 }
86 
87 TEST(rtde_parser, control_package_pause)
88 {
89  // Accepted control package pause
90  unsigned char raw_data[] = { 0x00, 0x04, 0x50, 0x01 };
91  comm::BinParser bp(raw_data, sizeof(raw_data));
92 
93  std::vector<std::unique_ptr<rtde_interface::RTDEPackage>> products;
94  rtde_interface::RTDEParser parser({ "" });
95  parser.parse(bp, products);
96 
97  EXPECT_EQ(products.size(), 1);
98 
99  if (rtde_interface::ControlPackagePause* data = dynamic_cast<rtde_interface::ControlPackagePause*>(products[0].get()))
100  {
101  EXPECT_EQ(data->accepted_, true);
102  }
103  else
104  {
105  std::cout << "Failed to get control package pause data" << std::endl;
106  GTEST_FAIL();
107  }
108 }
109 
110 TEST(rtde_parser, control_package_start)
111 {
112  // Accepted control package start
113  unsigned char raw_data[] = { 0x00, 0x04, 0x53, 0x01 };
114  comm::BinParser bp(raw_data, sizeof(raw_data));
115 
116  std::vector<std::unique_ptr<rtde_interface::RTDEPackage>> products;
117  rtde_interface::RTDEParser parser({ "" });
118  parser.parse(bp, products);
119 
120  EXPECT_EQ(products.size(), 1);
121 
122  if (rtde_interface::ControlPackageStart* data = dynamic_cast<rtde_interface::ControlPackageStart*>(products[0].get()))
123  {
124  EXPECT_EQ(data->accepted_, true);
125  }
126  else
127  {
128  std::cout << "Failed to get control package start data" << std::endl;
129  GTEST_FAIL();
130  }
131 }
132 
133 TEST(rtde_parser, control_package_setup_inputs)
134 {
135  // Accepted control package setup inputs, variable types are uint32 and double
136  unsigned char raw_data[] = { 0x00, 0x11, 0x49, 0x01, 0x55, 0x49, 0x4e, 0x54, 0x33,
137  0x32, 0x2c, 0x44, 0x4f, 0x55, 0x42, 0x4c, 0x45 };
138  comm::BinParser bp(raw_data, sizeof(raw_data));
139 
140  std::vector<std::unique_ptr<rtde_interface::RTDEPackage>> products;
141  rtde_interface::RTDEParser parser({ "" });
142  parser.parse(bp, products);
143 
144  EXPECT_EQ(products.size(), 1);
145 
147  dynamic_cast<rtde_interface::ControlPackageSetupInputs*>(products[0].get()))
148  {
149  EXPECT_EQ(data->input_recipe_id_, 1);
150  EXPECT_EQ(data->variable_types_, "UINT32,DOUBLE");
151  }
152  else
153  {
154  std::cout << "Failed to get control package setup inputs data" << std::endl;
155  GTEST_FAIL();
156  }
157 }
158 
159 TEST(rtde_parser, control_package_setup_outputs)
160 {
161  // Accepted control package setup outputs, variable types are double and vector6d
162  unsigned char raw_data[] = { 0x00, 0x11, 0x4f, 0x01, 0x44, 0x4f, 0x55, 0x42, 0x4c, 0x45,
163  0x2c, 0x56, 0x45, 0x43, 0x54, 0x4f, 0x52, 0x36, 0x44 };
164  comm::BinParser bp(raw_data, sizeof(raw_data));
165 
166  std::vector<std::unique_ptr<rtde_interface::RTDEPackage>> products;
167  rtde_interface::RTDEParser parser({ "" });
168  parser.setProtocolVersion(2);
169  parser.parse(bp, products);
170 
171  EXPECT_EQ(products.size(), 1);
172 
174  dynamic_cast<rtde_interface::ControlPackageSetupOutputs*>(products[0].get()))
175  {
176  EXPECT_EQ(data->output_recipe_id_, 1);
177  EXPECT_EQ(data->variable_types_, "DOUBLE,VECTOR6D");
178  }
179  else
180  {
181  std::cout << "Failed to get control package setup outputs data" << std::endl;
182  GTEST_FAIL();
183  }
184 }
185 
186 TEST(rtde_parser, data_package)
187 {
188  // received data package,
189  unsigned char raw_data[] = { 0x00, 0x14, 0x55, 0x01, 0x40, 0xd0, 0x07, 0x0d, 0x2f, 0x1a,
190  0x9f, 0xbe, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
191  comm::BinParser bp(raw_data, sizeof(raw_data));
192 
193  std::vector<std::unique_ptr<rtde_interface::RTDEPackage>> products;
194  std::vector<std::string> recipe = { "timestamp", "target_speed_fraction" };
195  rtde_interface::RTDEParser parser(recipe);
196  parser.setProtocolVersion(2);
197  parser.parse(bp, products);
198 
199  EXPECT_EQ(products.size(), 1);
200 
201  if (rtde_interface::DataPackage* data = dynamic_cast<rtde_interface::DataPackage*>(products[0].get()))
202  {
203  double timestamp, target_speed_fraction;
204  data->getData("timestamp", timestamp);
205  data->getData("target_speed_fraction", target_speed_fraction);
206 
207  EXPECT_FLOAT_EQ(timestamp, 16412.2);
208  EXPECT_EQ(target_speed_fraction, 1);
209  }
210  else
211  {
212  std::cout << "Failed to get data package data" << std::endl;
213  GTEST_FAIL();
214  }
215 }
216 
217 TEST(rtde_parser, test_to_string)
218 {
219  // Non-existent type
220  unsigned char raw_data[] = { 0x00, 0x05, 0x02, 0x00, 0x00 };
221  comm::BinParser bp(raw_data, sizeof(raw_data));
222 
223  std::vector<std::unique_ptr<rtde_interface::RTDEPackage>> products;
224  rtde_interface::RTDEParser parser({ "" });
225  parser.parse(bp, products);
226 
227  EXPECT_EQ(products.size(), 1);
228 
229  std::stringstream expected;
230  expected << "Type: 2" << std::endl;
231  expected << "Raw byte stream: 0 0 " << std::endl;
232 
233  EXPECT_EQ(products[0]->toString(), expected.str());
234 }
235 
236 TEST(rtde_parser, test_buffer_too_short)
237 {
238  // Non-existent type with false size information
239  unsigned char raw_data[] = { 0x00, 0x06, 0x02, 0x00, 0x00 };
240  comm::BinParser bp(raw_data, sizeof(raw_data));
241 
242  std::vector<std::unique_ptr<rtde_interface::RTDEPackage>> products;
243  rtde_interface::RTDEParser parser({ "" });
244  EXPECT_FALSE(parser.parse(bp, products));
245 }
246 
247 TEST(rtde_parser, test_buffer_too_long)
248 {
249  // Non-existent type with false size information
250  unsigned char raw_data[] = { 0x00, 0x04, 0x56, 0x01, 0x02, 0x01, 0x02 };
251  comm::BinParser bp(raw_data, sizeof(raw_data));
252 
253  std::vector<std::unique_ptr<rtde_interface::RTDEPackage>> products;
254  rtde_interface::RTDEParser parser({ "" });
255  EXPECT_FALSE(parser.parse(bp, products));
256 }
257 
258 int main(int argc, char* argv[])
259 {
260  ::testing::InitGoogleTest(&argc, argv);
261 
262  return RUN_ALL_TESTS();
263 }
void setProtocolVersion(uint16_t protocol_version)
Definition: rtde_parser.h:119
This class handles the robot&#39;s response to a requested start in RTDE data package communication...
The BinParser class handles a byte buffer and functionality to iteratively parse the content...
Definition: bin_parser.h:44
This class handles the package detailing the UR control version sent by the robot.
bool parse(comm::BinParser &bp, std::vector< std::unique_ptr< RTDEPackage >> &results)
Uses the given BinParser to create package objects from the contained serialization.
Definition: rtde_parser.h:68
The RTDE specific parser. Interprets a given byte stream as serialized RTDE packages and parses it ac...
Definition: rtde_parser.h:45
This class handles the robot&#39;s response to a requested stop in RTDE data package communication.
int main(int argc, char *argv[])
This class handles the robot&#39;s response to a requested output recipe setup.
This class handles the robot&#39;s response after trying to set the used RTDE protocol version...
This class handles the robot&#39;s response to a requested input recipe setup.
TEST(rtde_parser, request_protocol_version)
The DataPackage class handles communication in the form of RTDE data packages both to and from the ro...
Definition: data_package.h:60


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Tue Jul 4 2023 02:09:47