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 = 3264;
119 srv.request.pos_i_gain = 0;
120 srv.request.pos_d_gain = 9520;
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 = 400;
125 srv.request.vel_profile = 100;
126 srv.request.acc_profile = 200;
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;
146 EXPECT_EQ(srv.response.status, niryo_robot_msgs::CommandStatus::SUCCESS);
147 EXPECT_EQ(srv.response.pos_p_gain, 3264);
148 EXPECT_EQ(srv.response.pos_i_gain, 0);
149 EXPECT_EQ(srv.response.pos_d_gain, 9520);
150 EXPECT_EQ(srv.response.vel_p_gain, 0);
151 EXPECT_EQ(srv.response.vel_i_gain, 0);
152 EXPECT_EQ(srv.response.ff1_gain, 0);
153 EXPECT_EQ(srv.response.ff2_gain, 400);
156 TEST(TESTSuite, ReadPIDValueWrongParam)
158 auto client =
nh->serviceClient<ttl_driver::ReadPIDValue>(
"/niryo_robot/ttl_driver/read_pid_value");
160 bool exists(client.waitForExistence(ros::Duration(1)));
163 ttl_driver::ReadPIDValue srv;
169 EXPECT_EQ(srv.response.status, niryo_robot_msgs::CommandStatus::FAILURE);
172 int main(
int argc,
char **argv)
174 ros::init(argc, argv,
"ttl_driver_service_client");
176 testing::InitGoogleTest(&argc, argv);
178 nh = std::make_unique<ros::NodeHandle>(
"~");
181 return RUN_ALL_TESTS();