9 #define DXLPOS2RAD(pos) (( ((pos)*(360.0/POSITION_STEP) )/360) *2*M_PI) 10 #define RAD2DXLPOS(rad) (( ((rad)/2.0/M_PI)*360.0 ) * (POSITION_STEP / 360.0)) 11 #define INIT_EFFCNST_UNIT(c) ((c)*0.001) 20 int position_mode_joint_num = 0;
21 int current_mode_joint_num = 0;
22 int current_position_mode_joint_num = 0;
38 JOINT_CONTROL work( list[jj].name, list[jj].
id, list[jj].center, list[jj].home, list[jj].eff_cnst, list[jj].mode );
53 uint8_t dxl_id =
joints[jj].get_dxl_id();
57 error_queue.push(
"Bulk current write setting failed.");
78 error_queue.push(
"Bulk group read setting failed.");
96 uint8_t dxl_id =
joints[jj].get_dxl_id();
100 error_queue.push(
"Initialize communication failed.");
118 ++current_mode_joint_num;
121 ++position_mode_joint_num;
125 joints[jj].set_limits( limits );
131 reg_limits_handle( reg_joint_handle, limits, soft_limits );
135 if( position_mode_joint_num > 0 ){
138 if( current_mode_joint_num > 0 ){
183 uint8_t dxl_id =
joints[jj].get_dxl_id();
185 if( !dxl_getdata_result ){
187 ROS_INFO(
"readId error [%d]",dxl_id);
191 if( get_id == dxl_id ){
206 int32_t present_pos = 0;
207 uint8_t dxl_id =
joints[jj].get_dxl_id();
209 if( !dxl_getdata_result ){
214 joints[jj].set_dxl_pos( present_pos );
215 present_pos = (present_pos -
joints[jj].get_center());
228 int16_t present_current = 0;
229 uint8_t dxl_id =
joints[jj].get_dxl_id();
231 if( !dxl_getdata_result ){
236 joints[jj].set_dxl_curr( present_current );
250 uint8_t dxl_id =
joints[jj].get_dxl_id();
252 if( !dxl_getdata_result ){
257 joints[jj].set_dxl_temp( present_temp );
258 joints[jj].set_temprature( present_temp );
270 uint8_t dxl_id =
joints[jj].get_dxl_id();
272 if( !dxl_getdata_result ){
291 get_cmd =
joints[jj].get_command();
292 joints[jj].updt_d_command( get_cmd );
293 joints[jj].set_position( get_cmd );
299 #ifdef MASTER_WAIST_SLAVE_NECK 300 double slave_pos_data;
302 if(
joints[jj].get_dxl_id() == 18 ){
303 slave_pos_data =
joints[jj].get_command();
305 if(
joints[jj].get_dxl_id() == 19 ){
306 joints[jj].set_command( -slave_pos_data );
309 get_cmd =
joints[jj].get_command();
313 joints[jj].updt_d_command( 0.0 );
315 uint16_t dxl_cur = (uint32_t)round( work_cur );
316 uint8_t* goal_data =
joints[jj].get_dxl_goal_addr();
317 goal_data[0] = (uint8_t)(dxl_cur&0x000000FF);
318 goal_data[1] = (uint8_t)((dxl_cur&0x0000FF00)>>8);
323 uint16_t dxl_cur = (uint32_t)round( tau[jj] );
324 uint8_t* goal_data =
joints[jj].get_dxl_goal_addr();
325 goal_data[0] = (uint8_t)(dxl_cur&0x000000FF);
326 goal_data[1] = (uint8_t)((dxl_cur&0x0000FF00)>>8);
331 joints[jj].updt_d_command( get_cmd );
332 work_pos +=
joints[jj].get_center();
340 uint32_t dxl_pos = (uint32_t)round( work_pos );
341 uint8_t* goal_data =
joints[jj].get_dxl_goal_addr();
343 goal_data[0] = (uint8_t)(dxl_pos&0x000000FF);
344 goal_data[1] = (uint8_t)((dxl_pos&0x0000FF00)>>8);
345 goal_data[2] = (uint8_t)((dxl_pos&0x00FF0000)>>16);
346 goal_data[3] = (uint8_t)((dxl_pos&0xFF000000)>>24);
363 if( fabs(
joints[jj].get_d_command() ) > 0.0 ){
386 uint8_t dxl_error = 0;
394 }
else if( dxl_error != 0 ){
415 uint8_t dxl_error = 0;
423 }
else if( dxl_error != 0 ){
438 uint8_t dxl_error = 0;
445 }
else if( dxl_error != 0 ){
455 for( uint8_t jj=0 ; jj<
joint_num; ++jj ){
457 joints[jj].set_torque( torque );
468 uint8_t dxl_error = 0;
475 }
else if( dxl_error != 0 ){
483 for( uint8_t jj=0 ; jj<
joint_num; ++jj ){
495 std::vector<ST_HOME_MOTION_DATA> home_motion_data;
513 joints[jj].set_command( 0.0 );
517 home_motion_data.push_back( motion_work );
527 for(
int step=0 ; step<step_max ; ++step ){
543 joints[jj].set_command(
joints[jj].get_command() + home_motion_data[jj].step_rad );
554 joints[jj].set_command( home_motion_data[jj].home_rad );
560 joints[jj].updt_d_command( 0.0 );
567 uint8_t dxl_error = 0;
577 }
else if( dxl_error != 0 ){
581 if( read_data == equal ){
584 read_val = read_data;
589 uint8_t dxl_error = 0;
599 }
else if( dxl_error != 0 ){
603 if( read_data == equal ){
606 read_val = read_data;
611 uint8_t dxl_error = 0;
621 }
else if( dxl_error != 0 ){
625 if( read_data == equal ){
628 read_val = read_data;
695 std::string res_str =
"[DYNAMIXEL PARAMETER SELF CHECK]\n";
698 res_str =
"SKIP SELF CHECK...";
702 bool check_result =
true;
704 uint8_t chk_8data, read_8data;
705 uint16_t chk_16data, read_16data;
706 uint32_t chk_32data, read_32data;
712 chk_8data = (uint8_t)
RegTable[ii].init_value;
713 if(
RegTable[ii].name ==
"OPERATION_MODE" ){
714 chk_8data =
joints[ii].get_ope_mode();
718 if(
RegTable[ii].selfcheck && !read_result ){
719 res_str +=
" ID: " + std::to_string(
joints[jj].get_dxl_id()) +
" check NG\n";
720 check_result =
false;
724 joints[jj].set_joint_param( work );
728 chk_16data = (uint16_t)
RegTable[ii].init_value;
731 if(
RegTable[ii].selfcheck && !read_result ){
732 res_str +=
" ID: " + std::to_string(
joints[jj].get_dxl_id()) +
" check NG\n";
733 check_result =
false;
737 joints[jj].set_joint_param( work );
741 chk_32data = (uint32_t)
RegTable[ii].init_value;
744 if(
RegTable[ii].selfcheck && !read_result ){
745 res_str +=
" ID: " + std::to_string(
joints[jj].get_dxl_id()) +
" check NG\n";
746 check_result =
false;
750 joints[jj].set_joint_param( work );
756 res_str +=
" CHECK OK\n";
758 res_str +=
" CHECK NG!\n";
767 uint8_t set_param = (uint8_t)val;
773 if( dxl_id ==
joints[jj].get_dxl_id() ){
776 uint8_t dxl_error = 0;
783 }
else if( dxl_error != 0 ){
789 joints[jj].set_joint_param( new_param );
796 uint8_t set_param = (uint8_t)val;
802 if( dxl_id ==
joints[jj].get_dxl_id() ){
805 uint8_t dxl_error = 0;
812 }
else if( dxl_error != 0 ){
818 joints[jj].set_joint_param( new_param );
825 uint8_t set_param = (uint8_t)val;
831 if( dxl_id ==
joints[jj].get_dxl_id() ){
834 uint8_t dxl_error = 0;
841 }
else if( dxl_error != 0 ){
847 joints[jj].set_joint_param( new_param );
854 uint32_t set_param = (uint32_t)val;
860 if( dxl_id ==
joints[jj].get_dxl_id() ){
863 uint8_t dxl_error = 0;
870 }
else if( dxl_error != 0 ){
876 joints[jj].set_joint_param( new_param );
883 uint32_t set_param = (uint32_t)val;
889 if( dxl_id ==
joints[jj].get_dxl_id() ){
892 uint8_t dxl_error = 0;
899 }
else if( dxl_error != 0 ){
905 joints[jj].set_joint_param( new_param );
912 uint8_t set_param = (uint8_t)val;
918 if( dxl_id ==
joints[jj].get_dxl_id() ){
921 uint8_t dxl_error = 0;
928 }
else if( dxl_error != 0 ){
934 joints[jj].set_joint_param( new_param );
941 uint16_t set_max_param = (uint32_t)max;
942 uint16_t set_min_param = (uint32_t)min;
948 if( dxl_id ==
joints[jj].get_dxl_id() ){
951 uint8_t dxl_error = 0;
958 }
else if( dxl_error != 0 ){
964 uint8_t dxl_error = 0;
971 }
else if( dxl_error != 0 ){
978 joints[jj].set_joint_param( new_param );
985 uint16_t set_param = (uint16_t)val;
991 if( dxl_id ==
joints[jj].get_dxl_id() ){
994 uint8_t dxl_error = 0;
1001 }
else if( dxl_error != 0 ){
1007 joints[jj].set_joint_param( new_param );
1014 uint16_t set_p_param = (uint16_t)p;
1015 uint16_t set_i_param = (uint16_t)i;
1021 if( dxl_id ==
joints[jj].get_dxl_id() ){
1024 uint8_t dxl_error = 0;
1031 }
else if( dxl_error != 0 ){
1037 uint8_t dxl_error = 0;
1044 }
else if( dxl_error != 0 ){
1051 joints[jj].set_joint_param( new_param );
1069 uint16_t set_p_param = (uint16_t)p;
1070 uint16_t set_i_param = (uint16_t)i;
1071 uint16_t set_d_param = (uint16_t)d;
1077 if( dxl_id ==
joints[jj].get_dxl_id() ){
1080 uint8_t dxl_error = 0;
1087 }
else if( dxl_error != 0 ){
1093 uint8_t dxl_error = 0;
1100 }
else if( dxl_error != 0 ){
1106 uint8_t dxl_error = 0;
1113 }
else if( dxl_error != 0 ){
1121 joints[jj].set_joint_param( new_param );
1129 std::string::size_type result =
error_queue.size();
1139 uint8_t dxl_error = 0;
1140 uint16_t setup_data[] = { 224, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 146 };
1147 }
else if( dxl_error != 0 ){
1152 for(
int idx=0 ; idx<
sizeof(setup_data)/2 ; ++idx ){
1158 }
else if( dxl_error != 0 ){
void set_watchdog(uint8_t dxl_id, uint8_t value)
void registerInterface(T *iface)
void set_watchdog_all(uint8_t value)
void set_param_home_offset(uint8_t dxl_id, int val)
bool setup_indirect(uint8_t dxl_id)
void set_param_pos_gain_all(int p, int i, int d)
virtual int read1ByteTxRx(PortHandler *port, uint8_t id, uint16_t address, uint8_t *data, uint8_t *error=0)=0
bool isAvailable(uint8_t id, uint16_t address, uint16_t data_length)
#define ADDR_POSITION_DGAIN
static PortHandler * getPortHandler(const char *port_name)
#define DXL_VELOCITY2RAD_S(v)
#define ADDR_GOAL_CURRENT
DXLPORT_CONTROL(ros::NodeHandle handle, CONTROL_SETTING &setting)
std::string::size_type get_error(std::string &errorlog)
#define ADDR_MOVING_THRESHOLD
bool readCurrent(ros::Time, ros::Duration)
void set_goal_current(uint8_t dxl_id, uint16_t current)
virtual bool openPort()=0
bool readId(ros::Time, ros::Duration)
bool readVel(ros::Time, ros::Duration)
bool set_torque(uint8_t dxl_id, bool torque)
#define LEN_PRESENT_POSITION
bool addParam(uint8_t id, uint16_t start_address, uint16_t data_length)
void set_param_drive_mode(uint8_t dxl_id, int val)
uint32_t getjointNum(void)
bool changeParam(uint8_t id, uint16_t start_address, uint16_t data_length, uint8_t *data)
#define OPERATING_MODE_CURR_POS
#define ADDR_CURRENT_LIMIT
#define DXL_DEFAULT_PGAIN
#define ADDR_BUS_WATCHDOG
std::queue< std::string > error_queue
static const ST_DYNAMIXEL_REG_TABLE RegTable[]
void set_param_vol_limit(uint8_t dxl_id, int max, int min)
virtual int read2ByteTxRx(PortHandler *port, uint8_t id, uint16_t address, uint16_t *data, uint8_t *error=0)=0
bool readPos(ros::Time, ros::Duration)
void startup_motion(void)
dynamixel::GroupBulkRead * readIndirectGroup
std::vector< ST_SERVO_PARAM > getServoParam(void)
#define LEN_GOAL_POSITION
#define EFFORT2DXL_CURRENT(e, coef)
uint16_t moving_threshold
#define LEN_PRESENT_CURRENT
void write(ros::Time, ros::Duration)
#define DXL_CURRENT2EFFORT(c, coef)
#define OPERATING_MODE_CURRENT
#define ADDR_POSITION_PGAIN
bool is_change_positions(void)
virtual void closePort()=0
virtual const char * getRxPacketError(uint8_t error)=0
std::string getPortName(void)
#define DXL_TORQUE_ON_STEP_MAX
#define ADDR_VELOCITY_PGAIN
#define LEN_INDIRECT_GROUP
void set_goal_current_all(uint16_t current)
#define ADDR_TORQUE_ENABLE
hardware_interface::JointStateInterface joint_stat_if
ros::Duration getDuration(ros::Time t) const
#define DXL_TORQUR_ON_STEP
void set_gain_all(uint16_t gain)
bool readTemp(ros::Time, ros::Duration)
virtual int write1ByteTxRx(PortHandler *port, uint8_t id, uint16_t address, uint8_t data, uint8_t *error=0)=0
#define ADDR_VELOCITY_IGAIN
#define ADDR_INDIRECT_VELOCITY
ros::Time getTime() const
#define ADDR_RETURN_DELAY
uint32_t getBaudrate(void)
void set_gain(uint8_t dxl_id, uint16_t gain)
static PacketHandler * getPacketHandler(float protocol_version=2.0)
void set_param_current_limit(uint8_t dxl_id, int val)
void set_torque_all(bool torque)
void registerHandle(const JointStateHandle &handle)
void init_joint_params(ST_JOINT_PARAM ¶m, int table_id, int value)
void set_param_delay_time(uint8_t dxl_id, int val)
dynamixel::GroupBulkRead * readTempGroup
uint32_t getData(uint8_t id, uint16_t address, uint16_t data_length)
JointStateHandle getHandle(const std::string &name)
#define ADDR_TEMPRATURE_LIMIT
bool check_servo_param(uint8_t dxl_id, uint32_t test_addr, uint8_t equal, uint8_t &read_val)
uint8_t return_delay_time
dynamixel::GroupBulkWrite * writeGoalGroup
void set_param_moving_threshold(uint8_t dxl_id, int val)
virtual int write4ByteTxRx(PortHandler *port, uint8_t id, uint16_t address, uint32_t data, uint8_t *error=0)=0
bool read(ros::Time, ros::Duration)
#define ADDR_MAX_VOL_LIMIT
dynamixel::GroupBulkWrite * writePosGoalGroup
hardware_interface::EffortJointInterface joint_eff_if
#define ADDR_MIN_VOL_LIMIT
virtual int write2ByteTxRx(PortHandler *port, uint8_t id, uint16_t address, uint16_t data, uint8_t *error=0)=0
bool getJointLimits(urdf::JointConstSharedPtr urdf_joint, JointLimits &limits)
void set_param_vel_gain(uint8_t dxl_id, int p, int i)
#define ADDR_INDIRECT_TOP
hardware_interface::PositionJointInterface joint_pos_if
virtual int read4ByteTxRx(PortHandler *port, uint8_t id, uint16_t address, uint32_t *data, uint8_t *error=0)=0
#define ADDR_INDIRECT_DXLID
#define ADDR_INDIRECT_CURRENT
virtual bool setBaudRate(const int baudrate)=0
#define ADDR_HOMING_OFFSET
std::string self_check(void)
virtual const char * getTxRxResult(int result)=0
#define DATA_INDIRECT_TOP
#define LEN_INDIRECT_DXLID
dynamixel::PacketHandler * packetHandler
#define ADDR_GOAL_POSITION
#define ADDR_PRESENT_TEMP
std::vector< JOINT_CONTROL > joints
void set_param_ope_mode(uint8_t dxl_id, int val)
void set_param_temp_limit(uint8_t dxl_id, int val)
#define ADDR_INDIRECT_TEMP
#define ADDR_INDIRECT_POSITION
void set_param_pos_gain(uint8_t dxl_id, int p, int i, int d)
#define ADDR_POSITION_IGAIN
bool addParam(uint8_t id, uint16_t start_address, uint16_t data_length, uint8_t *data)
dynamixel::PortHandler * portHandler
joint_limits_interface::PositionJointSoftLimitsInterface joint_limits_if