18 #include "common/model/abstract_motor_state.hpp"
19 #include "common/model/bus_protocol_enum.hpp"
20 #include "common/model/dxl_command_type_enum.hpp"
21 #include "common/model/dxl_motor_state.hpp"
22 #include "common/model/hardware_type_enum.hpp"
23 #include "common/model/joint_state.hpp"
24 #include "common/model/single_motor_cmd.hpp"
25 #include "common/model/stepper_command_type_enum.hpp"
26 #include "common/model/stepper_motor_state.hpp"
27 #include "common/model/synchronize_motor_cmd.hpp"
28 #include "dynamixel_sdk/dynamixel_sdk.h"
29 #include "ros/node_handle.h"
35 #include <gtest/gtest.h>
37 #include <ros/console.h>
41 using ::common::model::BusProtocolEnum;
42 using ::common::model::DxlMotorState;
43 using ::common::model::EBusProtocol;
44 using ::common::model::EHardwareType;
45 using ::common::model::HardwareTypeEnum;
46 using ::common::model::StepperMotorState;
48 using ::std::to_string;
58 ros::NodeHandle robot_hwnh(
"joints_interface");
60 while (robot_hwnh.hasParam(
"joint_" + to_string(nb_joints + 1) +
"/id") &&
61 robot_hwnh.hasParam(
"joint_" + to_string(nb_joints + 1) +
"/name") &&
62 robot_hwnh.hasParam(
"joint_" + to_string(nb_joints + 1) +
"/type") &&
63 robot_hwnh.hasParam(
"joint_" + to_string(nb_joints + 1) +
"/bus"))
69 int currentIdStepper = 1;
71 for (
size_t j = 0; j < nb_joints; j++)
73 int joint_id_config = 0;
78 robot_hwnh.getParam(
"joint_" + to_string(j + 1) +
"/id", joint_id_config);
79 robot_hwnh.getParam(
"joint_" + to_string(j + 1) +
"/name", joint_name);
80 robot_hwnh.getParam(
"joint_" + to_string(j + 1) +
"/type", joint_type);
81 robot_hwnh.getParam(
"joint_" + to_string(j + 1) +
"/bus", joint_bus);
82 HardwareTypeEnum eType = HardwareTypeEnum(joint_type.c_str());
83 BusProtocolEnum eBusProto = BusProtocolEnum(joint_bus.c_str());
85 if (eType == EHardwareType::STEPPER || eType == EHardwareType::FAKE_STEPPER_MOTOR)
87 std::string currentStepperNamespace =
"steppers/stepper_" + to_string(currentIdStepper);
89 auto stepperState = std::make_shared<StepperMotorState>(joint_name, eType, common::model::EComponentType::JOINT,
90 eBusProto,
static_cast<uint8_t
>(joint_id_config));
93 double offsetPos = 0.0;
94 double gear_ratio = 1.0;
96 double max_effort = 0.0;
97 double home_position = 0.0;
98 double limit_position_min = 0.0;
99 double limit_position_max = 0.0;
100 double motor_ratio = 0.0;
102 robot_hwnh.getParam(currentStepperNamespace +
"/offset_position", offsetPos);
103 robot_hwnh.getParam(currentStepperNamespace +
"/gear_ratio", gear_ratio);
104 robot_hwnh.getParam(currentStepperNamespace +
"/direction", direction);
105 robot_hwnh.getParam(currentStepperNamespace +
"/max_effort", max_effort);
106 robot_hwnh.getParam(currentStepperNamespace +
"/default_home_position", home_position);
107 robot_hwnh.getParam(currentStepperNamespace +
"/limit_position_min", limit_position_min);
108 robot_hwnh.getParam(currentStepperNamespace +
"/limit_position_max", limit_position_max);
109 robot_hwnh.getParam(currentStepperNamespace +
"/motor_ratio", motor_ratio);
112 common::model::VelocityProfile profile{};
114 if (robot_hwnh.hasParam(currentStepperNamespace +
"/v_start"))
116 robot_hwnh.getParam(currentStepperNamespace +
"/v_start", data);
117 profile.v_start =
static_cast<uint32_t
>(data);
120 if (robot_hwnh.hasParam(currentStepperNamespace +
"/a_1"))
122 robot_hwnh.getParam(currentStepperNamespace +
"/a_1", data);
123 profile.a_1 =
static_cast<uint32_t
>(data);
125 if (robot_hwnh.hasParam(currentStepperNamespace +
"/v_1"))
127 robot_hwnh.getParam(currentStepperNamespace +
"/v_1", data);
128 profile.v_1 =
static_cast<uint32_t
>(data);
130 if (robot_hwnh.hasParam(currentStepperNamespace +
"/a_max"))
132 robot_hwnh.getParam(currentStepperNamespace +
"/a_max", data);
133 profile.a_max =
static_cast<uint32_t
>(data);
135 if (robot_hwnh.hasParam(currentStepperNamespace +
"/v_max"))
137 robot_hwnh.getParam(currentStepperNamespace +
"/v_max", data);
138 profile.v_max =
static_cast<uint32_t
>(data);
140 if (robot_hwnh.hasParam(currentStepperNamespace +
"/d_max"))
142 robot_hwnh.getParam(currentStepperNamespace +
"/d_max", data);
143 profile.d_max =
static_cast<uint32_t
>(data);
145 if (robot_hwnh.hasParam(currentStepperNamespace +
"/d_1"))
147 robot_hwnh.getParam(currentStepperNamespace +
"/d_1", data);
148 profile.d_1 =
static_cast<uint32_t
>(data);
150 if (robot_hwnh.hasParam(currentStepperNamespace +
"/v_stop"))
152 robot_hwnh.getParam(currentStepperNamespace +
"/v_stop", data);
153 profile.v_stop =
static_cast<uint32_t
>(data);
157 stepperState->setOffsetPosition(offsetPos);
158 stepperState->setGearRatio(gear_ratio);
159 stepperState->setDirection(
static_cast<int8_t
>(direction));
160 stepperState->setMaxEffort(max_effort);
161 stepperState->setHomePosition(home_position);
162 stepperState->setLimitPositionMax(limit_position_max);
163 stepperState->setLimitPositionMin(limit_position_min);
164 stepperState->setMotorRatio(motor_ratio);
165 stepperState->setVelocityProfile(profile);
167 if (eBusProto == EBusProtocol::TTL)
168 ttl_interface->addJoint(stepperState);
173 else if (eType != EHardwareType::UNKNOWN)
175 auto dxlState = std::make_shared<DxlMotorState>(joint_name, eType, common::model::EComponentType::JOINT,
176 static_cast<uint8_t
>(joint_id_config));
179 double offsetPos = 0.0;
181 int positionPGain = 0;
182 int positionIGain = 0;
183 int positionDGain = 0;
184 int velocityPGain = 0;
185 int velocityIGain = 0;
188 int velocityProfile = 0;
189 int accelerationProfile = 0;
190 double limit_position_min = 0.0;
191 double limit_position_max = 0.0;
192 double home_position = 0.0;
194 std::string currentDxlNamespace =
"dynamixels/dxl_" + to_string(currentIdDxl);
196 robot_hwnh.getParam(currentDxlNamespace +
"/offset_position", offsetPos);
197 robot_hwnh.getParam(currentDxlNamespace +
"/direction", direction);
199 robot_hwnh.getParam(currentDxlNamespace +
"/position_P_gain", positionPGain);
200 robot_hwnh.getParam(currentDxlNamespace +
"/position_I_gain", positionIGain);
201 robot_hwnh.getParam(currentDxlNamespace +
"/position_D_gain", positionDGain);
203 robot_hwnh.getParam(currentDxlNamespace +
"/velocity_P_gain", velocityPGain);
204 robot_hwnh.getParam(currentDxlNamespace +
"/velocity_I_gain", velocityIGain);
206 robot_hwnh.getParam(currentDxlNamespace +
"/FF1_gain", FF1Gain);
207 robot_hwnh.getParam(currentDxlNamespace +
"/FF2_gain", FF2Gain);
209 robot_hwnh.getParam(currentDxlNamespace +
"/velocity_profile", velocityProfile);
210 robot_hwnh.getParam(currentDxlNamespace +
"/acceleration_profile", accelerationProfile);
212 robot_hwnh.getParam(currentDxlNamespace +
"/default_home_position", home_position);
213 robot_hwnh.getParam(currentDxlNamespace +
"/limit_position_min", limit_position_min);
214 robot_hwnh.getParam(currentDxlNamespace +
"/limit_position_max", limit_position_max);
216 dxlState->setOffsetPosition(offsetPos);
217 dxlState->setDirection(
static_cast<int8_t
>(direction));
219 dxlState->setPositionPGain(
static_cast<uint32_t
>(positionPGain));
220 dxlState->setPositionIGain(
static_cast<uint32_t
>(positionIGain));
221 dxlState->setPositionDGain(
static_cast<uint32_t
>(positionDGain));
223 dxlState->setVelocityPGain(
static_cast<uint32_t
>(velocityPGain));
224 dxlState->setVelocityIGain(
static_cast<uint32_t
>(velocityIGain));
226 dxlState->setFF1Gain(
static_cast<uint32_t
>(FF1Gain));
227 dxlState->setFF2Gain(
static_cast<uint32_t
>(FF2Gain));
229 dxlState->setVelProfile(
static_cast<uint32_t
>(velocityProfile));
230 dxlState->setAccProfile(
static_cast<uint32_t
>(accelerationProfile));
232 dxlState->setLimitPositionMin(limit_position_min);
233 dxlState->setLimitPositionMax(limit_position_max);
235 dxlState->setHomePosition(home_position);
237 if (eBusProto == EBusProtocol::TTL)
238 ttl_interface->addJoint(dxlState);
252 size_t nb_joints = 0;
254 ros::NodeHandle robot_hwnh(
"joints_interface");
256 while (robot_hwnh.hasParam(
"joint_" + to_string(nb_joints + 1) +
"/id") &&
257 robot_hwnh.hasParam(
"joint_" + to_string(nb_joints + 1) +
"/name") &&
258 robot_hwnh.hasParam(
"joint_" + to_string(nb_joints + 1) +
"/type") &&
259 robot_hwnh.hasParam(
"joint_" + to_string(nb_joints + 1) +
"/bus"))
263 int currentIdStepper = 1;
264 int currentIdDxl = 1;
266 for (
size_t j = 0; j < nb_joints; j++)
268 int joint_id_config = 0;
273 robot_hwnh.getParam(
"joint_" + to_string(j + 1) +
"/id", joint_id_config);
274 robot_hwnh.getParam(
"joint_" + to_string(j + 1) +
"/name", joint_name);
275 robot_hwnh.getParam(
"joint_" + to_string(j + 1) +
"/type", joint_type);
276 robot_hwnh.getParam(
"joint_" + to_string(j + 1) +
"/bus", joint_bus);
278 HardwareTypeEnum eType = HardwareTypeEnum(joint_type.c_str());
279 BusProtocolEnum eBusProto = BusProtocolEnum(joint_bus.c_str());
281 if (eType == EHardwareType::STEPPER || eType == EHardwareType::FAKE_STEPPER_MOTOR)
283 std::string currentStepperNamespace =
"steppers/stepper_" + to_string(currentIdStepper);
285 auto stepperState = std::make_shared<StepperMotorState>(joint_name, eType, common::model::EComponentType::JOINT,
286 eBusProto,
static_cast<uint8_t
>(joint_id_config));
289 double offsetPos = 0.0;
290 double gear_ratio = 1.0;
292 double max_effort = 0.0;
293 double home_position = 0.0;
294 double limit_position_min = 0.0;
295 double limit_position_max = 0.0;
296 double motor_ratio = 0.0;
298 robot_hwnh.getParam(currentStepperNamespace +
"/offset_position", offsetPos);
299 robot_hwnh.getParam(currentStepperNamespace +
"/gear_ratio", gear_ratio);
300 robot_hwnh.getParam(currentStepperNamespace +
"/direction", direction);
301 robot_hwnh.getParam(currentStepperNamespace +
"/max_effort", max_effort);
302 robot_hwnh.getParam(currentStepperNamespace +
"/default_home_position", home_position);
303 robot_hwnh.getParam(currentStepperNamespace +
"/limit_position_min", limit_position_min);
304 robot_hwnh.getParam(currentStepperNamespace +
"/limit_position_max", limit_position_max);
305 robot_hwnh.getParam(currentStepperNamespace +
"/motor_ratio", motor_ratio);
308 common::model::VelocityProfile profile{};
310 if (robot_hwnh.hasParam(currentStepperNamespace +
"/v_start"))
312 robot_hwnh.getParam(currentStepperNamespace +
"/v_start", data);
313 profile.v_start =
static_cast<uint32_t
>(data);
316 if (robot_hwnh.hasParam(currentStepperNamespace +
"/a_1"))
318 robot_hwnh.getParam(currentStepperNamespace +
"/a_1", data);
319 profile.a_1 =
static_cast<uint32_t
>(data);
321 if (robot_hwnh.hasParam(currentStepperNamespace +
"/v_1"))
323 robot_hwnh.getParam(currentStepperNamespace +
"/v_1", data);
324 profile.v_1 =
static_cast<uint32_t
>(data);
326 if (robot_hwnh.hasParam(currentStepperNamespace +
"/a_max"))
328 robot_hwnh.getParam(currentStepperNamespace +
"/a_max", data);
329 profile.a_max =
static_cast<uint32_t
>(data);
331 if (robot_hwnh.hasParam(currentStepperNamespace +
"/v_max"))
333 robot_hwnh.getParam(currentStepperNamespace +
"/v_max", data);
334 profile.v_max =
static_cast<uint32_t
>(data);
336 if (robot_hwnh.hasParam(currentStepperNamespace +
"/d_max"))
338 robot_hwnh.getParam(currentStepperNamespace +
"/d_max", data);
339 profile.d_max =
static_cast<uint32_t
>(data);
341 if (robot_hwnh.hasParam(currentStepperNamespace +
"/d_1"))
343 robot_hwnh.getParam(currentStepperNamespace +
"/d_1", data);
344 profile.d_1 =
static_cast<uint32_t
>(data);
346 if (robot_hwnh.hasParam(currentStepperNamespace +
"/v_stop"))
348 robot_hwnh.getParam(currentStepperNamespace +
"/v_stop", data);
349 profile.v_stop =
static_cast<uint32_t
>(data);
353 stepperState->setOffsetPosition(offsetPos);
354 stepperState->setGearRatio(gear_ratio);
355 stepperState->setDirection(
static_cast<int8_t
>(direction));
356 stepperState->setMaxEffort(max_effort);
357 stepperState->setHomePosition(home_position);
358 stepperState->setLimitPositionMax(limit_position_max);
359 stepperState->setLimitPositionMin(limit_position_min);
360 stepperState->setMotorRatio(motor_ratio);
361 stepperState->setVelocityProfile(profile);
363 if (eBusProto == EBusProtocol::TTL)
365 ttl_drv->addHardwareComponent(stepperState);
370 else if (eType != EHardwareType::UNKNOWN)
372 auto dxlState = std::make_shared<DxlMotorState>(joint_name, eType, common::model::EComponentType::JOINT,
373 static_cast<uint8_t
>(joint_id_config));
376 double offsetPos = 0.0;
378 int positionPGain = 0;
379 int positionIGain = 0;
380 int positionDGain = 0;
381 int velocityPGain = 0;
382 int velocityIGain = 0;
385 int velocityProfile = 0;
386 int accelerationProfile = 0;
387 double limit_position_min = 0.0;
388 double limit_position_max = 0.0;
389 double home_position = 0.0;
391 std::string currentDxlNamespace =
"dynamixels/dxl_" + to_string(currentIdDxl);
393 robot_hwnh.getParam(currentDxlNamespace +
"/offset_position", offsetPos);
394 robot_hwnh.getParam(currentDxlNamespace +
"/direction", direction);
396 robot_hwnh.getParam(currentDxlNamespace +
"/position_P_gain", positionPGain);
397 robot_hwnh.getParam(currentDxlNamespace +
"/position_I_gain", positionIGain);
398 robot_hwnh.getParam(currentDxlNamespace +
"/position_D_gain", positionDGain);
400 robot_hwnh.getParam(currentDxlNamespace +
"/velocity_P_gain", velocityPGain);
401 robot_hwnh.getParam(currentDxlNamespace +
"/velocity_I_gain", velocityIGain);
403 robot_hwnh.getParam(currentDxlNamespace +
"/FF1_gain", FF1Gain);
404 robot_hwnh.getParam(currentDxlNamespace +
"/FF2_gain", FF2Gain);
406 robot_hwnh.getParam(currentDxlNamespace +
"/velocity_profile", velocityProfile);
407 robot_hwnh.getParam(currentDxlNamespace +
"/acceleration_profile", accelerationProfile);
409 robot_hwnh.getParam(currentDxlNamespace +
"/default_home_position", home_position);
410 robot_hwnh.getParam(currentDxlNamespace +
"/limit_position_min", limit_position_min);
411 robot_hwnh.getParam(currentDxlNamespace +
"/limit_position_max", limit_position_max);
413 dxlState->setOffsetPosition(offsetPos);
414 dxlState->setDirection(
static_cast<int8_t
>(direction));
416 dxlState->setPositionPGain(
static_cast<uint32_t
>(positionPGain));
417 dxlState->setPositionIGain(
static_cast<uint32_t
>(positionIGain));
418 dxlState->setPositionDGain(
static_cast<uint32_t
>(positionDGain));
420 dxlState->setVelocityPGain(
static_cast<uint32_t
>(velocityPGain));
421 dxlState->setVelocityIGain(
static_cast<uint32_t
>(velocityIGain));
423 dxlState->setFF1Gain(
static_cast<uint32_t
>(FF1Gain));
424 dxlState->setFF2Gain(
static_cast<uint32_t
>(FF2Gain));
426 dxlState->setVelProfile(
static_cast<uint32_t
>(velocityProfile));
427 dxlState->setAccProfile(
static_cast<uint32_t
>(accelerationProfile));
429 dxlState->setLimitPositionMin(limit_position_min);
430 dxlState->setLimitPositionMax(limit_position_max);
432 dxlState->setHomePosition(home_position);
434 if (eBusProto == EBusProtocol::TTL)
436 ttl_drv->addHardwareComponent(dxlState);
456 ros::NodeHandle
nh(
"ttl_driver");
457 ros::Duration(5.0).sleep();
474 static std::shared_ptr<ttl_driver::TtlInterfaceCore>
ttl_interface;
482 int resutl = ttl_interface->rebootHardware(ttl_interface->getJointState(2));
483 EXPECT_EQ(resutl,
static_cast<int>(niryo_robot_msgs::CommandStatus::SUCCESS));
490 result = ttl_interface->rebootHardware(std::make_shared<common::model::DxlMotorState>());
491 EXPECT_FALSE(result);
502 ros::NodeHandle
nh(
"ttl_driver");
504 ttl_drv = std::make_shared<ttl_driver::TtlManager>(
nh);
513 static std::shared_ptr<ttl_driver::TtlManager>
ttl_drv;
526 auto cmd_1 = std::make_unique<common::model::DxlSingleCmd>(common::model::EDxlCommandType::CMD_TYPE_TORQUE, 2,
527 std::initializer_list<uint32_t>{ 1 });
528 EXPECT_EQ(ttl_drv->writeSingleCommand(std::move(cmd_1)), COMM_SUCCESS);
529 ros::Duration(0.01).sleep();
532 auto cmd_2 = std::make_unique<common::model::DxlSingleCmd>(common::model::EDxlCommandType::CMD_TYPE_TORQUE, 20,
533 std::initializer_list<uint32_t>{ 1 });
534 EXPECT_NE(ttl_drv->writeSingleCommand(std::move(cmd_2)), COMM_SUCCESS);
535 ros::Duration(0.01).sleep();
538 auto cmd_3 = std::make_unique<common::model::DxlSingleCmd>(common::model::EDxlCommandType::CMD_TYPE_UNKNOWN, 2,
539 std::initializer_list<uint32_t>{ 1 });
540 EXPECT_NE(ttl_drv->writeSingleCommand(std::move(cmd_3)), COMM_SUCCESS);
541 ros::Duration(0.01).sleep();
544 auto cmd_4 = std::make_unique<common::model::StepperTtlSingleCmd>(common::model::EStepperCommandType::CMD_TYPE_TORQUE,
545 5, std::initializer_list<uint32_t>{ 1 });
546 EXPECT_NE(ttl_drv->writeSingleCommand(std::move(cmd_4)), COMM_SUCCESS);
552 auto cmd_1_torque = std::make_unique<common::model::DxlSingleCmd>(common::model::EDxlCommandType::CMD_TYPE_TORQUE, 2,
553 std::initializer_list<uint32_t>{ 1 });
555 EXPECT_EQ(ttl_drv->writeSingleCommand(std::move(cmd_1_torque)), COMM_SUCCESS);
556 ros::Duration(0.01).sleep();
558 auto cmd_2_torque = std::make_unique<common::model::DxlSingleCmd>(common::model::EDxlCommandType::CMD_TYPE_TORQUE, 3,
559 std::initializer_list<uint32_t>{ 1 });
560 EXPECT_EQ(ttl_drv->writeSingleCommand(std::move(cmd_2_torque)), COMM_SUCCESS);
561 ros::Duration(0.01).sleep();
563 auto cmd_3_torque = std::make_unique<common::model::DxlSingleCmd>(common::model::EDxlCommandType::CMD_TYPE_TORQUE, 6,
564 std::initializer_list<uint32_t>{ 1 });
565 EXPECT_EQ(ttl_drv->writeSingleCommand(std::move(cmd_3_torque)), COMM_SUCCESS);
566 ros::Duration(0.01).sleep();
568 ttl_drv->readJointsStatus();
569 auto state_motor_2 = std::dynamic_pointer_cast<common::model::JointState>(ttl_drv->getHardwareState(2));
570 assert(state_motor_2);
571 auto state_motor_3 = std::dynamic_pointer_cast<common::model::JointState>(ttl_drv->getHardwareState(3));
572 assert(state_motor_3);
573 auto state_motor_6 = std::dynamic_pointer_cast<common::model::JointState>(ttl_drv->getHardwareState(6));
574 assert(state_motor_6);
576 auto new_pos_2 =
static_cast<uint32_t
>(state_motor_2->to_motor_pos(state_motor_2->getHomePosition()));
577 auto new_pos_3 =
static_cast<uint32_t
>(state_motor_3->to_motor_pos(state_motor_3->getHomePosition()));
578 auto new_pos_6 =
static_cast<uint32_t
>(state_motor_6->to_motor_pos(state_motor_6->getHomePosition()));
581 auto cmd_1 = std::make_unique<common::model::DxlSingleCmd>(common::model::EDxlCommandType::CMD_TYPE_POSITION, 2,
582 std::initializer_list<uint32_t>{ new_pos_2 });
583 EXPECT_EQ(ttl_drv->writeSingleCommand(std::move(cmd_1)), COMM_SUCCESS);
584 ros::Duration(0.5).sleep();
587 auto cmd_2 = std::make_unique<common::model::DxlSingleCmd>(common::model::EDxlCommandType::CMD_TYPE_POSITION, 3,
588 std::initializer_list<uint32_t>{ new_pos_3 });
589 EXPECT_EQ(ttl_drv->writeSingleCommand(std::move(cmd_2)), COMM_SUCCESS);
590 ros::Duration(0.5).sleep();
593 auto cmd_3 = std::make_unique<common::model::DxlSingleCmd>(common::model::EDxlCommandType::CMD_TYPE_POSITION, 6,
594 std::initializer_list<uint32_t>{ new_pos_6 });
595 EXPECT_EQ(ttl_drv->writeSingleCommand(std::move(cmd_3)), COMM_SUCCESS);
596 ros::Duration(0.5).sleep();
598 ttl_drv->readJointsStatus();
601 EXPECT_NEAR(state_motor_2->getPosition(), new_pos_2, 2);
602 EXPECT_NEAR(state_motor_3->getPosition(), new_pos_3, 2);
603 EXPECT_NEAR(state_motor_6->getPosition(), new_pos_6, 2);
608 common::model::EHardwareType dxl_type;
610 dxl_type = common::model::EHardwareType::FAKE_DXL_MOTOR;
613 auto dynamixel_cmd_1 = std::make_unique<common::model::DxlSyncCmd>(common::model::EDxlCommandType::CMD_TYPE_TORQUE);
614 dynamixel_cmd_1->addMotorParam(dxl_type, 2, 1);
615 dynamixel_cmd_1->addMotorParam(dxl_type, 6, 1);
617 EXPECT_EQ(ttl_drv->writeSynchronizeCommand(std::move(dynamixel_cmd_1)), COMM_SUCCESS);
618 ros::Duration(0.5).sleep();
621 auto dynamixel_cmd_3 = std::make_unique<common::model::DxlSyncCmd>(common::model::EDxlCommandType::CMD_TYPE_TORQUE);
622 dynamixel_cmd_3->addMotorParam(dxl_type, 2, 1);
623 dynamixel_cmd_3->addMotorParam(dxl_type, 2, 1);
625 EXPECT_NE(ttl_drv->writeSynchronizeCommand(std::move(dynamixel_cmd_3)), COMM_SUCCESS);
628 auto dynamixel_cmd_4 = std::make_unique<common::model::DxlSyncCmd>(common::model::EDxlCommandType::CMD_TYPE_UNKNOWN);
629 dynamixel_cmd_4->addMotorParam(dxl_type, 2, 1);
630 dynamixel_cmd_4->addMotorParam(dxl_type, 6, 1);
632 EXPECT_NE(ttl_drv->writeSynchronizeCommand(std::move(dynamixel_cmd_4)), COMM_SUCCESS);
637 auto state_motor_2 = std::dynamic_pointer_cast<common::model::JointState>(ttl_drv->getHardwareState(2));
638 assert(state_motor_2);
639 auto state_motor_3 = std::dynamic_pointer_cast<common::model::JointState>(ttl_drv->getHardwareState(3));
640 assert(state_motor_3);
641 auto state_motor_6 = std::dynamic_pointer_cast<common::model::JointState>(ttl_drv->getHardwareState(6));
642 assert(state_motor_6);
645 auto cmd_1_torque = std::make_unique<common::model::DxlSyncCmd>(common::model::EDxlCommandType::CMD_TYPE_TORQUE);
646 cmd_1_torque->addMotorParam(state_motor_2->getHardwareType(), 2, 1);
647 cmd_1_torque->addMotorParam(state_motor_3->getHardwareType(), 3, 1);
648 cmd_1_torque->addMotorParam(state_motor_6->getHardwareType(), 6, 1);
650 EXPECT_EQ(ttl_drv->writeSynchronizeCommand(std::move(cmd_1_torque)), COMM_SUCCESS);
651 ros::Duration(0.01).sleep();
653 ttl_drv->readJointsStatus();
655 auto new_pos_2 =
static_cast<uint32_t
>(state_motor_2->to_motor_pos(0.47));
656 auto new_pos_3 =
static_cast<uint32_t
>(state_motor_3->to_motor_pos(0.577));
657 auto new_pos_6 =
static_cast<uint32_t
>(state_motor_6->to_motor_pos(1.08));
659 auto cmd_1 = std::make_unique<common::model::DxlSyncCmd>(common::model::EDxlCommandType::CMD_TYPE_POSITION);
660 cmd_1->addMotorParam(state_motor_2->getHardwareType(), 2, new_pos_2);
661 cmd_1->addMotorParam(state_motor_3->getHardwareType(), 3, new_pos_3);
662 cmd_1->addMotorParam(state_motor_6->getHardwareType(), 6, new_pos_6);
664 EXPECT_EQ(ttl_drv->writeSynchronizeCommand(std::move(cmd_1)), COMM_SUCCESS);
665 ros::Duration(0.5).sleep();
667 ttl_drv->readJointsStatus();
669 EXPECT_EQ(
static_cast<uint32_t
>(state_motor_2->getPosition()), new_pos_2);
670 EXPECT_EQ(
static_cast<uint32_t
>(state_motor_3->getPosition()), new_pos_3);
671 EXPECT_EQ(
static_cast<uint32_t
>(state_motor_6->getPosition()), new_pos_6);
676 auto state_motor_2 = std::dynamic_pointer_cast<common::model::JointState>(ttl_drv->getHardwareState(2));
677 assert(state_motor_2);
678 auto state_motor_3 = std::dynamic_pointer_cast<common::model::JointState>(ttl_drv->getHardwareState(3));
679 assert(state_motor_3);
680 auto state_motor_6 = std::dynamic_pointer_cast<common::model::JointState>(ttl_drv->getHardwareState(6));
681 assert(state_motor_6);
684 auto cmd_1_torque = std::make_unique<common::model::DxlSyncCmd>(common::model::EDxlCommandType::CMD_TYPE_TORQUE);
685 cmd_1_torque->addMotorParam(state_motor_2->getHardwareType(), 2, 1);
686 cmd_1_torque->addMotorParam(state_motor_3->getHardwareType(), 3, 1);
687 cmd_1_torque->addMotorParam(state_motor_6->getHardwareType(), 6, 1);
689 EXPECT_EQ(ttl_drv->writeSynchronizeCommand(std::move(cmd_1_torque)), COMM_SUCCESS);
690 ros::Duration(0.01).sleep();
692 auto new_pos_2 =
static_cast<uint32_t
>(state_motor_2->to_motor_pos(state_motor_2->getHomePosition()));
693 auto new_pos_3 =
static_cast<uint32_t
>(state_motor_3->to_motor_pos(state_motor_3->getHomePosition()));
694 auto new_pos_6 =
static_cast<uint32_t
>(state_motor_6->to_motor_pos(state_motor_6->getHomePosition()));
696 auto cmd_1 = std::make_unique<common::model::DxlSyncCmd>(common::model::EDxlCommandType::CMD_TYPE_POSITION);
697 cmd_1->addMotorParam(state_motor_2->getHardwareType(), 2, new_pos_2);
698 cmd_1->addMotorParam(state_motor_3->getHardwareType(), 3, new_pos_3);
699 cmd_1->addMotorParam(state_motor_6->getHardwareType(), 6, new_pos_6);
701 EXPECT_EQ(ttl_drv->writeSynchronizeCommand(std::move(cmd_1)), COMM_SUCCESS);
702 ros::Duration(0.5).sleep();
704 ttl_drv->readJointsStatus();
706 EXPECT_EQ(
static_cast<uint32_t
>(state_motor_6->getPosition()), new_pos_6);
707 EXPECT_EQ(
static_cast<uint32_t
>(state_motor_2->getPosition()), new_pos_2);
708 EXPECT_EQ(
static_cast<uint32_t
>(state_motor_3->getPosition()), new_pos_3);
714 EXPECT_EQ(ttl_drv->scanAndCheck(), COMM_SUCCESS);
718 int main(
int argc,
char **argv)
720 testing::InitGoogleTest(&argc, argv);
721 ros::init(argc, argv,
"ttl_driver_unit_tests");
723 std::string hardware_version;
725 return RUN_ALL_TESTS();