dynamixel.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright 2019 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: Darby Lim, Hye-Jong KIM, Ryan Shim, Yong-Ho Na */
18 
19 #include "../include/open_manipulator_p_libs/dynamixel.h"
20 
21 using namespace dynamixel;
22 using namespace robotis_manipulator;
23 
24 /*****************************************************************************
25 ** Joint Dynamixel Control Functions
26 *****************************************************************************/
27 void JointDynamixel::init(std::vector<uint8_t> actuator_id, const void *arg)
28 {
29  STRING *get_arg_ = (STRING *)arg;
30 
31  bool result = JointDynamixel::initialize(actuator_id ,get_arg_[0], get_arg_[1]);
32 
33  if (result == false)
34  return;
35 }
36 
37 void JointDynamixel::setMode(std::vector<uint8_t> actuator_id, const void *arg)
38 {
39  bool result = false;
40  // const char* log = NULL;
41 
42  STRING *get_arg_ = (STRING *)arg;
43 
44  if (get_arg_[0] == "position_mode" || get_arg_[0] == "current_based_position_mode")
45  {
46  result = JointDynamixel::setOperatingMode(actuator_id, get_arg_[0]);
47  if (result == false)
48  return;
49 
50  result = JointDynamixel::setSDKHandler(actuator_id.at(0));
51  if (result == false)
52  return;
53  }
54  else
55  {
56  result = JointDynamixel::writeProfileValue(actuator_id, get_arg_[0], std::atoi(get_arg_[1].c_str()));
57  if (result == false)
58  return;
59  }
60  return;
61 }
62 
63 std::vector<uint8_t> JointDynamixel::getId()
64 {
65  return dynamixel_.id;
66 }
67 
69 {
70  const char* log = NULL;
71  bool result = false;
72 
73  for (uint32_t index = 0; index < dynamixel_.num; index++)
74  {
75  result = dynamixel_workbench_->torqueOn(dynamixel_.id.at(index), &log);
76  if (result == false)
77  {
78  log::error(log);
79  }
80  }
81  enabled_state_ = true;
82 }
83 
85 {
86  const char* log = NULL;
87  bool result = false;
88 
89  for (uint32_t index = 0; index < dynamixel_.num; index++)
90  {
91  result = dynamixel_workbench_->torqueOff(dynamixel_.id.at(index), &log);
92  if (result == false)
93  {
94  log::error(log);
95  }
96  }
97  enabled_state_ = false;
98 }
99 
100 bool JointDynamixel::sendJointActuatorValue(std::vector<uint8_t> actuator_id, std::vector<robotis_manipulator::ActuatorValue> value_vector)
101 {
102  bool result = false;
103 
104  std::vector<double> radian_vector;
105  for(uint32_t index = 0; index < value_vector.size(); index++)
106  {
107  radian_vector.push_back(value_vector.at(index).position);
108  }
109  result = JointDynamixel::writeGoalPosition(actuator_id, radian_vector);
110  if (result == false)
111  return false;
112 
113  return true;
114 }
115 
116 std::vector<robotis_manipulator::ActuatorValue> JointDynamixel::receiveJointActuatorValue(std::vector<uint8_t> actuator_id)
117 {
118  return JointDynamixel::receiveAllDynamixelValue(actuator_id);
119 }
120 
121 
122 /*****************************************************************************
123 ** Functions called in Joint Dynamixel Control Functions
124 *****************************************************************************/
125 bool JointDynamixel::initialize(std::vector<uint8_t> actuator_id, STRING dxl_device_name, STRING dxl_baud_rate)
126 {
127  bool result = false;
128  const char* log = NULL;
129 
130  STRING return_delay_time_st = "Return_Delay_Time";
131  const char * return_delay_time_char = return_delay_time_st.c_str();
132 
133  dynamixel_.id = actuator_id;
134  dynamixel_.num = actuator_id.size();
135 
136  dynamixel_workbench_ = new DynamixelWorkbench;
137 
138  result = dynamixel_workbench_->init(dxl_device_name.c_str(), std::atoi(dxl_baud_rate.c_str()), &log);
139  if (result == false)
140  {
141  log::error(log);
142  }
143 
144  uint16_t get_model_number;
145  for (uint8_t index = 0; index < dynamixel_.num; index++)
146  {
147  uint8_t id = dynamixel_.id.at(index);
148  result = dynamixel_workbench_->ping(id, &get_model_number, &log);
149 
150  if (result == false)
151  {
152  log::error(log);
153  log::error("Please check your Dynamixel ID");
154  }
155  else
156  {
157  char str[100];
158  sprintf(str, "Joint Dynamixel ID : %d, Model Name : %s", id, dynamixel_workbench_->getModelName(id));
159  log::println(str);
160 
162  // result = dynamixel_workbench_->setVelocityBasedProfile(id, &log);
163  // if(result == false)
164  // {
165  // log::error(log);
166  // log::error("Please check your Dynamixel firmware version (v38~)");
167  // }
168 
169  result = dynamixel_workbench_->writeRegister(id, return_delay_time_char, 0, &log);
170  if (result == false)
171  {
172  log::error(log);
173  log::error("Please check your Dynamixel firmware version");
174  }
175  }
176  }
177  return true;
178 }
179 
180 bool JointDynamixel::setOperatingMode(std::vector<uint8_t> actuator_id, STRING dynamixel_mode)
181 {
182  const char* log = NULL;
183  bool result = false;
184 
185  const uint32_t velocity = 0;
186  const uint32_t acceleration = 0;
187  const uint32_t current = 0;
188 
189  if (dynamixel_mode == "position_mode")
190  {
191  for (uint8_t num = 0; num < actuator_id.size(); num++)
192  {
193  result = dynamixel_workbench_->jointMode(actuator_id.at(num), velocity, acceleration, &log);
194  if (result == false)
195  {
196  log::error(log);
197  }
198  }
199  }
200  else if (dynamixel_mode == "current_based_position_mode")
201  {
202  for (uint8_t num = 0; num < actuator_id.size(); num++)
203  {
204  result = dynamixel_workbench_->currentBasedPositionMode(actuator_id.at(num), current, &log);
205  if (result == false)
206  {
207  log::error(log);
208  }
209  }
210  }
211  else
212  {
213  for (uint8_t num = 0; num < actuator_id.size(); num++)
214  {
215  result = dynamixel_workbench_->jointMode(actuator_id.at(num), velocity, acceleration, &log);
216  if (result == false)
217  {
218  log::error(log);
219  }
220  }
221  }
222 
223  return true;
224 }
225 
226 bool JointDynamixel::setSDKHandler(uint8_t actuator_id)
227 {
228  bool result = false;
229  const char* log = NULL;
230 
231  result = dynamixel_workbench_->addSyncWriteHandler(actuator_id, "Goal_Position", &log);
232  if (result == false)
233  {
234  log::error(log);
235  }
236 
237  result = dynamixel_workbench_->addSyncReadHandler(ADDR_PRESENT_CURRENT_2,
239  &log);
240  if (result == false)
241  {
242  log::error(log);
243  }
244 
245  return true;
246 }
247 
248 bool JointDynamixel::writeProfileValue(std::vector<uint8_t> actuator_id, STRING profile_mode, uint32_t value)
249 {
250  const char* log = NULL;
251  bool result = false;
252 
253  const char * char_profile_mode = profile_mode.c_str();
254 
255  for (uint8_t num = 0; num < actuator_id.size(); num++)
256  {
257  result = dynamixel_workbench_->writeRegister(actuator_id.at(num), char_profile_mode, value, &log);
258  if (result == false)
259  {
260  log::error(log);
261  }
262  }
263 
264  return true;
265 }
266 
267 bool JointDynamixel::writeGoalPosition(std::vector<uint8_t> actuator_id, std::vector<double> radian_vector)
268 {
269  bool result = false;
270  const char* log = NULL;
271 
272  uint8_t id_array[actuator_id.size()];
273  int32_t goal_position[actuator_id.size()];
274 
275  for (uint8_t index = 0; index < actuator_id.size(); index++)
276  {
277  id_array[index] = actuator_id.at(index);
278  goal_position[index] = dynamixel_workbench_->convertRadian2Value(actuator_id.at(index), radian_vector.at(index));
279  }
280 
281  result = dynamixel_workbench_->syncWrite(SYNC_WRITE_HANDLER, id_array, actuator_id.size(), goal_position, 1, &log);
282  if (result == false)
283  {
284  log::error(log);
285  }
286 
287  return true;
288 }
289 
290 std::vector<robotis_manipulator::ActuatorValue> JointDynamixel::receiveAllDynamixelValue(std::vector<uint8_t> actuator_id)
291 {
292  bool result = false;
293  const char* log = NULL;
294 
295  std::vector<robotis_manipulator::ActuatorValue> all_actuator;
296 
297  uint8_t id_array[actuator_id.size()];
298  for (uint8_t index = 0; index < actuator_id.size(); index++)
299  id_array[index] = actuator_id.at(index);
300 
301  int32_t get_current[actuator_id.size()];
302  int32_t get_velocity[actuator_id.size()];
303  int32_t get_position[actuator_id.size()];
304 
305  result = dynamixel_workbench_->syncRead(SYNC_READ_HANDLER_FOR_PRESENT_POSITION_VELOCITY_CURRENT,
306  id_array,
307  actuator_id.size(),
308  &log);
309  if (result == false)
310  {
311  log::error(log);
312  }
313 
314  result = dynamixel_workbench_->getSyncReadData(SYNC_READ_HANDLER_FOR_PRESENT_POSITION_VELOCITY_CURRENT,
315  id_array,
316  actuator_id.size(),
319  get_current,
320  &log);
321  if (result == false)
322  {
323  log::error(log);
324  }
325 
326  result = dynamixel_workbench_->getSyncReadData(SYNC_READ_HANDLER_FOR_PRESENT_POSITION_VELOCITY_CURRENT,
327  id_array,
328  actuator_id.size(),
331  get_velocity,
332  &log);
333  if (result == false)
334  {
335  log::error(log);
336  }
337 
338  result = dynamixel_workbench_->getSyncReadData(SYNC_READ_HANDLER_FOR_PRESENT_POSITION_VELOCITY_CURRENT,
339  id_array,
340  actuator_id.size(),
343  get_position,
344  &log);
345  if (result == false)
346  {
347  log::error(log);
348  }
349 
350  for (uint8_t index = 0; index < actuator_id.size(); index++)
351  {
353  actuator.effort = dynamixel_workbench_->convertValue2Current(get_current[index]);
354  actuator.velocity = dynamixel_workbench_->convertValue2Velocity(actuator_id.at(index), get_velocity[index]);
355  actuator.position = dynamixel_workbench_->convertValue2Radian(actuator_id.at(index), get_position[index]);
356 
357  all_actuator.push_back(actuator);
358  }
359 
360  return all_actuator;
361 }
362 
363 
364 /*****************************************************************************
365 ** Joint Dynamixel Profile Control Functions
366 *****************************************************************************/
368 {
369  control_loop_time_ = control_loop_time;
370 }
371 
372 void JointDynamixelProfileControl::init(std::vector<uint8_t> actuator_id, const void *arg)
373 {
374  STRING *get_arg_ = (STRING *)arg;
375 
376  bool result = JointDynamixelProfileControl::initialize(actuator_id ,get_arg_[0], get_arg_[1]);
377 
378  if (result == false)
379  return;
380 }
381 
382 void JointDynamixelProfileControl::setMode(std::vector<uint8_t> actuator_id, const void *arg)
383 {
384  bool result = false;
385  // const char* log = NULL;
386 
387  STRING *get_arg_ = (STRING *)arg;
388 
389  if (get_arg_[0] == "position_mode" || get_arg_[0] == "current_based_position_mode")
390  {
391  result = JointDynamixelProfileControl::setOperatingMode(actuator_id, get_arg_[0]);
392  if (result == false)
393  return;
394 
395  result = JointDynamixelProfileControl::setSDKHandler(actuator_id.at(0));
396  if (result == false)
397  return;
398  }
399  else
400  {
401  result = JointDynamixelProfileControl::writeProfileValue(actuator_id, get_arg_[0], std::atoi(get_arg_[1].c_str()));
402  if (result == false)
403  return;
404  }
405  return;
406 }
407 
409 {
410  return dynamixel_.id;
411 }
412 
414 {
415  const char* log = NULL;
416  bool result = false;
417 
418  for (uint32_t index = 0; index < dynamixel_.num; index++)
419  {
420  result = dynamixel_workbench_->torqueOn(dynamixel_.id.at(index), &log);
421  if (result == false)
422  {
423  log::error(log);
424  }
425  }
426  enabled_state_ = true;
427 }
428 
430 {
431  const char* log = NULL;
432  bool result = false;
433 
434  for (uint32_t index = 0; index < dynamixel_.num; index++)
435  {
436  result = dynamixel_workbench_->torqueOff(dynamixel_.id.at(index), &log);
437  if (result == false)
438  {
439  log::error(log);
440  }
441  }
442  enabled_state_ = false;
443 }
444 
445 bool JointDynamixelProfileControl::sendJointActuatorValue(std::vector<uint8_t> actuator_id, std::vector<robotis_manipulator::ActuatorValue> value_vector)
446 {
447  bool result = false;
448 
449  result = JointDynamixelProfileControl::writeGoalProfilingControlValue(actuator_id, value_vector);
450  if (result == false)
451  return false;
452 
453  return true;
454 }
455 
456 std::vector<robotis_manipulator::ActuatorValue> JointDynamixelProfileControl::receiveJointActuatorValue(std::vector<uint8_t> actuator_id)
457 {
459 }
460 
461 
462 /*****************************************************************************
463 ** Functions called in Joint Dynamixel Profile Control Functions
464 *****************************************************************************/
465 bool JointDynamixelProfileControl::initialize(std::vector<uint8_t> actuator_id, STRING dxl_device_name, STRING dxl_baud_rate)
466 {
467  bool result = false;
468  const char* log = NULL;
469 
470  STRING return_delay_time_st = "Return_Delay_Time";
471  const char * return_delay_time_char = return_delay_time_st.c_str();
472 
473  dynamixel_.id = actuator_id;
474  dynamixel_.num = actuator_id.size();
475 
476  dynamixel_workbench_ = new DynamixelWorkbench;
477 
478  result = dynamixel_workbench_->init(dxl_device_name.c_str(), std::atoi(dxl_baud_rate.c_str()), &log);
479  if (result == false)
480  {
481  log::error(log);
482  }
483 
484  uint16_t get_model_number;
485  for (uint8_t index = 0; index < dynamixel_.num; index++)
486  {
487  uint8_t id = dynamixel_.id.at(index);
488  result = dynamixel_workbench_->ping(id, &get_model_number, &log);
489 
490  if (result == false)
491  {
492  log::error(log);
493  log::error("Please check your Dynamixel ID");
494  }
495  else
496  {
497  char str[100];
498  sprintf(str, "Joint Dynamixel ID : %d, Model Name : %s", id, dynamixel_workbench_->getModelName(id));
499  log::println(str);
500 
501  result = dynamixel_workbench_->setTimeBasedProfile(id, &log);
502  if(result == false)
503  {
504  log::error(log);
505  log::error("Please check your Dynamixel firmware version (v38~)");
506  }
507 
508  result = dynamixel_workbench_->writeRegister(id, return_delay_time_char, 0, &log);
509  if (result == false)
510  {
511  log::error(log);
512  log::error("Please check your Dynamixel firmware version");
513  }
514  }
515  }
516  return true;
517 }
518 
519 bool JointDynamixelProfileControl::setOperatingMode(std::vector<uint8_t> actuator_id, STRING dynamixel_mode)
520 {
521  const char* log = NULL;
522  bool result = false;
523 
524  const uint32_t velocity = uint32_t(control_loop_time_*1000) * 3;
525  const uint32_t acceleration = uint32_t(control_loop_time_*1000);
526  const uint32_t current = 0;
527 
528  if (dynamixel_mode == "position_mode")
529  {
530  for (uint8_t num = 0; num < actuator_id.size(); num++)
531  {
532  result = dynamixel_workbench_->jointMode(actuator_id.at(num), velocity, acceleration, &log);
533  if (result == false)
534  {
535  log::error(log);
536  }
537  }
538  }
539  else if (dynamixel_mode == "current_based_position_mode")
540  {
541  for (uint8_t num = 0; num < actuator_id.size(); num++)
542  {
543  result = dynamixel_workbench_->currentBasedPositionMode(actuator_id.at(num), current, &log);
544  if (result == false)
545  {
546  log::error(log);
547  }
548  }
549  }
550  else
551  {
552  for (uint8_t num = 0; num < actuator_id.size(); num++)
553  {
554  result = dynamixel_workbench_->jointMode(actuator_id.at(num), velocity, acceleration, &log);
555  if (result == false)
556  {
557  log::error(log);
558  }
559  }
560  }
561 
562  return true;
563 }
564 
566 {
567  bool result = false;
568  const char* log = NULL;
569 
570  result = dynamixel_workbench_->addSyncWriteHandler(actuator_id, "Goal_Position", &log);
571  if (result == false)
572  {
573  log::error(log);
574  }
575 
576  result = dynamixel_workbench_->addSyncReadHandler(ADDR_PRESENT_CURRENT_2,
578  &log);
579  if (result == false)
580  {
581  log::error(log);
582  }
583 
584  return true;
585 }
586 
587 bool JointDynamixelProfileControl::writeProfileValue(std::vector<uint8_t> actuator_id, STRING profile_mode, uint32_t value)
588 {
589  const char* log = NULL;
590  bool result = false;
591 
592  const char * char_profile_mode = profile_mode.c_str();
593 
594  for (uint8_t num = 0; num < actuator_id.size(); num++)
595  {
596  result = dynamixel_workbench_->writeRegister(actuator_id.at(num), char_profile_mode, value, &log);
597  if (result == false)
598  {
599  log::error(log);
600  }
601  }
602  return true;
603 }
604 
605 bool JointDynamixelProfileControl::writeGoalProfilingControlValue(std::vector<uint8_t> actuator_id, std::vector<robotis_manipulator::ActuatorValue> value_vector)
606 {
607  bool result = false;
608  const char* log = NULL;
609 
610  uint8_t id_array[actuator_id.size()];
611  int32_t goal_value[actuator_id.size()];
612 
613  //add tarajectory eq.
614  for(uint8_t index = 0; index < actuator_id.size(); index++)
615  {
616  float result_position;
617  float time_control = control_loop_time_; //ms
618 
619  if(previous_goal_value_.find(actuator_id.at(index)) == previous_goal_value_.end())
620  {
621  previous_goal_value_.insert(std::make_pair(actuator_id.at(index), value_vector.at(index)));
622  }
623 
624  result_position = value_vector.at(index).position + 3*(value_vector.at(index).velocity * (time_control))/2;
625 
626  id_array[index] = actuator_id.at(index);
627  goal_value[index] = dynamixel_workbench_->convertRadian2Value(actuator_id.at(index), result_position);
628 
629  previous_goal_value_[actuator_id.at(index)] = value_vector.at(index);
630  }
631 
632  result = dynamixel_workbench_->syncWrite(SYNC_WRITE_HANDLER, id_array, actuator_id.size(), goal_value, 1, &log);
633  if (result == false)
634  {
635  log::error(log);
636  }
637  return true;
638 }
639 
640 std::vector<robotis_manipulator::ActuatorValue> JointDynamixelProfileControl::receiveAllDynamixelValue(std::vector<uint8_t> actuator_id)
641 {
642  bool result = false;
643  const char* log = NULL;
644 
645  std::vector<robotis_manipulator::ActuatorValue> all_actuator;
646 
647  uint8_t id_array[actuator_id.size()];
648  for (uint8_t index = 0; index < actuator_id.size(); index++)
649  id_array[index] = actuator_id.at(index);
650 
651  int32_t get_current[actuator_id.size()];
652  int32_t get_velocity[actuator_id.size()];
653  int32_t get_position[actuator_id.size()];
654 
655  result = dynamixel_workbench_->syncRead(SYNC_READ_HANDLER_FOR_PRESENT_POSITION_VELOCITY_CURRENT,
656  id_array,
657  actuator_id.size(),
658  &log);
659  if (result == false)
660  {
661  log::error(log);
662  }
663 
664  result = dynamixel_workbench_->getSyncReadData(SYNC_READ_HANDLER_FOR_PRESENT_POSITION_VELOCITY_CURRENT,
665  id_array,
666  actuator_id.size(),
669  get_current,
670  &log);
671  if (result == false)
672  {
673  log::error(log);
674  }
675 
676  result = dynamixel_workbench_->getSyncReadData(SYNC_READ_HANDLER_FOR_PRESENT_POSITION_VELOCITY_CURRENT,
677  id_array,
678  actuator_id.size(),
681  get_velocity,
682  &log);
683  if (result == false)
684  {
685  log::error(log);
686  }
687 
688  result = dynamixel_workbench_->getSyncReadData(SYNC_READ_HANDLER_FOR_PRESENT_POSITION_VELOCITY_CURRENT,
689  id_array,
690  actuator_id.size(),
693  get_position,
694  &log);
695  if (result == false)
696  {
697  log::error(log);
698  }
699 
700  for (uint8_t index = 0; index < actuator_id.size(); index++)
701  {
703  actuator.effort = dynamixel_workbench_->convertValue2Current(get_current[index]);
704  actuator.velocity = dynamixel_workbench_->convertValue2Velocity(actuator_id.at(index), get_velocity[index]);
705  actuator.position = dynamixel_workbench_->convertValue2Radian(actuator_id.at(index), get_position[index]);
706 
707  all_actuator.push_back(actuator);
708  }
709 
710  return all_actuator;
711 }
712 
713 
714 /*****************************************************************************
715 ** Tool Dynamixel Control Functions
716 *****************************************************************************/
717 void GripperDynamixel::init(uint8_t actuator_id, const void *arg)
718 {
719  STRING *get_arg_ = (STRING *)arg;
720 
721  bool result = GripperDynamixel::initialize(actuator_id ,get_arg_[0], get_arg_[1]);
722 
723  if (result == false)
724  return;
725 }
726 
727 void GripperDynamixel::setMode(const void *arg)
728 {
729  bool result = false;
730 // const char* log = NULL;
731 
732  STRING *get_arg_ = (STRING *)arg;
733 
734  if (get_arg_[0] == "position_mode" || get_arg_[0] == "current_based_position_mode")
735  {
736  result = GripperDynamixel::setOperatingMode(get_arg_[0]);
737  if (result == false)
738  return;
739  }
740  else
741  {
742  result = GripperDynamixel::writeProfileValue(get_arg_[0], std::atoi(get_arg_[1].c_str()));
743  if (result == false)
744  return;
745  }
746 
748  if (result == false)
749  return;
750 }
751 
753 {
754  return dynamixel_.id.at(0);
755 }
756 
758 {
759  const char* log = NULL;
760  bool result = false;
761 
762  result = dynamixel_workbench_->torqueOn(dynamixel_.id.at(0), &log);
763  if (result == false)
764  {
765  log::error(log);
766  }
767  enabled_state_ = true;
768 }
769 
771 {
772  const char* log = NULL;
773  bool result = false;
774 
775  result = dynamixel_workbench_->torqueOff(dynamixel_.id.at(0), &log);
776  if (result == false)
777  {
778  log::error(log);
779  }
780  enabled_state_ = false;
781 }
782 
784 {
786 }
787 
789 {
792  result.velocity = 0.0;
793  result.acceleration = 0.0;
794  result.effort = 0.0;
795  return result;
796 }
797 
798 
799 /*****************************************************************************
800 ** Functions called in Tool Dynamixel Profile Control Functions
801 *****************************************************************************/
802 bool GripperDynamixel::initialize(uint8_t actuator_id, STRING dxl_device_name, STRING dxl_baud_rate)
803 {
804  const char* log = NULL;
805  bool result = false;
806 
807  STRING return_delay_time_st = "Return_Delay_Time";
808  const char * return_delay_time_char = return_delay_time_st.c_str();
809 
810  dynamixel_.id.push_back(actuator_id);
811  dynamixel_.num = 1;
812 
813  dynamixel_workbench_ = new DynamixelWorkbench;
814 
815  result = dynamixel_workbench_->init(dxl_device_name.c_str(), std::atoi(dxl_baud_rate.c_str()), &log);
816  if (result == false)
817  {
818  log::error(log);
819  }
820 
821  uint16_t get_model_number;
822  result = dynamixel_workbench_->ping(dynamixel_.id.at(0), &get_model_number, &log);
823  if (result == false)
824  {
825  log::error(log);
826  log::error("Please check your Dynamixel ID");
827  }
828  else
829  {
830  char str[100];
831  sprintf(str, "Gripper Dynamixel ID : %d, Model Name :", dynamixel_.id.at(0));
832  strcat(str, dynamixel_workbench_->getModelName(dynamixel_.id.at(0)));
833  log::println(str);
834 
835  // result = dynamixel_workbench_->setVelocityBasedProfile(dynamixel_.id.at(0), &log);
836  // if(result == false)
837  // {
838  // log::error(log);
839  // log::error("Please check your Dynamixel firmware version (v38~)");
840  // }
841 
842  result = dynamixel_workbench_->writeRegister(dynamixel_.id.at(0), return_delay_time_char, 0, &log);
843  if (result == false)
844  {
845  log::error(log);
846  log::error("Please check your Dynamixel firmware version");
847  }
848  }
849 
850  return true;
851 }
852 
854 {
855  const char* log = NULL;
856  bool result = false;
857 
858  const uint32_t velocity = 0;
859  const uint32_t acceleration = 0;
860  const uint32_t current = 300;
861 
862  if (dynamixel_mode == "position_mode")
863  {
864  result = dynamixel_workbench_->jointMode(dynamixel_.id.at(0), velocity, acceleration, &log);
865  if (result == false)
866  {
867  log::error(log);
868  }
869  }
870  else if (dynamixel_mode == "current_based_position_mode")
871  {
872  result = dynamixel_workbench_->currentBasedPositionMode(dynamixel_.id.at(0), current, &log);
873  if (result == false)
874  {
875  log::error(log);
876  }
877  }
878  else
879  {
880  result = dynamixel_workbench_->jointMode(dynamixel_.id.at(0), velocity, acceleration, &log);
881  if (result == false)
882  {
883  log::error(log);
884  }
885  }
886 
887  return true;
888 }
889 
890 bool GripperDynamixel::writeProfileValue(STRING profile_mode, uint32_t value)
891 {
892  const char* log = NULL;
893  bool result = false;
894 
895  const char * char_profile_mode = profile_mode.c_str();
896 
897  result = dynamixel_workbench_->writeRegister(dynamixel_.id.at(0), char_profile_mode, value, &log);
898  if (result == false)
899  {
900  log::error(log);
901  }
902 
903  return true;
904 }
905 
907 {
908  bool result = false;
909  const char* log = NULL;
910 
911  result = dynamixel_workbench_->addSyncWriteHandler(dynamixel_.id.at(0), "Goal_Position", &log);
912  if (result == false)
913  {
914  log::error(log);
915  }
916 
917  result = dynamixel_workbench_->addSyncReadHandler(dynamixel_.id.at(0),
918  "Present_Position",
919  &log);
920  if (result == false)
921  {
922  log::error(log);
923  }
924 
925  return true;
926 }
927 
929 {
930  bool result = false;
931  const char* log = NULL;
932 
933  int32_t goal_position = 0;
934 
935  goal_position = dynamixel_workbench_->convertRadian2Value(dynamixel_.id.at(0), radian);
936 
937  result = dynamixel_workbench_->syncWrite(SYNC_WRITE_HANDLER, &goal_position, &log);
938  if (result == false)
939  {
940  log::error(log);
941  }
942 
943  return true;
944 }
945 
947 {
948  bool result = false;
949  const char* log = NULL;
950 
951  int32_t get_value = 0;
952  uint8_t id_array[1] = {dynamixel_.id.at(0)};
953 
954  result = dynamixel_workbench_->syncRead(SYNC_READ_HANDLER_FOR_PRESENT_POSITION_VELOCITY_CURRENT,
955  id_array,
956  (uint8_t)1,
957  &log);
958  if (result == false)
959  {
960  log::error(log);
961  }
962 
963  result = dynamixel_workbench_->getSyncReadData(SYNC_READ_HANDLER_FOR_PRESENT_POSITION_VELOCITY_CURRENT,
964  id_array,
965  (uint8_t)1,
966  &get_value,
967  &log);
968  if (result == false)
969  {
970  log::error(log);
971  }
972 
973  return dynamixel_workbench_->convertValue2Radian(dynamixel_.id.at(0), get_value);
974 }
virtual bool sendJointActuatorValue(std::vector< uint8_t > actuator_id, std::vector< robotis_manipulator::ActuatorValue > value_vector)
Definition: dynamixel.cpp:445
bool writeGoalPosition(std::vector< uint8_t > actuator_id, std::vector< double > radian_vector)
Definition: dynamixel.cpp:267
#define SYNC_WRITE_HANDLER
Definition: dynamixel.h:33
virtual std::vector< robotis_manipulator::ActuatorValue > receiveJointActuatorValue(std::vector< uint8_t > actuator_id)
Definition: dynamixel.cpp:456
bool writeGoalProfilingControlValue(std::vector< uint8_t > actuator_id, std::vector< robotis_manipulator::ActuatorValue > value_vector)
Definition: dynamixel.cpp:605
#define LENGTH_PRESENT_CURRENT_2
Definition: dynamixel.h:49
bool initialize(std::vector< uint8_t > actuator_id, STRING dxl_device_name, STRING dxl_baud_rate)
Definition: dynamixel.cpp:125
bool init(const char *device_name="/dev/ttyUSB0", uint32_t baud_rate=57600, const char **log=NULL)
virtual std::vector< uint8_t > getId()
Definition: dynamixel.cpp:63
bool setOperatingMode(STRING dynamixel_mode="position_mode")
Definition: dynamixel.cpp:853
bool setOperatingMode(std::vector< uint8_t > actuator_id, STRING dynamixel_mode="position_mode")
Definition: dynamixel.cpp:519
#define ADDR_PRESENT_CURRENT_2
Definition: dynamixel.h:39
virtual uint8_t getId()
Definition: dynamixel.cpp:752
virtual void disable()
Definition: dynamixel.cpp:84
virtual robotis_manipulator::ActuatorValue receiveToolActuatorValue()
Definition: dynamixel.cpp:788
virtual bool sendJointActuatorValue(std::vector< uint8_t > actuator_id, std::vector< robotis_manipulator::ActuatorValue > value_vector)
Definition: dynamixel.cpp:100
virtual void init(uint8_t actuator_id, const void *arg)
Definition: dynamixel.cpp:717
bool setSDKHandler(uint8_t actuator_id)
Definition: dynamixel.cpp:565
bool writeProfileValue(STRING profile_mode, uint32_t value)
Definition: dynamixel.cpp:890
virtual void setMode(const void *arg)
Definition: dynamixel.cpp:727
virtual void setMode(std::vector< uint8_t > actuator_id, const void *arg)
Definition: dynamixel.cpp:37
virtual void init(std::vector< uint8_t > actuator_id, const void *arg)
Definition: dynamixel.cpp:27
#define SYNC_READ_HANDLER_FOR_PRESENT_POSITION_VELOCITY_CURRENT
Definition: dynamixel.h:34
bool writeProfileValue(std::vector< uint8_t > actuator_id, STRING profile_mode, uint32_t value)
Definition: dynamixel.cpp:248
bool setSDKHandler(uint8_t actuator_id)
Definition: dynamixel.cpp:226
virtual std::vector< uint8_t > getId()
Definition: dynamixel.cpp:408
virtual void init(std::vector< uint8_t > actuator_id, const void *arg)
Definition: dynamixel.cpp:372
#define LENGTH_PRESENT_VELOCITY_2
Definition: dynamixel.h:50
bool setOperatingMode(std::vector< uint8_t > actuator_id, STRING dynamixel_mode="position_mode")
Definition: dynamixel.cpp:180
std::vector< robotis_manipulator::ActuatorValue > receiveAllDynamixelValue(std::vector< uint8_t > actuator_id)
Definition: dynamixel.cpp:640
std::vector< robotis_manipulator::ActuatorValue > receiveAllDynamixelValue(std::vector< uint8_t > actuator_id)
Definition: dynamixel.cpp:290
bool writeGoalPosition(double radian)
Definition: dynamixel.cpp:928
bool initialize(uint8_t actuator_id, STRING dxl_device_name, STRING dxl_baud_rate)
Definition: dynamixel.cpp:802
bool initialize(std::vector< uint8_t > actuator_id, STRING dxl_device_name, STRING dxl_baud_rate)
Definition: dynamixel.cpp:465
virtual std::vector< robotis_manipulator::ActuatorValue > receiveJointActuatorValue(std::vector< uint8_t > actuator_id)
Definition: dynamixel.cpp:116
#define ADDR_PRESENT_POSITION_2
Definition: dynamixel.h:41
JointDynamixelProfileControl(float control_loop_time=0.010)
Definition: dynamixel.cpp:367
virtual bool sendToolActuatorValue(robotis_manipulator::ActuatorValue value)
Definition: dynamixel.cpp:783
#define ADDR_PRESENT_VELOCITY_2
Definition: dynamixel.h:40
#define LENGTH_PRESENT_POSITION_2
Definition: dynamixel.h:51
virtual void setMode(std::vector< uint8_t > actuator_id, const void *arg)
Definition: dynamixel.cpp:382
virtual void enable()
Definition: dynamixel.cpp:68
bool writeProfileValue(std::vector< uint8_t > actuator_id, STRING profile_mode, uint32_t value)
Definition: dynamixel.cpp:587
std::string STRING


open_manipulator_p_libs
Author(s): Ryan Shim , Yong-Ho Na , Hye-Jong KIM
autogenerated on Thu Oct 22 2020 03:16:37