dxl_motors_builder.cpp
Go to the documentation of this file.
1 //
2 // Created by sub on 16/10/17.
3 //
4 #include "dxl_motors_builder.h"
5 
6 namespace armadillo2_hw
7 {
9  {
10  nh_ = &nh;
11  ros::param::get("~load_dxl_hw", load_dxl_hw_);
12  if (load_dxl_hw_)
13  {
14  /* the order of calling the following methods is important */
15  /* because some calls load params / objects for following calls */
16  fetchParams();
17  buildMotors();
18  openPort();
19  pingMotors();
20  loadSpecs();
21  setTorque(true);
22 
23  for (dxl::motor &motor : motors_)
24  {
25  ROS_INFO ("[armadillo2_hw/dxl_motors_builder]: done building motor id: %d, model: %d",
26  motor.id, motor.spec.model);
27  }
28 
29  failed_reads_ = 0;
30  failed_writes_ = 0;
31 
33  ROS_INFO("[armadillo2_hw/ricboard_pub]: ricboard is up");
34  espeak_pub_ = nh.advertise<std_msgs::String>("/espeak_node/speak_line", 10);
35  /*speakMsg("dxl motors manager is up", 1);*/
36  }
37  else
38  ROS_WARN("[armadillo2_hw/dxl_motors_builder]: dxl motors hardware is disabled");
39  }
40 
42  {
43  if (!load_dxl_hw_)
44  return;
45  comm_mutex_.lock();
47  {
48  //ROS_ERROR("[dxl_motors_builder]: reading motors position failed");
49  failed_reads_++;
50  }
52  {
53  //ROS_ERROR("[dxl_motors_builder]: reading motors velocity failed");
54  failed_reads_++;
55  }
57  {
58  //ROS_ERROR("[dxl_motors_builder]: reading motors load failed");
59  failed_reads_++;
60  }
62  {
63  //ROS_ERROR("[dxl_motors_builder]: reading motors errors failed");
64  failed_reads_++;
65  }
67  {
68  speakMsg("dxl motors read error", 1);
69  ROS_ERROR("[dxl_motors_builder]: too many read errors, shutting down...");
70  ros::shutdown();
71  exit(EXIT_FAILURE);
72  }
73  comm_mutex_.unlock();
74  }
75 
76  void DxlMotorsBuilder::writeToMotor(int motor_id, double position, double velocity)
77  {
78  if (!load_dxl_hw_)
79  return;
80  for (dxl::motor motor : motors_)
81  {
82  if (motor.id == motor_id)
83  {
84  std::vector<dxl::motor> single_motor_vec;
85  motor.command_position = position;
86  motor.command_velocity = velocity;
87  single_motor_vec.push_back(motor);
88  write(single_motor_vec);
89  }
90  }
91  }
92 
93  void DxlMotorsBuilder::write(std::vector<dxl::motor> &motors)
94  {
95  if (!load_dxl_hw_)
96  return;
97  comm_mutex_.lock();
98  if (!dxl_interface_.bulkWriteVelocity(motors))
99  {
100  //ROS_ERROR("[dxl_motors_builder]: writing velocity failed");
101  failed_writes_++;
102  }
103 
104  if (!dxl_interface_.bulkWritePosition(motors))
105  {
106  //ROS_ERROR("[dxl_motors_builder]: writing postision failed");
107  failed_writes_++;
108  }
109 
111  {
112  speakMsg("dxl motors write error", 1);
113  ROS_ERROR("[dxl_motors_builder]: too many write errors, shutting down...");
114  ros::shutdown();
115  exit(EXIT_FAILURE);
116  }
117  comm_mutex_.unlock();
118  }
119 
121  {
122  write(motors_);
123  }
124 
126  {
127  if (!load_dxl_hw_)
128  return;
129  ros::Duration(1).sleep();
130  comm_mutex_.lock();
131  for (dxl::motor &motor : motors_)
132  {
133  int error_counter = 0;
134  while (!dxl_interface_.ping(motor))
135  {
136  error_counter++;
137  ROS_WARN("[dxl_motors_builder]: pinging motor id: %d failed", motor.id);
138  if (error_counter > MAX_PING_ERRORS)
139  {
140  speakMsg("too many dxl motor ping errors, shutting down", 1);
141  ROS_ERROR("[dxl_motors_builder]: too many ping errors, motor %d is not responding. \n"
142  "check if motor crashed (red blink) and try to restart. \n"
143  "also make sure LATENCY_TIMER is set to 1 in dynamixel_sdk, and that the appropriate"
144  "rule for dynamixel port is existed with LATENCY_TIMER=1.", motor.id);
145  ros::shutdown();
146  exit(EXIT_FAILURE);
147  }
148  ros::Rate(5).sleep();
149  }
150  }
151  comm_mutex_.unlock();
152  }
153 
155  {
156  if (!load_dxl_hw_)
157  return;
158  /* build motors */
159  for(int i = 0; i < dxl_spec_config_.size(); i++)
160  {
161  /* feed motor with user defined settings */
163  {
164  ROS_ERROR("[dxl_motors_builder]: motor spec at index %d param data type is invalid or missing. "
165  "make sure that this param exist in dxl_spec_config.yaml and that your launch includes this param file. shutting down...", i);
166  ros::shutdown();
167  exit (EXIT_FAILURE);
168  }
169 
170  struct dxl::spec spec;
171 
172  /* name */
173  if(dxl_spec_config_[i]["name"].getType() != XmlRpc::XmlRpcValue::TypeString)
174  {
175  ROS_ERROR("[dxl_motors_builder]: spec name at index %d: invalid data type or missing. "
176  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
177  ros::shutdown();
178  exit (EXIT_FAILURE);
179  }
180  spec.name = static_cast<std::string>(dxl_spec_config_[i]["name"]);
181 
182  /* model */
183  if(dxl_spec_config_[i]["model"].getType() != XmlRpc::XmlRpcValue::TypeInt)
184  {
185  ROS_ERROR("[dxl_motors_builder]: spec model at index %d: invalid data type or missing. "
186  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
187  ros::shutdown();
188  exit (EXIT_FAILURE);
189  }
190  spec.model = static_cast<int>(dxl_spec_config_[i]["model"]);
191 
192  /* cpr */
193  if(dxl_spec_config_[i]["cpr"].getType() != XmlRpc::XmlRpcValue::TypeInt)
194  {
195  ROS_ERROR("[dxl_motors_builder]: spec cpr at index %d: invalid data type or missing. "
196  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
197  ros::shutdown();
198  exit (EXIT_FAILURE);
199  }
200  spec.cpr = static_cast<int>(dxl_spec_config_[i]["cpr"]);
201 
202  /* rpm_factor */
203  if(dxl_spec_config_[i]["rpm_factor"].getType() != XmlRpc::XmlRpcValue::TypeDouble)
204  {
205  ROS_ERROR("[dxl_motors_builder]: spec rpm_factor at index %d: invalid data type or missing. "
206  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
207  ros::shutdown();
208  exit (EXIT_FAILURE);
209  }
210  spec.rpm_scale_factor = static_cast<double>(dxl_spec_config_[i]["rpm_factor"]);
211 
212  /* torque_const_a */
213  if(dxl_spec_config_[i]["torque_const_a"].getType() != XmlRpc::XmlRpcValue::TypeDouble)
214  {
215  ROS_ERROR("[dxl_motors_builder]: spec torque_const_a at index %d: invalid data type or missing. "
216  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
217  ros::shutdown();
218  exit (EXIT_FAILURE);
219  }
220  spec.torque_const_a = static_cast<double>(dxl_spec_config_[i]["torque_const_a"]);
221 
222  /* torque_const_b */
223  if(dxl_spec_config_[i]["torque_const_b"].getType() != XmlRpc::XmlRpcValue::TypeDouble)
224  {
225  ROS_ERROR("[dxl_motors_builder]: spec torque_const_b at index %d: invalid data type or missing. "
226  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
227  ros::shutdown();
228  exit (EXIT_FAILURE);
229  }
230  spec.torque_const_b = static_cast<double>(dxl_spec_config_[i]["torque_const_b"]);
231 
232 
233 
234  /* pos_read_addr */
235  if(dxl_spec_config_[i]["pos_read_addr"].getType() != XmlRpc::XmlRpcValue::TypeInt)
236  {
237  ROS_ERROR("[dxl_motors_builder]: spec pos_read_addr at index %d: invalid data type or missing. "
238  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
239  ros::shutdown();
240  exit (EXIT_FAILURE);
241  }
242  spec.pos_read_addr = static_cast<int>(dxl_spec_config_[i]["pos_read_addr"]);
243 
244  /* vel_read_addr */
245  if(dxl_spec_config_[i]["vel_read_addr"].getType() != XmlRpc::XmlRpcValue::TypeInt)
246  {
247  ROS_ERROR("[dxl_motors_builder]: spec vel_read_addr at index %d: invalid data type or missing. "
248  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
249  ros::shutdown();
250  exit (EXIT_FAILURE);
251  }
252  spec.vel_read_addr = static_cast<int>(dxl_spec_config_[i]["vel_read_addr"]);
253 
254 
255  /* current_read_addr */
256  if(dxl_spec_config_[i]["current_read_addr"].getType() != XmlRpc::XmlRpcValue::TypeInt)
257  {
258  ROS_ERROR("[dxl_motors_builder]: spec current_read_addr at index %d: invalid data type or missing. "
259  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
260  ros::shutdown();
261  exit (EXIT_FAILURE);
262  }
263  spec.current_read_addr = static_cast<int>(dxl_spec_config_[i]["current_read_addr"]);
264 
265  /* error_read_addr */
266  if(dxl_spec_config_[i]["error_read_addr"].getType() != XmlRpc::XmlRpcValue::TypeInt)
267  {
268  ROS_ERROR("[dxl_motors_builder]: spec error_read_addr at index %d: invalid data type or missing. "
269  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
270  ros::shutdown();
271  exit (EXIT_FAILURE);
272  }
273  spec.error_read_addr = static_cast<int>(dxl_spec_config_[i]["error_read_addr"]);
274 
275  /* torque_write_addr */
276  if(dxl_spec_config_[i]["torque_write_addr"].getType() != XmlRpc::XmlRpcValue::TypeInt)
277  {
278  ROS_ERROR("[dxl_motors_builder]: spec torque_write_addr at index %d: invalid data type or missing. "
279  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
280  ros::shutdown();
281  exit (EXIT_FAILURE);
282  }
283  spec.torque_write_addr = static_cast<int>(dxl_spec_config_[i]["torque_write_addr"]);
284 
285  /* vel_write_addr */
286  if(dxl_spec_config_[i]["vel_write_addr"].getType() != XmlRpc::XmlRpcValue::TypeInt)
287  {
288  ROS_ERROR("[dxl_motors_builder]: spec vel_write_addr at index %d: invalid data type or missing. "
289  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
290  ros::shutdown();
291  exit (EXIT_FAILURE);
292  }
293  spec.vel_write_addr = static_cast<int>(dxl_spec_config_[i]["vel_write_addr"]);
294 
295 
296  /* pos_write_addr */
297  if(dxl_spec_config_[i]["pos_write_addr"].getType() != XmlRpc::XmlRpcValue::TypeInt)
298  {
299  ROS_ERROR("[dxl_motors_builder]: spec pos_write_addr at index %d: invalid data type or missing. "
300  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
301  ros::shutdown();
302  exit (EXIT_FAILURE);
303  }
304  spec.pos_write_addr = static_cast<int>(dxl_spec_config_[i]["pos_write_addr"]);
305 
306  /* current_ratio */
307  if(dxl_spec_config_[i]["current_ratio"].getType() != XmlRpc::XmlRpcValue::TypeDouble)
308  {
309  ROS_ERROR("[dxl_motors_builder]: spec current_ratio at index %d: invalid data type or missing. "
310  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
311  ros::shutdown();
312  exit (EXIT_FAILURE);
313  }
314  spec.current_ratio = static_cast<double>(dxl_spec_config_[i]["current_ratio"]);
315 
316  /* len_present_speed */
317  if(dxl_spec_config_[i]["len_present_speed"].getType() != XmlRpc::XmlRpcValue::TypeInt)
318  {
319  ROS_ERROR("[dxl_motors_builder]: spec len_present_speed at index %d: invalid data type or missing. "
320  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
321  ros::shutdown();
322  exit (EXIT_FAILURE);
323  }
324  spec.len_present_speed = static_cast<int>(dxl_spec_config_[i]["len_present_speed"]);
325 
326  /* len_present_pos */
327  if(dxl_spec_config_[i]["len_present_pos"].getType() != XmlRpc::XmlRpcValue::TypeInt)
328  {
329  ROS_ERROR("[dxl_motors_builder]: spec len_present_pos at index %d: invalid data type or missing. "
330  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
331  ros::shutdown();
332  exit (EXIT_FAILURE);
333  }
334  spec.len_present_pos = static_cast<int>(dxl_spec_config_[i]["len_present_pos"]);
335 
336  /* len_present_curr */
337  if(dxl_spec_config_[i]["len_present_curr"].getType() != XmlRpc::XmlRpcValue::TypeInt)
338  {
339  ROS_ERROR("[dxl_motors_builder]: spec len_present_curr at index %d: invalid data type or missing. "
340  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
341  ros::shutdown();
342  exit (EXIT_FAILURE);
343  }
344  spec.len_present_curr = static_cast<int>(dxl_spec_config_[i]["len_present_curr"]);
345 
346  /* len_goal_speed */
347  if(dxl_spec_config_[i]["len_goal_speed"].getType() != XmlRpc::XmlRpcValue::TypeInt)
348  {
349  ROS_ERROR("[dxl_motors_builder]: spec len_goal_speed at index %d: invalid data type or missing. "
350  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
351  ros::shutdown();
352  exit (EXIT_FAILURE);
353  }
354  spec.len_goal_speed = static_cast<int>(dxl_spec_config_[i]["len_goal_speed"]);
355 
356  /* len_goal_pos */
357  if(dxl_spec_config_[i]["len_goal_pos"].getType() != XmlRpc::XmlRpcValue::TypeInt)
358  {
359  ROS_ERROR("[dxl_motors_builder]: spec len_goal_pos at index %d: invalid data type or missing. "
360  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
361  ros::shutdown();
362  exit (EXIT_FAILURE);
363  }
364  spec.len_goal_pos = static_cast<int>(dxl_spec_config_[i]["len_goal_pos"]);
365 
366  specs_[spec.model] = spec;
367  }
368 
369  /* feed motors with model specs */
370  for (dxl::motor &motor : motors_)
371  {
372  bool spec_found = specs_.find(motor.spec.model) != specs_.end();
373  if (spec_found)
374  {
375  motor.spec.name = specs_[motor.spec.model].name;
376  motor.spec.cpr = specs_[motor.spec.model].cpr;
377  motor.spec.rpm_scale_factor = specs_[motor.spec.model].rpm_scale_factor;
378  motor.spec.torque_const_a = specs_[motor.spec.model].torque_const_a;
379  motor.spec.torque_const_b = specs_[motor.spec.model].torque_const_b;
380 
381  /* read addrs */
382  motor.spec.pos_read_addr = specs_[motor.spec.model].pos_read_addr;
383  motor.spec.vel_read_addr = specs_[motor.spec.model].vel_read_addr;
384  motor.spec.current_read_addr = specs_[motor.spec.model].current_read_addr;
385  motor.spec.error_read_addr = specs_[motor.spec.model].error_read_addr;
386 
387  /* write addrs */
388  motor.spec.torque_write_addr = specs_[motor.spec.model].torque_write_addr;
389  motor.spec.vel_write_addr = specs_[motor.spec.model].vel_write_addr;
390  motor.spec.pos_write_addr = specs_[motor.spec.model].pos_write_addr;
391  motor.spec.len_present_speed = specs_[motor.spec.model].len_present_speed;
392  motor.spec.len_present_pos = specs_[motor.spec.model].len_present_pos;
393  motor.spec.len_present_curr = specs_[motor.spec.model].len_present_curr;
394  motor.spec.len_goal_speed = specs_[motor.spec.model].len_goal_speed;
395  motor.spec.len_goal_pos = specs_[motor.spec.model].len_goal_pos;
396 
397 
398 
399  motor.spec.current_ratio = specs_[motor.spec.model].current_ratio;
400 
401  }
402  else
403  {
404  ROS_ERROR("[dxl_motors_builder]: couldn't locate model specification for motor %d, model %d. "
405  "make sure dxl_motor_data.yaml contains all the necessary specs. shutting down...", motor.id, motor.spec.model);
406  ros::shutdown();
407  exit(EXIT_FAILURE);
408  }
409  }
410  }
411 
413  {
414  if (!load_dxl_hw_)
415  return false;
416  comm_mutex_.lock();
417  std::string str_flag = flag ? "on" : "off";
418  bool success = true;
419  for (dxl::motor &motor : motors_)
420  {
421  if (!dxl_interface_.setTorque(motor, flag))
422  {
423  success = false;
424  ROS_WARN("[dxl_motors_builder]: failed set torque of motor id %d to %s", motor.id, str_flag.c_str());
425  }
426  }
427  comm_mutex_.unlock();
428  if (success)
429  {
430  ROS_INFO("[dxl_motors_builder]: motors torque is %s", str_flag.c_str());
431  return true;
432  }
433  return false;
434  }
435 
436  bool DxlMotorsBuilder::torqueServiceCB(std_srvs::SetBool::Request &req,
437  std_srvs::SetBool::Response &res)
438  {
439  if (!load_dxl_hw_)
440  return false;
441  res.success = false;
442  if (DxlMotorsBuilder::setTorque(req.data))
443  res.success = true;
444  return true;
445  }
446 
447 
449  {
450  if (!load_dxl_hw_)
451  return;
452  /* DXL_JOINTS_CONFIG_PARAM */
454  {
455  ROS_ERROR("[dxl_motors_builder]: %s param is missing on param server. make sure that this param exist in dxl_joints_config.yaml "
456  "and that your launch includes this param file. shutting down...", DXL_JOINTS_CONFIG_PARAM);
457  ros::shutdown();
458  exit (EXIT_FAILURE);
459  }
462  {
463  ROS_ERROR("[dxl_motors_builder]: %s param is invalid (need to be an of type array) or missing. "
464  "make sure that this param exist in dxl_joints_config.yaml and that your launch "
465  "includes this param file. shutting down...", DXL_JOINTS_CONFIG_PARAM);
466  ros::shutdown();
467  exit (EXIT_FAILURE);
468  }
469 
470  /* SPEC_CONFIG_PARAM */
472  {
473  ROS_ERROR("[dxl_motors_builder]: %s param is missing on param server. make sure that this param exist in dxl_joints_config.yaml "
474  "and that your launch includes this param file. shutting down...", SPEC_CONFIG_PARAM);
475  ros::shutdown();
476  exit (EXIT_FAILURE);
477  }
480  {
481  ROS_ERROR("[dxl_motors_builder]: %s param is invalid (need to be an of type array) or missing. "
482  "make sure that this param exist in dxl_joints_config.yaml and that your launch "
483  "includes this param file. shutting down...", SPEC_CONFIG_PARAM);
484  ros::shutdown();
485  exit (EXIT_FAILURE);
486  }
487 
488  /* DXL_PROTOCOL_PARAM */
490  {
491  ROS_ERROR("[dxl_motors_builder]: %s param is missing on param server. make sure that this param exist in dxl_joints_config.yaml "
492  "and that your launch includes this param file. shutting down...", DXL_PROTOCOL_PARAM);
493  ros::shutdown();
494  exit (EXIT_FAILURE);
495  }
496 
497  /* DXL_PORT_PARAM */
499  {
500  ROS_ERROR("[dxl_motors_builder]: %s param is missing on param server. make sure that this param exist in dxl_joints_config.yaml "
501  "and that your launch includes this param file. shutting down...", DXL_PORT_PARAM);
502  ros::shutdown();
503  exit (EXIT_FAILURE);
504  }
505 
506  /* DXL_PORT_BAUD_PARAM */
508  {
509  ROS_ERROR("[dxl_motors_builder]: %s param is missing on param server. make sure that this param exist in dxl_joints_config.yaml "
510  "and that your launch includes this param file. shutting down...", DXL_PORT_BAUD_PARAM);
511  ros::shutdown();
512  exit (EXIT_FAILURE);
513  }
514  }
515 
517  {
518  if (!load_dxl_hw_)
519  return;
520  /* build motors */
521  for(int i = 0; i < dxl_joints_config_.size(); i++)
522  {
523  /* feed motor with user defined settings */
525  {
526  ROS_ERROR("[dxl_motors_builder]: dxl motor id at index %d param data type is invalid or missing. "
527  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
528  ros::shutdown();
529  exit (EXIT_FAILURE);
530  }
531 
532  struct dxl::motor new_motor;
533 
534  /* defaults to prevent bad movement on startup */
535  new_motor.spec.model = 0;
536  new_motor.command_position = 0.0;
537  new_motor.command_velocity = 0.5;
538  new_motor.first_pos_read = true;
539  new_motor.dont_allow_zero_ticks_vel = true;
540 
541  if(dxl_joints_config_[i]["id"].getType() != XmlRpc::XmlRpcValue::TypeInt) //invalid id field
542  {
543  ROS_ERROR("[dxl_motors_builder]: dxl motor id at index %d: invalid data type or missing. "
544  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
545  ros::shutdown();
546  exit (EXIT_FAILURE);
547  }
548  new_motor.id = static_cast<int>(dxl_joints_config_[i]["id"]);
549 
550  if (dxl_joints_config_[i]["joint_name"].getType() != XmlRpc::XmlRpcValue::TypeString) //invalid joint_name field
551  {
552  ROS_ERROR("[dxl_motors_builder]: dxl motor joint_name at index %d: invalid data type or missing. "
553  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
554  ros::shutdown();
555  exit (EXIT_FAILURE);
556  }
557  new_motor.joint_name = static_cast<std::string>(dxl_joints_config_[i]["joint_name"]);
558 
559  if (dxl_joints_config_[i]["interface"].getType() != XmlRpc::XmlRpcValue::TypeString) //invalid interface field
560  {
561  ROS_ERROR("[dxl_motors_builder]: dxl motor interface_type at index %d: invalid data type or missing. "
562  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
563  ros::shutdown();
564  exit (EXIT_FAILURE);
565  }
566  std::string string_interface_type = static_cast<std::string>(dxl_joints_config_[i]["interface"]);
567  new_motor.interface_type = dxl::motor::stringToInterfaceType(string_interface_type);
568 
569  if(dxl_joints_config_[i]["direction"].getType() != XmlRpc::XmlRpcValue::TypeInt) //invalid direction field
570  {
571  ROS_ERROR("[dxl_motors_builder]: dxl motor direction at index %d: invalid data type or missing. "
572  "make sure that this param exist in dxl_joints_config.yaml and that your launch includes this param file. shutting down...", i);
573  ros::shutdown();
574  exit (EXIT_FAILURE);
575  }
576  new_motor.direction = static_cast<int>(dxl_joints_config_[i]["direction"]);
577 
578  motors_.push_back(new_motor);
579  }
580  }
581 
583  hardware_interface::PositionJointInterface &position_interface,
585  {
586  if (!load_dxl_hw_)
587  return;
588  for(dxl::motor &motor : motors_)
589  {
590  /* joint state registration */
591 
593  &motor.position,
594  &motor.velocity,
595  &motor.current));
596  joint_state_interface.registerHandle(joint_state_handles_.back());
597 
598  /* joint command registration */
599  switch (motor.interface_type)
600  {
601  case dxl::motor::POS:
602 
603  pos_handles_.push_back(hardware_interface::JointHandle (joint_state_interface.getHandle(motor.joint_name),
604  &motor.command_position));
605  position_interface.registerHandle(pos_handles_.back());
606  break;
607 
608  case dxl::motor::POS_VEL:
609  posvel_handles_.push_back(hardware_interface::PosVelJointHandle (joint_state_interface.getHandle(motor.joint_name),
610  &motor.command_position,
611  &motor.command_velocity));
612  posvel_interface.registerHandle(posvel_handles_.back());
613  break;
614  }
615  }
616  }
617 
619  {
620  if (!load_dxl_hw_)
621  return;
624  protocol_);
625  switch (port_state)
626  {
628  ROS_ERROR("[dxl_motors_builder]: open dxl port %s failed. "
629  "make sure cable is connected and port has the right permissions. shutting down...", dxl_port_.c_str());
630  ros::shutdown();
631  exit (EXIT_FAILURE);
633  ROS_ERROR("[dxl_motors_builder]: setting dxl baudrate to %d failed. shutting down...", dxl_baudrate_);
634  ros::shutdown();
635  exit (EXIT_FAILURE);
637  ROS_ERROR("[dxl_motors_builder]: protocol version %f is invalid. shutting down...", protocol_);
638  ros::shutdown();
639  exit (EXIT_FAILURE);
641  ROS_INFO("[dxl_motors_builder]: dxl port opened successfully \nport name: %s \nbaudrate: %d", dxl_port_.c_str(), dxl_baudrate_);
642  }
643  }
644 }
float torque_const_a
std::vector< hardware_interface::JointHandle > pos_handles_
std::vector< hardware_interface::JointStateHandle > joint_state_handles_
void registerHandles(hardware_interface::JointStateInterface &joint_state_interface, hardware_interface::PositionJointInterface &position_interface, hardware_interface::PosVelJointInterface &posvel_interface)
uint16_t vel_read_addr
DxlMotorsBuilder(ros::NodeHandle &nh)
void speakMsg(std::string msg, int sleep_time)
InterfaceType interface_type
XmlRpc::XmlRpcValue dxl_joints_config_
double command_position
uint16_t pos_read_addr
uint16_t vel_write_addr
uint16_t len_goal_speed
#define MAX_READ_ERRORS
int size() const
uint16_t torque_write_addr
bool first_pos_read
bool sleep() const
uint16_t len_present_speed
uint16_t current_read_addr
bool readMotorsError(std::vector< motor > &motors)
dxl::spec spec
uint16_t pos_write_addr
std::string joint_name
bool dont_allow_zero_ticks_vel
#define DXL_PROTOCOL_PARAM
uint16_t error_read_addr
#define SPEC_CONFIG_PARAM
bool readMotorsVel(std::vector< motor > &motors)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
Type const & getType() const
std::map< uint16_t, dxl::spec > specs_
#define ROS_WARN(...)
#define DXL_PORT_PARAM
XmlRpc::XmlRpcValue dxl_spec_config_
std::vector< hardware_interface::PosVelJointHandle > posvel_handles_
std::string name
uint16_t model
ROSCPP_DECL bool get(const std::string &key, std::string &s)
#define ROS_INFO(...)
void writeToMotor(int motor_id, double position, double velocity)
double rpm_scale_factor
uint16_t len_present_pos
uint16_t len_present_curr
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define MAX_PING_ERRORS
uint16_t len_goal_pos
void registerHandle(const JointStateHandle &handle)
static InterfaceType stringToInterfaceType(std::string type)
bool bulkWritePosition(std::vector< motor > &motors)
#define MAX_WRITE_ERRORS
bool sleep()
JointStateHandle getHandle(const std::string &name)
bool readMotorsPos(std::vector< motor > &motors)
float torque_const_b
#define DXL_JOINTS_CONFIG_PARAM
bool getParam(const std::string &key, std::string &s) const
ROSCPP_DECL void shutdown()
double current_ratio
double command_velocity
bool hasParam(const std::string &key) const
std::vector< dxl::motor > motors_
#define ROS_ERROR(...)
bool torqueServiceCB(std_srvs::SetBool::Request &req, std_srvs::SetBool::Response &res)
PortState openPort(std::string port_name, unsigned int baudrate, float protocol)
uint8_t id
#define DXL_PORT_BAUD_PARAM
bool readMotorsLoad(std::vector< motor > &motors)
bool setTorque(motor &motor, bool flag)
bool bulkWriteVelocity(std::vector< motor > &motors)
bool ping(motor &motor)


armadillo2_hw
Author(s):
autogenerated on Wed Jan 3 2018 03:48:27