dynamixel_workbench.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright 2018 ROBOTIS CO., LTD.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16 
17 /* Authors: Taehun Lim (Darby), Ryan Shim */
18 
19 #include "../../include/dynamixel_workbench_toolbox/dynamixel_workbench.h"
20 
21 static const uint8_t WHEEL_MODE = 1;
22 static const uint8_t JOINT_MODE = 2;
23 
24 static const uint8_t CURRENT_CONTROL_MODE = 0;
25 static const uint8_t VELOCITY_CONTROL_MODE = 1;
26 static const uint8_t POSITION_CONTROL_MODE = 3;
27 static const uint8_t EXTENDED_POSITION_CONTROL_MODE = 4;
28 static const uint8_t CURRENT_BASED_POSITION_CONTROL_MODE = 5;
29 static const uint8_t PWM_CONTROL_MODE = 16;
30 static const uint8_t TORQUE_CONTROL_MODE = 100;
31 static const uint8_t MULTI_TURN_MODE = 101;
32 
33 static const char* model_name = NULL;
34 static const ModelInfo* model_info = NULL;
35 
37 
39 
40 bool DynamixelWorkbench::torque(uint8_t id, int32_t onoff, const char **log)
41 {
42  bool result = false;
43 
44  result = itemWrite(id, "Torque_Enable", (int32_t)onoff, log);
45  if (result == false)
46  {
47  if (log != NULL) *log = "[DynamixelWorkbench] Failed to change torque status!";
48  return false;
49  }
50 
51  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to change torque status!";
52  return result;
53 }
54 
55 bool DynamixelWorkbench::torqueOn(uint8_t id, const char **log)
56 {
57  bool result = false;
58 
59  result = torque(id, 1, log);
60 
61  return result;
62 }
63 
64 bool DynamixelWorkbench::torqueOff(uint8_t id, const char **log)
65 {
66  bool result = false;
67 
68  result = torque(id, 0, log);
69 
70  return result;
71 }
72 
73 bool DynamixelWorkbench::changeID(uint8_t id, uint8_t new_id, const char **log)
74 {
75  bool result = false;
76 
77  result = torqueOff(id, log);
78  if (result == false) return false;
79 
80  result = writeRegister(id, "ID", new_id, log);
81  if (result == false)
82  {
83  if (log != NULL) *log = "[DynamixelWorkbench] Failed to change ID!";
84  return false;
85  }
86  // millis(1000);
87 
88  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to change ID!";
89  return result;
90 }
91 
92 bool DynamixelWorkbench::changeBaudrate(uint8_t id, uint32_t new_baudrate, const char **log)
93 {
94  bool result = false;
95 
96  result = torqueOff(id, log);
97  if (result == false) return false;
98 
99  if (getProtocolVersion() == 1.0f)
100  {
101  switch (new_baudrate)
102  {
103  case 9600:
104  result = writeRegister(id, "Baud_Rate", 207, log);
105  break;
106 
107  case 19200:
108  result = writeRegister(id, "Baud_Rate", 103, log);
109  break;
110 
111  case 57600:
112  result = writeRegister(id, "Baud_Rate", 34, log);
113  break;
114 
115  case 115200:
116  result = writeRegister(id, "Baud_Rate", 16, log);
117  break;
118 
119  case 200000:
120  result = writeRegister(id, "Baud_Rate", 9, log);
121  break;
122 
123  case 250000:
124  result = writeRegister(id, "Baud_Rate", 7, log);
125  break;
126 
127  case 400000:
128  result = writeRegister(id, "Baud_Rate", 4, log);
129  break;
130 
131  case 500000:
132  result = writeRegister(id, "Baud_Rate", 3, log);
133  break;
134 
135  case 1000000:
136  result = writeRegister(id, "Baud_Rate", 1, log);
137  break;
138 
139  case 2250000:
140  result = writeRegister(id, "Baud_Rate", 250, log);
141  break;
142 
143  case 2500000:
144  result = writeRegister(id, "Baud_Rate", 251, log);
145  break;
146 
147  case 3000000:
148  result = writeRegister(id, "Baud_Rate", 252, log);
149  break;
150 
151  default:
152  result = writeRegister(id, "Baud_Rate", 34, log);
153  break;
154  }
155  }
156  else if (getProtocolVersion() == 2.0f)
157  {
158  switch (new_baudrate)
159  {
160  case 9600:
161  result = writeRegister(id, "Baud_Rate", 0, log);
162  break;
163 
164  case 57600:
165  result = writeRegister(id, "Baud_Rate", 1, log);
166  break;
167 
168  case 115200:
169  result = writeRegister(id, "Baud_Rate", 2, log);
170  break;
171 
172  case 1000000:
173  result = writeRegister(id, "Baud_Rate", 3, log);
174  break;
175 
176  case 2000000:
177  result = writeRegister(id, "Baud_Rate", 4, log);
178  break;
179 
180  case 3000000:
181  result = writeRegister(id, "Baud_Rate", 5, log);
182  break;
183 
184  case 4000000:
185  result = writeRegister(id, "Baud_Rate", 6, log);
186  break;
187 
188  case 4500000:
189  result = writeRegister(id, "Baud_Rate", 7, log);
190  break;
191 
192  case 10500000:
193  result = writeRegister(id, "Baud_Rate", 8, log);
194  break;
195 
196  default:
197  result = writeRegister(id, "Baud_Rate", 1, log);
198  break;
199  }
200  }
201 #if defined(__OPENCR__) || defined(__OPENCM904__)
202  delay(2000);
203 #else
204  usleep(1000*2000);
205 #endif
206 
207  if (result == false)
208  {
209  if (log != NULL) *log = "[DynamixelWorkbench] Failed to change Baud Rate!";
210  return result;
211  }
212 
213  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to change Baud Rate!";
214  return result;
215 }
216 
217 bool DynamixelWorkbench::changeProtocolVersion(uint8_t id, uint8_t version, const char **log)
218 {
219  bool result = false;
220 
221  model_name = getModelName(id, log);
222  if (model_name == NULL) return false;
223 
224  if (!strncmp(model_name, "MX-28-2", strlen("MX-28-2")) ||
225  !strncmp(model_name, "MX-64-2", strlen("MX-64-2")) ||
226  !strncmp(model_name, "MX-106-2", strlen("MX-106-2")) ||
227  !strncmp(model_name, "XM", strlen("XM")) ||
228  !strncmp(model_name, "XL430", strlen("XL430")) ||
229  !strncmp(model_name, "XC430", strlen("XC430")) ||
230  !strncmp(model_name, "XH", strlen("XH")) ||
231  !strncmp(model_name, "XW", strlen("XW")))
232  {
233  result = writeRegister(id, "Protocol_Version", version, log);
234  if (result == false)
235  {
236  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set protocol version!";
237  return false;
238  }
239  }
240 
241  result = setPacketHandler((float)version, log);
242 
243  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set protocol version!";
244  return result;
245 }
246 
247 bool DynamixelWorkbench::itemWrite(uint8_t id, const char *item_name, int32_t data, const char **log)
248 {
249  return writeRegister(id, item_name, data, log);
250 }
251 
252 bool DynamixelWorkbench::itemRead(uint8_t id, const char *item_name, int32_t *data, const char **log)
253 {
254  return readRegister(id, item_name, data, log);
255 }
256 
257 bool DynamixelWorkbench::led(uint8_t id, int32_t onoff, const char **log)
258 {
259  bool result = false;
260 
261  result = writeRegister(id, "LED", onoff, log);
262  if (result == false)
263  {
264  if (log != NULL) *log = "[DynamixelWorkbench] Failed to change led status!";
265  return false;
266  }
267 
268  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to change led status!";
269  return result;
270 }
271 
272 bool DynamixelWorkbench::ledOn(uint8_t id, const char **log)
273 {
274  bool result = false;
275 
276  result = led(id, 1, log);
277 
278  return result;
279 }
280 
281 bool DynamixelWorkbench::ledOff(uint8_t id, const char **log)
282 {
283  bool result = false;
284 
285  result = led(id, 0, log);
286 
287  return result;
288 }
289 
290 bool DynamixelWorkbench::setNormalDirection(uint8_t id, const char **log)
291 {
292  bool result = false;
293  int32_t data = 0;
294 
295  model_name = getModelName(id, log);
296  if (model_name == NULL) return false;
297 
298  if (!strncmp(model_name, "MX-28-2", strlen("MX-28-2")) ||
299  !strncmp(model_name, "MX-64-2", strlen("MX-64-2")) ||
300  !strncmp(model_name, "MX-106-2", strlen("MX-106-2")) ||
301  !strncmp(model_name, "XM", strlen("XM")) ||
302  !strncmp(model_name, "XL430", strlen("XL430")) ||
303  !strncmp(model_name, "XC430", strlen("XC430")) ||
304  !strncmp(model_name, "XH", strlen("XH")) ||
305  !strncmp(model_name, "XW", strlen("XW")))
306  {
307  result = readRegister(id, "Drive_Mode", &data, log);
308 
309  data = data & 0b00000100;
310  result = writeRegister(id, "Drive_Mode", data, log);
311  if (result == false)
312  {
313  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set normal direction!";
314  return false;
315  }
316  }
317 
318  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set normal direction!";
319  return result;
320 }
321 
322 bool DynamixelWorkbench::setReverseDirection(uint8_t id, const char **log)
323 {
324  bool result = false;
325  int32_t data = 0;
326 
327  model_name = getModelName(id, log);
328  if (model_name == NULL) return false;
329 
330  if (!strncmp(model_name, "MX-28-2", strlen("MX-28-2")) ||
331  !strncmp(model_name, "MX-64-2", strlen("MX-64-2")) ||
332  !strncmp(model_name, "MX-106-2", strlen("MX-106-2")) ||
333  !strncmp(model_name, "XM", strlen("XM")) ||
334  !strncmp(model_name, "XL430", strlen("XL430")) ||
335  !strncmp(model_name, "XC430", strlen("XC430")) ||
336  !strncmp(model_name, "XH", strlen("XH")) ||
337  !strncmp(model_name, "XW", strlen("XW")))
338  {
339  result = readRegister(id, "Drive_Mode", &data, log);
340 
341  data = data | 0b00000001;
342  result = writeRegister(id, "Drive_Mode", data, log);
343  if (result == false)
344  {
345  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set reverse direction!";
346  return false;
347  }
348  }
349 
350  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set reverse direction!";
351  return result;
352 }
353 
354 bool DynamixelWorkbench::setVelocityBasedProfile(uint8_t id, const char **log)
355 {
356  bool result = false;
357  int32_t data = 0;
358 
359  model_name = getModelName(id, log);
360  if (model_name == NULL) return false;
361 
362  if (!strncmp(model_name, "MX-28-2", strlen("MX-28-2")) ||
363  !strncmp(model_name, "MX-64-2", strlen("MX-64-2")) ||
364  !strncmp(model_name, "MX-106-2", strlen("MX-106-2")) ||
365  !strncmp(model_name, "XM", strlen("XM")) ||
366  !strncmp(model_name, "XL430", strlen("XL430")) ||
367  !strncmp(model_name, "XC430", strlen("XC430")) ||
368  !strncmp(model_name, "XH", strlen("XH")) ||
369  !strncmp(model_name, "XW", strlen("XW")))
370  {
371  result = readRegister(id, "Drive_Mode", &data, log);
372 
373  data = data & 0b00000001;
374  result = writeRegister(id, "Drive_Mode", data, log);
375  if (result == false)
376  {
377  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set velocity based profile!";
378  return false;
379  }
380  }
381 
382  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set velocity based profile!";
383  return result;
384 }
385 
386 bool DynamixelWorkbench::setTimeBasedProfile(uint8_t id, const char **log)
387 {
388  bool result = false;
389  int32_t data = 0;
390 
391  model_name = getModelName(id, log);
392  if (model_name == NULL) return false;
393 
394  if (!strncmp(model_name, "MX-28-2", strlen("MX-28-2")) ||
395  !strncmp(model_name, "MX-64-2", strlen("MX-64-2")) ||
396  !strncmp(model_name, "MX-106-2", strlen("MX-106-2")) ||
397  !strncmp(model_name, "XM", strlen("XM")) ||
398  !strncmp(model_name, "XL430", strlen("XL430")) ||
399  !strncmp(model_name, "XC430", strlen("XC430")) ||
400  !strncmp(model_name, "XH", strlen("XH")) ||
401  !strncmp(model_name, "XW", strlen("XW")))
402  {
403  result = readRegister(id, "Drive_Mode", &data, log);
404 
405  data = data | 0b00000100;
406  result = writeRegister(id, "Drive_Mode", data, log);
407  if (result == false)
408  {
409  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set time based profile!";
410  return false;
411  }
412  }
413 
414  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set time based profile!";
415  return result;
416 }
417 
418 bool DynamixelWorkbench::setSecondaryID(uint8_t id, uint8_t secondary_id, const char **log)
419 {
420  bool result = false;
421 
422  model_name = getModelName(id, log);
423  if (model_name == NULL) return false;
424 
425  if (!strncmp(model_name, "MX-28-2", strlen("MX-28-2")) ||
426  !strncmp(model_name, "MX-64-2", strlen("MX-64-2")) ||
427  !strncmp(model_name, "MX-106-2", strlen("MX-106-2")) ||
428  !strncmp(model_name, "XM", strlen("XM")) ||
429  !strncmp(model_name, "XL430", strlen("XL430")) ||
430  !strncmp(model_name, "XC430", strlen("XC430")) ||
431  !strncmp(model_name, "XH", strlen("XH")) ||
432  !strncmp(model_name, "XW", strlen("XW")) ||
433  !strncmp(model_name, "RH", strlen("RH")))
434  {
435  result = torqueOff(id, log);
436  if (result == false) return false;
437 
438  result = writeRegister(id, "Secondary_ID", secondary_id, log);
439  if (result == false)
440  {
441  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set secondary ID!";
442  return false;
443  }
444  }
445 
446  // millis(1000);
447 
448  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set secondary ID!";
449  return result;
450 }
451 
452 bool DynamixelWorkbench::setPositionControlMode(uint8_t id, const char **log)
453 {
454  bool result = false;
455 
456  result = setOperatingMode(id, POSITION_CONTROL_MODE, log);
457 
458  if (result == false)
459  {
460  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set Position Control Mode!";
461  return false;
462  }
463 
464  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set Position Control Mode!";
465  return result;
466 }
467 
468 bool DynamixelWorkbench::setVelocityControlMode(uint8_t id, const char **log)
469 {
470  bool result = false;
471 
472  result = setOperatingMode(id, VELOCITY_CONTROL_MODE, log);
473 
474  if (result == false)
475  {
476  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set Velocity Control Mode!";
477  return false;
478  }
479 
480  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set Velocity Control Mode!";
481  return result;
482 }
483 
484 bool DynamixelWorkbench::setCurrentControlMode(uint8_t id, const char **log)
485 {
486  bool result = false;
487 
488  result = setOperatingMode(id, CURRENT_CONTROL_MODE, log);
489 
490  if (result == false)
491  {
492  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set Current Control Mode!";
493  return false;
494  }
495 
496  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set Current Control Mode!";
497  return result;
498 }
499 
500 bool DynamixelWorkbench::setTorqueControlMode(uint8_t id, const char **log)
501 {
502  bool result = false;
503 
504  result = setOperatingMode(id, TORQUE_CONTROL_MODE, log);
505 
506  if (result == false)
507  {
508  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set Torque Control Mode!";
509  return false;
510  }
511 
512  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set Torque Control Mode!";
513  return result;
514 }
515 
516 bool DynamixelWorkbench::setExtendedPositionControlMode(uint8_t id, const char **log)
517 {
518  bool result = false;
519 
521 
522  if (result == false)
523  {
524  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set Extended Position Control Mode!";
525  return false;
526  }
527 
528  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set Extended Position Control Mode!";
529  return result;
530 }
531 
532 bool DynamixelWorkbench::setMultiTurnControlMode(uint8_t id, const char **log)
533 {
534  bool result = false;
535 
536  result = setOperatingMode(id, MULTI_TURN_MODE, log);
537 
538  if (result == false)
539  {
540  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set Multi-Turn Control Mode!";
541  return false;
542  }
543 
544  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set Multi-Turn Control Mode!";
545  return result;
546 }
547 
549 {
550  bool result = false;
551 
553 
554  if (result == false)
555  {
556  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set Current Based Position Control Mode!";
557  return false;
558  }
559 
560  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set Current Based Position Control Mode!";
561  return result;
562 }
563 
564 bool DynamixelWorkbench::setPWMControlMode(uint8_t id, const char **log)
565 {
566  bool result = false;
567 
568  result = setOperatingMode(id, PWM_CONTROL_MODE, log);
569 
570  if (result == false)
571  {
572  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set PWM Control Mode!";
573  return false;
574  }
575 
576  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set PWM Control Mode!";
577  return result;
578 }
579 
580 bool DynamixelWorkbench::setOperatingMode(uint8_t id, uint8_t index, const char **log)
581 {
582  bool result = false;
583 
584  model_name = getModelName(id, log);
585  if (model_name == NULL) return false;
586 
587  if (getProtocolVersion() == 1.0)
588  {
589  if (index == POSITION_CONTROL_MODE)
590  {
591  if (!strncmp(model_name, "MX-28-2", strlen("MX-28-2")) ||
592  !strncmp(model_name, "MX-64-2", strlen("MX-64-2")) ||
593  !strncmp(model_name, "MX-106-2", strlen("MX-106-2")) ||
594  !strncmp(model_name, "XL430", strlen("XL430")) ||
595  !strncmp(model_name, "XC430", strlen("XC430")) ||
596  !strncmp(model_name, "XM", strlen("XM")) ||
597  !strncmp(model_name, "XH", strlen("XH")) ||
598  !strncmp(model_name, "XW", strlen("XW")) ||
599  !strncmp(model_name, "PRO", strlen("PRO")) ||
600  !strncmp(model_name, "RH", strlen("RH")))
601  {
602  result = writeRegister(id, "Operating_Mode", POSITION_CONTROL_MODE, log);
603  }
604  else if (!strncmp(model_name, "AX", 2) || !strncmp(model_name, "RX", 2))
605  {
606  result = writeRegister(id, "CW_Angle_Limit", 0, log);
607  result = writeRegister(id, "CCW_Angle_Limit", 1023, log);
608  }
609  else
610  {
611  result = writeRegister(id, "CW_Angle_Limit", 0, log);
612  result = writeRegister(id, "CCW_Angle_Limit", 4095, log);
613  }
614  }
615  else if (index == VELOCITY_CONTROL_MODE)
616  {
617  if (!strncmp(model_name, "MX-28-2", strlen("MX-28-2")) ||
618  !strncmp(model_name, "MX-64-2", strlen("MX-64-2")) ||
619  !strncmp(model_name, "MX-106-2", strlen("MX-106-2")) ||
620  !strncmp(model_name, "XL430", strlen("XL430")) ||
621  !strncmp(model_name, "XC430", strlen("XC430")) ||
622  !strncmp(model_name, "XM", strlen("XM")) ||
623  !strncmp(model_name, "XH", strlen("XH")) ||
624  !strncmp(model_name, "XW", strlen("XW")) ||
625  !strncmp(model_name, "PRO", strlen("PRO")))
626  {
627  result = writeRegister(id, "Operating_Mode", VELOCITY_CONTROL_MODE);
628  }
629  else
630  {
631  result = writeRegister(id, "CW_Angle_Limit", 0, log);
632  result = writeRegister(id, "CCW_Angle_Limit", 0, log);
633  }
634  }
635  else if (index == CURRENT_CONTROL_MODE)
636  {
637  if (!strncmp(model_name, "XM", strlen("XM")) ||
638  !strncmp(model_name, "XH", strlen("XH")) ||
639  !strncmp(model_name, "XW", strlen("XW")) ||
640  !strncmp(model_name, "MX-64-2", strlen("MX-64-2")) ||
641  !strncmp(model_name, "MX-106-2", strlen("MX-106-2")) ||
642  !strncmp(model_name, "RH", strlen("RH")))
643  {
644  result = writeRegister(id, "Operating_Mode", CURRENT_CONTROL_MODE, log);
645  }
646  }
647  else if (index == TORQUE_CONTROL_MODE)
648  {
649  if (!strncmp(model_name, "MX-64", strlen("MX-64")) ||
650  !strncmp(model_name, "MX-106", strlen("MX-106")) )
651  {
652  result = writeRegister(id, "Torque_Control_Mode_Enable", 1, log);
653  }
654  }
655  else if (index == MULTI_TURN_MODE)
656  {
657  if (!strncmp(model_name, "MX-64", strlen("MX-64")) ||
658  !strncmp(model_name, "MX-106", strlen("MX-106")) )
659  {
660  result = writeRegister(id, "CW_Angle_Limit", 4095, log);
661  result = writeRegister(id, "CCW_Angle_Limit", 4095, log);
662  }
663  }
664  else if (index == CURRENT_BASED_POSITION_CONTROL_MODE)
665  {
666  if (!strncmp(model_name, "MX-64-2", strlen("MX-64-2")) ||
667  !strncmp(model_name, "MX-106-2", strlen("MX-106-2")) ||
668  !strncmp(model_name, "XM", strlen("XM")) ||
669  !strncmp(model_name, "XH", strlen("XH")) ||
670  !strncmp(model_name, "XW", strlen("XW")) ||
671  !strncmp(model_name, "RH", strlen("RH")))
672  {
673  result = writeRegister(id, "Operating_Mode", CURRENT_BASED_POSITION_CONTROL_MODE, log);
674  }
675  }
676  else if (index == PWM_CONTROL_MODE)
677  {
678  if (!strncmp(model_name, "MX-28-2", strlen("MX-28-2")) ||
679  !strncmp(model_name, "MX-64-2", strlen("MX-64-2")) ||
680  !strncmp(model_name, "MX-106-2", strlen("MX-106-2")) ||
681  !strncmp(model_name, "XM", strlen("XM")) ||
682  !strncmp(model_name, "XH", strlen("XH")) ||
683  !strncmp(model_name, "XW", strlen("XW")))
684  {
685  result = writeRegister(id, "Operating_Mode", PWM_CONTROL_MODE, log);
686  }
687  }
688  }
689  else if (getProtocolVersion() == 2.0)
690  {
691  if (index == POSITION_CONTROL_MODE)
692  {
693  if (!strncmp(model_name, "XL-320", strlen("XL-320")))
694  result = writeRegister(id, "Control_Mode", JOINT_MODE, log);
695  else
696  result = writeRegister(id, "Operating_Mode", POSITION_CONTROL_MODE, log);
697  }
698  else if (index == VELOCITY_CONTROL_MODE)
699  {
700  if (!strncmp(model_name, "XL-320", strlen("XL-320")))
701  result = writeRegister(id, "Control_Mode", WHEEL_MODE, log);
702  else
703  result = writeRegister(id, "Operating_Mode", VELOCITY_CONTROL_MODE, log);
704  }
705  else if (index == CURRENT_CONTROL_MODE)
706  {
707  if (!strncmp(model_name, "XM", strlen("XM")) ||
708  !strncmp(model_name, "XH", strlen("XH")) ||
709  !strncmp(model_name, "XW", strlen("XW")) ||
710  !strncmp(model_name, "MX-64-2", strlen("MX-64-2")) ||
711  !strncmp(model_name, "MX-106-2", strlen("MX-106-2")) ||
712  !strncmp(model_name, "RH", strlen("RH")) ||
713  !strncmp(model_name, "PRO-PLUS", strlen("PRO-PLUS")))
714  {
715  result = writeRegister(id, "Operating_Mode", CURRENT_CONTROL_MODE, log);
716  }
717  }
718  else if (index == TORQUE_CONTROL_MODE)
719  {
720  if (!strncmp(model_name, "PRO", strlen("PRO")) ||
721  strncmp(model_name, "PRO-L42", strlen("PRO-L42")) )
722  {
723  result = writeRegister(id, "Operating_Mode", 0, log);
724  }
725  }
726  else if (index == EXTENDED_POSITION_CONTROL_MODE)
727  {
728  if (!strncmp(model_name, "PRO", strlen("PRO")) ||
729  strncmp(model_name, "PRO-L42", strlen("PRO-L42")) )
730  {
731  result = writeRegister(id, "Operating_Mode", EXTENDED_POSITION_CONTROL_MODE, log);
732  }
733  }
734  else if (index == CURRENT_BASED_POSITION_CONTROL_MODE)
735  {
736  if (!strncmp(model_name, "MX-64-2", strlen("MX-64-2")) ||
737  !strncmp(model_name, "MX-106-2", strlen("MX-106-2")) ||
738  !strncmp(model_name, "XM", strlen("XM")) ||
739  !strncmp(model_name, "XH", strlen("XH")) ||
740  !strncmp(model_name, "XW", strlen("XW")) ||
741  !strncmp(model_name, "RH", strlen("RH")))
742  {
743  result = writeRegister(id, "Operating_Mode", CURRENT_BASED_POSITION_CONTROL_MODE, log);
744  }
745  }
746  else if (index == PWM_CONTROL_MODE)
747  {
748  if (!strncmp(model_name, "MX-28-2", strlen("MX-28-2")) ||
749  !strncmp(model_name, "MX-64-2", strlen("MX-64-2")) ||
750  !strncmp(model_name, "MX-106-2", strlen("MX-106-2")) ||
751  !strncmp(model_name, "XM", strlen("XM")) ||
752  !strncmp(model_name, "XH", strlen("XH")) ||
753  !strncmp(model_name, "XW", strlen("XW")) ||
754  !strncmp(model_name, "XL430", strlen("XL430")) ||
755  !strncmp(model_name, "XC430", strlen("XC430")) ||
756  !strncmp(model_name, "PRO", strlen("PRO")))
757  {
758  result = writeRegister(id, "Operating_Mode", PWM_CONTROL_MODE, log);
759  }
760  }
761  }
762 
763  if (result == false)
764  {
765  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set Operating Mode!";
766  return false;
767  }
768 
769  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set Operating Mode!";
770  return result;
771 }
772 
773 
774 bool DynamixelWorkbench::jointMode(uint8_t id, int32_t velocity, int32_t acceleration, const char **log)
775 {
776  bool result = false;
777 
778  model_name = getModelName(id, log);
779  if (model_name == NULL) return false;
780 
781  result = torqueOff(id, log);
782  if (result == false) return false;
783 
784  result = setPositionControlMode(id, log);
785  if (result == false) return false;
786 
787  if (getProtocolVersion() == 1.0)
788  {
789  if (!strncmp(model_name, "MX-28-2", strlen("MX-28-2")) ||
790  !strncmp(model_name, "MX-64-2", strlen("MX-64-2")) ||
791  !strncmp(model_name, "MX-106-2", strlen("MX-106-2")) ||
792  !strncmp(model_name, "XL430", strlen("XL430")) ||
793  !strncmp(model_name, "XC430", strlen("XC430")) ||
794  !strncmp(model_name, "XM", strlen("XM")) ||
795  !strncmp(model_name, "XH", strlen("XH")) ||
796  !strncmp(model_name, "XW", strlen("XW")))
797  {
798  result = writeRegister(id, "Profile_Acceleration", acceleration, log);
799  result = writeRegister(id, "Profile_Velocity", velocity, log);
800  }
801  else if (!strncmp(model_name, "MX-28", strlen("MX-28")) ||
802  !strncmp(model_name, "MX-64", strlen("MX-64")) ||
803  !strncmp(model_name, "MX-106", strlen("MX-106")))
804  {
805  result = writeRegister(id, "Moving_Speed", velocity, log);
806  result = writeRegister(id, "Goal_Acceleration", acceleration, log);
807  }
808  else
809  {
810  result = writeRegister(id, "Moving_Speed", velocity, log);
811  }
812  }
813  else if (getProtocolVersion() == 2.0)
814  {
815  if (!strncmp(model_name, "XL-320", strlen("XL-320")))
816  {
817  result = writeRegister(id, "Moving_Speed", velocity, log);
818  }
819  else if (!strncmp(model_name, "PRO-M42-10-S260-R-A", strlen("PRO-M42-10-S260-R-A")) ||
820  !strncmp(model_name, "PRO-M54-40-S250-R-A", strlen("PRO-M54-40-S250-R-A")) ||
821  !strncmp(model_name, "PRO-M54-60-S250-R-A", strlen("PRO-M54-60-S250-R-A")) ||
822  !strncmp(model_name, "PRO-H42-20-S300-R-A", strlen("PRO-H42-20-S300-R-A")) ||
823  !strncmp(model_name, "PRO-H54-100-S500-R-A", strlen("PRO-H54-100-S500-R-A")) ||
824  !strncmp(model_name, "PRO-H54-200-S500-R-A", strlen("PRO-H54-200-S500-R-A")) ||
825  !strncmp(model_name, "PRO-PLUS", strlen("PRO-PLUS")))
826  {
827  result = writeRegister(id, "Profile_Acceleration", acceleration, log);
828  result = writeRegister(id, "Profile_Velocity", velocity, log);
829  }
830  else if (!strncmp(model_name, "PRO-L", strlen("PRO-L")) ||
831  !strncmp(model_name, "PRO-M", strlen("PRO-M")) ||
832  !strncmp(model_name, "PRO-H", strlen("PRO-H")))
833  {
834  result = writeRegister(id, "Goal_Velocity", velocity, log);
835  result = writeRegister(id, "Goal_Acceleration", acceleration, log);
836  }
837  else
838  {
839  result = writeRegister(id, "Profile_Acceleration", acceleration, log);
840  result = writeRegister(id, "Profile_Velocity", velocity, log);
841  }
842  }
843 
844  if (result == false)
845  {
846  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set Joint Mode!";
847  return false;
848  }
849 
850  result = torqueOn(id, log);
851  if (result == false) return false;
852 
853  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set Joint Mode!";
854  return result;
855 }
856 
857 bool DynamixelWorkbench::wheelMode(uint8_t id, int32_t acceleration, const char **log)
858 {
859  bool result = false;
860 
861  model_name = getModelName(id, log);
862  if (model_name == NULL) return false;
863 
864  result = torqueOff(id, log);
865  if (result == false) return false;
866 
867  result = setVelocityControlMode(id, log);
868  if (result == false) return false;
869 
870  if (getProtocolVersion() == 1.0)
871  {
872  if (!strncmp(model_name, "MX-28-2", strlen("MX-28-2")) ||
873  !strncmp(model_name, "MX-64-2", strlen("MX-64-2")) ||
874  !strncmp(model_name, "MX-106-2", strlen("MX-106-2")) ||
875  !strncmp(model_name, "XL430", strlen("XL430")) ||
876  !strncmp(model_name, "XC430", strlen("XC430")) ||
877  !strncmp(model_name, "XM", strlen("XM")) ||
878  !strncmp(model_name, "XH", strlen("XH")) ||
879  !strncmp(model_name, "XW", strlen("XW")))
880  {
881  result = writeRegister(id, "Profile_Acceleration", acceleration, log);
882  }
883  else if (!strncmp(model_name, "MX-28", strlen("MX-28")) ||
884  !strncmp(model_name, "MX-64", strlen("MX-64")) ||
885  !strncmp(model_name, "MX-106", strlen("MX-106")))
886  {
887  result = writeRegister(id, "Goal_Acceleration", acceleration, log);
888  }
889  }
890  else if (getProtocolVersion() == 2.0)
891  {
892  if (!strncmp(model_name, "PRO-PLUS", strlen("PRO-PLUS")))
893  {
894  result = writeRegister(id, "Profile_Acceleration", acceleration, log);
895  }
896  else if (!strncmp(model_name, "PRO", strlen("PRO")))
897  {
898  result = writeRegister(id, "Goal_Acceleration", acceleration, log);
899  }
900  else
901  {
902  result = writeRegister(id, "Profile_Acceleration", acceleration, log);
903  }
904  }
905 
906  if (result == false)
907  {
908  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set Wheel Mode!";
909  return false;
910  }
911 
912  result = torqueOn(id, log);
913  if (result == false) return false;
914 
915  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set Wheel Mode!";
916  return result;
917 }
918 
919 bool DynamixelWorkbench::currentBasedPositionMode(uint8_t id, int32_t current, const char **log)
920 {
921  bool result = false;
922 
923  model_name = getModelName(id, log);
924  if (model_name == NULL) return false;
925 
926  result = torqueOff(id, log);
927  if (result == false) return false;
928 
929  result = setCurrentBasedPositionControlMode(id, log);
930  if (result == false) return false;
931 
932  if (!strncmp(model_name, "MX-64-2", strlen("MX-64-2")) ||
933  !strncmp(model_name, "MX-106-2", strlen("MX-106-2")) ||
934  !strncmp(model_name, "XM", strlen("XM")) ||
935  !strncmp(model_name, "XH", strlen("XH")) ||
936  !strncmp(model_name, "XW", strlen("XW")) ||
937  !strncmp(model_name, "RH", strlen("RH")))
938  {
939  result = writeRegister(id, "Goal_Current", current, log);
940  }
941 
942  if (result == false)
943  {
944  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set Current Based Position Mode!";
945  return false;
946  }
947 
948  result = torqueOn(id, log);
949  if (result == false) return false;
950 
951  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set Current Based Position Wheel Mode!";
952  return result;
953 }
954 
955 //keep compatibility with older codes
956 bool DynamixelWorkbench::goalPosition(uint8_t id, int value, const char **log)
957 {
958 // goalPosition(id, (int32_t)value, log);
959 // }
960 
961 // bool DynamixelWorkbench::goalPosition(uint8_t id, int32_t value, const char **log)
962 // {
963  bool result = false;
964 
965  result = itemWrite(id, "Goal_Position", value, log);
966 
967  if (result == false)
968  {
969  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set goal position!";
970  return false;
971  }
972 
973  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set goal position!";
974  return result;
975 }
976 
977 //keep compatibility with older codes
978 bool DynamixelWorkbench::goalSpeed(uint8_t id, int value, const char **log)
979 {
980  bool result = false;
981  result = goalVelocity(id, (int32_t)value, log);
982  return result;
983 }
984 
985 //keep compatibility with older codes
986 bool DynamixelWorkbench::goalVelocity(uint8_t id, int value, const char **log)
987 {
988 // goalVelocity(id, (int32_t)value, log);
989 // }
990 
991 // bool DynamixelWorkbench::goalVelocity(uint8_t id, int32_t value, const char **log)
992 // {
993  bool result[2] = {false, false};
994 
995  if (getProtocolVersion() == 2.0f)
996  {
997  result[0] = writeRegister(id, "Goal_Velocity", value, log);
998  if (result[0] == false)
999  {
1000  if (value < 0)
1001  {
1002  value = (-1) * value;
1003  value |= 1024;
1004  }
1005  result[1] = writeRegister(id, "Moving_Speed", value, log);
1006  if (result[1] == false)
1007  {
1008  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set goal velocity!";
1009  return false;
1010  }
1011  else
1012  {
1013  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set goal velocity!";
1014  return true;
1015  }
1016  }
1017  else
1018  {
1019  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set goal velocity!";
1020  return true;
1021  }
1022  }
1023  else
1024  {
1025  result[0] = writeRegister(id, "Goal_Velocity", value, log);
1026  if (result[0] == false)
1027  {
1028  if (value < 0)
1029  {
1030  value = (-1) * value;
1031  value |= 1024;
1032  }
1033  result[1] = writeRegister(id, "Moving_Speed", value, log);
1034  if (result[1] == false)
1035  {
1036  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set goal velocity!";
1037  return false;
1038  }
1039  else
1040  {
1041  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set goal velocity!";
1042  return true;
1043  }
1044  }
1045  else
1046  {
1047  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set goal velocity!";
1048  return true;
1049  }
1050  }
1051 
1052  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set goal velocity!";
1053  return false;
1054 }
1055 
1056 bool DynamixelWorkbench::goalPosition(uint8_t id, float radian, const char **log)
1057 {
1058  bool result = 0;
1059  uint32_t value = 0;
1060 
1061  value = convertRadian2Value(id, radian);
1062 
1063  result = goalPosition(id, (int32_t)value, log);
1064  if (result == false)
1065  {
1066  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set goal position!";
1067  return false;
1068  }
1069 
1070  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set goal position!";
1071  return true;
1072 }
1073 
1074 bool DynamixelWorkbench::goalVelocity(uint8_t id, float velocity, const char **log)
1075 {
1076  bool result = 0;
1077  int32_t value = 0;
1078 
1079  value = convertVelocity2Value(id, velocity);
1080 
1081  result = goalVelocity(id, value, log);
1082  if (result == false)
1083  {
1084  if (log != NULL) *log = "[DynamixelWorkbench] Failed to set goal velocity!";
1085  return result;
1086  }
1087 
1088  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to set goal velocity!";
1089  return result;
1090 }
1091 
1092 bool DynamixelWorkbench::getPresentPositionData(uint8_t id, int32_t* data, const char **log)
1093 {
1094  bool result = 0;
1095  int32_t get_data = 0;
1096 
1097  result = readRegister(id, "Present_Position", &get_data, log);
1098  if (result == false)
1099  {
1100  if (log != NULL) *log = "[DynamixelWorkbench] Failed to get present position data!";
1101  return result;
1102  }
1103 
1104  *data = get_data;
1105 
1106  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to get present position data!";
1107  return result;
1108 }
1109 
1110 bool DynamixelWorkbench::getRadian(uint8_t id, float* radian, const char **log)
1111 {
1112  bool result = 0;
1113  int32_t get_data = 0;
1114 
1115  result = getPresentPositionData(id, &get_data, log);
1116  if (result == false)
1117  {
1118  if (log != NULL) *log = "[DynamixelWorkbench] Failed to get radian!";
1119  return result;
1120  }
1121 
1122  *radian = convertValue2Radian(id, get_data);
1123 
1124  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to get radian!";
1125  return result;
1126 }
1127 
1128 bool DynamixelWorkbench::getVelocity(uint8_t id, float* velocity, const char **log)
1129 {
1130  bool result = 0;
1131  int32_t get_data = 0;
1132 
1133  result = getPresentVelocityData(id, &get_data, log);
1134  if (result == false)
1135  {
1136  if (log != NULL) *log = "[DynamixelWorkbench] Failed to get velocity!";
1137  return result;
1138  }
1139 
1140  *velocity = convertValue2Velocity(id, get_data);
1141 
1142  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to get velocity!";
1143  return result;
1144 }
1145 
1146 bool DynamixelWorkbench::getPresentVelocityData(uint8_t id, int32_t* data, const char **log)
1147 {
1148  bool result = 0;
1149  int32_t get_data = 0;
1150 
1151  result = readRegister(id, "Present_Speed", &get_data, log);
1152  if (result == false)
1153  {
1154  if (log != NULL) *log = "[DynamixelWorkbench] Failed to get present speed data!";
1155  return result;
1156  }
1157 
1158  *data = get_data;
1159  if (log != NULL) *log = "[DynamixelWorkbench] Succeeded to get present speed data!";
1160  return result;
1161 }
1162 
1163 int32_t DynamixelWorkbench::convertRadian2Value(uint8_t id, float radian)
1164 {
1165  int32_t position = 0;
1166 
1167  model_info = getModelInfo(id);
1168  if (model_info == NULL) return false;
1169 
1170  if (radian > 0)
1171  {
1172  position = (radian * (model_info->value_of_max_radian_position - model_info->value_of_zero_radian_position) / model_info->max_radian) + model_info->value_of_zero_radian_position;
1173  }
1174  else if (radian < 0)
1175  {
1176  position = (radian * (model_info->value_of_min_radian_position - model_info->value_of_zero_radian_position) / model_info->min_radian) + model_info->value_of_zero_radian_position;
1177  }
1178  else
1179  {
1180  position = model_info->value_of_zero_radian_position;
1181  }
1182 
1183  return position;
1184 }
1185 
1186 float DynamixelWorkbench::convertValue2Radian(uint8_t id, int32_t value)
1187 {
1188  float radian = 0.0;
1189 
1190  model_info = getModelInfo(id);
1191  if (model_info == NULL) return false;
1192 
1193  if (value > model_info->value_of_zero_radian_position)
1194  {
1195  radian = (float)(value - model_info->value_of_zero_radian_position) * model_info->max_radian / (float)(model_info->value_of_max_radian_position - model_info->value_of_zero_radian_position);
1196  }
1197  else if (value < model_info->value_of_zero_radian_position)
1198  {
1199  radian = (float)(value - model_info->value_of_zero_radian_position) * model_info->min_radian / (float)(model_info->value_of_min_radian_position - model_info->value_of_zero_radian_position);
1200  }
1201 
1202  return radian;
1203 }
1204 
1205 int32_t DynamixelWorkbench::convertRadian2Value(float radian, int32_t max_position, int32_t min_position, float max_radian, float min_radian)
1206 {
1207  int32_t value = 0;
1208  int32_t zero_position = (max_position + min_position)/2;
1209 
1210  if (radian > 0)
1211  {
1212  value = (radian * (max_position - zero_position) / max_radian) + zero_position;
1213  }
1214  else if (radian < 0)
1215  {
1216  value = (radian * (min_position - zero_position) / min_radian) + zero_position;
1217  }
1218  else
1219  {
1220  value = zero_position;
1221  }
1222 
1223  return value;
1224 }
1225 
1226 float DynamixelWorkbench::convertValue2Radian(int32_t value, int32_t max_position, int32_t min_position, float max_radian, float min_radian)
1227 {
1228  float radian = 0.0;
1229  int32_t zero_position = (max_position + min_position)/2;
1230 
1231  if (value > zero_position)
1232  {
1233  radian = (float)(value - zero_position) * max_radian / (float)(max_position - zero_position);
1234  }
1235  else if (value < zero_position)
1236  {
1237  radian = (float)(value - zero_position) * min_radian / (float)(min_position - zero_position);
1238  }
1239 
1240  return radian;
1241 }
1242 
1243 int32_t DynamixelWorkbench::convertVelocity2Value(uint8_t id, float velocity)
1244 {
1245  int32_t value = 0;
1246  const float RPM2RADPERSEC = 0.104719755f;
1247 
1248  model_info = getModelInfo(id);
1249  if (model_info == NULL) return false;
1250 
1251  if (getProtocolVersion() == 1.0f)
1252  {
1253  if (strncmp(getModelName(id), "AX", strlen("AX")) == 0 ||
1254  strncmp(getModelName(id), "RX", strlen("RX")) == 0 ||
1255  strncmp(getModelName(id), "EX", strlen("EX")) == 0 ||
1256  strncmp(getModelName(id), "MX", strlen("MX")) == 0)
1257  {
1258  if (velocity == 0.0f) value = 0;
1259  else if (velocity < 0.0f) value = (velocity / (model_info->rpm * RPM2RADPERSEC));
1260  else if (velocity > 0.0f) value = (velocity / (model_info->rpm * RPM2RADPERSEC)) + 1023;
1261 
1262  return value;
1263  }
1264  }
1265  else if (getProtocolVersion() == 2.0f)
1266  {
1267  if (strcmp(getModelName(id), "XL-320") == 0)
1268  {
1269  if (velocity == 0.0f) value = 0;
1270  else if (velocity < 0.0f) value = (velocity / (model_info->rpm * RPM2RADPERSEC));
1271  else if (velocity > 0.0f) value = (velocity / (model_info->rpm * RPM2RADPERSEC)) + 1023;
1272 
1273  return value;
1274  }
1275  else
1276  {
1277  value = velocity / (model_info->rpm * RPM2RADPERSEC);
1278  }
1279 
1280  return value;
1281  }
1282 
1283  return 0;
1284 }
1285 
1286 float DynamixelWorkbench::convertValue2Velocity(uint8_t id, int32_t value)
1287 {
1288  float velocity = 0;
1289  const float RPM2RADPERSEC = 0.104719755f;
1290 
1291  model_info = getModelInfo(id);
1292  if (model_info == NULL) return false;
1293 
1294  if (getProtocolVersion() == 1.0f)
1295  {
1296  if (strncmp(getModelName(id), "AX", strlen("AX")) == 0 ||
1297  strncmp(getModelName(id), "RX", strlen("RX")) == 0 ||
1298  strncmp(getModelName(id), "EX", strlen("EX")) == 0 ||
1299  strncmp(getModelName(id), "MX", strlen("MX")) == 0)
1300  {
1301  if (value == 1023 || value == 0) velocity = 0.0f;
1302  else if (value > 0 && value < 1023) velocity = value * model_info->rpm * RPM2RADPERSEC;
1303  else if (value > 1023 && value < 2048) velocity = (value - 1023) * model_info->rpm * RPM2RADPERSEC * (-1.0f);
1304 
1305  return velocity;
1306  }
1307  }
1308  else if (getProtocolVersion() == 2.0f)
1309  {
1310  if (strcmp(getModelName(id), "XL-320") == 0)
1311  {
1312  if (value == 1023 || value == 0) velocity = 0.0f;
1313  else if (value > 0 && value < 1023) velocity = value * model_info->rpm * RPM2RADPERSEC;
1314  else if (value > 1023 && value < 2048) velocity = (value - 1023) * model_info->rpm * RPM2RADPERSEC * (-1.0f);
1315  }
1316  else
1317  {
1318  velocity = value * (model_info->rpm * RPM2RADPERSEC);
1319  }
1320 
1321  return velocity;
1322  }
1323 
1324  return 0.0f;
1325 }
1326 
1327 int16_t DynamixelWorkbench::convertCurrent2Value(uint8_t id, float current)
1328 {
1329  float CURRENT_UNIT = 2.69f; //Unit : mA, Ref : http://emanual.robotis.com/docs/en/dxl/x/xm430-w350/#goal-current102
1330 
1331  model_info = getModelInfo(id);
1332  if (model_info == NULL) return false;
1333 
1334  if (getProtocolVersion() == 1.0f)
1335  {
1336  return (current / CURRENT_UNIT);
1337  }
1338  else if (getProtocolVersion() == 2.0f)
1339  {
1340  if (strncmp(getModelName(id), "PRO-L", strlen("PRO-L")) == 0 ||
1341  strncmp(getModelName(id), "PRO-M", strlen("PRO-M")) == 0 ||
1342  strncmp(getModelName(id), "PRO-H", strlen("PRO-H")) == 0)
1343  {
1344  CURRENT_UNIT = 16.11328f;
1345  return (current / CURRENT_UNIT);
1346  }
1347  else if (strncmp(getModelName(id), "PRO-PLUS", strlen("PRO-PLUS")) == 0)
1348  {
1349  CURRENT_UNIT = 1.0f;
1350  return (current / CURRENT_UNIT);
1351  }
1352  else
1353  {
1354  return (current / CURRENT_UNIT);
1355  }
1356  }
1357 
1358  return (current / CURRENT_UNIT);
1359 }
1360 
1362 {
1363  int16_t value = 0;
1364  const float CURRENT_UNIT = 2.69f; //Unit : mA, Ref : http://emanual.robotis.com/docs/en/dxl/x/xm430-w350/#goal-current102
1365 
1366  value = current / CURRENT_UNIT;
1367 
1368  return value;
1369 }
1370 
1371 float DynamixelWorkbench::convertValue2Current(uint8_t id, int16_t value)
1372 {
1373  float current = 0;
1374  float CURRENT_UNIT = 2.69f; //Unit : mA, Ref : http://emanual.robotis.com/docs/en/dxl/x/xm430-w350/#goal-current102
1375 
1376  model_info = getModelInfo(id);
1377  if (model_info == NULL) return false;
1378 
1379  if (getProtocolVersion() == 1.0f)
1380  {
1381  current = (int16_t)value * CURRENT_UNIT;
1382  return current;
1383  }
1384  else if (getProtocolVersion() == 2.0f)
1385  {
1386  if (strncmp(getModelName(id), "PRO-L", strlen("PRO-L")) == 0 ||
1387  strncmp(getModelName(id), "PRO-M", strlen("PRO-M")) == 0 ||
1388  strncmp(getModelName(id), "PRO-H", strlen("PRO-H")) == 0)
1389  {
1390  CURRENT_UNIT = 16.11328f;
1391  current = (int16_t)value * CURRENT_UNIT;
1392  return current;
1393  }
1394  else if (strncmp(getModelName(id), "PRO-PLUS", strlen("PRO-PLUS")) == 0)
1395  {
1396  CURRENT_UNIT = 1.0f;
1397  current = (int16_t)value * CURRENT_UNIT;
1398  return current;
1399  }
1400  else
1401  {
1402  current = (int16_t)value * CURRENT_UNIT;
1403  return current;
1404  }
1405  }
1406 
1407  current = (int16_t)value * CURRENT_UNIT;
1408 
1409  return current;
1410 }
1411 
1413 {
1414  float current = 0;
1415  const float CURRENT_UNIT = 2.69f; //Unit : mA, Ref : http://emanual.robotis.com/docs/en/dxl/x/xm430-w350/#goal-current102
1416 
1417  current = (int16_t)value * CURRENT_UNIT;
1418 
1419  return current;
1420 }
1421 
1423 {
1424  float load = 0;
1425  const float LOAD_UNIT = 0.1f; //Unit : %, Ref : http://emanual.robotis.com/docs/en/dxl/mx/mx-28/#present-load
1426 
1427  if (value == 1023 || value == 0) load = 0.0f;
1428  else if (value > 0 && value < 1023) load = value * LOAD_UNIT;
1429  else if (value > 1023 && value < 2048) load = (value - 1023) * LOAD_UNIT * (-1.0f);
1430 
1431  return load;
1432 }
bool setOperatingMode(uint8_t id, uint8_t index, const char **log=NULL)
bool torqueOff(uint8_t id, const char **log=NULL)
bool changeID(uint8_t id, uint8_t new_id, const char **log=NULL)
bool setCurrentBasedPositionControlMode(uint8_t id, const char **log=NULL)
static const uint8_t CURRENT_CONTROL_MODE
bool setSecondaryID(uint8_t id, uint8_t secondary_id, const char **log=NULL)
f
bool getVelocity(uint8_t id, float *velocity, const char **log=NULL)
bool setCurrentControlMode(uint8_t id, const char **log=NULL)
bool setPacketHandler(float protocol_version, const char **log=NULL)
static const uint8_t EXTENDED_POSITION_CONTROL_MODE
bool changeProtocolVersion(uint8_t id, uint8_t version, const char **log=NULL)
bool torque(uint8_t id, int32_t onoff, const char **log=NULL)
int64_t value_of_min_radian_position
int32_t convertRadian2Value(uint8_t id, float radian)
bool itemWrite(uint8_t id, const char *item_name, int32_t data, const char **log=NULL)
bool torqueOn(uint8_t id, const char **log=NULL)
bool readRegister(uint8_t id, uint16_t address, uint16_t length, uint32_t *data, const char **log=NULL)
const char * getModelName(uint8_t id, const char **log=NULL)
bool writeRegister(uint8_t id, uint16_t address, uint16_t length, uint8_t *data, const char **log=NULL)
static const char * model_name
int32_t convertVelocity2Value(uint8_t id, float velocity)
bool getRadian(uint8_t id, float *radian, const char **log=NULL)
bool ledOn(uint8_t id, const char **log=NULL)
float convertValue2Current(uint8_t id, int16_t value)
static const uint8_t JOINT_MODE
bool setTimeBasedProfile(uint8_t id, const char **log=NULL)
float convertValue2Load(int16_t value)
static const uint8_t POSITION_CONTROL_MODE
bool getPresentVelocityData(uint8_t id, int32_t *data, const char **log=NULL)
bool goalVelocity(uint8_t id, int value, const char **log=NULL)
int16_t convertCurrent2Value(uint8_t id, float current)
int64_t value_of_max_radian_position
float max_radian
bool setExtendedPositionControlMode(uint8_t id, const char **log=NULL)
bool setMultiTurnControlMode(uint8_t id, const char **log=NULL)
float convertValue2Radian(uint8_t id, int32_t value)
bool setVelocityControlMode(uint8_t id, const char **log=NULL)
bool getPresentPositionData(uint8_t id, int32_t *data, const char **log=NULL)
bool setPWMControlMode(uint8_t id, const char **log=NULL)
static const uint8_t VELOCITY_CONTROL_MODE
static const uint8_t MULTI_TURN_MODE
int64_t value_of_zero_radian_position
const ModelInfo * getModelInfo(uint8_t id, const char **log=NULL)
bool goalSpeed(uint8_t id, int value, const char **log=NULL)
bool goalPosition(uint8_t id, int value, const char **log=NULL)
static const uint8_t WHEEL_MODE
bool changeBaudrate(uint8_t id, uint32_t new_baudrate, const char **log=NULL)
bool setNormalDirection(uint8_t id, const char **log=NULL)
bool itemRead(uint8_t id, const char *item_name, int32_t *data, const char **log=NULL)
bool wheelMode(uint8_t id, int32_t acceleration=0, const char **log=NULL)
bool setPositionControlMode(uint8_t id, const char **log=NULL)
static const uint8_t CURRENT_BASED_POSITION_CONTROL_MODE
bool setTorqueControlMode(uint8_t id, const char **log=NULL)
static const uint8_t PWM_CONTROL_MODE
static const ModelInfo * model_info
float convertValue2Velocity(uint8_t id, int32_t value)
bool setReverseDirection(uint8_t id, const char **log=NULL)
bool jointMode(uint8_t id, int32_t velocity=0, int32_t acceleration=0, const char **log=NULL)
static const uint8_t TORQUE_CONTROL_MODE
float getProtocolVersion(void)
float min_radian
bool led(uint8_t id, int32_t onoff, const char **log=NULL)
bool ledOff(uint8_t id, const char **log=NULL)
bool currentBasedPositionMode(uint8_t id, int32_t current=0, const char **log=NULL)
bool setVelocityBasedProfile(uint8_t id, const char **log=NULL)


dynamixel_workbench_toolbox
Author(s): Darby Lim , Ryan Shim
autogenerated on Mon Sep 28 2020 03:37:05