29 #include <gtest/gtest.h> 35 TEST(rtde_data_package, serialize_pkg)
37 std::vector<std::string> recipe{
"speed_slider_mask" };
42 package.
setData(
"speed_slider_mask", value);
50 uint8_t expected[] = { 0x0, 0x08, 0x55, 0x01, 0x00, 0x00, 0x00, 0x01 };
52 for (
size_t i = 0; i < size; ++i)
54 EXPECT_EQ(buffer[i], expected[i]);
58 TEST(rtde_data_package, parse_pkg_protocolv2)
60 std::vector<std::string> recipe{
"timestamp",
"actual_q" };
64 uint8_t data_package[] = { 0x01, 0x40, 0xd0, 0x75, 0x8c, 0x49, 0xba, 0x5e, 0x35, 0xbf, 0xf9, 0x9c, 0x77, 0xd1, 0x10,
65 0xb4, 0x60, 0xbf, 0xfb, 0xa2, 0x33, 0xd1, 0x10, 0xb4, 0x60, 0xc0, 0x01, 0x9f, 0xbe, 0x68,
66 0x88, 0x5a, 0x30, 0xbf, 0xe9, 0xdb, 0x22, 0xa2, 0x21, 0x68, 0xc0, 0x3f, 0xf9, 0x85, 0x87,
67 0xa0, 0x00, 0x00, 0x00, 0xbf, 0x9f, 0xbe, 0x74, 0x44, 0x2d, 0x18, 0x00 };
73 vector6d_t expected_q = { -1.6007, -1.7271, -2.203, -0.808, 1.5951, -0.031 };
75 package.
getData(
"actual_q", actual_q);
78 EXPECT_NEAR(expected_q[0], actual_q[0], abs);
79 EXPECT_NEAR(expected_q[1], actual_q[1], abs);
80 EXPECT_NEAR(expected_q[2], actual_q[2], abs);
81 EXPECT_NEAR(expected_q[3], actual_q[3], abs);
82 EXPECT_NEAR(expected_q[4], actual_q[4], abs);
83 EXPECT_NEAR(expected_q[5], actual_q[5], abs);
85 double expected_timestamp = 16854.1919;
86 double actual_timestamp;
87 package.
getData(
"timestamp", actual_timestamp);
89 EXPECT_NEAR(expected_timestamp, actual_timestamp, abs);
92 TEST(rtde_data_package, parse_pkg_protocolv1)
94 std::vector<std::string> recipe{
"timestamp",
"actual_q" };
98 uint8_t data_package[] = { 0x40, 0xd0, 0x75, 0x8c, 0x49, 0xba, 0x5e, 0x35, 0xbf, 0xf9, 0x9c, 0x77, 0xd1, 0x10,
99 0xb4, 0x60, 0xbf, 0xfb, 0xa2, 0x33, 0xd1, 0x10, 0xb4, 0x60, 0xc0, 0x01, 0x9f, 0xbe,
100 0x68, 0x88, 0x5a, 0x30, 0xbf, 0xe9, 0xdb, 0x22, 0xa2, 0x21, 0x68, 0xc0, 0x3f, 0xf9,
101 0x85, 0x87, 0xa0, 0x00, 0x00, 0x00, 0xbf, 0x9f, 0xbe, 0x74, 0x44, 0x2d, 0x18, 0x00 };
106 vector6d_t expected_q = { -1.6007, -1.7271, -2.203, -0.808, 1.5951, -0.031 };
108 package.
getData(
"actual_q", actual_q);
111 EXPECT_NEAR(expected_q[0], actual_q[0], abs);
112 EXPECT_NEAR(expected_q[1], actual_q[1], abs);
113 EXPECT_NEAR(expected_q[2], actual_q[2], abs);
114 EXPECT_NEAR(expected_q[3], actual_q[3], abs);
115 EXPECT_NEAR(expected_q[4], actual_q[4], abs);
116 EXPECT_NEAR(expected_q[5], actual_q[5], abs);
118 double expected_timestamp = 16854.1919;
119 double actual_timestamp;
120 package.
getData(
"timestamp", actual_timestamp);
122 EXPECT_NEAR(expected_timestamp, actual_timestamp, abs);
125 TEST(rtde_data_package, get_data_not_part_of_recipe)
127 std::vector<std::string> recipe{
"timestamp",
"actual_q" };
131 uint32_t speed_slider_mask;
132 EXPECT_FALSE(package.
getData(
"speed_slider_mask", speed_slider_mask));
135 TEST(rtde_data_package, set_data_not_part_of_recipe)
137 std::vector<std::string> recipe{
"timestamp",
"actual_q" };
141 uint32_t speed_slider_mask = 1;
142 EXPECT_FALSE(package.
setData(
"speed_slider_mask", speed_slider_mask));
145 TEST(rtde_data_package, parse_and_get_bitset_data)
147 std::vector<std::string> recipe{
"robot_status_bits" };
151 uint8_t data_package[] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x40, 0xb2, 0x3d, 0xa9, 0xfb, 0xe7, 0x6c, 0x8b };
156 std::bitset<4> expected_robot_status_bits = 0000;
157 std::bitset<4> actual_robot_status_bits;
158 package.
getData<uint32_t>(
"robot_status_bits", actual_robot_status_bits);
160 EXPECT_EQ(expected_robot_status_bits, actual_robot_status_bits);
163 int main(
int argc,
char* argv[])
165 ::testing::InitGoogleTest(&argc, argv);
167 return RUN_ALL_TESTS();
TEST(rtde_data_package, serialize_pkg)
The BinParser class handles a byte buffer and functionality to iteratively parse the content...
bool getData(const std::string &name, T &val)
Get a data field from the DataPackage.
int main(int argc, char *argv[])
virtual bool parseWith(comm::BinParser &bp)
Sets the attributes of the package by parsing a serialized representation of the package.
size_t serializePackage(uint8_t *buffer)
Serializes the package.
void setRecipeID(const uint8_t &recipe_id)
Setter of the recipe id value used to identify the used recipe to the robot.
std::array< double, 6 > vector6d_t
The DataPackage class handles communication in the form of RTDE data packages both to and from the ro...
void initEmpty()
Initializes to contained list with empty values based on the recipe.
bool setData(const std::string &name, T &val)
Set a data field in the DataPackage.