dxlport_control.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 #include <ros/package.h>
3 #include <angles/angles.h>
5 #include <math.h>
6 #include <stdio.h>
7 
8 /* MACRO */
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)
12 
13 //#define MASTER_WAIST_SLAVE_NECK
14 
16 {
17  int jj;
20  int position_mode_joint_num = 0;
21  int current_mode_joint_num = 0;
22  int current_position_mode_joint_num = 0;
23 
24  init_stat = false;
25  tx_err = rx_err = 0;
26  tempCount = 0;
27  tempTime = getTime();
28 
29  portHandler = NULL;
30  writeGoalGroup = NULL;
31  writePosGoalGroup= NULL;
32  readTempGroup = NULL;
33  readIndirectGroup= NULL;
34 
35  joint_num = setting.getjointNum();
36  std::vector<ST_SERVO_PARAM> list = setting.getServoParam();
37  for( jj=0 ; jj<joint_num ; ++jj ){
38  JOINT_CONTROL work( list[jj].name, list[jj].id, list[jj].center, list[jj].home, list[jj].eff_cnst, list[jj].mode );
39  joints.push_back( work );
40  }
41 
42  dev_mtx = new DEVICE_MUTEX( setting.getPortName().c_str() );
43 
44  /* DynamixelSDKとros_controlへの接続初期化 */
49  readTempGroup = new dynamixel::GroupBulkRead( portHandler, packetHandler );
51 
52  for( jj=0 ; jj<joint_num ; ++jj ){
53  uint8_t dxl_id = joints[jj].get_dxl_id();
54  if( joints[jj].get_ope_mode() == OPERATING_MODE_CURRENT ){
55  //CURRENT MODE
56  if( !writeGoalGroup->addParam( dxl_id, ADDR_GOAL_CURRENT, LEN_GOAL_CURRENT, joints[jj].get_dxl_goal_addr() ) ){// [TODO]
57  error_queue.push("Bulk current write setting failed.");
58  return;
59  }
60  }else if( joints[jj].get_ope_mode() == OPERATING_MODE_CURR_POS ){
61  //CURRENT base POSITION MODE
62  if( !writePosGoalGroup->addParam( dxl_id, ADDR_GOAL_POSITION, LEN_GOAL_POSITION, joints[jj].get_dxl_goal_addr() ) ){// [TODO]
63  error_queue.push("Bulk pos write setting failed.");
64  return;
65  }
66  }else{
67  //POSITION MODE
68  if( !writeGoalGroup->addParam( dxl_id, ADDR_GOAL_POSITION, LEN_GOAL_POSITION, joints[jj].get_dxl_goal_addr() ) ){// [TODO]
69  error_queue.push("Bulk pos write setting failed.");
70  return;
71  }
72  }
74  error_queue.push("Bulk temp read setting failed.");
75  return;
76  }
78  error_queue.push("Bulk group read setting failed.");
79  return;
80  }
81  }
82 
83  // Open port
84  lock_port();
85  if( !portHandler->openPort() ){
86  error_queue.push("Port open failed.");
87  port_stat = false;
88  }else{
89  // Set port baudrate
90  if( !portHandler->setBaudRate( setting.getBaudrate() ) ){
91  error_queue.push("Setup baudrate failed.");
92  port_stat = false;
93  }else{
94  port_stat = true; // 有効と仮定してread
95  for( jj=0 ; jj<joint_num ; ++jj ){
96  uint8_t dxl_id = joints[jj].get_dxl_id();
97  setup_indirect( dxl_id );
98  }
99  if( !read( ros::Time::now(), ros::Duration(0) ) ){
100  error_queue.push("Initialize communication failed.");
101  port_stat = false;
102  }
103  }
104  }
106  unlock_port();
107 
108  for( jj=0 ; jj<joint_num ; ++jj ){
109  hardware_interface::JointStateHandle reg_state_handle( joints[jj].get_joint_name(), joints[jj].get_position_addr(), joints[jj].get_velocity_addr(), joints[jj].get_effort_addr() );
110  joint_stat_if.registerHandle( reg_state_handle );
111  }
113 
114  for( jj=0 ; jj<joint_num ; ++jj ){
115  hardware_interface::JointHandle reg_joint_handle( joint_stat_if.getHandle(joints[jj].get_joint_name()), joints[jj].get_command_addr() );
116  if( joints[jj].get_ope_mode() == OPERATING_MODE_CURRENT ){
117  joint_eff_if.registerHandle( reg_joint_handle );
118  ++current_mode_joint_num;
119  }else{//POS & Current base POS
120  joint_pos_if.registerHandle( reg_joint_handle );
121  ++position_mode_joint_num;
122  }
123  // Get limits
124  if( joint_limits_interface::getJointLimits( joints[jj].get_joint_name(), handle, limits ) ){
125  joints[jj].set_limits( limits );
126  soft_limits.k_position = 1.0;
127  soft_limits.k_velocity = 1.0;
128  soft_limits.max_position = limits.max_position;
129  soft_limits.min_position = limits.min_position;
131  reg_limits_handle( reg_joint_handle, limits, soft_limits );
132  joint_limits_if.registerHandle( reg_limits_handle );
133  }
134  }
135  if( position_mode_joint_num > 0 ){
137  }
138  if( current_mode_joint_num > 0 ){
140  }
141 
142  init_stat = true;
143 }
144 
146 {
148  delete( portHandler );
149  delete( dev_mtx );
150  if(readTempGroup!=NULL) delete( readTempGroup );
151  if(writeGoalGroup!=NULL) delete( writeGoalGroup );
152  if(writePosGoalGroup!=NULL) delete( writePosGoalGroup );
153  if(readIndirectGroup!=NULL) delete( readIndirectGroup );
154 }
155 
157 {
158  bool result = false;
159 
160  if( !port_stat ){
161  return true;
162  }
163 
164  int dxl_comm_result = readIndirectGroup->txRxPacket();
165  if (dxl_comm_result != COMM_SUCCESS){
166  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
167  ++rx_err;
168  }else{
169  if( readId(time, period) && readCurrent( time, period ) && readVel( time, period ) && readPos( time, period ) && readTemp( time, period ) ){
170  result = true;
171  }
172  }
173 
174  return result;
175 }
176 
178 {
179  bool result = false;
180 
181  for( int jj=0 ; jj<joint_num ; ++jj ){
182  uint8_t get_id = 0;
183  uint8_t dxl_id = joints[jj].get_dxl_id();
184  bool dxl_getdata_result = readIndirectGroup->isAvailable( dxl_id, ADDR_INDIRECT_DXLID, LEN_INDIRECT_DXLID );
185  if( !dxl_getdata_result ){
186  ++rx_err;
187  ROS_INFO("readId error [%d]",dxl_id);
188  break;
189  }else{
191  if( get_id == dxl_id ){
192  result = true;
193  }else{
194  break;
195  }
196  }
197  }
198  return result;
199 }
200 
202 {
203  bool result = false;
204 
205  for( int jj=0 ; jj<joint_num ; ++jj ){
206  int32_t present_pos = 0;
207  uint8_t dxl_id = joints[jj].get_dxl_id();
208  bool dxl_getdata_result = readIndirectGroup->isAvailable( dxl_id, ADDR_INDIRECT_POSITION, LEN_PRESENT_POSITION );
209  if( !dxl_getdata_result ){
210  ++rx_err;
211  break;
212  }else{
214  joints[jj].set_dxl_pos( present_pos );
215  present_pos = (present_pos - joints[jj].get_center());
216  joints[jj].set_position( DXLPOS2RAD( present_pos ) );
217  result = true;
218  }
219  }
220  return result;
221 }
222 
224 {
225  bool result = false;
226 
227  for( int jj=0 ; jj<joint_num ; ++jj ){
228  int16_t present_current = 0;
229  uint8_t dxl_id = joints[jj].get_dxl_id();
230  bool dxl_getdata_result = readIndirectGroup->isAvailable( dxl_id, ADDR_INDIRECT_CURRENT, LEN_PRESENT_CURRENT );
231  if( !dxl_getdata_result ){
232  ++rx_err;
233  break;
234  }else{
236  joints[jj].set_dxl_curr( present_current );
237  joints[jj].set_current( (DXL_CURRENT_UNIT * present_current) );
238  joints[jj].set_effort( DXL_CURRENT2EFFORT( present_current, joints[jj].get_eff_const() ) );
239  result = true;
240  }
241  }
242  return result;
243 }
244 
246 {
247  bool result = false;
248 
249  for( int jj=0 ; jj<joint_num ; ++jj ){
250  uint8_t dxl_id = joints[jj].get_dxl_id();
251  bool dxl_getdata_result = readIndirectGroup->isAvailable( dxl_id, ADDR_INDIRECT_TEMP, LEN_PRESENT_TEMP );
252  if( !dxl_getdata_result ){
253  ++rx_err;
254  break;
255  }else{
256  uint8_t present_temp = readIndirectGroup->getData( dxl_id, ADDR_INDIRECT_TEMP, LEN_PRESENT_TEMP );
257  joints[jj].set_dxl_temp( present_temp );
258  joints[jj].set_temprature( present_temp );
259  result = true;
260  }
261  }
262  return result;
263 }
264 
266 {
267  bool result = false;
268 
269  for( int jj=0 ; jj<joint_num ; ++jj ){
270  uint8_t dxl_id = joints[jj].get_dxl_id();
271  bool dxl_getdata_result = readIndirectGroup->isAvailable( dxl_id, ADDR_INDIRECT_VELOCITY, LEN_PRESENT_VEL );
272  if( !dxl_getdata_result ){
273  ++rx_err;
274  break;
275  }else{
276  int32_t present_velocity = readIndirectGroup->getData( dxl_id, ADDR_INDIRECT_VELOCITY, LEN_PRESENT_VEL );
277  joints[jj].set_velocity( DXL_VELOCITY2RAD_S(present_velocity) );
278  result = true;
279  }
280  }
281  return result;
282 }
283 
285 {
286  double get_cmd;
287  float* tau;
288 
289  if( !port_stat){
290  for( int jj=0 ; jj<joint_num ; ++jj ){
291  get_cmd = joints[jj].get_command();
292  joints[jj].updt_d_command( get_cmd );
293  joints[jj].set_position( get_cmd );
294  }
295  return;
296  }
297 
298  for( int jj=0 ; jj<joint_num ; ++jj ){
299 #ifdef MASTER_WAIST_SLAVE_NECK
300  double slave_pos_data;
301  // Slave pos function
302  if( joints[jj].get_dxl_id() == 18 ){
303  slave_pos_data = joints[jj].get_command();
304  }
305  if( joints[jj].get_dxl_id() == 19 ){
306  joints[jj].set_command( -slave_pos_data );
307  }
308 #endif
309  get_cmd = joints[jj].get_command();
310  if( joints[jj].get_ope_mode() == OPERATING_MODE_CURRENT ){
311  // Current control
312  double work_cur = EFFORT2DXL_CURRENT( get_cmd, joints[jj].get_eff_const() );
313  joints[jj].updt_d_command( 0.0 );
314 
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);
319 
320  writeGoalGroup->changeParam( joints[jj].get_dxl_id(), ADDR_GOAL_CURRENT, LEN_GOAL_CURRENT, goal_data );
321  }else if(joints[jj].get_ope_mode() == OPERATING_MODE_CURR_POS ){
322  // Current update
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);
327  writeGoalGroup->changeParam( joints[jj].get_dxl_id(), ADDR_GOAL_CURRENT, LEN_GOAL_CURRENT, goal_data );
328  }else{
329  // Position control
330  double work_pos = RAD2DXLPOS( get_cmd );
331  joints[jj].updt_d_command( get_cmd );
332  work_pos += joints[jj].get_center(); // ROS(-180 <=> +180) => DXL(0 <=> 4095)
333  if( work_pos < DXL_MIN_LIMIT ){
334  work_pos = DXL_MIN_LIMIT;
335  }
336  if( work_pos > DXL_MAX_LIMIT ){
337  work_pos = DXL_MAX_LIMIT;
338  }
339 
340  uint32_t dxl_pos = (uint32_t)round( work_pos );
341  uint8_t* goal_data = joints[jj].get_dxl_goal_addr();
342 
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);
347 
348  writeGoalGroup->changeParam( joints[jj].get_dxl_id(), ADDR_GOAL_POSITION, LEN_GOAL_POSITION, goal_data );
349  }
350  }
351  int dxl_comm_result = writeGoalGroup->txPacket();
352  if( dxl_comm_result != COMM_SUCCESS ){
353  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
354  ++tx_err;
355  }
356 }
357 
359 {
360  bool result = false;
361 
362  for( int jj=0 ; jj<joint_num ; ++jj ){
363  if( fabs( joints[jj].get_d_command() ) > 0.0 ){
364  result = true;
365  break;
366  }
367  }
368  return result;
369 }
370 
371 void DXLPORT_CONTROL::set_gain_all( uint16_t gain )
372 {
373  if( !port_stat ){
374  return;
375  }
376  for( int jj=0 ; jj<joint_num ; ++jj ){
377  if( joints[jj].get_ope_mode() == OPERATING_MODE_CURRENT ){
378  continue;
379  }
380  set_gain( joints[jj].get_dxl_id(), gain );
381  }
382 }
383 
384 void DXLPORT_CONTROL::set_gain( uint8_t dxl_id, uint16_t gain )
385 {
386  uint8_t dxl_error = 0; // Dynamixel error
387 
388  lock_port();
389  int dxl_comm_result = packetHandler->write2ByteTxRx( portHandler, dxl_id, ADDR_POSITION_PGAIN, gain, &dxl_error );
390  unlock_port();
391  if( dxl_comm_result != COMM_SUCCESS ){
392  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
393  ++tx_err;
394  }else if( dxl_error != 0 ){
395  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
396  ++tx_err;
397  }
398 }
399 
401 {
402  if( !port_stat ){
403  return;
404  }
405  for( int jj=0 ; jj<joint_num ; ++jj ){
406  if( joints[jj].get_ope_mode() == OPERATING_MODE_CURRENT ){
407  set_goal_current( joints[jj].get_dxl_id(), current );
408  }
409  }
410 }
411 
412 
413 void DXLPORT_CONTROL::set_goal_current( uint8_t dxl_id, uint16_t current )
414 {
415  uint8_t dxl_error = 0; // Dynamixel error
416 
417  lock_port();
418  int dxl_comm_result = packetHandler->write2ByteTxRx( portHandler, dxl_id, ADDR_GOAL_CURRENT, current, &dxl_error );
419  unlock_port();
420  if( dxl_comm_result != COMM_SUCCESS ){
421  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
422  ++tx_err;
423  }else if( dxl_error != 0 ){
424  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
425  ++tx_err;
426  }
427 }
428 
429 bool DXLPORT_CONTROL::set_torque( uint8_t dxl_id, bool torque )
430 {
431  uint32_t set_param = torque ? TORQUE_ENABLE:TORQUE_DISABLE;
432  bool result = false;
433 
434  if( !port_stat ){
435  return true;
436  }
437 
438  uint8_t dxl_error = 0; // Dynamixel error
439  lock_port();
440  int dxl_comm_result = packetHandler->write1ByteTxRx( portHandler, dxl_id, ADDR_TORQUE_ENABLE, set_param, &dxl_error );
441  unlock_port();
442  if( dxl_comm_result != COMM_SUCCESS ){
443  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
444  ++tx_err;
445  }else if( dxl_error != 0 ){
446  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
447  ++tx_err;
448  }else{
449  result = true;
450  }
451  return result;
452 }
454 {
455  for( uint8_t jj=0 ; jj<joint_num; ++jj ){
456  if( set_torque( joints[jj].get_dxl_id(), torque ) ){
457  joints[jj].set_torque( torque );
458  }
459  }
460 }
461 
462 void DXLPORT_CONTROL::set_watchdog( uint8_t dxl_id, uint8_t value )
463 {
464  if( !port_stat ){
465  return;
466  }
467 
468  uint8_t dxl_error = 0; // Dynamixel error
469  lock_port();
470  int dxl_comm_result = packetHandler->write1ByteTxRx( portHandler, dxl_id, ADDR_BUS_WATCHDOG, value, &dxl_error );
471  unlock_port();
472  if( dxl_comm_result != COMM_SUCCESS ){
473  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
474  ++tx_err;
475  }else if( dxl_error != 0 ){
476  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
477  ++tx_err;
478  }
479 }
480 
482 {
483  for( uint8_t jj=0 ; jj<joint_num; ++jj ){
484  set_watchdog( joints[jj].get_dxl_id(), value );
485  }
486 }
487 
488 /* 起動時モーション */
490 {
492  int step_max = DXL_TORQUE_ON_STEP_MAX;
493  ros::Time t = getTime();
495  std::vector<ST_HOME_MOTION_DATA> home_motion_data;
496 
497  /* 開始位置取り込みと差分計算 */
498 
499  lock_port();
500  read( t, d );
501  unlock_port();
502 
503  for( int jj=0 ; jj<joint_num ; ++jj ){
504  ST_HOME_MOTION_DATA motion_work;
505  motion_work.home = joints[jj].get_home();
506  motion_work.home_rad = DXLPOS2RAD( motion_work.home ) - DXLPOS2RAD( joints[jj].get_center() );
507  motion_work.start_rad = joints[jj].get_position();
508  motion_work.start = RAD2DXLPOS( motion_work.start_rad ) + joints[jj].get_center();
509  motion_work.step_rad =
510  (motion_work.home > motion_work.start) ? ((motion_work.home_rad - motion_work.start_rad)/step_max)
511  : -((motion_work.start_rad - motion_work.home_rad)/step_max);
512  if( joints[jj].get_ope_mode() == OPERATING_MODE_CURRENT ){
513  joints[jj].set_command( 0.0 );
514  }else{
515  joints[jj].set_command( joints[jj].get_position() );
516  }
517  home_motion_data.push_back( motion_work );
518  }
519  lock_port();
520  write( t, d );
521  unlock_port();
522 
523  set_torque_all( true ); // 全関節トルクON
525 
526  /* ホームポジションへ移動する */
527  for( int step=0 ; step<step_max ; ++step ){
528  d = getDuration(t);
529  t = getTime();
530  if( !port_stat ){
531  for( int jj=0 ; jj<joint_num ; ++jj ){
532  if( joints[jj].get_ope_mode() == OPERATING_MODE_CURRENT ){
533  continue;
534  }
535  joints[jj].set_command( DXLPOS2RAD( joints[jj].get_home() ) - DXLPOS2RAD( joints[jj].get_center() ) );
536  }
537  continue;
538  }
539  for( int jj=0 ; jj<joint_num ; ++jj ){
540  if( joints[jj].get_ope_mode() == OPERATING_MODE_CURRENT ){
541  continue;
542  }
543  joints[jj].set_command( joints[jj].get_command() + home_motion_data[jj].step_rad );
544  }
545  lock_port();
546  write( t, d );
547  unlock_port();
548  rate.sleep();
549  }
550  for( int jj=0 ; jj<joint_num ; ++jj ){
551  if( joints[jj].get_ope_mode() == OPERATING_MODE_CURRENT ){
552  continue;
553  }
554  joints[jj].set_command( home_motion_data[jj].home_rad );
555  }
556  lock_port();
557  write( t, d );
558  unlock_port();
559  for( int jj=0 ; jj<joint_num ; ++jj ){
560  joints[jj].updt_d_command( 0.0 );//差分の初期化
561  }
562 }
563 
564 /* セルフチェック */
565 bool DXLPORT_CONTROL::check_servo_param( uint8_t dxl_id, uint32_t test_addr, uint8_t equal, uint8_t& read_val )
566 {
567  uint8_t dxl_error = 0; // Dynamixel error
568  uint8_t read_data;
569  bool result = false;
570 
571  lock_port();
572  int dxl_comm_result = packetHandler->read1ByteTxRx(portHandler, dxl_id, test_addr, &read_data, &dxl_error);
573  unlock_port();
574  if( dxl_comm_result != COMM_SUCCESS ){
575  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
576  ++rx_err;
577  }else if( dxl_error != 0 ){
578  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
579  ++rx_err;
580  }
581  if( read_data == equal ){
582  result = true;
583  }
584  read_val = read_data;
585  return result;
586 }
587 bool DXLPORT_CONTROL::check_servo_param( uint8_t dxl_id, uint32_t test_addr, uint16_t equal, uint16_t& read_val )
588 {
589  uint8_t dxl_error = 0; // Dynamixel error
590  uint16_t read_data;
591  bool result = false;
592 
593  lock_port();
594  int dxl_comm_result = packetHandler->read2ByteTxRx(portHandler, dxl_id, test_addr, &read_data, &dxl_error);
595  unlock_port();
596  if( dxl_comm_result != COMM_SUCCESS ){
597  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
598  ++rx_err;
599  }else if( dxl_error != 0 ){
600  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
601  ++rx_err;
602  }
603  if( read_data == equal ){
604  result = true;
605  }
606  read_val = read_data;
607  return result;
608 }
609 bool DXLPORT_CONTROL::check_servo_param( uint8_t dxl_id, uint32_t test_addr, uint32_t equal, uint32_t& read_val )
610 {
611  uint8_t dxl_error = 0; // Dynamixel error
612  uint32_t read_data;
613  bool result = false;
614 
615  lock_port();
616  int dxl_comm_result = packetHandler->read4ByteTxRx(portHandler, dxl_id, test_addr, &read_data, &dxl_error);
617  unlock_port();
618  if( dxl_comm_result != COMM_SUCCESS ){
619  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
620  ++rx_err;
621  }else if( dxl_error != 0 ){
622  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
623  ++rx_err;
624  }
625  if( read_data == equal ){
626  result = true;
627  }
628  read_val = read_data;
629  return result;
630 }
631 
632 void DXLPORT_CONTROL::init_joint_params( ST_JOINT_PARAM &param, int table_id, int value )
633 {
634  switch( table_id ){
636  param.return_delay_time = (uint8_t)value;
637  break;
638  case enTableId_DriveMode:
639  param.drive_mode = (uint8_t)value;
640  break;
641  case enTableId_OpeMode:
642  param.operation_mode = (uint8_t)value;
643  break;
645  param.homing_offset = (int32_t)value;
646  break;
648  param.moving_threshold = (uint16_t)value;
649  break;
650  case enTableId_TempLimit:
651  param.temprature_limit = (uint8_t)value;
652  break;
654  param.max_vol_limit = (uint8_t)value;
655  break;
657  param.min_vol_limit = (uint8_t)value;
658  break;
660  param.current_limit = (uint16_t)value;
661  break;
663  param.torque_enable = (uint8_t)value;
664  break;
666  param.velocity_i_gain = (uint16_t)value;
667  break;
669  param.velocity_p_gain = (uint16_t)value;
670  break;
672  param.position_d_gain = (uint16_t)value;
673  break;
675  param.position_i_gain = (uint16_t)value;
676  break;
678  param.position_p_gain = (uint16_t)value;
679  break;
687  case enTableId_Shutdown:
688  default:
689  break;
690  }
691 }
692 
693 std::string DXLPORT_CONTROL::self_check( void )
694 {
695  std::string res_str = "[DYNAMIXEL PARAMETER SELF CHECK]\n";
696 
697  if( !port_stat ){
698  res_str = "SKIP SELF CHECK...";
699  return res_str;
700  }
701  for( int ii=0 ; ii<(sizeof(RegTable)/sizeof(ST_DYNAMIXEL_REG_TABLE)) ; ++ii ){
702  bool check_result = true;
703  bool read_result;
704  uint8_t chk_8data, read_8data;
705  uint16_t chk_16data, read_16data;
706  uint32_t chk_32data, read_32data;
707  if( RegTable[ii].selfcheck ){
708  res_str += RegTable[ii].name + " test...\n";
709  }
710  switch( RegTable[ii].length ){
711  case REG_LENGTH_BYTE:
712  chk_8data = (uint8_t)RegTable[ii].init_value;
713  if( RegTable[ii].name == "OPERATION_MODE" ){
714  chk_8data = joints[ii].get_ope_mode();
715  }
716  for( int jj=0 ; jj<joint_num ; ++jj ){
717  read_result = check_servo_param( joints[jj].get_dxl_id(), RegTable[ii].address, chk_8data, read_8data );
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;
721  }
722  ST_JOINT_PARAM work = joints[jj].get_joint_param();
723  init_joint_params( work, ii, read_8data );
724  joints[jj].set_joint_param( work );
725  }
726  break;
727  case REG_LENGTH_WORD:
728  chk_16data = (uint16_t)RegTable[ii].init_value;
729  for( int jj=0 ; jj<joint_num ; ++jj ){
730  read_result = check_servo_param( joints[jj].get_dxl_id(), RegTable[ii].address, chk_16data, read_16data );
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;
734  }
735  ST_JOINT_PARAM work = joints[jj].get_joint_param();
736  init_joint_params( work, ii, read_16data );
737  joints[jj].set_joint_param( work );
738  }
739  break;
740  case REG_LENGTH_DWORD:
741  chk_32data = (uint32_t)RegTable[ii].init_value;
742  for( int jj=0 ; jj<joint_num ; ++jj ){
743  read_result = check_servo_param( joints[jj].get_dxl_id(), RegTable[ii].address, chk_32data, read_32data );
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;
747  }
748  ST_JOINT_PARAM work = joints[jj].get_joint_param();
749  init_joint_params( work, ii, read_32data );
750  joints[jj].set_joint_param( work );
751  }
752  break;
753  }
754  if( RegTable[ii].selfcheck ){
755  if( check_result ){
756  res_str += " CHECK OK\n";
757  }else{
758  res_str += " CHECK NG!\n";
759  }
760  }
761  }
762  return res_str;
763 }
764 
765 void DXLPORT_CONTROL::set_param_delay_time( uint8_t dxl_id, int val )
766 {
767  uint8_t set_param = (uint8_t)val;
768 
769  if( !port_stat ){
770  return;
771  }
772  for( int jj=0 ; jj<joint_num; ++jj ){
773  if( dxl_id == joints[jj].get_dxl_id() ){
774  ST_JOINT_PARAM new_param = joints[jj].get_joint_param();
775  if( new_param.return_delay_time != set_param ){
776  uint8_t dxl_error = 0; // Dynamixel error
777  lock_port();
778  int dxl_comm_result = packetHandler->write1ByteTxRx( portHandler, dxl_id, ADDR_RETURN_DELAY, set_param, &dxl_error );
779  unlock_port();
780  if( dxl_comm_result != COMM_SUCCESS ){
781  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
782  ++tx_err;
783  }else if( dxl_error != 0 ){
784  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
785  ++tx_err;
786  }
787  }
788  new_param.return_delay_time = set_param;
789  joints[jj].set_joint_param( new_param );
790  break;
791  }
792  }
793 }
794 void DXLPORT_CONTROL::set_param_drive_mode( uint8_t dxl_id, int val )
795 {
796  uint8_t set_param = (uint8_t)val;
797 
798  if( !port_stat ){
799  return;
800  }
801  for( int jj=0 ; jj<joint_num; ++jj ){
802  if( dxl_id == joints[jj].get_dxl_id() ){
803  ST_JOINT_PARAM new_param = joints[jj].get_joint_param();
804  if( new_param.drive_mode != set_param ){
805  uint8_t dxl_error = 0; // Dynamixel error
806  lock_port();
807  int dxl_comm_result = packetHandler->write1ByteTxRx( portHandler, dxl_id, ADDR_DRIVE_MODE, set_param, &dxl_error );
808  unlock_port();
809  if( dxl_comm_result != COMM_SUCCESS ){
810  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
811  ++tx_err;
812  }else if( dxl_error != 0 ){
813  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
814  ++tx_err;
815  }
816  }
817  new_param.drive_mode = set_param;
818  joints[jj].set_joint_param( new_param );
819  break;
820  }
821  }
822 }
823 void DXLPORT_CONTROL::set_param_ope_mode( uint8_t dxl_id, int val )
824 {
825  uint8_t set_param = (uint8_t)val;
826 
827  if( !port_stat ){
828  return;
829  }
830  for( int jj=0 ; jj<joint_num; ++jj ){
831  if( dxl_id == joints[jj].get_dxl_id() ){
832  ST_JOINT_PARAM new_param = joints[jj].get_joint_param();
833  if( new_param.operation_mode != set_param ){
834  uint8_t dxl_error = 0; // Dynamixel error
835  lock_port();
836  int dxl_comm_result = packetHandler->write1ByteTxRx( portHandler, dxl_id, ADDR_OPE_MODE, set_param, &dxl_error );
837  unlock_port();
838  if( dxl_comm_result != COMM_SUCCESS ){
839  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
840  ++tx_err;
841  }else if( dxl_error != 0 ){
842  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
843  ++tx_err;
844  }
845  }
846  new_param.operation_mode = set_param;
847  joints[jj].set_joint_param( new_param );
848  break;
849  }
850  }
851 }
852 void DXLPORT_CONTROL::set_param_home_offset( uint8_t dxl_id, int val )
853 {
854  uint32_t set_param = (uint32_t)val;
855 
856  if( !port_stat ){
857  return;
858  }
859  for( int jj=0 ; jj<joint_num; ++jj ){
860  if( dxl_id == joints[jj].get_dxl_id() ){
861  ST_JOINT_PARAM new_param = joints[jj].get_joint_param();
862  if( new_param.homing_offset != set_param ){
863  uint8_t dxl_error = 0; // Dynamixel error
864  lock_port();
865  int dxl_comm_result = packetHandler->write4ByteTxRx( portHandler, dxl_id, ADDR_HOMING_OFFSET, set_param, &dxl_error );
866  unlock_port();
867  if( dxl_comm_result != COMM_SUCCESS ){
868  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
869  ++tx_err;
870  }else if( dxl_error != 0 ){
871  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
872  ++tx_err;
873  }
874  }
875  new_param.homing_offset = (int32_t)set_param;
876  joints[jj].set_joint_param( new_param );
877  break;
878  }
879  }
880 }
881 void DXLPORT_CONTROL::set_param_moving_threshold( uint8_t dxl_id, int val )
882 {
883  uint32_t set_param = (uint32_t)val;
884 
885  if( !port_stat ){
886  return;
887  }
888  for( int jj=0 ; jj<joint_num; ++jj ){
889  if( dxl_id == joints[jj].get_dxl_id() ){
890  ST_JOINT_PARAM new_param = joints[jj].get_joint_param();
891  if( new_param.moving_threshold != set_param ){
892  uint8_t dxl_error = 0; // Dynamixel error
893  lock_port();
894  int dxl_comm_result = packetHandler->write4ByteTxRx( portHandler, dxl_id, ADDR_MOVING_THRESHOLD, set_param, &dxl_error );
895  unlock_port();
896  if( dxl_comm_result != COMM_SUCCESS ){
897  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
898  ++tx_err;
899  }else if( dxl_error != 0 ){
900  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
901  ++tx_err;
902  }
903  }
904  new_param.moving_threshold = set_param;
905  joints[jj].set_joint_param( new_param );
906  break;
907  }
908  }
909 }
910 void DXLPORT_CONTROL::set_param_temp_limit( uint8_t dxl_id, int val )
911 {
912  uint8_t set_param = (uint8_t)val;
913 
914  if( !port_stat ){
915  return;
916  }
917  for( int jj=0 ; jj<joint_num; ++jj ){
918  if( dxl_id == joints[jj].get_dxl_id() ){
919  ST_JOINT_PARAM new_param = joints[jj].get_joint_param();
920  if( new_param.temprature_limit != set_param ){
921  uint8_t dxl_error = 0; // Dynamixel error
922  lock_port();
923  int dxl_comm_result = packetHandler->write1ByteTxRx( portHandler, dxl_id, ADDR_TEMPRATURE_LIMIT, set_param, &dxl_error );
924  unlock_port();
925  if( dxl_comm_result != COMM_SUCCESS ){
926  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
927  ++tx_err;
928  }else if( dxl_error != 0 ){
929  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
930  ++tx_err;
931  }
932  }
933  new_param.temprature_limit = set_param;
934  joints[jj].set_joint_param( new_param );
935  break;
936  }
937  }
938 }
939 void DXLPORT_CONTROL::set_param_vol_limit( uint8_t dxl_id, int max, int min )
940 {
941  uint16_t set_max_param = (uint32_t)max;
942  uint16_t set_min_param = (uint32_t)min;
943 
944  if( !port_stat ){
945  return;
946  }
947  for( int jj=0 ; jj<joint_num; ++jj ){
948  if( dxl_id == joints[jj].get_dxl_id() ){
949  ST_JOINT_PARAM new_param = joints[jj].get_joint_param();
950  if( new_param.max_vol_limit != set_max_param ){
951  uint8_t dxl_error = 0; // Dynamixel error
952  lock_port();
953  int dxl_comm_result = packetHandler->write2ByteTxRx( portHandler, dxl_id, ADDR_MAX_VOL_LIMIT, set_max_param, &dxl_error );
954  unlock_port();
955  if( dxl_comm_result != COMM_SUCCESS ){
956  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
957  ++tx_err;
958  }else if( dxl_error != 0 ){
959  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
960  ++tx_err;
961  }
962  }
963  if( new_param.min_vol_limit != set_min_param ){
964  uint8_t dxl_error = 0; // Dynamixel error
965  lock_port();
966  int dxl_comm_result = packetHandler->write2ByteTxRx( portHandler, dxl_id, ADDR_MIN_VOL_LIMIT, set_min_param, &dxl_error );
967  unlock_port();
968  if( dxl_comm_result != COMM_SUCCESS ){
969  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
970  ++tx_err;
971  }else if( dxl_error != 0 ){
972  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
973  ++tx_err;
974  }
975  }
976  new_param.max_vol_limit = set_max_param;
977  new_param.min_vol_limit = set_min_param;
978  joints[jj].set_joint_param( new_param );
979  break;
980  }
981  }
982 }
983 void DXLPORT_CONTROL::set_param_current_limit( uint8_t dxl_id, int val )
984 {
985  uint16_t set_param = (uint16_t)val;
986 
987  if( !port_stat ){
988  return;
989  }
990  for( int jj=0 ; jj<joint_num; ++jj ){
991  if( dxl_id == joints[jj].get_dxl_id() ){
992  ST_JOINT_PARAM new_param = joints[jj].get_joint_param();
993  if( new_param.current_limit != set_param ){
994  uint8_t dxl_error = 0; // Dynamixel error
995  lock_port();
996  int dxl_comm_result = packetHandler->write2ByteTxRx( portHandler, dxl_id, ADDR_CURRENT_LIMIT, set_param, &dxl_error );
997  unlock_port();
998  if( dxl_comm_result != COMM_SUCCESS ){
999  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
1000  ++tx_err;
1001  }else if( dxl_error != 0 ){
1002  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
1003  ++tx_err;
1004  }
1005  }
1006  new_param.current_limit = set_param;
1007  joints[jj].set_joint_param( new_param );
1008  break;
1009  }
1010  }
1011 }
1012 void DXLPORT_CONTROL::set_param_vel_gain( uint8_t dxl_id, int p, int i )
1013 {
1014  uint16_t set_p_param = (uint16_t)p;
1015  uint16_t set_i_param = (uint16_t)i;
1016 
1017  if( !port_stat ){
1018  return;
1019  }
1020  for( int jj=0 ; jj<joint_num; ++jj ){
1021  if( dxl_id == joints[jj].get_dxl_id() ){
1022  ST_JOINT_PARAM new_param = joints[jj].get_joint_param();
1023  if( (new_param.velocity_p_gain != set_p_param) ){
1024  uint8_t dxl_error = 0; // Dynamixel error
1025  lock_port();
1026  int dxl_comm_result = packetHandler->write2ByteTxRx( portHandler, dxl_id, ADDR_VELOCITY_PGAIN, set_p_param, &dxl_error );
1027  unlock_port();
1028  if( dxl_comm_result != COMM_SUCCESS ){
1029  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
1030  ++tx_err;
1031  }else if( dxl_error != 0 ){
1032  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
1033  ++tx_err;
1034  }
1035  }
1036  if( (new_param.velocity_i_gain != set_i_param) ){
1037  uint8_t dxl_error = 0; // Dynamixel error
1038  lock_port();
1039  int dxl_comm_result = packetHandler->write2ByteTxRx( portHandler, dxl_id, ADDR_VELOCITY_IGAIN, set_i_param, &dxl_error );
1040  unlock_port();
1041  if( dxl_comm_result != COMM_SUCCESS ){
1042  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
1043  ++tx_err;
1044  }else if( dxl_error != 0 ){
1045  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
1046  ++tx_err;
1047  }
1048  }
1049  new_param.velocity_p_gain = set_p_param;
1050  new_param.velocity_i_gain = set_i_param;
1051  joints[jj].set_joint_param( new_param );
1052  break;
1053  }
1054  }
1055 }
1056 
1057 void DXLPORT_CONTROL::set_param_pos_gain_all( int p, int i, int d )
1058 {
1059  if( !port_stat ){
1060  return;
1061  }
1062  for( int jj=0 ; jj<joint_num ; ++jj ){
1063  set_param_pos_gain( joints[jj].get_dxl_id(), p, i, d);
1064  }
1065 }
1066 
1067 void DXLPORT_CONTROL::set_param_pos_gain( uint8_t dxl_id, int p, int i, int d )
1068 {
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;
1072 
1073  if( !port_stat ){
1074  return;
1075  }
1076  for( int jj=0 ; jj<joint_num; ++jj ){
1077  if( dxl_id == joints[jj].get_dxl_id() ){
1078  ST_JOINT_PARAM new_param = joints[jj].get_joint_param();
1079  if( new_param.position_p_gain != set_p_param ){
1080  uint8_t dxl_error = 0; // Dynamixel error
1081  lock_port();
1082  int dxl_comm_result = packetHandler->write2ByteTxRx( portHandler, dxl_id, ADDR_POSITION_PGAIN, set_p_param, &dxl_error );
1083  unlock_port();
1084  if( dxl_comm_result != COMM_SUCCESS ){
1085  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
1086  ++tx_err;
1087  }else if( dxl_error != 0 ){
1088  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
1089  ++tx_err;
1090  }
1091  }
1092  if( new_param.position_i_gain != set_i_param ){
1093  uint8_t dxl_error = 0; // Dynamixel error
1094  lock_port();
1095  int dxl_comm_result = packetHandler->write2ByteTxRx( portHandler, dxl_id, ADDR_POSITION_IGAIN, set_i_param, &dxl_error );
1096  unlock_port();
1097  if( dxl_comm_result != COMM_SUCCESS ){
1098  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
1099  ++tx_err;
1100  }else if( dxl_error != 0 ){
1101  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
1102  ++tx_err;
1103  }
1104  }
1105  if( new_param.position_d_gain != set_d_param ){
1106  uint8_t dxl_error = 0; // Dynamixel error
1107  lock_port();
1108  int dxl_comm_result = packetHandler->write2ByteTxRx( portHandler, dxl_id, ADDR_POSITION_DGAIN, set_d_param, &dxl_error );
1109  unlock_port();
1110  if( dxl_comm_result != COMM_SUCCESS ){
1111  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
1112  ++tx_err;
1113  }else if( dxl_error != 0 ){
1114  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
1115  ++tx_err;
1116  }
1117  }
1118  new_param.position_p_gain = set_p_param;
1119  new_param.position_i_gain = set_i_param;
1120  new_param.position_d_gain = set_d_param;
1121  joints[jj].set_joint_param( new_param );
1122  break;
1123  }
1124  }
1125 }
1126 
1127 std::string::size_type DXLPORT_CONTROL::get_error( std::string& errorlog )
1128 {
1129  std::string::size_type result = error_queue.size();
1130  if( result > 0 ){
1131  errorlog = error_queue.front();
1132  error_queue.pop();
1133  }
1134  return result;
1135 }
1136 
1137 bool DXLPORT_CONTROL::setup_indirect( uint8_t dxl_id )
1138 {
1139  uint8_t dxl_error = 0; // Dynamixel error
1140  uint16_t setup_data[] = { 224, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 146 };
1141 
1142  // Write DXL ID data
1143  int dxl_comm_result = packetHandler->write1ByteTxRx( portHandler, dxl_id, ADDR_INDIRECT_DXLID, dxl_id, &dxl_error );
1144  if( dxl_comm_result != COMM_SUCCESS ){
1145  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
1146  ++tx_err;
1147  }else if( dxl_error != 0 ){
1148  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
1149  ++tx_err;
1150  }
1151 
1152  for( int idx=0 ; idx<sizeof(setup_data)/2 ; ++idx ){
1153  uint32_t set_addr = ADDR_INDIRECT_TOP + (idx*2);
1154  int dxl_comm_result = packetHandler->write2ByteTxRx( portHandler, dxl_id, set_addr, setup_data[idx], &dxl_error );
1155  if( dxl_comm_result != COMM_SUCCESS ){
1156  error_queue.push( (std::string(__func__) + " ") + packetHandler->getTxRxResult( dxl_comm_result ) );
1157  ++tx_err;
1158  }else if( dxl_error != 0 ){
1159  error_queue.push( (std::string(__func__) + " ") + packetHandler->getRxPacketError( dxl_error ) );
1160  ++tx_err;
1161  }
1162  }
1163 
1164  return true;
1165 }
void set_watchdog(uint8_t dxl_id, uint8_t value)
void set_watchdog_all(uint8_t value)
d
#define DXLPOS2RAD(pos)
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)
uint16_t current_limit
Definition: joint_control.h:99
#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)
#define TORQUE_DISABLE
bool readVel(ros::Time, ros::Duration)
#define REG_LENGTH_DWORD
Definition: joint_control.h:31
bool set_torque(uint8_t dxl_id, bool torque)
int32_t homing_offset
Definition: joint_control.h:95
#define LEN_PRESENT_POSITION
uint8_t temprature_limit
Definition: joint_control.h:96
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[]
Definition: joint_control.h:60
void set_param_vol_limit(uint8_t dxl_id, int max, int min)
#define DXL_MIN_LIMIT
uint8_t torque_enable
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
Definition: joint_control.h:94
#define LEN_PRESENT_CURRENT
#define DXL_MAX_LIMIT
void write(ros::Time, ros::Duration)
#define DXL_CURRENT2EFFORT(c, coef)
#define OPERATING_MODE_CURRENT
#define ADDR_POSITION_PGAIN
int COMM_SUCCESS
#define ADDR_DRIVE_MODE
bool is_change_positions(void)
virtual void closePort()=0
DEVICE_MUTEX * dev_mtx
#define PROTOCOL_VERSION
Definition: joint_control.h:13
uint16_t position_p_gain
virtual const char * getRxPacketError(uint8_t error)=0
#define DXL_CURRENT_UNIT
std::string getPortName(void)
#define DXL_TORQUE_ON_STEP_MAX
#define ADDR_VELOCITY_PGAIN
#define LEN_INDIRECT_GROUP
#define ROS_INFO(...)
void lock_port(void)
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 RAD2DXLPOS(rad)
#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)
#define REG_LENGTH_WORD
Definition: joint_control.h:30
uint16_t position_i_gain
void registerHandle(const JointStateHandle &handle)
void init_joint_params(ST_JOINT_PARAM &param, int table_id, int value)
uint8_t max_vol_limit
Definition: joint_control.h:97
ros::Time tempTime
bool sleep()
uint16_t velocity_p_gain
void set_param_delay_time(uint8_t dxl_id, int val)
uint8_t min_vol_limit
Definition: joint_control.h:98
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
Definition: joint_control.h:91
dynamixel::GroupBulkWrite * writeGoalGroup
void set_param_moving_threshold(uint8_t dxl_id, int val)
uint16_t velocity_i_gain
virtual int write4ByteTxRx(PortHandler *port, uint8_t id, uint16_t address, uint32_t data, uint8_t *error=0)=0
#define LEN_PRESENT_VEL
bool read(ros::Time, ros::Duration)
#define ADDR_MAX_VOL_LIMIT
dynamixel::GroupBulkWrite * writePosGoalGroup
#define LEN_PRESENT_TEMP
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
uint16_t position_d_gain
bool getJointLimits(urdf::JointConstSharedPtr urdf_joint, JointLimits &limits)
void unlock_port(void)
static Time now()
#define REG_LENGTH_BYTE
Definition: joint_control.h:29
void set_param_vel_gain(uint8_t dxl_id, int p, int i)
uint8_t drive_mode
Definition: joint_control.h:92
#define ADDR_INDIRECT_TOP
hardware_interface::PositionJointInterface joint_pos_if
#define TORQUE_ENABLE
virtual int read4ByteTxRx(PortHandler *port, uint8_t id, uint16_t address, uint32_t *data, uint8_t *error=0)=0
#define LEN_GOAL_CURRENT
#define ADDR_INDIRECT_DXLID
#define ADDR_INDIRECT_CURRENT
uint8_t operation_mode
Definition: joint_control.h:93
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_OPE_MODE
#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


sciurus17_control
Author(s): Hiroyuki Nomura
autogenerated on Sun Oct 2 2022 02:21:42