kinematics_interface.cpp
Go to the documentation of this file.
1 /*
2  * RDL - Robot Dynamics Library
3  * Copyright (c) 2017 Jordan Lack <jlack1987@gmail.com>
4  *
5  * Licensed under the zlib license. See LICENSE for more details.
6  */
7 
13 #include <geometry_msgs/PointStamped.h>
14 #include <ros/ros.h>
15 
16 #include "rdl_dynamics/Dynamics.h"
19 #include "rdl_dynamics/Model.h"
21 #include "rdl_dynamics/rdl_utils.h"
22 #include "rdl_msgs/ChangeOrientationFrame.h"
23 #include "rdl_msgs/ChangePointFrame.h"
24 #include "rdl_msgs/ChangePointArrayFrame.h"
25 #include "rdl_msgs/ChangePoseFrame.h"
26 #include "rdl_msgs/Change3DVectorFrame.h"
27 #include "rdl_msgs/Change3DVectorArrayFrame.h"
28 #include "rdl_msgs/ChangeTwistFrame.h"
29 #include "rdl_msgs/ChangeTwistArrayFrame.h"
30 #include "rdl_msgs/ChangeWrenchArrayFrame.h"
31 #include "rdl_msgs/ChangeWrenchFrame.h"
32 #include "rdl_msgs/GetTransform.h"
33 #include "rdl_msgs/GetTwist.h"
34 #include "rdl_msgs/GetBodyGravityWrench.h"
35 #include "rdl_msgs/GetRobotCenterOfMass.h"
36 #include "rdl_msgs/RobotState.h"
38 
40 std::map<std::string, std::string> joint_to_body_name_map;
41 std::map<std::string, unsigned int> joint_name_q_index;
43 
45 {
47 }
48 
49 void robotStateCallback(const rdl_msgs::RobotState& msg)
50 {
51  if (msg.position.size() != model->q_size)
52  {
53  std::cout << "kinematics_interface: position vector has incorrect size. Should be " << model->q_size << std::endl;
54  return;
55  }
56 
57  for (unsigned int i = 0; i < msg.position.size(); i++)
58  {
59  q[i] = msg.position[i];
60  }
61 
62  if (msg.velocity.size() != model->qdot_size)
63  {
64  qdot.setZero();
65  }
66  else
67  {
68  for (unsigned int i = 0; i < model->qdot_size; i++)
69  {
70  qdot[i] = msg.velocity[i];
71  }
72  }
73 
75 }
76 
77 bool hasEnding(std::string const& fullString, std::string const& ending)
78 {
79  if (fullString.length() >= ending.length())
80  {
81  return (0 == fullString.compare(fullString.length() - ending.length(), ending.length(), ending));
82  }
83  else
84  {
85  return false;
86  }
87 }
88 
90 {
91  try
92  {
93  if (!std::strcmp(name.c_str(), "world"))
94  {
95  return model->worldFrame;
96  }
97  else
98  {
99  return model->referenceFrameMap.at(name);
100  }
101  }
102  catch (const std::out_of_range& e)
103  {
104  // Check and see if it's a link COM frame. All com frame
105  // names end with '_com'
106  if (hasEnding(name, "_com"))
107  {
108  // Name does end in '_com', now get the body name the com frame is on
109  std::string parent_body_name = name.substr(0, name.size() - 4);
110 
111  // now get the body if of the body the com frame lives on
112  unsigned int parent_body_id = model->GetBodyId(parent_body_name.c_str());
113 
114  // didn't find the body
115  if (parent_body_id == std::numeric_limits<unsigned int>::max())
116  {
118  }
119 
120  return model->bodyCenteredFrames[parent_body_id];
121  }
122 
124  }
125 }
126 
127 bool changePoseFrame(rdl_msgs::ChangePoseFrameRequest& req, rdl_msgs::ChangePoseFrameResponse& resp)
128 {
129  RobotDynamics::ReferenceFramePtr old_frame = getFrame(req.pose_in.header.frame_id);
130  if (old_frame == nullptr)
131  {
132  resp.report = "No reference frame found with name " + req.pose_in.header.frame_id;
133  resp.success = false;
134  return true;
135  }
136 
137  RobotDynamics::ReferenceFramePtr new_frame = getFrame(req.new_reference_frame);
138  if (new_frame == nullptr)
139  {
140  resp.report = "No reference frame found with name " + req.new_reference_frame;
141  resp.success = false;
142  return true;
143  }
144 
145  RobotDynamics::Math::Quaternion orientation(req.pose_in.pose.orientation.x, req.pose_in.pose.orientation.y, req.pose_in.pose.orientation.z,
146  req.pose_in.pose.orientation.w);
147  RobotDynamics::Math::FrameOrientation quat(old_frame, orientation);
148  RobotDynamics::Math::FramePoint p(old_frame, req.pose_in.pose.position.x, req.pose_in.pose.position.y, req.pose_in.pose.position.z);
149 
150  quat.changeFrame(new_frame);
151  p.changeFrame(new_frame);
152 
153  resp.pose_out.header.frame_id = new_frame->getName();
154  resp.pose_out.pose.orientation.x = quat.x();
155  resp.pose_out.pose.orientation.y = quat.y();
156  resp.pose_out.pose.orientation.z = quat.z();
157  resp.pose_out.pose.orientation.w = quat.w();
158  resp.pose_out.pose.position.x = p.x();
159  resp.pose_out.pose.position.y = p.y();
160  resp.pose_out.pose.position.z = p.z();
161  resp.success = true;
162 
163  return true;
164 }
165 
166 bool changeOrientationFrame(rdl_msgs::ChangeOrientationFrameRequest& req, rdl_msgs::ChangeOrientationFrameResponse& resp)
167 {
168  RobotDynamics::ReferenceFramePtr old_frame = getFrame(req.orientation_in.header.frame_id);
169  if (old_frame == nullptr)
170  {
171  resp.report = "No reference frame found with name " + req.orientation_in.header.frame_id;
172  resp.success = false;
173  return true;
174  }
175 
176  RobotDynamics::ReferenceFramePtr new_frame = getFrame(req.new_reference_frame);
177  if (new_frame == nullptr)
178  {
179  resp.report = "No reference frame found with name " + req.new_reference_frame;
180  resp.success = false;
181  return true;
182  }
183 
184  RobotDynamics::Math::FrameOrientation quat(old_frame, req.orientation_in.quaternion.x, req.orientation_in.quaternion.y, req.orientation_in.quaternion.z,
185  req.orientation_in.quaternion.w);
186 
187  quat.changeFrame(new_frame);
188 
189  resp.orientation_out.header.frame_id = new_frame->getName();
190  resp.orientation_out.quaternion.x = quat.x();
191  resp.orientation_out.quaternion.y = quat.y();
192  resp.orientation_out.quaternion.z = quat.z();
193  resp.orientation_out.quaternion.w = quat.w();
194  resp.success = true;
195 
196  return true;
197 }
198 
199 bool changePointFrame(rdl_msgs::ChangePointFrameRequest& req, rdl_msgs::ChangePointFrameResponse& resp)
200 {
201  RobotDynamics::ReferenceFramePtr old_frame = getFrame(req.point_in.header.frame_id);
202  if (old_frame == nullptr)
203  {
204  resp.report = "No reference frame found with name " + req.point_in.header.frame_id;
205  resp.success = false;
206  return true;
207  }
208 
209  RobotDynamics::ReferenceFramePtr new_frame = getFrame(req.new_reference_frame);
210  if (new_frame == nullptr)
211  {
212  resp.report = "No reference frame found with name " + req.new_reference_frame;
213  resp.success = false;
214  return true;
215  }
216 
217  RobotDynamics::Math::FramePoint p(old_frame, req.point_in.point.x, req.point_in.point.y, req.point_in.point.z);
218 
219  p.changeFrame(new_frame);
220 
221  resp.point_out.header.frame_id = new_frame->getName();
222  resp.point_out.point.x = p.x();
223  resp.point_out.point.y = p.y();
224  resp.point_out.point.z = p.z();
225  resp.success = true;
226 
227  return true;
228 }
229 
230 bool changePointArrayFrame(rdl_msgs::ChangePointArrayFrameRequest& req, rdl_msgs::ChangePointArrayFrameResponse& resp)
231 {
232  if (req.point_array_in.size() != req.new_reference_frame.size())
233  {
234  resp.success = false;
235  resp.report = "Size of point array doesn't match size of new reference frame array";
236  return true;
237  }
238 
239  geometry_msgs::PointStamped point;
240  for (unsigned int i = 0; i < req.point_array_in.size(); i++)
241  {
242  RobotDynamics::ReferenceFramePtr old_frame = getFrame(req.point_array_in[i].header.frame_id);
243  if (old_frame == nullptr)
244  {
245  resp.report = "No reference frame found with name " + req.point_array_in[i].header.frame_id;
246  resp.success = false;
247  return true;
248  }
249 
250  RobotDynamics::ReferenceFramePtr new_frame = getFrame(req.new_reference_frame[i]);
251  if (new_frame == nullptr)
252  {
253  resp.report = "No reference frame found with name " + req.new_reference_frame[i];
254  resp.success = false;
255  return true;
256  }
257 
258  RobotDynamics::Math::FramePoint p(old_frame, req.point_array_in[i].point.x, req.point_array_in[i].point.y, req.point_array_in[i].point.z);
259 
260  p.changeFrame(new_frame);
261 
262  point.header.frame_id = new_frame->getName();
263  point.point.x = p.x();
264  point.point.y = p.y();
265  point.point.z = p.z();
266 
267  resp.point_array_out.push_back(point);
268  }
269 
270  resp.success = true;
271 
272  return true;
273 }
274 
275 bool change3DVectorFrame(rdl_msgs::Change3DVectorFrameRequest& req, rdl_msgs::Change3DVectorFrameResponse& resp)
276 {
277  RobotDynamics::ReferenceFramePtr old_frame = getFrame(req.vector_in.header.frame_id);
278  if (old_frame == nullptr)
279  {
280  resp.report = "No reference frame found with name " + req.vector_in.header.frame_id;
281  resp.success = false;
282  return true;
283  }
284 
285  RobotDynamics::ReferenceFramePtr new_frame = getFrame(req.new_reference_frame);
286  if (new_frame == nullptr)
287  {
288  resp.report = "No reference frame found with name " + req.new_reference_frame;
289  resp.success = false;
290  return true;
291  }
292 
293  RobotDynamics::Math::FrameVector v(old_frame, req.vector_in.vector.x, req.vector_in.vector.y, req.vector_in.vector.z);
294 
295  v.changeFrame(new_frame);
296 
297  resp.vector_out.header.frame_id = new_frame->getName();
298  resp.vector_out.vector.x = v.x();
299  resp.vector_out.vector.y = v.y();
300  resp.vector_out.vector.z = v.z();
301  resp.success = true;
302 
303  return true;
304 }
305 
306 bool change3DVectorArrayFrame(rdl_msgs::Change3DVectorArrayFrameRequest& req, rdl_msgs::Change3DVectorArrayFrameResponse& resp)
307 {
308  geometry_msgs::Vector3Stamped vector;
309  for (unsigned int i = 0; i < req.vector_array_in.size(); i++)
310  {
311  RobotDynamics::ReferenceFramePtr old_frame = getFrame(req.vector_array_in[i].header.frame_id);
312  if (old_frame == nullptr)
313  {
314  resp.report = "No reference frame found with name " + req.vector_array_in[i].header.frame_id;
315  resp.success = false;
316  return true;
317  }
318 
319  RobotDynamics::ReferenceFramePtr new_frame = getFrame(req.new_reference_frame[i]);
320  if (new_frame == nullptr)
321  {
322  resp.report = "No reference frame found with name " + req.new_reference_frame[i];
323  resp.success = false;
324  return true;
325  }
326 
327  RobotDynamics::Math::FrameVector v(old_frame, req.vector_array_in[i].vector.x, req.vector_array_in[i].vector.y, req.vector_array_in[i].vector.z);
328 
329  v.changeFrame(new_frame);
330 
331  vector.header.frame_id = new_frame->getName();
332  vector.vector.x = v.x();
333  vector.vector.y = v.y();
334  vector.vector.z = v.z();
335 
336  resp.vector_array_out.push_back(vector);
337  }
338 
339  resp.success = true;
340 
341  return true;
342 }
343 
344 bool changeWrenchFrame(rdl_msgs::ChangeWrenchFrameRequest& req, rdl_msgs::ChangeWrenchFrameResponse& resp)
345 {
346  RobotDynamics::ReferenceFramePtr old_frame = getFrame(req.wrench_in.header.frame_id);
347 
348  if (old_frame == nullptr)
349  {
350  resp.report = "No reference frame found with name " + req.wrench_in.header.frame_id;
351  resp.success = false;
352  return true;
353  }
354 
355  RobotDynamics::ReferenceFramePtr new_frame = getFrame(req.new_reference_frame);
356  if (new_frame == nullptr)
357  {
358  resp.report = "No reference frame found with name " + req.new_reference_frame;
359  resp.success = false;
360  return true;
361  }
362 
363  RobotDynamics::Math::SpatialForce force(old_frame, req.wrench_in.wrench.torque.x, req.wrench_in.wrench.torque.y, req.wrench_in.wrench.torque.z,
364  req.wrench_in.wrench.force.x, req.wrench_in.wrench.force.y, req.wrench_in.wrench.force.z);
365 
366  force.changeFrame(new_frame);
367 
368  resp.wrench_out.header.frame_id = new_frame->getName();
369  resp.wrench_out.wrench.torque.x = force.mx();
370  resp.wrench_out.wrench.torque.y = force.my();
371  resp.wrench_out.wrench.torque.z = force.mz();
372  resp.wrench_out.wrench.force.x = force.fx();
373  resp.wrench_out.wrench.force.y = force.fy();
374  resp.wrench_out.wrench.force.z = force.fz();
375  resp.success = true;
376 
377  return true;
378 }
379 
380 bool changeWrenchArrayFrame(rdl_msgs::ChangeWrenchArrayFrameRequest& req, rdl_msgs::ChangeWrenchArrayFrameResponse& resp)
381 {
382  if (req.wrench_array_in.size() != req.new_reference_frame.size())
383  {
384  resp.report = "Size of wrench array does not match size of new reference frame array";
385  resp.success = false;
386  return true;
387  }
388 
389  geometry_msgs::WrenchStamped wrench;
390  for (unsigned int i = 0; i < req.wrench_array_in.size(); i++)
391  {
392  RobotDynamics::ReferenceFramePtr old_frame = getFrame(req.wrench_array_in[i].header.frame_id);
393 
394  if (old_frame == nullptr)
395  {
396  resp.report = "No reference frame found with name " + req.wrench_array_in[i].header.frame_id;
397  resp.success = false;
398  return true;
399  }
400 
401  RobotDynamics::ReferenceFramePtr new_frame = getFrame(req.new_reference_frame[i]);
402  if (new_frame == nullptr)
403  {
404  resp.report = "No reference frame found with name " + req.new_reference_frame[i];
405  resp.success = false;
406  return true;
407  }
408 
409  RobotDynamics::Math::SpatialForce force(old_frame, req.wrench_array_in[i].wrench.torque.x, req.wrench_array_in[i].wrench.torque.y,
410  req.wrench_array_in[i].wrench.torque.z, req.wrench_array_in[i].wrench.force.x, req.wrench_array_in[i].wrench.force.y,
411  req.wrench_array_in[i].wrench.force.z);
412 
413  force.changeFrame(new_frame);
414 
415  wrench.header.frame_id = new_frame->getName();
416  wrench.wrench.torque.x = force.mx();
417  wrench.wrench.torque.y = force.my();
418  wrench.wrench.torque.z = force.mz();
419  wrench.wrench.force.x = force.fx();
420  wrench.wrench.force.y = force.fy();
421  wrench.wrench.force.z = force.fz();
422  resp.wrench_array_out.push_back(wrench);
423  }
424 
425  resp.success = true;
426  return true;
427 }
428 
429 bool changeTwistFrame(rdl_msgs::ChangeTwistFrameRequest& req, rdl_msgs::ChangeTwistFrameResponse& resp)
430 {
431  RobotDynamics::ReferenceFramePtr old_frame = getFrame(req.twist_in.header.frame_id);
432  if (old_frame == nullptr)
433  {
434  resp.report = "No reference frame found with name " + req.twist_in.header.frame_id;
435  resp.success = false;
436  return true;
437  }
438 
439  RobotDynamics::ReferenceFramePtr new_frame = getFrame(req.new_reference_frame);
440  if (new_frame == nullptr)
441  {
442  resp.report = "No reference frame found with name " + req.new_reference_frame;
443  resp.success = false;
444  return true;
445  }
446 
447  RobotDynamics::Math::MotionVector twist(req.twist_in.twist.angular.x, req.twist_in.twist.angular.y, req.twist_in.twist.angular.z, req.twist_in.twist.linear.x,
448  req.twist_in.twist.linear.y, req.twist_in.twist.linear.z);
449 
450  RobotDynamics::Math::SpatialTransform X = old_frame->getTransformToDesiredFrame(new_frame);
451  twist.transform(X);
452 
453  resp.twist_out.header.frame_id = new_frame->getName();
454  resp.twist_out.twist.angular.x = twist.wx();
455  resp.twist_out.twist.angular.y = twist.wy();
456  resp.twist_out.twist.angular.z = twist.wz();
457  resp.twist_out.twist.linear.x = twist.vx();
458  resp.twist_out.twist.linear.y = twist.vy();
459  resp.twist_out.twist.linear.z = twist.vz();
460  resp.success = true;
461 
462  return true;
463 }
464 
465 bool changeTwistArrayFrame(rdl_msgs::ChangeTwistArrayFrameRequest& req, rdl_msgs::ChangeTwistArrayFrameResponse& resp)
466 {
467  if (req.twist_array_in.size() != req.new_reference_frame.size())
468  {
469  resp.report = "Size of twist array does not match size of new reference frame array";
470  resp.success = false;
471  return true;
472  }
473 
474  geometry_msgs::TwistStamped twist_msg;
475  for (unsigned int i = 0; i < req.twist_array_in.size(); i++)
476  {
477  RobotDynamics::ReferenceFramePtr old_frame = getFrame(req.twist_array_in[i].header.frame_id);
478  if (old_frame == nullptr)
479  {
480  resp.report = "No reference frame found with name " + req.twist_array_in[i].header.frame_id;
481  resp.success = false;
482  return true;
483  }
484 
485  RobotDynamics::ReferenceFramePtr new_frame = getFrame(req.new_reference_frame[i]);
486  if (new_frame == nullptr)
487  {
488  resp.report = "No reference frame found with name " + req.new_reference_frame[i];
489  resp.success = false;
490  return true;
491  }
492 
493  RobotDynamics::Math::MotionVector twist(req.twist_array_in[i].twist.angular.x, req.twist_array_in[i].twist.angular.y, req.twist_array_in[i].twist.angular.z,
494  req.twist_array_in[i].twist.linear.x, req.twist_array_in[i].twist.linear.y, req.twist_array_in[i].twist.linear.z);
495 
496  RobotDynamics::Math::SpatialTransform X = old_frame->getTransformToDesiredFrame(new_frame);
497  twist.transform(X);
498 
499  twist_msg.header.frame_id = new_frame->getName();
500  twist_msg.twist.angular.x = twist.wx();
501  twist_msg.twist.angular.y = twist.wy();
502  twist_msg.twist.angular.z = twist.wz();
503  twist_msg.twist.linear.x = twist.vx();
504  twist_msg.twist.linear.y = twist.vy();
505  twist_msg.twist.linear.z = twist.vz();
506  resp.twist_array_out.push_back(twist_msg);
507  }
508 
509  resp.success = true;
510 
511  return true;
512 }
513 
514 bool getTwist(rdl_msgs::GetTwistRequest& req, rdl_msgs::GetTwistResponse& resp)
515 {
516  RobotDynamics::ReferenceFramePtr body_frame = getFrame(req.body_frame);
517  if (body_frame == nullptr)
518  {
519  resp.report = "No reference frame found with name " + req.body_frame;
520  resp.success = false;
521  return true;
522  }
523 
524  RobotDynamics::ReferenceFramePtr base_frame = getFrame(req.base_frame);
525  if (base_frame == nullptr)
526  {
527  resp.report = "No reference frame found with name " + req.base_frame;
528  resp.success = false;
529  return true;
530  }
531 
532  RobotDynamics::ReferenceFramePtr expressed_in_frame = getFrame(req.expressed_in_frame);
533  if (expressed_in_frame == nullptr)
534  {
535  resp.report = "No reference frame found with name " + req.expressed_in_frame;
536  resp.success = false;
537  return true;
538  }
539 
540  RobotDynamics::Math::SpatialMotion m = RobotDynamics::calcSpatialVelocity(*model, q, qdot, body_frame, base_frame, expressed_in_frame, false);
541  resp.success = true;
542  resp.twist_out.header.frame_id = expressed_in_frame->getName();
543  resp.twist_out.twist.angular.x = m.wx();
544  resp.twist_out.twist.angular.y = m.wy();
545  resp.twist_out.twist.angular.z = m.wz();
546  resp.twist_out.twist.linear.x = m.vx();
547  resp.twist_out.twist.linear.y = m.vy();
548  resp.twist_out.twist.linear.z = m.vz();
549 
550  return true;
551 }
552 
553 bool getTransform(rdl_msgs::GetTransformRequest& req, rdl_msgs::GetTransformResponse& resp)
554 {
555  RobotDynamics::ReferenceFramePtr body_frame = getFrame(req.from_reference_frame);
556 
557  if (body_frame == nullptr)
558  {
559  resp.report = "No reference frame found with name " + req.from_reference_frame;
560  resp.success = false;
561  return true;
562  }
563 
564  RobotDynamics::ReferenceFramePtr base_frame = getFrame(req.to_reference_frame);
565  if (base_frame == nullptr)
566  {
567  resp.report = "No reference frame found with name " + req.to_reference_frame;
568  resp.success = false;
569  return true;
570  }
571 
572  RobotDynamics::Math::SpatialTransform X = body_frame->getTransformToDesiredFrame(base_frame);
574 
575  resp.success = true;
576  resp.transform.header.frame_id = body_frame->getName();
577  resp.transform.child_frame_id = base_frame->getName();
578  resp.transform.transform.rotation.x = orientation.x();
579  resp.transform.transform.rotation.y = orientation.y();
580  resp.transform.transform.rotation.z = orientation.z();
581  resp.transform.transform.rotation.w = orientation.w();
582 
583  resp.transform.transform.translation.x = X.r.x();
584  resp.transform.transform.translation.y = X.r.y();
585  resp.transform.transform.translation.z = X.r.z();
586 
587  return true;
588 }
589 
590 bool getRobotCenterOfMass(rdl_msgs::GetRobotCenterOfMassRequest& req, rdl_msgs::GetRobotCenterOfMassResponse& resp)
591 {
594  RobotDynamics::Utils::calcCenterOfMass(*model, q, qdot, p_com, &v_com, false);
595 
596  resp.success = true;
597  resp.com.header.frame_id = p_com.getReferenceFrame()->getName();
598  resp.com.point.x = p_com.x();
599  resp.com.point.y = p_com.y();
600  resp.com.point.z = p_com.z();
601 
602  resp.com_vel.header.frame_id = v_com.getReferenceFrame()->getName();
603  resp.com_vel.vector.x = v_com.x();
604  resp.com_vel.vector.y = v_com.y();
605  resp.com_vel.vector.z = v_com.z();
606 
607  return true;
608 }
609 
610 bool getBodyGravityWrench(rdl_msgs::GetBodyGravityWrenchRequest& req, rdl_msgs::GetBodyGravityWrenchResponse& resp)
611 {
612  unsigned int body_id = model->GetBodyId(req.body.c_str());
613 
614  if (body_id == std::numeric_limits<unsigned int>::max())
615  {
616  resp.report = "No body found with name " + req.body;
617  resp.success = false;
618  return true;
619  }
620 
622  RobotDynamics::calcBodyGravityWrench(*model, body_id, wrench);
623 
624  resp.success = true;
625  resp.wrench.header.frame_id = wrench.getReferenceFrame()->getName();
626  resp.wrench.wrench.torque.x = wrench.mx();
627  resp.wrench.wrench.torque.y = wrench.my();
628  resp.wrench.wrench.torque.z = wrench.mz();
629 
630  resp.wrench.wrench.force.x = wrench.fx();
631  resp.wrench.wrench.force.y = wrench.fy();
632  resp.wrench.wrench.force.z = wrench.fz();
633 
634  return true;
635 }
636 
637 int main(int argc, char* argv[])
638 {
639  ros::init(argc, argv, "rdl_kinematics_interface");
640  ros::NodeHandle nh("~");
641  std::string joint_states_topic;
642  nh.param<std::string>("joint_states_topic", joint_states_topic, "joint_states");
643 
644  std::string urdf_string;
645  if (!nh.getParam("robot_description", urdf_string))
646  {
647  ROS_ERROR_STREAM("kinematics_interface: Unable to retrieve urdf from param server at " << nh.getNamespace() << "/robot_description");
648  return 1;
649  }
650 
651  model.reset(new RobotDynamics::Model());
653  {
654  return 1;
655  }
656 
657  q = RobotDynamics::Math::VectorNd::Zero(model->q_size);
658  qdot = RobotDynamics::Math::VectorNd::Zero(model->qdot_size);
659 
661  {
662  return 1;
663  }
664 
665  for (std::pair<std::string, std::string> pair : joint_to_body_name_map)
666  {
667  try
668  {
669  joint_name_q_index[pair.first] = model->mJoints[model->GetBodyId(pair.second.c_str())].q_index;
670  }
671  catch (const std::out_of_range& e)
672  {
673  ROS_ERROR_STREAM("Error determining q_index for " << pair.first << ": " << e.what());
674  return 1;
675  }
676  }
677 
678  ros::Subscriber joint_states_subscriber;
679  ros::Subscriber robot_state_subscriber;
680 
681  robot_state_subscriber = nh.subscribe("robot_state", 0, robotStateCallback);
682 
683  ros::ServiceServer changePointFrameSrv = nh.advertiseService("change_frame_point", changePointFrame);
684  ros::ServiceServer changePoseFrameSrv = nh.advertiseService("change_frame_pose", changePoseFrame);
685  ros::ServiceServer changeOrientationFrameSrv = nh.advertiseService("change_frame_orientation", changeOrientationFrame);
686  ros::ServiceServer changePointArrayFrameSrv = nh.advertiseService("change_frame_point_array", changePointArrayFrame);
687  ros::ServiceServer change3DVectorFrameSrv = nh.advertiseService("change_frame_3dvector", change3DVectorFrame);
688  ros::ServiceServer change3DVectorArrayFrameSrv = nh.advertiseService("change_frame_3dvector_array", change3DVectorArrayFrame);
689  ros::ServiceServer changeWrenchFrameSrv = nh.advertiseService("change_frame_wrench", changeWrenchFrame);
690  ros::ServiceServer changeWrenchArrayFrameSrv = nh.advertiseService("change_frame_wrench_array", changeWrenchArrayFrame);
691  ros::ServiceServer changeTwistFrameSrv = nh.advertiseService("change_frame_twist", changeTwistFrame);
692  ros::ServiceServer changeTwistArrayFrameSrv = nh.advertiseService("change_frame_twist_array", changeTwistArrayFrame);
693  ros::ServiceServer getTwistSrv = nh.advertiseService("get_twist", getTwist);
694  ros::ServiceServer getTransformSrv = nh.advertiseService("get_transform", getTransform);
695  ros::ServiceServer getRobotCenterOfMassSrv = nh.advertiseService("get_robot_com", getRobotCenterOfMass);
696  ros::ServiceServer getBodyGravityWrenchSrv = nh.advertiseService("get_body_grav_wrench", getBodyGravityWrench);
697 
698  while (ros::ok())
699  {
700  ros::spin();
701  }
702 
703  return 0;
704 }
EIGEN_STRONG_INLINE double & x()
RobotDynamics::Math::VectorNd qdot
bool changePoseFrame(rdl_msgs::ChangePoseFrameRequest &req, rdl_msgs::ChangePoseFrameResponse &resp)
RobotDynamics::ReferenceFramePtr getFrame(const std::string &name)
EIGEN_STRONG_INLINE double & w()
ReferenceFramePtr getReferenceFrame() const
bool changeWrenchArrayFrame(rdl_msgs::ChangeWrenchArrayFrameRequest &req, rdl_msgs::ChangeWrenchArrayFrameResponse &resp)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
std::shared_ptr< Model > ModelPtr
Math::SpatialMotion calcSpatialVelocity(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, ReferenceFramePtr body_frame, ReferenceFramePtr relative_body_frame, ReferenceFramePtr expressedInFrame=nullptr, const bool update_kinematics=true)
void robotStateCallback(const rdl_msgs::RobotState &msg)
EIGEN_STRONG_INLINE double & vz()
void transform(const SpatialTransform &X)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool change3DVectorArrayFrame(rdl_msgs::Change3DVectorArrayFrameRequest &req, rdl_msgs::Change3DVectorArrayFrameResponse &resp)
EIGEN_STRONG_INLINE double & fy()
static Quaternion toQuaternion(const Vector3d &axis, double angle_rad)
bool getRobotCenterOfMass(rdl_msgs::GetRobotCenterOfMassRequest &req, rdl_msgs::GetRobotCenterOfMassResponse &resp)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
RobotDynamics::ModelPtr model
EIGEN_STRONG_INLINE double & wx()
EIGEN_STRONG_INLINE double & wy()
std::map< std::string, unsigned int > joint_name_q_index
EIGEN_STRONG_INLINE double & fx()
void updateKinematics()
bool changePointFrame(rdl_msgs::ChangePointFrameRequest &req, rdl_msgs::ChangePointFrameResponse &resp)
EIGEN_STRONG_INLINE double & vx()
bool changePointArrayFrame(rdl_msgs::ChangePointArrayFrameRequest &req, rdl_msgs::ChangePointArrayFrameResponse &resp)
EIGEN_STRONG_INLINE double & fz()
std::shared_ptr< ReferenceFrame > ReferenceFramePtr
EIGEN_STRONG_INLINE double & my()
bool hasEnding(std::string const &fullString, std::string const &ending)
virtual void changeFrame(ReferenceFramePtr desiredFrame)
EIGEN_STRONG_INLINE double & y()
bool changeWrenchFrame(rdl_msgs::ChangeWrenchFrameRequest &req, rdl_msgs::ChangeWrenchFrameResponse &resp)
int main(int argc, char *argv[])
bool param(const std::string &param_name, T &param_val, const T &default_val) const
bool getTwist(rdl_msgs::GetTwistRequest &req, rdl_msgs::GetTwistResponse &resp)
void transform(const RobotDynamics::Math::SpatialTransform &X)
void calcBodyGravityWrench(Model &model, unsigned int body_id, RobotDynamics::Math::SpatialForce &gravity_wrench)
ROSCPP_DECL bool ok()
const std::string & getNamespace() const
bool getTransform(rdl_msgs::GetTransformRequest &req, rdl_msgs::GetTransformResponse &resp)
Eigen::VectorXd VectorNd
EIGEN_STRONG_INLINE double & mz()
EIGEN_STRONG_INLINE double & wz()
bool change3DVectorFrame(rdl_msgs::Change3DVectorFrameRequest &req, rdl_msgs::Change3DVectorFrameResponse &resp)
ROSCPP_DECL void spin()
bool changeTwistArrayFrame(rdl_msgs::ChangeTwistArrayFrameRequest &req, rdl_msgs::ChangeTwistArrayFrameResponse &resp)
bool parseJointBodyNameMapFromString(const char *model_xml_string, std::map< std::string, std::string > &jointBodyMap)
EIGEN_STRONG_INLINE double & vy()
void updateKinematicsCustom(Model &model, const Math::VectorNd *Q, const Math::VectorNd *QDot=nullptr, const Math::VectorNd *QDDot=nullptr)
EIGEN_STRONG_INLINE double & x()
void calcCenterOfMass(Model &model, const Math::VectorNd &q, Math::Vector3d &com, bool update_kinematics=true)
EIGEN_STRONG_INLINE double & y()
bool changeTwistFrame(rdl_msgs::ChangeTwistFrameRequest &req, rdl_msgs::ChangeTwistFrameResponse &resp)
bool getBodyGravityWrench(rdl_msgs::GetBodyGravityWrenchRequest &req, rdl_msgs::GetBodyGravityWrenchResponse &resp)
bool getParam(const std::string &key, std::string &s) const
EIGEN_STRONG_INLINE double & mx()
RobotDynamics::Math::VectorNd q
EIGEN_STRONG_INLINE double & z()
#define ROS_ERROR_STREAM(args)
bool changeOrientationFrame(rdl_msgs::ChangeOrientationFrameRequest &req, rdl_msgs::ChangeOrientationFrameResponse &resp)
EIGEN_STRONG_INLINE double & z()
std::map< std::string, std::string > joint_to_body_name_map
bool urdfReadFromString(const char *model_xml_string, ModelPtr model, bool floating_base, bool verbose=false)


rdl_ros_tools
Author(s):
autogenerated on Tue Apr 20 2021 02:25:40