20 #include <ros/service_client.h>
22 #include <gtest/gtest.h>
25 #include "ros/duration.h"
31 static std::unique_ptr<ros::NodeHandle>
nh;
36 auto client =
nh->serviceClient<niryo_robot_msgs::SetInt>(
"/niryo_robot/ttl_driver/set_dxl_leds");
38 bool exists(client.waitForExistence(ros::Duration(1)));
41 niryo_robot_msgs::SetInt srv;
42 srv.request.value = 2;
45 EXPECT_EQ(srv.response.status, niryo_robot_msgs::CommandStatus::SUCCESS);
48 TEST(TESTSuite, WriteCustomValue)
50 auto client =
nh->serviceClient<ttl_driver::WriteCustomValue>(
"/niryo_robot/ttl_driver/send_custom_value");
52 bool exists(client.waitForExistence(ros::Duration(1)));
55 ttl_driver::WriteCustomValue srv;
58 srv.request.reg_address = 64;
59 srv.request.value = 1;
60 srv.request.byte_number = 1;
64 EXPECT_EQ(srv.response.status, niryo_robot_msgs::CommandStatus::SUCCESS);
67 TEST(TESTSuite, WriteCustomValueWrongParam)
69 auto client =
nh->serviceClient<ttl_driver::WriteCustomValue>(
"/niryo_robot/ttl_driver/send_custom_value");
71 bool exists(client.waitForExistence(ros::Duration(1)));
74 ttl_driver::WriteCustomValue srv;
77 srv.request.reg_address = 64;
78 srv.request.value = 1;
79 srv.request.byte_number = 1;
83 EXPECT_EQ(srv.response.status, niryo_robot_msgs::CommandStatus::WRONG_MOTOR_TYPE);
86 TEST(TESTSuite, ReadCustomValue)
88 auto client =
nh->serviceClient<ttl_driver::ReadCustomValue>(
"/niryo_robot/ttl_driver/read_custom_value");
90 bool exists(client.waitForExistence(ros::Duration(1)));
93 ttl_driver::ReadCustomValue srv;
95 srv.request.reg_address = 64;
96 srv.request.byte_number = 1;
100 EXPECT_EQ(srv.response.status, niryo_robot_msgs::CommandStatus::SUCCESS);
104 EXPECT_EQ(srv.response.value, 1);
110 auto client =
nh->serviceClient<ttl_driver::WritePIDValue>(
"/niryo_robot/ttl_driver/write_pid_value");
112 bool exists(client.waitForExistence(ros::Duration(1)));
115 ttl_driver::WritePIDValue srv;
118 srv.request.pos_p_gain = 1024;
119 srv.request.pos_i_gain = 3642;
120 srv.request.pos_d_gain = 11200;
121 srv.request.vel_p_gain = 0;
122 srv.request.vel_i_gain = 0;
123 srv.request.ff1_gain = 0;
124 srv.request.ff2_gain = 0;
125 srv.request.vel_profile = 0;
126 srv.request.acc_profile = 0;
130 EXPECT_EQ(srv.response.status, niryo_robot_msgs::CommandStatus::SUCCESS);
131 ros::Duration(1.0).sleep();
136 auto client =
nh->serviceClient<ttl_driver::ReadPIDValue>(
"/niryo_robot/ttl_driver/read_pid_value");
138 bool exists(client.waitForExistence(ros::Duration(1)));
141 ttl_driver::ReadPIDValue srv;
147 for (
int i = 0; i < 5; i++)
150 if (srv.response.status == niryo_robot_msgs::CommandStatus::SUCCESS)
159 EXPECT_EQ(srv.response.pos_p_gain, 1024);
160 EXPECT_EQ(srv.response.pos_i_gain, 3642);
161 EXPECT_EQ(srv.response.pos_d_gain, 11200);
162 EXPECT_EQ(srv.response.vel_p_gain, 0);
163 EXPECT_EQ(srv.response.vel_i_gain, 0);
164 EXPECT_EQ(srv.response.ff1_gain, 0);
165 EXPECT_EQ(srv.response.ff2_gain, 0);
168 TEST(TESTSuite, ReadPIDValueWrongParam)
170 auto client =
nh->serviceClient<ttl_driver::ReadPIDValue>(
"/niryo_robot/ttl_driver/read_pid_value");
172 bool exists(client.waitForExistence(ros::Duration(1)));
175 ttl_driver::ReadPIDValue srv;
181 EXPECT_EQ(srv.response.status, niryo_robot_msgs::CommandStatus::FAILURE);
184 TEST(TESTSuite, WriteVelocityProfile)
186 auto client =
nh->serviceClient<ttl_driver::WriteVelocityProfile>(
"/niryo_robot/ttl_driver/write_velocity_profile");
188 bool exists(client.waitForExistence(ros::Duration(1)));
191 ttl_driver::WriteVelocityProfile srv;
194 srv.request.v_start = 0;
195 srv.request.a_1 = 1260;
196 srv.request.v_1 = 500;
197 srv.request.a_max = 2500;
198 srv.request.v_max = 1500;
199 srv.request.d_max = 2500;
200 srv.request.d_1 = 1228;
201 srv.request.v_stop = 20;
205 EXPECT_EQ(srv.response.status, niryo_robot_msgs::CommandStatus::SUCCESS);
207 ros::Duration(1.0).sleep();
210 TEST(TESTSuite, ReadVelocityProfile)
212 auto client =
nh->serviceClient<ttl_driver::ReadVelocityProfile>(
"/niryo_robot/ttl_driver/read_velocity_profile");
214 bool exists(client.waitForExistence(ros::Duration(1)));
217 ttl_driver::ReadVelocityProfile srv;
223 for (
int i = 0; i < 3; i++)
226 if (srv.response.status == niryo_robot_msgs::CommandStatus::SUCCESS)
236 EXPECT_DOUBLE_EQ(round(srv.response.v_start), 0.0);
237 EXPECT_DOUBLE_EQ(round(srv.response.a_1), 1260.0);
238 EXPECT_DOUBLE_EQ(round(srv.response.v_1), 500.0);
239 EXPECT_DOUBLE_EQ(round(srv.response.a_max), 2500.0);
240 EXPECT_DOUBLE_EQ(round(srv.response.v_max), 1500.0);
241 EXPECT_DOUBLE_EQ(round(srv.response.d_max), 2500.0);
242 EXPECT_DOUBLE_EQ(round(srv.response.d_1), 1228.0);
243 EXPECT_DOUBLE_EQ(round(srv.response.v_stop), 20.0);
246 int main(
int argc,
char **argv)
248 ros::init(argc, argv,
"ttl_driver_service_client");
250 testing::InitGoogleTest(&argc, argv);
252 nh = std::make_unique<ros::NodeHandle>(
"~");
256 ros::Duration(2.0).sleep();
258 return RUN_ALL_TESTS();