19 #include "../include/open_manipulator_p_libs/dynamixel.h" 44 if (get_arg_[0] ==
"position_mode" || get_arg_[0] ==
"current_based_position_mode")
70 const char* log = NULL;
73 for (uint32_t index = 0; index < dynamixel_.num; index++)
75 result = dynamixel_workbench_->torqueOn(dynamixel_.id.at(index), &log);
81 enabled_state_ =
true;
86 const char* log = NULL;
89 for (uint32_t index = 0; index < dynamixel_.num; index++)
91 result = dynamixel_workbench_->torqueOff(dynamixel_.id.at(index), &log);
97 enabled_state_ =
false;
104 std::vector<double> radian_vector;
105 for(uint32_t index = 0; index < value_vector.size(); index++)
107 radian_vector.push_back(value_vector.at(index).position);
128 const char* log = NULL;
130 STRING return_delay_time_st =
"Return_Delay_Time";
131 const char * return_delay_time_char = return_delay_time_st.c_str();
133 dynamixel_.id = actuator_id;
134 dynamixel_.num = actuator_id.size();
138 result = dynamixel_workbench_->
init(dxl_device_name.c_str(), std::atoi(dxl_baud_rate.c_str()), &log);
144 uint16_t get_model_number;
145 for (uint8_t index = 0; index < dynamixel_.num; index++)
147 uint8_t
id = dynamixel_.id.at(index);
148 result = dynamixel_workbench_->ping(
id, &get_model_number, &log);
153 log::error(
"Please check your Dynamixel ID");
158 sprintf(str,
"Joint Dynamixel ID : %d, Model Name : %s",
id, dynamixel_workbench_->getModelName(
id));
169 result = dynamixel_workbench_->writeRegister(
id, return_delay_time_char, 0, &log);
173 log::error(
"Please check your Dynamixel firmware version");
182 const char* log = NULL;
185 const uint32_t velocity = 0;
186 const uint32_t acceleration = 0;
187 const uint32_t current = 0;
189 if (dynamixel_mode ==
"position_mode")
191 for (uint8_t num = 0; num < actuator_id.size(); num++)
193 result = dynamixel_workbench_->jointMode(actuator_id.at(num), velocity, acceleration, &log);
200 else if (dynamixel_mode ==
"current_based_position_mode")
202 for (uint8_t num = 0; num < actuator_id.size(); num++)
204 result = dynamixel_workbench_->currentBasedPositionMode(actuator_id.at(num), current, &log);
213 for (uint8_t num = 0; num < actuator_id.size(); num++)
215 result = dynamixel_workbench_->jointMode(actuator_id.at(num), velocity, acceleration, &log);
229 const char* log = NULL;
231 result = dynamixel_workbench_->addSyncWriteHandler(actuator_id,
"Goal_Position", &log);
250 const char* log = NULL;
253 const char * char_profile_mode = profile_mode.c_str();
255 for (uint8_t num = 0; num < actuator_id.size(); num++)
257 result = dynamixel_workbench_->writeRegister(actuator_id.at(num), char_profile_mode, value, &log);
270 const char* log = NULL;
272 uint8_t id_array[actuator_id.size()];
273 int32_t goal_position[actuator_id.size()];
275 for (uint8_t index = 0; index < actuator_id.size(); index++)
277 id_array[index] = actuator_id.at(index);
278 goal_position[index] = dynamixel_workbench_->convertRadian2Value(actuator_id.at(index), radian_vector.at(index));
281 result = dynamixel_workbench_->syncWrite(
SYNC_WRITE_HANDLER, id_array, actuator_id.size(), goal_position, 1, &log);
293 const char* log = NULL;
295 std::vector<robotis_manipulator::ActuatorValue> all_actuator;
297 uint8_t id_array[actuator_id.size()];
298 for (uint8_t index = 0; index < actuator_id.size(); index++)
299 id_array[index] = actuator_id.at(index);
301 int32_t get_current[actuator_id.size()];
302 int32_t get_velocity[actuator_id.size()];
303 int32_t get_position[actuator_id.size()];
350 for (uint8_t index = 0; index < actuator_id.size(); index++)
353 actuator.
effort = dynamixel_workbench_->convertValue2Current(get_current[index]);
354 actuator.
velocity = dynamixel_workbench_->convertValue2Velocity(actuator_id.at(index), get_velocity[index]);
355 actuator.
position = dynamixel_workbench_->convertValue2Radian(actuator_id.at(index), get_position[index]);
357 all_actuator.push_back(actuator);
369 control_loop_time_ = control_loop_time;
389 if (get_arg_[0] ==
"position_mode" || get_arg_[0] ==
"current_based_position_mode")
410 return dynamixel_.id;
415 const char* log = NULL;
418 for (uint32_t index = 0; index < dynamixel_.num; index++)
420 result = dynamixel_workbench_->torqueOn(dynamixel_.id.at(index), &log);
426 enabled_state_ =
true;
431 const char* log = NULL;
434 for (uint32_t index = 0; index < dynamixel_.num; index++)
436 result = dynamixel_workbench_->torqueOff(dynamixel_.id.at(index), &log);
442 enabled_state_ =
false;
468 const char* log = NULL;
470 STRING return_delay_time_st =
"Return_Delay_Time";
471 const char * return_delay_time_char = return_delay_time_st.c_str();
473 dynamixel_.id = actuator_id;
474 dynamixel_.num = actuator_id.size();
478 result = dynamixel_workbench_->
init(dxl_device_name.c_str(), std::atoi(dxl_baud_rate.c_str()), &log);
484 uint16_t get_model_number;
485 for (uint8_t index = 0; index < dynamixel_.num; index++)
487 uint8_t
id = dynamixel_.id.at(index);
488 result = dynamixel_workbench_->ping(
id, &get_model_number, &log);
493 log::error(
"Please check your Dynamixel ID");
498 sprintf(str,
"Joint Dynamixel ID : %d, Model Name : %s",
id, dynamixel_workbench_->getModelName(
id));
501 result = dynamixel_workbench_->setTimeBasedProfile(
id, &log);
505 log::error(
"Please check your Dynamixel firmware version (v38~)");
508 result = dynamixel_workbench_->writeRegister(
id, return_delay_time_char, 0, &log);
512 log::error(
"Please check your Dynamixel firmware version");
521 const char* log = NULL;
524 const uint32_t velocity = uint32_t(control_loop_time_*1000) * 3;
525 const uint32_t acceleration = uint32_t(control_loop_time_*1000);
526 const uint32_t current = 0;
528 if (dynamixel_mode ==
"position_mode")
530 for (uint8_t num = 0; num < actuator_id.size(); num++)
532 result = dynamixel_workbench_->jointMode(actuator_id.at(num), velocity, acceleration, &log);
539 else if (dynamixel_mode ==
"current_based_position_mode")
541 for (uint8_t num = 0; num < actuator_id.size(); num++)
543 result = dynamixel_workbench_->currentBasedPositionMode(actuator_id.at(num), current, &log);
552 for (uint8_t num = 0; num < actuator_id.size(); num++)
554 result = dynamixel_workbench_->jointMode(actuator_id.at(num), velocity, acceleration, &log);
568 const char* log = NULL;
570 result = dynamixel_workbench_->addSyncWriteHandler(actuator_id,
"Goal_Position", &log);
589 const char* log = NULL;
592 const char * char_profile_mode = profile_mode.c_str();
594 for (uint8_t num = 0; num < actuator_id.size(); num++)
596 result = dynamixel_workbench_->writeRegister(actuator_id.at(num), char_profile_mode, value, &log);
608 const char* log = NULL;
610 uint8_t id_array[actuator_id.size()];
611 int32_t goal_value[actuator_id.size()];
614 for(uint8_t index = 0; index < actuator_id.size(); index++)
616 float result_position;
617 float time_control = control_loop_time_;
619 if(previous_goal_value_.find(actuator_id.at(index)) == previous_goal_value_.end())
621 previous_goal_value_.insert(std::make_pair(actuator_id.at(index), value_vector.at(index)));
624 result_position = value_vector.at(index).position + 3*(value_vector.at(index).velocity * (time_control))/2;
626 id_array[index] = actuator_id.at(index);
627 goal_value[index] = dynamixel_workbench_->convertRadian2Value(actuator_id.at(index), result_position);
629 previous_goal_value_[actuator_id.at(index)] = value_vector.at(index);
632 result = dynamixel_workbench_->syncWrite(
SYNC_WRITE_HANDLER, id_array, actuator_id.size(), goal_value, 1, &log);
643 const char* log = NULL;
645 std::vector<robotis_manipulator::ActuatorValue> all_actuator;
647 uint8_t id_array[actuator_id.size()];
648 for (uint8_t index = 0; index < actuator_id.size(); index++)
649 id_array[index] = actuator_id.at(index);
651 int32_t get_current[actuator_id.size()];
652 int32_t get_velocity[actuator_id.size()];
653 int32_t get_position[actuator_id.size()];
700 for (uint8_t index = 0; index < actuator_id.size(); index++)
703 actuator.
effort = dynamixel_workbench_->convertValue2Current(get_current[index]);
704 actuator.
velocity = dynamixel_workbench_->convertValue2Velocity(actuator_id.at(index), get_velocity[index]);
705 actuator.
position = dynamixel_workbench_->convertValue2Radian(actuator_id.at(index), get_position[index]);
707 all_actuator.push_back(actuator);
734 if (get_arg_[0] ==
"position_mode" || get_arg_[0] ==
"current_based_position_mode")
754 return dynamixel_.id.at(0);
759 const char* log = NULL;
762 result = dynamixel_workbench_->torqueOn(dynamixel_.id.at(0), &log);
767 enabled_state_ =
true;
772 const char* log = NULL;
775 result = dynamixel_workbench_->torqueOff(dynamixel_.id.at(0), &log);
780 enabled_state_ =
false;
804 const char* log = NULL;
807 STRING return_delay_time_st =
"Return_Delay_Time";
808 const char * return_delay_time_char = return_delay_time_st.c_str();
810 dynamixel_.id.push_back(actuator_id);
815 result = dynamixel_workbench_->
init(dxl_device_name.c_str(), std::atoi(dxl_baud_rate.c_str()), &log);
821 uint16_t get_model_number;
822 result = dynamixel_workbench_->ping(dynamixel_.id.at(0), &get_model_number, &log);
826 log::error(
"Please check your Dynamixel ID");
831 sprintf(str,
"Gripper Dynamixel ID : %d, Model Name :", dynamixel_.id.at(0));
832 strcat(str, dynamixel_workbench_->getModelName(dynamixel_.id.at(0)));
842 result = dynamixel_workbench_->writeRegister(dynamixel_.id.at(0), return_delay_time_char, 0, &log);
846 log::error(
"Please check your Dynamixel firmware version");
855 const char* log = NULL;
858 const uint32_t velocity = 0;
859 const uint32_t acceleration = 0;
860 const uint32_t current = 300;
862 if (dynamixel_mode ==
"position_mode")
864 result = dynamixel_workbench_->jointMode(dynamixel_.id.at(0), velocity, acceleration, &log);
870 else if (dynamixel_mode ==
"current_based_position_mode")
872 result = dynamixel_workbench_->currentBasedPositionMode(dynamixel_.id.at(0), current, &log);
880 result = dynamixel_workbench_->jointMode(dynamixel_.id.at(0), velocity, acceleration, &log);
892 const char* log = NULL;
895 const char * char_profile_mode = profile_mode.c_str();
897 result = dynamixel_workbench_->writeRegister(dynamixel_.id.at(0), char_profile_mode, value, &log);
909 const char* log = NULL;
911 result = dynamixel_workbench_->addSyncWriteHandler(dynamixel_.id.at(0),
"Goal_Position", &log);
917 result = dynamixel_workbench_->addSyncReadHandler(dynamixel_.id.at(0),
931 const char* log = NULL;
933 int32_t goal_position = 0;
935 goal_position = dynamixel_workbench_->convertRadian2Value(dynamixel_.id.at(0), radian);
949 const char* log = NULL;
951 int32_t get_value = 0;
952 uint8_t id_array[1] = {dynamixel_.id.at(0)};
973 return dynamixel_workbench_->convertValue2Radian(dynamixel_.id.at(0), get_value);
virtual bool sendJointActuatorValue(std::vector< uint8_t > actuator_id, std::vector< robotis_manipulator::ActuatorValue > value_vector)
bool writeGoalPosition(std::vector< uint8_t > actuator_id, std::vector< double > radian_vector)
#define SYNC_WRITE_HANDLER
virtual std::vector< robotis_manipulator::ActuatorValue > receiveJointActuatorValue(std::vector< uint8_t > actuator_id)
bool writeGoalProfilingControlValue(std::vector< uint8_t > actuator_id, std::vector< robotis_manipulator::ActuatorValue > value_vector)
#define LENGTH_PRESENT_CURRENT_2
bool initialize(std::vector< uint8_t > actuator_id, STRING dxl_device_name, STRING dxl_baud_rate)
bool init(const char *device_name="/dev/ttyUSB0", uint32_t baud_rate=57600, const char **log=NULL)
virtual std::vector< uint8_t > getId()
bool setOperatingMode(STRING dynamixel_mode="position_mode")
bool setOperatingMode(std::vector< uint8_t > actuator_id, STRING dynamixel_mode="position_mode")
#define ADDR_PRESENT_CURRENT_2
virtual robotis_manipulator::ActuatorValue receiveToolActuatorValue()
virtual bool sendJointActuatorValue(std::vector< uint8_t > actuator_id, std::vector< robotis_manipulator::ActuatorValue > value_vector)
virtual void init(uint8_t actuator_id, const void *arg)
bool setSDKHandler(uint8_t actuator_id)
bool writeProfileValue(STRING profile_mode, uint32_t value)
virtual void setMode(const void *arg)
virtual void setMode(std::vector< uint8_t > actuator_id, const void *arg)
virtual void init(std::vector< uint8_t > actuator_id, const void *arg)
#define SYNC_READ_HANDLER_FOR_PRESENT_POSITION_VELOCITY_CURRENT
bool writeProfileValue(std::vector< uint8_t > actuator_id, STRING profile_mode, uint32_t value)
bool setSDKHandler(uint8_t actuator_id)
virtual std::vector< uint8_t > getId()
virtual void init(std::vector< uint8_t > actuator_id, const void *arg)
#define LENGTH_PRESENT_VELOCITY_2
bool setOperatingMode(std::vector< uint8_t > actuator_id, STRING dynamixel_mode="position_mode")
std::vector< robotis_manipulator::ActuatorValue > receiveAllDynamixelValue(std::vector< uint8_t > actuator_id)
std::vector< robotis_manipulator::ActuatorValue > receiveAllDynamixelValue(std::vector< uint8_t > actuator_id)
bool writeGoalPosition(double radian)
bool initialize(uint8_t actuator_id, STRING dxl_device_name, STRING dxl_baud_rate)
bool initialize(std::vector< uint8_t > actuator_id, STRING dxl_device_name, STRING dxl_baud_rate)
virtual std::vector< robotis_manipulator::ActuatorValue > receiveJointActuatorValue(std::vector< uint8_t > actuator_id)
#define ADDR_PRESENT_POSITION_2
JointDynamixelProfileControl(float control_loop_time=0.010)
virtual bool sendToolActuatorValue(robotis_manipulator::ActuatorValue value)
#define ADDR_PRESENT_VELOCITY_2
#define LENGTH_PRESENT_POSITION_2
virtual void setMode(std::vector< uint8_t > actuator_id, const void *arg)
bool writeProfileValue(std::vector< uint8_t > actuator_id, STRING profile_mode, uint32_t value)
double receiveDynamixelValue()