robot_state.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2013, Ioan A. Sucan
5  * Copyright (c) 2013, Willow Garage, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of the Willow Garage nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 
36 /* Author: Ioan Sucan, Sachin Chitta, Acorn Pooley, Mario Prats, Dave Coleman */
37 
43 #include <tf2_eigen/tf2_eigen.h>
47 #include <functional>
49 
50 namespace moveit
51 {
52 namespace core
53 {
54 namespace
55 {
56 constexpr char LOGNAME[] = "robot_state";
57 } // namespace
58 
59 RobotState::RobotState(const RobotModelConstPtr& robot_model)
60  : robot_model_(robot_model)
61  , has_velocity_(false)
62  , has_acceleration_(false)
63  , has_effort_(false)
64  , dirty_link_transforms_(nullptr)
65  , dirty_collision_body_transforms_(nullptr)
66  , rng_(nullptr)
67 {
68  if (robot_model == nullptr)
69  {
70  throw std::invalid_argument("RobotState cannot be constructed with nullptr RobotModelConstPtr");
71  }
72 
73  dirty_link_transforms_ = robot_model_->getRootJoint();
74  allocMemory();
75  initTransforms();
76 }
77 
78 RobotState::RobotState(const RobotState& other) : rng_(nullptr)
79 {
80  robot_model_ = other.robot_model_;
81  allocMemory();
82  copyFrom(other);
83 }
84 
86 {
88  free(memory_);
89  if (rng_)
90  delete rng_;
91 }
92 
94 {
95  static_assert((sizeof(Eigen::Isometry3d) / EIGEN_MAX_ALIGN_BYTES) * EIGEN_MAX_ALIGN_BYTES == sizeof(Eigen::Isometry3d),
96  "sizeof(Eigen::Isometry3d) should be a multiple of EIGEN_MAX_ALIGN_BYTES");
97 
98  constexpr unsigned int extra_alignment_bytes = EIGEN_MAX_ALIGN_BYTES - 1;
99  // memory for the dirty joint transforms
100  const int nr_doubles_for_dirty_joint_transforms =
101  1 + robot_model_->getJointModelCount() / (sizeof(double) / sizeof(unsigned char));
102  const size_t bytes =
103  sizeof(Eigen::Isometry3d) * (robot_model_->getJointModelCount() + robot_model_->getLinkModelCount() +
104  robot_model_->getLinkGeometryCount()) +
105  sizeof(double) * (robot_model_->getVariableCount() * 3 + nr_doubles_for_dirty_joint_transforms) +
106  extra_alignment_bytes;
107  memory_ = malloc(bytes);
108 
109  // make the memory for transforms align at EIGEN_MAX_ALIGN_BYTES
110  // https://eigen.tuxfamily.org/dox/classEigen_1_1aligned__allocator.html
111  variable_joint_transforms_ = reinterpret_cast<Eigen::Isometry3d*>(((uintptr_t)memory_ + extra_alignment_bytes) &
112  ~(uintptr_t)extra_alignment_bytes);
116  reinterpret_cast<unsigned char*>(global_collision_body_transforms_ + robot_model_->getLinkGeometryCount());
117  position_ = reinterpret_cast<double*>(dirty_joint_transforms_) + nr_doubles_for_dirty_joint_transforms;
118  velocity_ = position_ + robot_model_->getVariableCount();
119  // acceleration and effort share the memory (not both can be specified)
120  effort_ = acceleration_ = velocity_ + robot_model_->getVariableCount();
121 }
122 
124 {
125  // mark all transforms as dirty
126  const int nr_doubles_for_dirty_joint_transforms =
127  1 + robot_model_->getJointModelCount() / (sizeof(double) / sizeof(unsigned char));
128  memset(dirty_joint_transforms_, 1, sizeof(double) * nr_doubles_for_dirty_joint_transforms);
129 
130  // initialize last row of transformation matrices, which will not be modified by transform updates anymore
131  for (size_t i = 0, end = robot_model_->getJointModelCount() + robot_model_->getLinkModelCount() +
132  robot_model_->getLinkGeometryCount();
133  i != end; ++i)
134  variable_joint_transforms_[i].makeAffine();
135 
136  // Initialize fixed joints because they are not computed later by update().
137  for (const JointModel* joint : robot_model_->getJointModels())
138  if (joint->getType() == JointModel::FIXED)
139  getJointTransform(joint);
140 }
141 
143 {
144  if (this != &other)
145  copyFrom(other);
146  return *this;
147 }
148 
149 void RobotState::copyFrom(const RobotState& other)
150 {
153  has_effort_ = other.has_effort_;
154 
157 
158  if (dirty_link_transforms_ == robot_model_->getRootJoint())
159  {
160  // everything is dirty; no point in copying transforms; copy positions, potentially velocity & acceleration
161  memcpy(position_, other.position_,
162  robot_model_->getVariableCount() * sizeof(double) *
163  (1 + (has_velocity_ ? 1 : 0) + ((has_acceleration_ || has_effort_) ? 1 : 0)));
164  // and just initialize transforms
165  initTransforms();
166  }
167  else
168  {
169  // copy all the memory; maybe avoid copying velocity and acceleration if possible
170  const int nr_doubles_for_dirty_joint_transforms =
171  1 + robot_model_->getJointModelCount() / (sizeof(double) / sizeof(unsigned char));
172  const size_t bytes =
173  sizeof(Eigen::Isometry3d) * (robot_model_->getJointModelCount() + robot_model_->getLinkModelCount() +
174  robot_model_->getLinkGeometryCount()) +
175  sizeof(double) *
176  (robot_model_->getVariableCount() * (1 + ((has_velocity_ || has_acceleration_ || has_effort_) ? 1 : 0) +
177  ((has_acceleration_ || has_effort_) ? 1 : 0)) +
178  nr_doubles_for_dirty_joint_transforms);
179  memcpy((void*)variable_joint_transforms_, (void*)other.variable_joint_transforms_, bytes);
180  }
181 
182  // copy attached bodies
184  for (const auto& attached_body : other.attached_body_map_)
185  attachBody(std::make_unique<AttachedBody>(*attached_body.second));
186 }
187 
188 bool RobotState::checkJointTransforms(const JointModel* joint) const
189 {
190  if (dirtyJointTransform(joint))
191  {
192  ROS_WARN_NAMED(LOGNAME, "Returning dirty joint transforms for joint '%s'", joint->getName().c_str());
193  return false;
194  }
195  return true;
196 }
197 
199 {
200  if (dirtyLinkTransforms())
201  {
202  ROS_WARN_NAMED(LOGNAME, "Returning dirty link transforms");
203  return false;
204  }
205  return true;
206 }
207 
209 {
211  {
212  ROS_WARN_NAMED(LOGNAME, "Returning dirty collision body transforms");
213  return false;
214  }
215  return true;
216 }
217 
219 {
220  if (!has_velocity_)
221  {
222  has_velocity_ = true;
223  memset(velocity_, 0, sizeof(double) * robot_model_->getVariableCount());
224  }
225 }
226 
228 {
229  if (!has_acceleration_)
230  {
231  has_acceleration_ = true;
232  has_effort_ = false;
233  memset(acceleration_, 0, sizeof(double) * robot_model_->getVariableCount());
234  }
235 }
236 
238 {
239  if (!has_effort_)
240  {
241  has_acceleration_ = false;
242  has_effort_ = true;
243  memset(effort_, 0, sizeof(double) * robot_model_->getVariableCount());
244  }
245 }
246 
248 {
249  has_velocity_ = false;
250  markVelocity();
251 }
252 
254 {
255  has_acceleration_ = false;
257 }
258 
260 {
261  has_effort_ = false;
262  markEffort();
263 }
264 
266 {
267  has_velocity_ = false;
268 }
269 
271 {
272  has_acceleration_ = false;
273 }
274 
276 {
277  has_effort_ = false;
278 }
279 
281 {
282  dropVelocities();
285 }
286 
288 {
290 }
291 
293 {
294  robot_model_->getVariableRandomPositions(rng, position_);
295  memset(dirty_joint_transforms_, 1, robot_model_->getJointModelCount() * sizeof(unsigned char));
296  dirty_link_transforms_ = robot_model_->getRootJoint();
297  // mimic values are correctly set in RobotModel
298 }
299 
301 {
302  // we do not make calls to RobotModel for random number generation because mimic joints
303  // could trigger updates outside the state of the group itself
305  setToRandomPositions(group, rng);
306 }
308 {
309  const std::vector<const JointModel*>& joints = group->getActiveJointModels();
310  for (const JointModel* joint : joints)
311  joint->getVariableRandomPositions(rng, position_ + joint->getFirstVariableIndex());
312  updateMimicJoints(group);
313 }
314 
316  const std::vector<double>& distances)
317 {
318  // we do not make calls to RobotModel for random number generation because mimic joints
319  // could trigger updates outside the state of the group itself
321  setToRandomPositionsNearBy(group, seed, distances, rng);
322 }
323 
325  const std::vector<double>& distances,
327 {
328  const std::vector<const JointModel*>& joints = group->getActiveJointModels();
329  assert(distances.size() == joints.size());
330  for (std::size_t i = 0; i < joints.size(); ++i)
331  {
332  const int idx = joints[i]->getFirstVariableIndex();
333  joints[i]->getVariableRandomPositionsNearBy(rng, position_ + joints[i]->getFirstVariableIndex(),
334  seed.position_ + idx, distances[i]);
335  }
337 }
338 
339 void RobotState::setToRandomPositionsNearBy(const JointModelGroup* group, const RobotState& seed, double distance)
340 {
341  // we do not make calls to RobotModel for random number generation because mimic joints
342  // could trigger updates outside the state of the group itself
344  setToRandomPositionsNearBy(group, seed, distance, rng);
345 }
346 
347 void RobotState::setToRandomPositionsNearBy(const JointModelGroup* group, const RobotState& seed, double distance,
349 {
350  const std::vector<const JointModel*>& joints = group->getActiveJointModels();
351  for (const JointModel* joint : joints)
352  {
353  const int idx = joint->getFirstVariableIndex();
354  joint->getVariableRandomPositionsNearBy(rng, position_ + joint->getFirstVariableIndex(), seed.position_ + idx,
355  distance);
356  }
357  updateMimicJoints(group);
358 }
359 
360 bool RobotState::setToDefaultValues(const JointModelGroup* group, const std::string& name)
361 {
362  std::map<std::string, double> m;
363  bool r = group->getVariableDefaultPositions(name, m); // mimic values are updated
365  return r;
366 }
367 
369 {
370  robot_model_->getVariableDefaultPositions(position_); // mimic values are updated
371  // set velocity & acceleration to 0
372  memset(velocity_, 0, sizeof(double) * 2 * robot_model_->getVariableCount());
373  memset(dirty_joint_transforms_, 1, robot_model_->getJointModelCount() * sizeof(unsigned char));
374  dirty_link_transforms_ = robot_model_->getRootJoint();
375 }
376 
377 void RobotState::setVariablePositions(const double* position)
378 {
379  // assume everything is in order in terms of array lengths (for efficiency reasons)
380  memcpy(position_, position, robot_model_->getVariableCount() * sizeof(double));
381 
382  // the full state includes mimic joint values, so no need to update mimic here
383 
384  // Since all joint values have potentially changed, we will need to recompute all transforms
385  memset(dirty_joint_transforms_, 1, robot_model_->getJointModelCount() * sizeof(unsigned char));
386  dirty_link_transforms_ = robot_model_->getRootJoint();
387 }
388 
389 void RobotState::setVariablePositions(const std::map<std::string, double>& variable_map)
390 {
391  for (const std::pair<const std::string, double>& it : variable_map)
392  {
393  const int index = robot_model_->getVariableIndex(it.first);
394  position_[index] = it.second;
395  const JointModel* jm = robot_model_->getJointOfVariable(index);
397  updateMimicJoint(jm);
398  }
399 }
400 
401 void RobotState::getMissingKeys(const std::map<std::string, double>& variable_map,
402  std::vector<std::string>& missing_variables) const
403 {
404  missing_variables.clear();
405  const std::vector<std::string>& nm = robot_model_->getVariableNames();
406  for (const std::string& variable_name : nm)
407  if (variable_map.find(variable_name) == variable_map.end())
408  if (robot_model_->getJointOfVariable(variable_name)->getMimic() == nullptr)
409  missing_variables.push_back(variable_name);
410 }
411 
412 void RobotState::setVariablePositions(const std::map<std::string, double>& variable_map,
413  std::vector<std::string>& missing_variables)
414 {
415  setVariablePositions(variable_map);
416  getMissingKeys(variable_map, missing_variables);
417 }
418 
419 void RobotState::setVariablePositions(const std::vector<std::string>& variable_names,
420  const std::vector<double>& variable_position)
421 {
422  for (std::size_t i = 0; i < variable_names.size(); ++i)
423  {
424  const int index = robot_model_->getVariableIndex(variable_names[i]);
425  position_[index] = variable_position[i];
426  const JointModel* jm = robot_model_->getJointOfVariable(index);
428  updateMimicJoint(jm);
429  }
430 }
431 
432 void RobotState::setVariableVelocities(const std::map<std::string, double>& variable_map)
433 {
435  for (const std::pair<const std::string, double>& it : variable_map)
436  velocity_[robot_model_->getVariableIndex(it.first)] = it.second;
437 }
438 
439 void RobotState::setVariableVelocities(const std::map<std::string, double>& variable_map,
440  std::vector<std::string>& missing_variables)
441 {
442  setVariableVelocities(variable_map);
443  getMissingKeys(variable_map, missing_variables);
444 }
445 
446 void RobotState::setVariableVelocities(const std::vector<std::string>& variable_names,
447  const std::vector<double>& variable_velocity)
448 {
449  markVelocity();
450  assert(variable_names.size() == variable_velocity.size());
451  for (std::size_t i = 0; i < variable_names.size(); ++i)
452  velocity_[robot_model_->getVariableIndex(variable_names[i])] = variable_velocity[i];
453 }
454 
455 void RobotState::setVariableAccelerations(const std::map<std::string, double>& variable_map)
456 {
458  for (const std::pair<const std::string, double>& it : variable_map)
459  acceleration_[robot_model_->getVariableIndex(it.first)] = it.second;
460 }
461 
462 void RobotState::setVariableAccelerations(const std::map<std::string, double>& variable_map,
463  std::vector<std::string>& missing_variables)
464 {
465  setVariableAccelerations(variable_map);
466  getMissingKeys(variable_map, missing_variables);
467 }
468 
469 void RobotState::setVariableAccelerations(const std::vector<std::string>& variable_names,
470  const std::vector<double>& variable_acceleration)
471 {
473  assert(variable_names.size() == variable_acceleration.size());
474  for (std::size_t i = 0; i < variable_names.size(); ++i)
475  acceleration_[robot_model_->getVariableIndex(variable_names[i])] = variable_acceleration[i];
476 }
477 
478 void RobotState::setVariableEffort(const std::map<std::string, double>& variable_map)
479 {
480  markEffort();
481  for (const std::pair<const std::string, double>& it : variable_map)
482  effort_[robot_model_->getVariableIndex(it.first)] = it.second;
483 }
484 
485 void RobotState::setVariableEffort(const std::map<std::string, double>& variable_map,
486  std::vector<std::string>& missing_variables)
487 {
488  setVariableEffort(variable_map);
489  getMissingKeys(variable_map, missing_variables);
490 }
491 
492 void RobotState::setVariableEffort(const std::vector<std::string>& variable_names,
493  const std::vector<double>& variable_effort)
494 {
495  markEffort();
496  assert(variable_names.size() == variable_effort.size());
497  for (std::size_t i = 0; i < variable_names.size(); ++i)
498  effort_[robot_model_->getVariableIndex(variable_names[i])] = variable_effort[i];
499 }
500 
502 {
503  if (has_velocity_)
504  {
505  for (size_t i = 0; i < robot_model_->getVariableCount(); ++i)
506  velocity_[i] *= -1;
507  }
508 }
509 
510 void RobotState::setJointEfforts(const JointModel* joint, const double* effort)
511 {
513  {
514  ROS_ERROR_NAMED(LOGNAME, "Unable to set joint efforts because array is being used for accelerations");
515  return;
516  }
517  has_effort_ = true;
518 
519  memcpy(effort_ + joint->getFirstVariableIndex(), effort, joint->getVariableCount() * sizeof(double));
520 }
521 
522 void RobotState::setJointGroupPositions(const JointModelGroup* group, const double* gstate)
523 {
524  const std::vector<int>& il = group->getVariableIndexList();
525  if (group->isContiguousWithinState())
526  memcpy(position_ + il[0], gstate, group->getVariableCount() * sizeof(double));
527  else
528  {
529  for (std::size_t i = 0; i < il.size(); ++i)
530  position_[il[i]] = gstate[i];
531  }
532  updateMimicJoints(group);
533 }
534 
535 void RobotState::setJointGroupPositions(const JointModelGroup* group, const Eigen::VectorXd& values)
536 {
537  const std::vector<int>& il = group->getVariableIndexList();
538  for (std::size_t i = 0; i < il.size(); ++i)
539  position_[il[i]] = values(i);
540  updateMimicJoints(group);
541 }
542 
543 void RobotState::setJointGroupActivePositions(const JointModelGroup* group, const std::vector<double>& gstate)
544 {
545  assert(gstate.size() == group->getActiveVariableCount());
546  std::size_t i = 0;
547  for (const JointModel* jm : group->getActiveJointModels())
548  {
549  setJointPositions(jm, &gstate[i]);
550  i += jm->getVariableCount();
551  }
552  updateMimicJoints(group);
553 }
554 
555 void RobotState::setJointGroupActivePositions(const JointModelGroup* group, const Eigen::VectorXd& values)
556 {
557  assert(values.size() == group->getActiveVariableCount());
558  std::size_t i = 0;
559  for (const JointModel* jm : group->getActiveJointModels())
560  {
561  setJointPositions(jm, &values(i));
562  i += jm->getVariableCount();
563  }
564  updateMimicJoints(group);
565 }
566 
567 void RobotState::copyJointGroupPositions(const JointModelGroup* group, double* gstate) const
568 {
569  const std::vector<int>& il = group->getVariableIndexList();
570  if (group->isContiguousWithinState())
571  memcpy(gstate, position_ + il[0], group->getVariableCount() * sizeof(double));
572  else
573  for (std::size_t i = 0; i < il.size(); ++i)
574  gstate[i] = position_[il[i]];
575 }
576 
577 void RobotState::copyJointGroupPositions(const JointModelGroup* group, Eigen::VectorXd& values) const
578 {
579  const std::vector<int>& il = group->getVariableIndexList();
580  values.resize(il.size());
581  for (std::size_t i = 0; i < il.size(); ++i)
582  values(i) = position_[il[i]];
583 }
584 
585 void RobotState::setJointGroupVelocities(const JointModelGroup* group, const double* gstate)
586 {
587  markVelocity();
588  const std::vector<int>& il = group->getVariableIndexList();
589  if (group->isContiguousWithinState())
590  memcpy(velocity_ + il[0], gstate, group->getVariableCount() * sizeof(double));
591  else
592  {
593  for (std::size_t i = 0; i < il.size(); ++i)
594  velocity_[il[i]] = gstate[i];
595  }
596 }
597 
598 void RobotState::setJointGroupVelocities(const JointModelGroup* group, const Eigen::VectorXd& values)
599 {
600  markVelocity();
601  const std::vector<int>& il = group->getVariableIndexList();
602  for (std::size_t i = 0; i < il.size(); ++i)
603  velocity_[il[i]] = values(i);
604 }
605 
606 void RobotState::copyJointGroupVelocities(const JointModelGroup* group, double* gstate) const
607 {
608  const std::vector<int>& il = group->getVariableIndexList();
610  memcpy(gstate, velocity_ + il[0], group->getVariableCount() * sizeof(double));
611  else
612  for (std::size_t i = 0; i < il.size(); ++i)
613  gstate[i] = velocity_[il[i]];
614 }
615 
616 void RobotState::copyJointGroupVelocities(const JointModelGroup* group, Eigen::VectorXd& values) const
617 {
618  const std::vector<int>& il = group->getVariableIndexList();
619  values.resize(il.size());
620  for (std::size_t i = 0; i < il.size(); ++i)
621  values(i) = velocity_[il[i]];
622 }
623 
624 void RobotState::setJointGroupAccelerations(const JointModelGroup* group, const double* gstate)
625 {
627  const std::vector<int>& il = group->getVariableIndexList();
628  if (group->isContiguousWithinState())
629  memcpy(acceleration_ + il[0], gstate, group->getVariableCount() * sizeof(double));
630  else
631  {
632  for (std::size_t i = 0; i < il.size(); ++i)
633  acceleration_[il[i]] = gstate[i];
634  }
635 }
636 
637 void RobotState::setJointGroupAccelerations(const JointModelGroup* group, const Eigen::VectorXd& values)
638 {
640  const std::vector<int>& il = group->getVariableIndexList();
641  for (std::size_t i = 0; i < il.size(); ++i)
642  acceleration_[il[i]] = values(i);
643 }
644 
645 void RobotState::copyJointGroupAccelerations(const JointModelGroup* group, double* gstate) const
646 {
647  const std::vector<int>& il = group->getVariableIndexList();
648  if (group->isContiguousWithinState())
649  memcpy(gstate, acceleration_ + il[0], group->getVariableCount() * sizeof(double));
650  else
651  for (std::size_t i = 0; i < il.size(); ++i)
652  gstate[i] = acceleration_[il[i]];
653 }
654 
655 void RobotState::copyJointGroupAccelerations(const JointModelGroup* group, Eigen::VectorXd& values) const
656 {
657  const std::vector<int>& il = group->getVariableIndexList();
658  values.resize(il.size());
659  for (std::size_t i = 0; i < il.size(); ++i)
660  values(i) = acceleration_[il[i]];
661 }
662 
663 void RobotState::update(bool force)
664 {
665  // make sure we do everything from scratch if needed
666  if (force)
667  {
668  memset(dirty_joint_transforms_, 1, robot_model_->getJointModelCount() * sizeof(unsigned char));
669  dirty_link_transforms_ = robot_model_->getRootJoint();
670  }
671 
672  // this actually triggers all needed updates
674 }
675 
677 {
678  if (dirty_link_transforms_ != nullptr)
680 
681  if (dirty_collision_body_transforms_ != nullptr)
682  {
683  const std::vector<const LinkModel*>& links = dirty_collision_body_transforms_->getDescendantLinkModels();
685 
686  for (const LinkModel* link : links)
687  {
688  const EigenSTL::vector_Isometry3d& ot = link->getCollisionOriginTransforms();
689  const std::vector<int>& ot_id = link->areCollisionOriginTransformsIdentity();
690  const int index_co = link->getFirstCollisionBodyTransformIndex();
691  const int index_l = link->getLinkIndex();
692  for (std::size_t j = 0, end = ot.size(); j != end; ++j)
693  {
694  if (ot_id[j])
696  else
697  global_collision_body_transforms_[index_co + j].affine().noalias() =
698  global_link_transforms_[index_l].affine() * ot[j].matrix();
699  }
700  }
701  }
702 }
703 
705 {
706  if (dirty_link_transforms_ != nullptr)
707  {
712  else
714  dirty_link_transforms_ = nullptr;
715  }
716 }
717 
718 void RobotState::updateLinkTransformsInternal(const JointModel* start)
719 {
720  for (const LinkModel* link : start->getDescendantLinkModels())
721  {
722  int idx_link = link->getLinkIndex();
723  const LinkModel* parent = link->getParentLinkModel();
724  if (parent) // root JointModel will not have a parent
725  {
726  int idx_parent = parent->getLinkIndex();
727  if (link->parentJointIsFixed()) // fixed joint
728  global_link_transforms_[idx_link].affine().noalias() =
729  global_link_transforms_[idx_parent].affine() * link->getJointOriginTransform().matrix();
730  else // non-fixed joint
731  {
732  if (link->jointOriginTransformIsIdentity()) // Link has identity transform
733  global_link_transforms_[idx_link].affine().noalias() =
734  global_link_transforms_[idx_parent].affine() * getJointTransform(link->getParentJointModel()).matrix();
735  else // Link has non-identity transform
736  global_link_transforms_[idx_link].affine().noalias() =
737  global_link_transforms_[idx_parent].affine() * link->getJointOriginTransform().matrix() *
738  getJointTransform(link->getParentJointModel()).matrix();
739  }
740  }
741  else // is the origin / root / 'model frame'
742  {
743  if (link->jointOriginTransformIsIdentity())
744  global_link_transforms_[idx_link] = getJointTransform(link->getParentJointModel());
745  else
746  global_link_transforms_[idx_link].affine().noalias() =
747  link->getJointOriginTransform().affine() * getJointTransform(link->getParentJointModel()).matrix();
748  }
749  }
750 
751  // update attached bodies tf; these are usually very few, so we update them all
752  for (const auto& attached_body : attached_body_map_)
753  attached_body.second->computeTransform(
754  global_link_transforms_[attached_body.second->getAttachedLink()->getLinkIndex()]);
755 }
756 
757 void RobotState::updateStateWithLinkAt(const LinkModel* link, const Eigen::Isometry3d& transform, bool backward)
758 {
759  updateLinkTransforms(); // no link transforms must be dirty, otherwise the transform we set will be overwritten
760 
761  // update the fact that collision body transforms are out of date
764  robot_model_->getCommonRoot(dirty_collision_body_transforms_, link->getParentJointModel());
765  else
766  dirty_collision_body_transforms_ = link->getParentJointModel();
767 
768  global_link_transforms_[link->getLinkIndex()] = transform;
769 
770  // update link transforms for descendant links only (leaving the transform for the current link untouched)
771  const std::vector<const JointModel*>& cj = link->getChildJointModels();
772  for (const JointModel* joint : cj)
774 
775  // if we also need to go backward
776  if (backward)
777  {
778  const LinkModel* parent_link = link;
779  const LinkModel* child_link;
780  while (parent_link->getParentJointModel()->getParentLinkModel())
781  {
782  child_link = parent_link;
783  parent_link = parent_link->getParentJointModel()->getParentLinkModel();
784 
785  // update the transform of the parent
786  global_link_transforms_[parent_link->getLinkIndex()] =
787  global_link_transforms_[child_link->getLinkIndex()] *
788  (child_link->getJointOriginTransform() *
790  .inverse();
791 
792  // update link transforms for descendant links only (leaving the transform for the current link untouched)
793  // with the exception of the child link we are coming backwards from
794  const std::vector<const JointModel*>& cj = parent_link->getChildJointModels();
795  for (const JointModel* joint : cj)
796  if (joint != child_link->getParentJointModel())
798  }
799  // all collision body transforms are invalid now
801  }
802 
803  // update attached bodies tf; these are usually very few, so we update them all
804  for (const auto& attached_body : attached_body_map_)
805  attached_body.second->computeTransform(
806  global_link_transforms_[attached_body.second->getAttachedLink()->getLinkIndex()]);
807 }
808 
809 const LinkModel* RobotState::getRigidlyConnectedParentLinkModel(const std::string& frame, Eigen::Isometry3d* transform,
810  const moveit::core::JointModelGroup* jmg) const
811 {
812  const moveit::core::LinkModel* link{ nullptr };
813 
814  if (getRobotModel()->hasLinkModel(frame))
815  {
816  link = getLinkModel(frame);
817  if (transform)
818  transform->setIdentity();
819  }
820  else if (const auto it = attached_body_map_.find(frame); it != attached_body_map_.end())
821  {
822  const auto& body{ it->second };
823  link = body->getAttachedLink();
824  if (transform)
825  *transform = body->getPose();
826  }
827  else
828  {
829  bool found = false;
830  for (const auto& it : attached_body_map_)
831  {
832  const auto& body{ it.second };
833  const Eigen::Isometry3d& subframe = body->getSubframeTransform(frame, &found);
834  if (found)
835  {
836  if (transform) // prepend the body transform
837  *transform = body->getPose() * subframe;
838  link = body->getAttachedLink();
839  break;
840  }
841  }
842  if (!found)
843  return nullptr;
844  }
845 
846  // link is valid and transform describes pose of frame w.r.t. global frame
847  Eigen::Isometry3d link_transform;
848  auto* parent = getRobotModel()->getRigidlyConnectedParentLinkModel(link, link_transform, jmg);
849  if (parent && transform)
850  // prepend link_transform to get transform from parent link to frame
851  *transform = link_transform * *transform;
852  return parent;
853 }
854 
855 bool RobotState::satisfiesBounds(double margin) const
856 {
857  const std::vector<const JointModel*>& jm = robot_model_->getActiveJointModels();
858  for (const JointModel* joint : jm)
859  if (!satisfiesBounds(joint, margin))
860  return false;
861  return true;
862 }
863 
864 bool RobotState::satisfiesBounds(const JointModelGroup* group, double margin) const
865 {
866  const std::vector<const JointModel*>& jm = group->getActiveJointModels();
867  for (const JointModel* joint : jm)
868  if (!satisfiesBounds(joint, margin))
869  return false;
870  return true;
871 }
872 
874 {
875  const std::vector<const JointModel*>& jm = robot_model_->getActiveJointModels();
876  for (const JointModel* joint : jm)
877  enforceBounds(joint);
878 }
879 
880 void RobotState::enforceBounds(const JointModelGroup* joint_group)
881 {
882  const std::vector<const JointModel*>& jm = joint_group->getActiveJointModels();
883  for (const JointModel* joint : jm)
884  enforceBounds(joint);
885 }
886 
888 {
889  for (const JointModel* jm : robot_model_->getActiveJointModels())
890  harmonizePosition(jm);
891 }
892 
893 void RobotState::harmonizePositions(const JointModelGroup* joint_group)
894 {
895  for (const JointModel* jm : joint_group->getActiveJointModels())
896  harmonizePosition(jm);
897 }
898 
899 std::pair<double, const JointModel*> RobotState::getMinDistanceToPositionBounds() const
900 {
901  return getMinDistanceToPositionBounds(robot_model_->getActiveJointModels());
902 }
903 
904 std::pair<double, const JointModel*> RobotState::getMinDistanceToPositionBounds(const JointModelGroup* group) const
905 {
906  return getMinDistanceToPositionBounds(group->getActiveJointModels());
907 }
908 
909 std::pair<double, const JointModel*>
910 RobotState::getMinDistanceToPositionBounds(const std::vector<const JointModel*>& joints) const
911 {
912  double distance = std::numeric_limits<double>::max();
913  const JointModel* index = nullptr;
914  for (const JointModel* joint : joints)
915  {
916  if (joint->getType() == JointModel::PLANAR || joint->getType() == JointModel::FLOATING)
917  continue;
918  if (joint->getType() == JointModel::REVOLUTE)
919  if (static_cast<const RevoluteJointModel*>(joint)->isContinuous())
920  continue;
921 
922  const double* joint_values = getJointPositions(joint);
923  const JointModel::Bounds& bounds = joint->getVariableBounds();
924  std::vector<double> lower_bounds(bounds.size()), upper_bounds(bounds.size());
925  for (std::size_t j = 0; j < bounds.size(); ++j)
926  {
927  lower_bounds[j] = bounds[j].min_position_;
928  upper_bounds[j] = bounds[j].max_position_;
929  }
930  double new_distance = joint->distance(joint_values, &lower_bounds[0]);
931  if (new_distance < distance)
932  {
933  index = joint;
934  distance = new_distance;
935  }
936  new_distance = joint->distance(joint_values, &upper_bounds[0]);
937  if (new_distance < distance)
938  {
939  index = joint;
940  distance = new_distance;
941  }
942  }
943  return std::make_pair(distance, index);
944 }
945 
946 bool RobotState::isValidVelocityMove(const RobotState& other, const JointModelGroup* group, double dt) const
947 {
948  const std::vector<const JointModel*>& jm = group->getActiveJointModels();
949  for (const JointModel* joint_id : jm)
950  {
951  const int idx = joint_id->getFirstVariableIndex();
952  const std::vector<VariableBounds>& bounds = joint_id->getVariableBounds();
953 
954  // Check velocity for each joint variable
955  for (std::size_t var_id = 0; var_id < joint_id->getVariableCount(); ++var_id)
956  {
957  const double dtheta = std::abs(*(position_ + idx + var_id) - *(other.getVariablePositions() + idx + var_id));
958 
959  if (dtheta > dt * bounds[var_id].max_velocity_)
960  return false;
961  }
962  }
963  return true;
964 }
965 
966 double RobotState::distance(const RobotState& other, const JointModelGroup* joint_group) const
967 {
968  double d = 0.0;
969  const std::vector<const JointModel*>& jm = joint_group->getActiveJointModels();
970  for (const JointModel* joint : jm)
971  {
972  const int idx = joint->getFirstVariableIndex();
973  d += joint->getDistanceFactor() * joint->distance(position_ + idx, other.position_ + idx);
974  }
975  return d;
976 }
977 
978 void RobotState::interpolate(const RobotState& to, double t, RobotState& state) const
979 {
982 
983  memset(state.dirty_joint_transforms_, 1, state.robot_model_->getJointModelCount() * sizeof(unsigned char));
984  state.dirty_link_transforms_ = state.robot_model_->getRootJoint();
985 }
986 
987 void RobotState::interpolate(const RobotState& to, double t, RobotState& state, const JointModelGroup* joint_group) const
988 {
990  const std::vector<const JointModel*>& jm = joint_group->getActiveJointModels();
991  for (const JointModel* joint : jm)
992  {
993  const int idx = joint->getFirstVariableIndex();
994  joint->interpolate(position_ + idx, to.position_ + idx, t, state.position_ + idx);
995  }
996  state.updateMimicJoints(joint_group);
997 }
998 
1000 {
1001  attached_body_update_callback_ = callback;
1002 }
1003 
1004 bool RobotState::hasAttachedBody(const std::string& id) const
1005 {
1006  return attached_body_map_.find(id) != attached_body_map_.end();
1007 }
1008 
1009 const AttachedBody* RobotState::getAttachedBody(const std::string& id) const
1010 {
1011  const auto it = attached_body_map_.find(id);
1012  if (it == attached_body_map_.end())
1013  {
1014  ROS_ERROR_NAMED(LOGNAME, "Attached body '%s' not found", id.c_str());
1015  return nullptr;
1016  }
1017  else
1018  return it->second.get();
1019 }
1020 
1021 void RobotState::attachBody(std::unique_ptr<AttachedBody> attached_body)
1022 {
1023  // If an attached body with the same id exists, remove it
1024  clearAttachedBody(attached_body->getName());
1025 
1026  attached_body->computeTransform(getGlobalLinkTransform(attached_body->getAttachedLink()));
1028  attached_body_update_callback_(attached_body.get(), true);
1029  attached_body_map_[attached_body->getName()] = std::move(attached_body);
1030 }
1031 
1033 {
1034  attachBody(std::unique_ptr<AttachedBody>(attached_body));
1035 }
1036 
1037 void RobotState::attachBody(const std::string& id, const Eigen::Isometry3d& pose,
1038  const std::vector<shapes::ShapeConstPtr>& shapes,
1039  const EigenSTL::vector_Isometry3d& shape_poses, const std::set<std::string>& touch_links,
1040  const std::string& link, const trajectory_msgs::JointTrajectory& detach_posture,
1041  const moveit::core::FixedTransformsMap& subframe_poses)
1042 {
1043  attachBody(std::make_unique<AttachedBody>(robot_model_->getLinkModel(link), id, pose, shapes, shape_poses,
1044  touch_links, detach_posture, subframe_poses));
1045 }
1046 
1047 void RobotState::getAttachedBodies(std::vector<const AttachedBody*>& attached_bodies) const
1048 {
1049  attached_bodies.clear();
1050  attached_bodies.reserve(attached_body_map_.size());
1051  for (const auto& it : attached_body_map_)
1052  attached_bodies.push_back(it.second.get());
1054 
1055 void RobotState::getAttachedBodies(std::vector<const AttachedBody*>& attached_bodies, const JointModelGroup* group) const
1056 {
1057  attached_bodies.clear();
1058  for (const auto& it : attached_body_map_)
1059  if (group->hasLinkModel(it.second->getAttachedLinkName()))
1060  attached_bodies.push_back(it.second.get());
1061 }
1062 
1063 void RobotState::getAttachedBodies(std::vector<const AttachedBody*>& attached_bodies, const LinkModel* link_model) const
1064 {
1065  attached_bodies.clear();
1066  for (const auto& it : attached_body_map_)
1067  if (it.second->getAttachedLink() == link_model)
1068  attached_bodies.push_back(it.second.get());
1069 }
1072 {
1073  for (const auto& it : attached_body_map_)
1074  {
1076  attached_body_update_callback_(it.second.get(), false);
1077  }
1078  attached_body_map_.clear();
1079 }
1080 
1081 void RobotState::clearAttachedBodies(const LinkModel* link)
1082 {
1083  for (auto it = attached_body_map_.cbegin(); it != attached_body_map_.cend(); ++it)
1084  {
1085  if (it->second->getAttachedLink() != link)
1086  {
1087  continue;
1088  }
1090  attached_body_update_callback_(it->second.get(), false);
1091  const auto del = it++;
1092  attached_body_map_.erase(del);
1093  }
1094 }
1095 
1096 void RobotState::clearAttachedBodies(const JointModelGroup* group)
1097 {
1098  for (auto it = attached_body_map_.cbegin(); it != attached_body_map_.cend(); ++it)
1099  {
1100  if (!group->hasLinkModel(it->second->getAttachedLinkName()))
1101  {
1102  continue;
1103  }
1105  attached_body_update_callback_(it->second.get(), false);
1106  const auto del = it++;
1107  attached_body_map_.erase(del);
1108  }
1109 }
1110 
1111 bool RobotState::clearAttachedBody(const std::string& id)
1112 {
1113  const auto it = attached_body_map_.find(id);
1114  if (it != attached_body_map_.end())
1115  {
1117  attached_body_update_callback_(it->second.get(), false);
1118  attached_body_map_.erase(it);
1119  return true;
1120  }
1121  else
1122  return false;
1123 }
1124 
1125 const Eigen::Isometry3d& RobotState::getFrameTransform(const std::string& frame_id, bool* frame_found)
1126 {
1128  return static_cast<const RobotState*>(this)->getFrameTransform(frame_id, frame_found);
1130 
1131 const Eigen::Isometry3d& RobotState::getFrameTransform(const std::string& frame_id, bool* frame_found) const
1132 {
1133  const LinkModel* ignored_link;
1134  bool found;
1135  const auto& result = getFrameInfo(frame_id, ignored_link, found);
1136 
1137  if (frame_found)
1138  *frame_found = found;
1139  else if (!found)
1140  ROS_WARN_NAMED(LOGNAME, "getFrameTransform() did not find a frame with name %s.", frame_id.c_str());
1141 
1142  return result;
1143 }
1144 
1145 const Eigen::Isometry3d& RobotState::getFrameInfo(const std::string& frame_id, const LinkModel*& robot_link,
1146  bool& frame_found) const
1148  if (!frame_id.empty() && frame_id[0] == '/')
1149  return getFrameInfo(frame_id.substr(1), robot_link, frame_found);
1150 
1151  static const Eigen::Isometry3d IDENTITY_TRANSFORM = Eigen::Isometry3d::Identity();
1152  if (frame_id == robot_model_->getModelFrame())
1153  {
1154  robot_link = robot_model_->getRootLink();
1155  frame_found = true;
1156  return IDENTITY_TRANSFORM;
1157  }
1158  if ((robot_link = robot_model_->getLinkModel(frame_id, &frame_found)))
1159  {
1160  BOOST_VERIFY(checkLinkTransforms());
1161  return global_link_transforms_[robot_link->getLinkIndex()];
1162  }
1163  robot_link = nullptr;
1164 
1165  // Check names of the attached bodies
1166  const auto jt = attached_body_map_.find(frame_id);
1167  if (jt != attached_body_map_.end())
1168  {
1169  const Eigen::Isometry3d& transform = jt->second->getGlobalPose();
1170  robot_link = jt->second->getAttachedLink();
1171  frame_found = true;
1172  BOOST_VERIFY(checkLinkTransforms());
1173  return transform;
1174  }
1175 
1176  // Check if an AttachedBody has a subframe with name frame_id
1177  for (const auto& body : attached_body_map_)
1178  {
1179  const Eigen::Isometry3d& transform = body.second->getGlobalSubframeTransform(frame_id, &frame_found);
1180  if (frame_found)
1181  {
1182  robot_link = body.second->getAttachedLink();
1183  BOOST_VERIFY(checkLinkTransforms());
1184  return transform;
1185  }
1186  }
1187 
1188  robot_link = nullptr;
1189  frame_found = false;
1190  return IDENTITY_TRANSFORM;
1192 
1193 bool RobotState::knowsFrameTransform(const std::string& frame_id) const
1194 {
1195  if (!frame_id.empty() && frame_id[0] == '/')
1196  return knowsFrameTransform(frame_id.substr(1));
1197  if (robot_model_->hasLinkModel(frame_id))
1198  return true;
1199 
1200  // Check if an AttachedBody with name frame_id exists
1201  const auto it = attached_body_map_.find(frame_id);
1202  if (it != attached_body_map_.end())
1203  return !it->second->getGlobalCollisionBodyTransforms().empty();
1204 
1205  // Check if an AttachedBody has a subframe with name frame_id
1206  for (const auto& body : attached_body_map_)
1207  {
1208  if (body.second->hasSubframeTransform(frame_id))
1209  return true;
1210  }
1211  return false;
1212 }
1213 
1214 void RobotState::getRobotMarkers(visualization_msgs::MarkerArray& arr, const std::vector<std::string>& link_names,
1215  const std_msgs::ColorRGBA& color, const std::string& ns, const ros::Duration& dur,
1216  bool include_attached) const
1217 {
1218  std::size_t cur_num = arr.markers.size();
1219  getRobotMarkers(arr, link_names, include_attached);
1220  unsigned int id = cur_num;
1221  for (std::size_t i = cur_num; i < arr.markers.size(); ++i, ++id)
1222  {
1223  arr.markers[i].ns = ns;
1224  arr.markers[i].id = id;
1225  arr.markers[i].lifetime = dur;
1226  arr.markers[i].color = color;
1227  }
1228 }
1229 
1230 void RobotState::getRobotMarkers(visualization_msgs::MarkerArray& arr, const std::vector<std::string>& link_names,
1231  bool include_attached) const
1232 {
1233  ros::Time tm = ros::Time::now();
1234  for (const std::string& link_name : link_names)
1235  {
1236  ROS_DEBUG_NAMED(LOGNAME, "Trying to get marker for link '%s'", link_name.c_str());
1237  const LinkModel* link_model = robot_model_->getLinkModel(link_name);
1238  if (!link_model)
1239  continue;
1240  if (include_attached)
1241  for (const auto& it : attached_body_map_)
1242  if (it.second->getAttachedLink() == link_model)
1243  {
1244  for (std::size_t j = 0; j < it.second->getShapes().size(); ++j)
1245  {
1246  visualization_msgs::Marker att_mark;
1247  att_mark.header.frame_id = robot_model_->getModelFrame();
1248  att_mark.header.stamp = tm;
1249  if (shapes::constructMarkerFromShape(it.second->getShapes()[j].get(), att_mark))
1250  {
1251  // if the object is invisible (0 volume) we skip it
1252  if (fabs(att_mark.scale.x * att_mark.scale.y * att_mark.scale.z) < std::numeric_limits<float>::epsilon())
1253  continue;
1254  att_mark.pose = tf2::toMsg(it.second->getGlobalCollisionBodyTransforms()[j]);
1255  arr.markers.push_back(att_mark);
1256  }
1257  }
1258  }
1260  if (link_model->getShapes().empty())
1261  continue;
1262 
1263  for (std::size_t j = 0; j < link_model->getShapes().size(); ++j)
1264  {
1265  visualization_msgs::Marker mark;
1266  mark.header.frame_id = robot_model_->getModelFrame();
1267  mark.header.stamp = tm;
1268 
1269  // we prefer using the visual mesh, if a mesh is available and we have one body to render
1270  const std::string& mesh_resource = link_model->getVisualMeshFilename();
1271  if (mesh_resource.empty() || link_model->getShapes().size() > 1)
1272  {
1273  if (!shapes::constructMarkerFromShape(link_model->getShapes()[j].get(), mark))
1274  continue;
1275  // if the object is invisible (0 volume) we skip it
1276  if (fabs(mark.scale.x * mark.scale.y * mark.scale.z) < std::numeric_limits<float>::epsilon())
1277  continue;
1278  mark.pose =
1279  tf2::toMsg(global_collision_body_transforms_[link_model->getFirstCollisionBodyTransformIndex() + j]);
1280  }
1281  else
1282  {
1283  mark.type = mark.MESH_RESOURCE;
1284  mark.mesh_use_embedded_materials = false;
1285  mark.mesh_resource = mesh_resource;
1286  const Eigen::Vector3d& mesh_scale = link_model->getVisualMeshScale();
1287 
1288  mark.scale.x = mesh_scale[0];
1289  mark.scale.y = mesh_scale[1];
1290  mark.scale.z = mesh_scale[2];
1291  mark.pose = tf2::toMsg(global_link_transforms_[link_model->getLinkIndex()] * link_model->getVisualMeshOrigin());
1292  }
1293 
1294  arr.markers.push_back(mark);
1295  }
1296  }
1297 }
1298 
1299 Eigen::MatrixXd RobotState::getJacobian(const JointModelGroup* group,
1300  const Eigen::Vector3d& reference_point_position) const
1301 {
1302  Eigen::MatrixXd result;
1303  if (!getJacobian(group, group->getLinkModels().back(), reference_point_position, result, false))
1304  throw Exception("Unable to compute Jacobian");
1305  return result;
1306 }
1307 
1308 bool RobotState::getJacobian(const JointModelGroup* group, const LinkModel* link,
1309  const Eigen::Vector3d& reference_point_position, Eigen::MatrixXd& jacobian,
1310  bool use_quaternion_representation) const
1311 {
1312  BOOST_VERIFY(checkLinkTransforms());
1313 
1314  if (!group->isChain())
1315  {
1316  ROS_ERROR_NAMED(LOGNAME, "The group '%s' is not a chain. Cannot compute Jacobian.", group->getName().c_str());
1317  return false;
1318  }
1319 
1320  if (!group->isLinkUpdated(link->getName()))
1321  {
1322  ROS_ERROR_NAMED(LOGNAME, "Link name '%s' does not exist in the chain '%s' or is not a child for this chain",
1323  link->getName().c_str(), group->getName().c_str());
1324  return false;
1325  }
1326 
1327  const moveit::core::JointModel* root_joint_model = group->getJointModels()[0]; // group->getJointRoots()[0];
1328  const moveit::core::LinkModel* root_link_model = root_joint_model->getParentLinkModel();
1329  // getGlobalLinkTransform() returns a valid isometry by contract
1330  Eigen::Isometry3d reference_transform =
1331  root_link_model ? getGlobalLinkTransform(root_link_model).inverse() : Eigen::Isometry3d::Identity();
1332  int rows = use_quaternion_representation ? 7 : 6;
1333  int columns = group->getVariableCount();
1334  jacobian = Eigen::MatrixXd::Zero(rows, columns);
1335 
1336  // getGlobalLinkTransform() returns a valid isometry by contract
1337  Eigen::Isometry3d link_transform = reference_transform * getGlobalLinkTransform(link); // valid isometry
1338  Eigen::Vector3d point_transform = link_transform * reference_point_position;
1339 
1340  /*
1341  ROS_DEBUG_NAMED(LOGNAME, "Point from reference origin expressed in world coordinates: %f %f %f",
1342  point_transform.x(),
1343  point_transform.y(),
1344  point_transform.z());
1345  */
1346 
1347  Eigen::Vector3d joint_axis;
1348  Eigen::Isometry3d joint_transform;
1349 
1350  while (link)
1351  {
1352  /*
1353  ROS_DEBUG_NAMED(LOGNAME, "Link: %s, %f %f %f",link_state->getName().c_str(),
1354  link_state->getGlobalLinkTransform().translation().x(),
1355  link_state->getGlobalLinkTransform().translation().y(),
1356  link_state->getGlobalLinkTransform().translation().z());
1357  ROS_DEBUG_NAMED(LOGNAME, "Joint: %s",link_state->getParentJointState()->getName().c_str());
1358  */
1359  const JointModel* pjm = link->getParentJointModel();
1360  if (pjm->getVariableCount() > 0)
1361  {
1362  if (!group->hasJointModel(pjm->getName()))
1363  {
1364  link = pjm->getParentLinkModel();
1365  continue;
1366  }
1367  unsigned int joint_index = group->getVariableGroupIndex(pjm->getName());
1368  // getGlobalLinkTransform() returns a valid isometry by contract
1369  joint_transform = reference_transform * getGlobalLinkTransform(link); // valid isometry
1370  if (pjm->getType() == moveit::core::JointModel::REVOLUTE)
1371  {
1372  joint_axis = joint_transform.linear() * static_cast<const moveit::core::RevoluteJointModel*>(pjm)->getAxis();
1373  jacobian.block<3, 1>(0, joint_index) =
1374  jacobian.block<3, 1>(0, joint_index) + joint_axis.cross(point_transform - joint_transform.translation());
1375  jacobian.block<3, 1>(3, joint_index) = jacobian.block<3, 1>(3, joint_index) + joint_axis;
1376  }
1377  else if (pjm->getType() == moveit::core::JointModel::PRISMATIC)
1378  {
1379  joint_axis = joint_transform.linear() * static_cast<const moveit::core::PrismaticJointModel*>(pjm)->getAxis();
1380  jacobian.block<3, 1>(0, joint_index) = jacobian.block<3, 1>(0, joint_index) + joint_axis;
1381  }
1382  else if (pjm->getType() == moveit::core::JointModel::PLANAR)
1383  {
1384  joint_axis = joint_transform.linear() * Eigen::Vector3d(1.0, 0.0, 0.0);
1385  jacobian.block<3, 1>(0, joint_index) = jacobian.block<3, 1>(0, joint_index) + joint_axis;
1386  joint_axis = joint_transform.linear() * Eigen::Vector3d(0.0, 1.0, 0.0);
1387  jacobian.block<3, 1>(0, joint_index + 1) = jacobian.block<3, 1>(0, joint_index + 1) + joint_axis;
1388  joint_axis = joint_transform.linear() * Eigen::Vector3d(0.0, 0.0, 1.0);
1389  jacobian.block<3, 1>(0, joint_index + 2) = jacobian.block<3, 1>(0, joint_index + 2) +
1390  joint_axis.cross(point_transform - joint_transform.translation());
1391  jacobian.block<3, 1>(3, joint_index + 2) = jacobian.block<3, 1>(3, joint_index + 2) + joint_axis;
1392  }
1393  else
1394  ROS_ERROR_NAMED(LOGNAME, "Unknown type of joint in Jacobian computation");
1395  }
1396  if (pjm == root_joint_model)
1397  break;
1398  link = pjm->getParentLinkModel();
1399  }
1400  if (use_quaternion_representation)
1401  { // Quaternion representation
1402  // From "Advanced Dynamics and Motion Simulation" by Paul Mitiguy
1403  // d/dt ( [w] ) = 1/2 * [ -x -y -z ] * [ omega_1 ]
1404  // [x] [ w -z y ] [ omega_2 ]
1405  // [y] [ z w -x ] [ omega_3 ]
1406  // [z] [ -y x w ]
1407  Eigen::Quaterniond q(link_transform.linear());
1408  double w = q.w(), x = q.x(), y = q.y(), z = q.z();
1409  Eigen::MatrixXd quaternion_update_matrix(4, 3);
1410  quaternion_update_matrix << -x, -y, -z, w, -z, y, z, w, -x, -y, x, w;
1411  jacobian.block(3, 0, 4, columns) = 0.5 * quaternion_update_matrix * jacobian.block(3, 0, 3, columns);
1412  }
1413  return true;
1414 }
1415 
1416 bool RobotState::getJacobianDerivative(const JointModelGroup* group, const LinkModel* link,
1417  const Eigen::Vector3d& reference_point_position, Eigen::MatrixXd& jacobian,
1418  Eigen::MatrixXd& jacobian_derivative) const
1419 {
1420  const int rows = 6;
1421  const int columns = group->getVariableCount();
1422  jacobian_derivative.setZero(rows, columns);
1423 
1424  // Calculate the Jacobian with use_quaternion_representation = false
1425  if (!getJacobian(group, link, reference_point_position, jacobian, false))
1426  {
1427  ROS_ERROR_NAMED(LOGNAME, "Jacobian computation failed");
1428  return false;
1429  }
1430 
1431  auto velocities = getJointVelocities(group->getJointModels()[0]);
1432 
1433  while (link)
1434  {
1435  const JointModel* pjm = link->getParentJointModel();
1436  if (pjm->getVariableCount() > 0)
1437  {
1438  if (!group->hasJointModel(pjm->getName()))
1439  {
1440  link = pjm->getParentLinkModel();
1441  continue;
1442  }
1443  unsigned int current_joint_index = group->getVariableGroupIndex(pjm->getName());
1444  if (pjm->getType() == moveit::core::JointModel::REVOLUTE || pjm->getType() == moveit::core::JointModel::PRISMATIC)
1445  {
1446  // iterate over all joints, pd_joint_index - partial derivative joint index
1447  for (unsigned int pd_joint_index = 0; pd_joint_index < group->getVariableCount(); pd_joint_index++)
1448  {
1449  jacobian_derivative.col(current_joint_index) +=
1450  getJacobianColumnPartialDerivative(jacobian, current_joint_index, pd_joint_index) *
1451  velocities[pd_joint_index];
1452  }
1453  }
1454  else
1455  ROS_ERROR_NAMED(LOGNAME, "Unsupported type of joint in Jacobian derivative computation");
1456  }
1457  if (pjm == group->getJointModels()[0])
1458  break;
1459  link = pjm->getParentLinkModel();
1460  }
1461  return true;
1462 }
1463 
1464 Eigen::Matrix<double, 6, 1> RobotState::getJacobianColumnPartialDerivative(const Eigen::MatrixXd& jacobian,
1465  int column_index, int joint_index)
1466 {
1467  // Twist is [v omega]^T
1468  const Eigen::Matrix<double, 6, 1>& jac_j = jacobian.col(joint_index);
1469  const Eigen::Matrix<double, 6, 1>& jac_i = jacobian.col(column_index);
1470 
1471  Eigen::Matrix<double, 6, 1> t_djdq = Eigen::Matrix<double, 6, 1>::Zero();
1472 
1473  if (joint_index <= column_index)
1474  {
1475  // ref (20)
1476  const Eigen::Vector3d& jac_j_angular = jac_j.segment<3>(3);
1477  t_djdq.segment<3>(0) = jac_j_angular.cross(jac_i.segment<3>(0));
1478  t_djdq.segment<3>(3) = jac_j_angular.cross(jac_i.segment<3>(3));
1479  }
1480  else if (joint_index > column_index)
1481  {
1482  // ref (23)
1483  t_djdq.segment<3>(0) = -jac_j.segment<3>(0).cross(jac_i.segment<3>(3));
1484  }
1485  return t_djdq;
1486 }
1487 
1488 bool RobotState::setFromDiffIK(const JointModelGroup* jmg, const Eigen::VectorXd& twist, const std::string& tip,
1489  double dt, const GroupStateValidityCallbackFn& constraint)
1490 {
1491  Eigen::VectorXd qdot;
1492  computeVariableVelocity(jmg, qdot, twist, getLinkModel(tip));
1493  return integrateVariableVelocity(jmg, qdot, dt, constraint);
1494 }
1495 
1496 bool RobotState::setFromDiffIK(const JointModelGroup* jmg, const geometry_msgs::Twist& twist, const std::string& tip,
1497  double dt, const GroupStateValidityCallbackFn& constraint)
1498 {
1499  Eigen::Matrix<double, 6, 1> t;
1500  tf2::fromMsg(twist, t);
1501  return setFromDiffIK(jmg, t, tip, dt, constraint);
1502 }
1503 
1504 void RobotState::computeVariableVelocity(const JointModelGroup* jmg, Eigen::VectorXd& qdot,
1505  const Eigen::VectorXd& twist, const LinkModel* tip) const
1506 {
1507  // Get the Jacobian of the group at the current configuration
1508  Eigen::MatrixXd j(6, jmg->getVariableCount());
1509  Eigen::Vector3d reference_point(0.0, 0.0, 0.0);
1510  getJacobian(jmg, tip, reference_point, j, false);
1511 
1512  // Rotate the jacobian to the end-effector frame
1513  Eigen::Isometry3d e_mb = getGlobalLinkTransform(tip).inverse();
1514  Eigen::MatrixXd e_wb = Eigen::ArrayXXd::Zero(6, 6);
1515  e_wb.block(0, 0, 3, 3) = e_mb.matrix().block(0, 0, 3, 3);
1516  e_wb.block(3, 3, 3, 3) = e_mb.matrix().block(0, 0, 3, 3);
1517  j = e_wb * j;
1518 
1519  // Do the Jacobian moore-penrose pseudo-inverse
1520  Eigen::JacobiSVD<Eigen::MatrixXd> svd_of_j(j, Eigen::ComputeThinU | Eigen::ComputeThinV);
1521  const Eigen::MatrixXd& u = svd_of_j.matrixU();
1522  const Eigen::MatrixXd& v = svd_of_j.matrixV();
1523  const Eigen::VectorXd& s = svd_of_j.singularValues();
1524 
1525  Eigen::VectorXd sinv = s;
1526  static const double PINVTOLER = std::numeric_limits<float>::epsilon();
1527  double maxsv = 0.0;
1528  for (std::size_t i = 0; i < static_cast<std::size_t>(s.rows()); ++i)
1529  if (fabs(s(i)) > maxsv)
1530  maxsv = fabs(s(i));
1531  for (std::size_t i = 0; i < static_cast<std::size_t>(s.rows()); ++i)
1532  {
1533  // Those singular values smaller than a percentage of the maximum singular value are removed
1534  if (fabs(s(i)) > maxsv * PINVTOLER)
1535  sinv(i) = 1.0 / s(i);
1536  else
1537  sinv(i) = 0.0;
1538  }
1539  Eigen::MatrixXd jinv = (v * sinv.asDiagonal() * u.transpose());
1540 
1541  // Compute joint velocity
1542  qdot = jinv * twist;
1543 }
1544 
1545 bool RobotState::integrateVariableVelocity(const JointModelGroup* jmg, const Eigen::VectorXd& qdot, double dt,
1546  const GroupStateValidityCallbackFn& constraint)
1547 {
1548  Eigen::VectorXd q(jmg->getVariableCount());
1549  copyJointGroupPositions(jmg, q);
1550  q = q + dt * qdot;
1551  setJointGroupPositions(jmg, q);
1552  enforceBounds(jmg);
1553 
1554  if (constraint)
1555  {
1556  std::vector<double> values;
1558  return constraint(this, jmg, &values[0]);
1559  }
1560  else
1561  return true;
1563 
1564 bool RobotState::setFromIK(const JointModelGroup* jmg, const geometry_msgs::Pose& pose, double timeout,
1565  const GroupStateValidityCallbackFn& constraint,
1566  const kinematics::KinematicsQueryOptions& options)
1567 {
1568  const kinematics::KinematicsBaseConstPtr& solver = jmg->getSolverInstance();
1569  if (!solver)
1570  {
1571  ROS_ERROR_NAMED(LOGNAME, "No kinematics solver instantiated for group '%s'", jmg->getName().c_str());
1572  return false;
1573  }
1574  return setFromIK(jmg, pose, solver->getTipFrame(), timeout, constraint, options);
1575 }
1576 
1577 bool RobotState::setFromIK(const JointModelGroup* jmg, const geometry_msgs::Pose& pose, const std::string& tip,
1578  double timeout, const GroupStateValidityCallbackFn& constraint,
1579  const kinematics::KinematicsQueryOptions& options)
1580 {
1581  Eigen::Isometry3d mat;
1582  tf2::fromMsg(pose, mat);
1583  static std::vector<double> consistency_limits;
1584  return setFromIK(jmg, mat, tip, consistency_limits, timeout, constraint, options);
1585 }
1586 
1587 bool RobotState::setFromIK(const JointModelGroup* jmg, const Eigen::Isometry3d& pose, double timeout,
1588  const GroupStateValidityCallbackFn& constraint,
1589  const kinematics::KinematicsQueryOptions& options)
1590 {
1591  const kinematics::KinematicsBaseConstPtr& solver = jmg->getSolverInstance();
1592  if (!solver)
1593  {
1594  ROS_ERROR_NAMED(LOGNAME, "No kinematics solver instantiated for group '%s'", jmg->getName().c_str());
1595  return false;
1596  }
1597  static std::vector<double> consistency_limits;
1598  return setFromIK(jmg, pose, solver->getTipFrame(), consistency_limits, timeout, constraint, options);
1599 }
1600 
1601 bool RobotState::setFromIK(const JointModelGroup* jmg, const Eigen::Isometry3d& pose_in, const std::string& tip_in,
1602  double timeout, const GroupStateValidityCallbackFn& constraint,
1603  const kinematics::KinematicsQueryOptions& options)
1604 {
1605  static std::vector<double> consistency_limits;
1606  return setFromIK(jmg, pose_in, tip_in, consistency_limits, timeout, constraint, options);
1607 }
1608 
1609 namespace
1610 {
1611 void ikCallbackFnAdapter(RobotState* state, const JointModelGroup* group,
1612  const GroupStateValidityCallbackFn& constraint, const geometry_msgs::Pose& /*unused*/,
1613  const std::vector<double>& ik_sol, moveit_msgs::MoveItErrorCodes& error_code)
1614 {
1615  const std::vector<unsigned int>& bij = group->getKinematicsSolverJointBijection();
1616  std::vector<double> solution(bij.size());
1617  for (std::size_t i = 0; i < bij.size(); ++i)
1618  solution[bij[i]] = ik_sol[i];
1619  if (constraint(state, group, &solution[0]))
1620  error_code.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
1621  else
1623 }
1624 } // namespace
1625 
1626 bool RobotState::setToIKSolverFrame(Eigen::Isometry3d& pose, const kinematics::KinematicsBaseConstPtr& solver)
1627 {
1628  return setToIKSolverFrame(pose, solver->getBaseFrame());
1629 }
1631 bool RobotState::setToIKSolverFrame(Eigen::Isometry3d& pose, const std::string& ik_frame)
1632 {
1633  // Bring the pose to the frame of the IK solver
1634  if (!Transforms::sameFrame(ik_frame, robot_model_->getModelFrame()))
1635  {
1636  const LinkModel* link_model =
1637  getLinkModel((!ik_frame.empty() && ik_frame[0] == '/') ? ik_frame.substr(1) : ik_frame);
1638  if (!link_model)
1639  {
1640  ROS_ERROR_STREAM_NAMED(LOGNAME, "IK frame '" << ik_frame << "' does not exist.");
1641  return false;
1642  }
1643  pose = getGlobalLinkTransform(link_model).inverse() * pose;
1644  }
1645  return true;
1646 }
1647 
1648 bool RobotState::setFromIK(const JointModelGroup* jmg, const Eigen::Isometry3d& pose_in, const std::string& tip_in,
1649  const std::vector<double>& consistency_limits_in, double timeout,
1650  const GroupStateValidityCallbackFn& constraint,
1651  const kinematics::KinematicsQueryOptions& options)
1652 {
1653  // Convert from single pose and tip to vectors
1655  poses.push_back(pose_in);
1656 
1657  std::vector<std::string> tips;
1658  tips.push_back(tip_in);
1659 
1660  std::vector<std::vector<double> > consistency_limits;
1661  consistency_limits.push_back(consistency_limits_in);
1662 
1663  return setFromIK(jmg, poses, tips, consistency_limits, timeout, constraint, options);
1664 }
1665 
1666 bool RobotState::setFromIK(const JointModelGroup* jmg, const EigenSTL::vector_Isometry3d& poses_in,
1667  const std::vector<std::string>& tips_in, double timeout,
1668  const GroupStateValidityCallbackFn& constraint,
1669  const kinematics::KinematicsQueryOptions& options)
1670 {
1671  const std::vector<std::vector<double> > consistency_limits;
1672  return setFromIK(jmg, poses_in, tips_in, consistency_limits, timeout, constraint, options);
1673 }
1674 
1675 bool RobotState::setFromIK(const JointModelGroup* jmg, const EigenSTL::vector_Isometry3d& poses_in,
1676  const std::vector<std::string>& tips_in,
1677  const std::vector<std::vector<double> >& consistency_limit_sets, double timeout,
1678  const GroupStateValidityCallbackFn& constraint,
1679  const kinematics::KinematicsQueryOptions& options)
1680 {
1681  // Error check
1682  if (poses_in.size() != tips_in.size())
1683  {
1684  ROS_ERROR_NAMED(LOGNAME, "Number of poses must be the same as number of tips");
1685  return false;
1686  }
1687 
1688  // Load solver
1689  const kinematics::KinematicsBaseConstPtr& solver = jmg->getSolverInstance();
1690 
1691  // Check if this jmg has a solver
1692  bool valid_solver = true;
1693  if (!solver)
1694  {
1695  valid_solver = false;
1696  }
1697  // Check if this jmg's IK solver can handle multiple tips (non-chain solver)
1698  else if (poses_in.size() > 1)
1699  {
1700  std::string error_msg;
1701  if (!solver->supportsGroup(jmg, &error_msg))
1702  {
1703  // skirt around clang-diagnostic-potentially-evaluated-expression
1704  const kinematics::KinematicsBase& solver_ref = *solver;
1705  ROS_ERROR_NAMED(LOGNAME, "Kinematics solver %s does not support joint group %s. Error: %s",
1706  typeid(solver_ref).name(), jmg->getName().c_str(), error_msg.c_str());
1707  valid_solver = false;
1708  }
1709  }
1710 
1711  if (!valid_solver)
1712  {
1713  // Check if there are subgroups that can solve this for us (non-chains)
1714  if (poses_in.size() > 1)
1715  {
1716  // Forward to setFromIKSubgroups() to allow different subgroup IK solvers to work together
1717  return setFromIKSubgroups(jmg, poses_in, tips_in, consistency_limit_sets, timeout, constraint, options);
1718  }
1719  else
1720  {
1721  ROS_ERROR_NAMED(LOGNAME, "No kinematics solver instantiated for group '%s'", jmg->getName().c_str());
1722  return false;
1723  }
1724  }
1725 
1726  // Check that no, or only one set of consistency limits has been passed in, and choose that one
1727  std::vector<double> consistency_limits;
1728  if (consistency_limit_sets.size() > 1)
1729  {
1731  "Invalid number (%zu) of sets of consistency limits for a setFromIK request "
1732  "that is being solved by a single IK solver",
1733  consistency_limit_sets.size());
1734  return false;
1735  }
1736  else if (consistency_limit_sets.size() == 1)
1737  consistency_limits = consistency_limit_sets[0];
1738 
1739  // ensure RobotState is up-to-date before employing it in the IK solver
1740  update(false);
1741 
1742  const std::vector<std::string>& solver_tip_frames = solver->getTipFrames();
1743 
1744  // Track which possible tips frames we have filled in so far
1745  std::vector<bool> tip_frames_used(solver_tip_frames.size(), false);
1746 
1747  // Create vector to hold the output frames in the same order as solver_tip_frames
1748  std::vector<geometry_msgs::Pose> ik_queries(solver_tip_frames.size());
1749 
1750  // Bring each pose to the frame of the IK solver
1751  for (std::size_t i = 0; i < poses_in.size(); ++i)
1752  {
1753  // Make non-const
1754  Eigen::Isometry3d pose = poses_in[i];
1755  std::string pose_frame = tips_in[i];
1756 
1757  // Remove extra slash
1758  if (!pose_frame.empty() && pose_frame[0] == '/')
1759  pose_frame = pose_frame.substr(1);
1760 
1761  // bring the pose to the frame of the IK solver
1762  if (!setToIKSolverFrame(pose, solver))
1763  return false;
1764 
1765  // try all of the solver's possible tip frames to see if they match with any of the passed-in pose tip frames
1766  bool found_valid_frame = false;
1767  std::size_t solver_tip_id; // our current index
1768  for (solver_tip_id = 0; solver_tip_id < solver_tip_frames.size(); ++solver_tip_id)
1769  {
1770  // Check if this tip frame is already accounted for
1771  if (tip_frames_used[solver_tip_id])
1772  continue; // already has a pose
1773 
1774  // check if the tip frame can be transformed via fixed transforms to the frame known to the IK solver
1775  std::string solver_tip_frame = solver_tip_frames[solver_tip_id];
1776 
1777  // remove the frame '/' if there is one, so we can avoid calling Transforms::sameFrame() which may copy strings
1778  // more often that we need to
1779  if (!solver_tip_frame.empty() && solver_tip_frame[0] == '/')
1780  solver_tip_frame = solver_tip_frame.substr(1);
1781 
1782  if (pose_frame != solver_tip_frame)
1783  {
1784  Eigen::Isometry3d pose_parent_to_frame;
1785  auto* pose_parent = getRigidlyConnectedParentLinkModel(pose_frame, &pose_parent_to_frame, jmg);
1786  if (!pose_parent)
1787  {
1788  ROS_ERROR_STREAM_NAMED(LOGNAME, "Pose frame '" << pose_frame << "' does not exist.");
1789  return false;
1790  }
1791  Eigen::Isometry3d tip_parent_to_tip;
1792  auto* tip_parent = getRigidlyConnectedParentLinkModel(solver_tip_frame, &tip_parent_to_tip, jmg);
1793  if (!tip_parent)
1794  {
1795  ROS_ERROR_STREAM_NAMED(LOGNAME, "Solver tip frame '" << solver_tip_frame << "' does not exist.");
1796  return false;
1797  }
1798  if (pose_parent == tip_parent)
1799  {
1800  // transform goal pose as target for solver_tip_frame (instead of pose_frame)
1801  pose = pose * pose_parent_to_frame.inverse() * tip_parent_to_tip;
1802  found_valid_frame = true;
1803  break;
1804  }
1805  }
1806  else
1807  {
1808  found_valid_frame = true;
1809  break;
1810  }
1811  } // end for solver_tip_frames
1812 
1813  // Make sure one of the tip frames worked
1814  if (!found_valid_frame)
1815  {
1816  ROS_ERROR_NAMED(LOGNAME, "Cannot compute IK for query %zu pose reference frame '%s'", i, pose_frame.c_str());
1817  // Debug available tip frames
1818  std::stringstream ss;
1819  for (solver_tip_id = 0; solver_tip_id < solver_tip_frames.size(); ++solver_tip_id)
1820  ss << solver_tip_frames[solver_tip_id] << ", ";
1821  ROS_ERROR_NAMED(LOGNAME, "Available tip frames: [%s]", ss.str().c_str());
1822  return false;
1823  }
1824 
1825  // Remove that tip from the list of available tip frames because each can only have one pose
1826  tip_frames_used[solver_tip_id] = true;
1827 
1828  // Convert Eigen pose to geometry_msgs pose
1829  geometry_msgs::Pose ik_query;
1830  ik_query = tf2::toMsg(pose);
1831 
1832  // Save into vectors
1833  ik_queries[solver_tip_id] = ik_query;
1834  } // end for poses_in
1835 
1836  // Create poses for all remaining tips a solver expects, even if not passed into this function
1837  for (std::size_t solver_tip_id = 0; solver_tip_id < solver_tip_frames.size(); ++solver_tip_id)
1838  {
1839  // Check if this tip frame is already accounted for
1840  if (tip_frames_used[solver_tip_id])
1841  continue; // already has a pose
1842 
1843  // Process this tip
1844  std::string solver_tip_frame = solver_tip_frames[solver_tip_id];
1845 
1846  // remove the frame '/' if there is one, so we can avoid calling Transforms::sameFrame() which may copy strings more
1847  // often that we need to
1848  if (!solver_tip_frame.empty() && solver_tip_frame[0] == '/')
1849  solver_tip_frame = solver_tip_frame.substr(1);
1850 
1851  // Get the pose of a different EE tip link
1852  Eigen::Isometry3d current_pose = getGlobalLinkTransform(solver_tip_frame);
1853 
1854  // bring the pose to the frame of the IK solver
1855  if (!setToIKSolverFrame(current_pose, solver))
1856  return false;
1857 
1858  // Convert Eigen pose to geometry_msgs pose
1859  geometry_msgs::Pose ik_query;
1860  ik_query = tf2::toMsg(current_pose);
1861 
1862  // Save into vectors - but this needs to be ordered in the same order as the IK solver expects its tip frames
1863  ik_queries[solver_tip_id] = ik_query;
1864 
1865  // Remove that tip from the list of available tip frames because each can only have one pose
1866  tip_frames_used[solver_tip_id] = true;
1867  }
1868 
1869  // if no timeout has been specified, use the default one
1870  if (timeout < std::numeric_limits<double>::epsilon())
1871  timeout = jmg->getDefaultIKTimeout();
1872 
1873  // set callback function
1875  if (constraint)
1876  ik_callback_fn = [this, jmg, constraint](const geometry_msgs::Pose& pose, const std::vector<double>& joints,
1877  moveit_msgs::MoveItErrorCodes& error_code) {
1878  ikCallbackFnAdapter(this, jmg, constraint, pose, joints, error_code);
1879  };
1880 
1881  // Bijection
1882  const std::vector<unsigned int>& bij = jmg->getKinematicsSolverJointBijection();
1883 
1884  std::vector<double> initial_values;
1885  copyJointGroupPositions(jmg, initial_values);
1886  std::vector<double> seed(bij.size());
1887  for (std::size_t i = 0; i < bij.size(); ++i)
1888  seed[i] = initial_values[bij[i]];
1889 
1890  // compute the IK solution
1891  std::vector<double> ik_sol;
1892  moveit_msgs::MoveItErrorCodes error;
1893 
1894  if (solver->searchPositionIK(ik_queries, seed, timeout, consistency_limits, ik_sol, ik_callback_fn, error, options,
1895  this))
1896  {
1897  std::vector<double> solution(bij.size());
1898  for (std::size_t i = 0; i < bij.size(); ++i)
1899  solution[bij[i]] = ik_sol[i];
1900  setJointGroupPositions(jmg, solution);
1901  return true;
1902  }
1903  return false;
1904 }
1905 
1906 bool RobotState::setFromIKSubgroups(const JointModelGroup* jmg, const EigenSTL::vector_Isometry3d& poses_in,
1907  const std::vector<std::string>& tips_in,
1908  const std::vector<std::vector<double> >& consistency_limits, double timeout,
1909  const GroupStateValidityCallbackFn& constraint,
1910  const kinematics::KinematicsQueryOptions& /*options*/)
1911 {
1912  // Assume we have already ran setFromIK() and those checks
1913 
1914  // Get containing subgroups
1915  std::vector<const JointModelGroup*> sub_groups;
1916  jmg->getSubgroups(sub_groups);
1917 
1918  // Error check
1919  if (poses_in.size() != sub_groups.size())
1920  {
1921  ROS_ERROR_NAMED(LOGNAME, "Number of poses (%zu) must be the same as number of sub-groups (%zu)", poses_in.size(),
1922  sub_groups.size());
1923  return false;
1924  }
1925 
1926  if (tips_in.size() != sub_groups.size())
1927  {
1928  ROS_ERROR_NAMED(LOGNAME, "Number of tip names (%zu) must be same as number of sub-groups (%zu)", tips_in.size(),
1929  sub_groups.size());
1930  return false;
1931  }
1932 
1933  if (!consistency_limits.empty() && consistency_limits.size() != sub_groups.size())
1934  {
1935  ROS_ERROR_NAMED(LOGNAME, "Number of consistency limit vectors must be the same as number of sub-groups");
1936  return false;
1937  }
1938 
1939  for (std::size_t i = 0; i < consistency_limits.size(); ++i)
1940  {
1941  if (consistency_limits[i].size() != sub_groups[i]->getVariableCount())
1942  {
1943  ROS_ERROR_NAMED(LOGNAME, "Number of joints in consistency_limits[%zu] is %zu but it should be should be %u", i,
1944  consistency_limits[i].size(), sub_groups[i]->getVariableCount());
1945  return false;
1946  }
1947  }
1948 
1949  // Populate list of kin solvers for the various subgroups
1950  std::vector<kinematics::KinematicsBaseConstPtr> solvers;
1951  for (std::size_t i = 0; i < poses_in.size(); ++i)
1952  {
1953  kinematics::KinematicsBaseConstPtr solver = sub_groups[i]->getSolverInstance();
1954  if (!solver)
1955  {
1956  ROS_ERROR_NAMED(LOGNAME, "Could not find solver for group '%s'", sub_groups[i]->getName().c_str());
1957  return false;
1958  }
1959  solvers.push_back(solver);
1960  }
1961 
1962  // Make non-const versions
1963  EigenSTL::vector_Isometry3d transformed_poses = poses_in;
1964  std::vector<std::string> pose_frames = tips_in;
1965 
1966  // Each each pose's tip frame naming
1967  for (std::size_t i = 0; i < poses_in.size(); ++i)
1968  {
1969  ASSERT_ISOMETRY(transformed_poses[i]) // unsanitized input, could contain a non-isometry
1970  Eigen::Isometry3d& pose = transformed_poses[i];
1971  std::string& pose_frame = pose_frames[i];
1972 
1973  // bring the pose to the frame of the IK solver
1974  if (!setToIKSolverFrame(pose, solvers[i]))
1975  return false;
1976 
1977  // see if the tip frame can be transformed via fixed transforms to the frame known to the IK solver
1978  std::string solver_tip_frame = solvers[i]->getTipFrame();
1979 
1980  // remove the frame '/' if there is one, so we can avoid calling Transforms::sameFrame() which may copy strings more
1981  // often that we need to
1982  if (!solver_tip_frame.empty() && solver_tip_frame[0] == '/')
1983  solver_tip_frame = solver_tip_frame.substr(1);
1984 
1985  if (pose_frame != solver_tip_frame)
1986  {
1987  if (hasAttachedBody(pose_frame))
1988  {
1989  const AttachedBody* body = getAttachedBody(pose_frame);
1990  pose_frame = body->getAttachedLinkName();
1991  pose = pose * body->getPose().inverse(); // valid isometry
1992  }
1993  if (pose_frame != solver_tip_frame)
1994  {
1995  const moveit::core::LinkModel* link_model = getLinkModel(pose_frame);
1996  if (!link_model)
1997  return false;
1998  // getAssociatedFixedTransforms() returns valid isometries by contract
1999  const moveit::core::LinkTransformMap& fixed_links = link_model->getAssociatedFixedTransforms();
2000  for (const std::pair<const LinkModel* const, Eigen::Isometry3d>& fixed_link : fixed_links)
2001  if (fixed_link.first->getName() == solver_tip_frame)
2002  {
2003  pose_frame = solver_tip_frame;
2004  pose = pose * fixed_link.second; // valid isometry
2005  break;
2006  }
2007  }
2008  }
2009 
2010  if (pose_frame != solver_tip_frame)
2011  {
2012  ROS_ERROR_NAMED(LOGNAME, "Cannot compute IK for query pose reference frame '%s', desired: '%s'",
2013  pose_frame.c_str(), solver_tip_frame.c_str());
2014  return false;
2015  }
2016  }
2017 
2018  // Convert Eigen poses to geometry_msg format
2019  std::vector<geometry_msgs::Pose> ik_queries(poses_in.size());
2020  for (std::size_t i = 0; i < transformed_poses.size(); ++i)
2021  {
2022  Eigen::Quaterniond quat(transformed_poses[i].linear());
2023  Eigen::Vector3d point(transformed_poses[i].translation());
2024  ik_queries[i].position.x = point.x();
2025  ik_queries[i].position.y = point.y();
2026  ik_queries[i].position.z = point.z();
2027  ik_queries[i].orientation.x = quat.x();
2028  ik_queries[i].orientation.y = quat.y();
2029  ik_queries[i].orientation.z = quat.z();
2030  ik_queries[i].orientation.w = quat.w();
2031  }
2032 
2033  // if no timeout has been specified, use the default one
2034  if (timeout < std::numeric_limits<double>::epsilon())
2035  timeout = jmg->getDefaultIKTimeout();
2037  double elapsed = 0;
2038 
2039  bool first_seed = true;
2040  unsigned int attempts = 0;
2041  do
2042  {
2043  ++attempts;
2044  ROS_DEBUG_NAMED(LOGNAME, "IK attempt: %d", attempts);
2045  bool found_solution = true;
2046  for (std::size_t sg = 0; sg < sub_groups.size(); ++sg)
2047  {
2048  const std::vector<unsigned int>& bij = sub_groups[sg]->getKinematicsSolverJointBijection();
2049  std::vector<double> seed(bij.size());
2050  // the first seed is the initial state
2051  if (first_seed)
2052  {
2053  std::vector<double> initial_values;
2054  copyJointGroupPositions(sub_groups[sg], initial_values);
2055  for (std::size_t i = 0; i < bij.size(); ++i)
2056  seed[i] = initial_values[bij[i]];
2057  }
2058  else
2059  {
2060  // sample a random seed
2062  std::vector<double> random_values;
2063  sub_groups[sg]->getVariableRandomPositions(rng, random_values);
2064  for (std::size_t i = 0; i < bij.size(); ++i)
2065  seed[i] = random_values[bij[i]];
2066  }
2067 
2068  // compute the IK solution
2069  std::vector<double> ik_sol;
2070  moveit_msgs::MoveItErrorCodes error;
2071  const std::vector<double>& climits = consistency_limits.empty() ? std::vector<double>() : consistency_limits[sg];
2072  if (solvers[sg]->searchPositionIK(ik_queries[sg], seed, (timeout - elapsed) / sub_groups.size(), climits, ik_sol,
2073  error))
2074  {
2075  std::vector<double> solution(bij.size());
2076  for (std::size_t i = 0; i < bij.size(); ++i)
2077  solution[bij[i]] = ik_sol[i];
2078  setJointGroupPositions(sub_groups[sg], solution);
2079  }
2080  else
2081  {
2082  found_solution = false;
2083  break;
2084  }
2085  }
2086  if (found_solution)
2087  {
2088  std::vector<double> full_solution;
2089  copyJointGroupPositions(jmg, full_solution);
2090  if (constraint ? constraint(this, jmg, &full_solution[0]) : true)
2091  {
2092  ROS_DEBUG_NAMED(LOGNAME, "Found IK solution");
2093  return true;
2094  }
2095  }
2096  elapsed = (ros::WallTime::now() - start).toSec();
2097  first_seed = false;
2098  } while (elapsed < timeout);
2099  return false;
2100 }
2101 
2102 void RobotState::computeAABB(std::vector<double>& aabb) const
2103 {
2104  BOOST_VERIFY(checkLinkTransforms());
2105 
2106  core::AABB bounding_box;
2107  std::vector<const LinkModel*> links = robot_model_->getLinkModelsWithCollisionGeometry();
2108  for (const LinkModel* link : links)
2109  {
2110  Eigen::Isometry3d transform = getGlobalLinkTransform(link); // intentional copy, we will translate
2111  const Eigen::Vector3d& extents = link->getShapeExtentsAtOrigin();
2112  transform.translate(link->getCenteredBoundingBoxOffset());
2113  bounding_box.extendWithTransformedBox(transform, extents);
2114  }
2115  for (const auto& it : attached_body_map_)
2116  {
2117  const EigenSTL::vector_Isometry3d& transforms = it.second->getGlobalCollisionBodyTransforms();
2118  const std::vector<shapes::ShapeConstPtr>& shapes = it.second->getShapes();
2119  for (std::size_t i = 0; i < transforms.size(); ++i)
2120  {
2122  bounding_box.extendWithTransformedBox(transforms[i], extents);
2123  }
2124  }
2125 
2126  aabb.clear();
2127  aabb.resize(6, 0.0);
2128  if (!bounding_box.isEmpty())
2129  {
2130  // The following is a shorthand for something like:
2131  // aabb[0, 2, 4] = bounding_box.min(); aabb[1, 3, 5] = bounding_box.max();
2132  Eigen::Map<Eigen::VectorXd, Eigen::Unaligned, Eigen::InnerStride<2> >(aabb.data(), 3) = bounding_box.min();
2133  Eigen::Map<Eigen::VectorXd, Eigen::Unaligned, Eigen::InnerStride<2> >(aabb.data() + 1, 3) = bounding_box.max();
2134  }
2135 }
2136 
2137 void RobotState::printStatePositions(std::ostream& out) const
2138 {
2139  const std::vector<std::string>& nm = robot_model_->getVariableNames();
2140  for (std::size_t i = 0; i < nm.size(); ++i)
2141  out << nm[i] << "=" << position_[i] << std::endl;
2142 }
2143 
2144 void RobotState::printStatePositionsWithJointLimits(const moveit::core::JointModelGroup* jmg, std::ostream& out) const
2145 {
2146  // TODO(davetcoleman): support joints with multiple variables / multiple DOFs such as floating joints
2147  // TODO(davetcoleman): support unbounded joints
2148 
2149  const std::vector<const moveit::core::JointModel*>& joints = jmg->getActiveJointModels();
2150 
2151  // Loop through joints
2152  for (const JointModel* joint : joints)
2153  {
2154  // Ignore joints with more than one variable
2155  if (joint->getVariableCount() > 1)
2156  continue;
2157 
2158  double current_value = getVariablePosition(joint->getName());
2159 
2160  // check if joint is beyond limits
2161  bool out_of_bounds = !satisfiesBounds(joint);
2162 
2163  const moveit::core::VariableBounds& bound = joint->getVariableBounds()[0];
2164 
2165  if (out_of_bounds)
2166  out << MOVEIT_CONSOLE_COLOR_RED;
2167 
2168  out << " " << std::fixed << std::setprecision(5) << bound.min_position_ << "\t";
2169  double delta = bound.max_position_ - bound.min_position_;
2170  double step = delta / 20.0;
2171 
2172  bool marker_shown = false;
2173  for (double value = bound.min_position_; value < bound.max_position_; value += step)
2174  {
2175  // show marker of current value
2176  if (!marker_shown && current_value < value)
2177  {
2178  out << "|";
2179  marker_shown = true;
2180  }
2181  else
2182  out << "-";
2183  }
2184  if (!marker_shown)
2185  out << "|";
2186 
2187  // show max position
2188  out << " \t" << std::fixed << std::setprecision(5) << bound.max_position_ << " \t" << joint->getName()
2189  << " current: " << std::fixed << std::setprecision(5) << current_value << std::endl;
2190 
2191  if (out_of_bounds)
2193  }
2194 }
2195 
2196 void RobotState::printDirtyInfo(std::ostream& out) const
2197 {
2198  out << " * Dirty Joint Transforms: " << std::endl;
2199  const std::vector<const JointModel*>& jm = robot_model_->getJointModels();
2200  for (const JointModel* joint : jm)
2201  if (joint->getVariableCount() > 0 && dirtyJointTransform(joint))
2202  out << " " << joint->getName() << std::endl;
2203  out << " * Dirty Link Transforms: " << (dirty_link_transforms_ ? dirty_link_transforms_->getName() : "NULL")
2204  << std::endl;
2205  out << " * Dirty Collision Body Transforms: "
2207 }
2208 
2209 void RobotState::printStateInfo(std::ostream& out) const
2211  out << "Robot State @" << this << std::endl;
2212 
2213  std::size_t n = robot_model_->getVariableCount();
2214  if (position_)
2215  {
2216  out << " * Position: ";
2217  for (std::size_t i = 0; i < n; ++i)
2218  out << position_[i] << " ";
2219  out << std::endl;
2220  }
2221  else
2222  out << " * Position: NULL" << std::endl;
2223 
2224  if (velocity_)
2225  {
2226  out << " * Velocity: ";
2227  for (std::size_t i = 0; i < n; ++i)
2228  out << velocity_[i] << " ";
2229  out << std::endl;
2230  }
2231  else
2232  out << " * Velocity: NULL" << std::endl;
2233 
2234  if (acceleration_)
2235  {
2236  out << " * Acceleration: ";
2237  for (std::size_t i = 0; i < n; ++i)
2238  out << acceleration_[i] << " ";
2239  out << std::endl;
2240  }
2241  else
2242  out << " * Acceleration: NULL" << std::endl;
2243 
2244  out << " * Dirty Link Transforms: " << (dirty_link_transforms_ ? dirty_link_transforms_->getName() : "NULL")
2245  << std::endl;
2246  out << " * Dirty Collision Body Transforms: "
2248 
2249  printTransforms(out);
2250 }
2251 
2252 void RobotState::printTransform(const Eigen::Isometry3d& transform, std::ostream& out) const
2253 {
2254  if (checkIsometry(transform, CHECK_ISOMETRY_PRECISION, false))
2255  {
2256  Eigen::Quaterniond q(transform.linear());
2257  out << "T.xyz = [" << transform.translation().x() << ", " << transform.translation().y() << ", "
2258  << transform.translation().z() << "], Q.xyzw = [" << q.x() << ", " << q.y() << ", " << q.z() << ", " << q.w()
2259  << "]";
2260  }
2261  else
2262  {
2263  out << "[NON-ISOMETRY] "
2264  << transform.matrix().format(
2265  Eigen::IOFormat(Eigen::StreamPrecision, Eigen::DontAlignCols, ", ", "; ", "", "", "[", "]"));
2266  }
2267  out << std::endl;
2268 }
2269 
2270 void RobotState::printTransforms(std::ostream& out) const
2271 {
2273  {
2274  out << "No transforms computed" << std::endl;
2275  return;
2276  }
2277 
2278  out << "Joint transforms:" << std::endl;
2279  const std::vector<const JointModel*>& jm = robot_model_->getJointModels();
2280  for (const JointModel* joint : jm)
2281  {
2282  if (joint->getType() == JointModel::FIXED)
2283  continue;
2284 
2285  out << " " << joint->getName();
2286  const int idx = joint->getJointIndex();
2287  if (dirty_joint_transforms_[idx])
2288  out << " [dirty]";
2289  out << ": ";
2291  }
2292 
2293  out << "Link poses:" << std::endl;
2294  const std::vector<const LinkModel*>& link_model = robot_model_->getLinkModels();
2295  for (const LinkModel* link : link_model)
2296  {
2297  out << " " << link->getName() << ": ";
2298  printTransform(global_link_transforms_[link->getLinkIndex()], out);
2299  }
2300 }
2301 
2302 std::string RobotState::getStateTreeString() const
2303 {
2304  std::stringstream ss;
2305  ss << "ROBOT: " << robot_model_->getName() << std::endl;
2306  getStateTreeJointString(ss, robot_model_->getRootJoint(), " ", true);
2307  return ss.str();
2308 }
2309 
2310 namespace
2311 {
2312 void getPoseString(std::ostream& ss, const Eigen::Isometry3d& pose, const std::string& pfx)
2313 {
2314  ss.precision(3);
2315  for (int y = 0; y < 4; ++y)
2316  {
2317  ss << pfx;
2318  for (int x = 0; x < 4; ++x)
2319  {
2320  ss << std::setw(8) << pose(y, x) << " ";
2321  }
2322  ss << std::endl;
2323  }
2324 }
2325 } // namespace
2326 
2327 void RobotState::getStateTreeJointString(std::ostream& ss, const JointModel* jm, const std::string& pfx0,
2328  bool last) const
2329 {
2330  std::string pfx = pfx0 + "+--";
2331 
2332  ss << pfx << "Joint: " << jm->getName() << std::endl;
2333 
2334  pfx = pfx0 + (last ? " " : "| ");
2335 
2336  for (std::size_t i = 0; i < jm->getVariableCount(); ++i)
2337  {
2338  ss.precision(3);
2339  ss << pfx << jm->getVariableNames()[i] << std::setw(12) << position_[jm->getFirstVariableIndex() + i] << std::endl;
2340  }
2341 
2342  const LinkModel* link_model = jm->getChildLinkModel();
2343 
2344  ss << pfx << "Link: " << link_model->getName() << std::endl;
2345  getPoseString(ss, link_model->getJointOriginTransform(), pfx + "joint_origin:");
2347  {
2348  getPoseString(ss, variable_joint_transforms_[jm->getJointIndex()], pfx + "joint_variable:");
2349  getPoseString(ss, global_link_transforms_[link_model->getLinkIndex()], pfx + "link_global:");
2350  }
2351 
2352  for (std::vector<const JointModel*>::const_iterator it = link_model->getChildJointModels().begin();
2353  it != link_model->getChildJointModels().end(); ++it)
2354  getStateTreeJointString(ss, *it, pfx, it + 1 == link_model->getChildJointModels().end());
2355 }
2356 
2357 std::ostream& operator<<(std::ostream& out, const RobotState& s)
2358 {
2359  s.printStateInfo(out);
2360  return out;
2361 }
2362 
2363 bool haveSameAttachedObjects(const RobotState& left, const RobotState& right, const std::string& prefix)
2364 {
2365  std::vector<const moveit::core::AttachedBody*> left_attached;
2366  std::vector<const moveit::core::AttachedBody*> right_attached;
2367  left.getAttachedBodies(left_attached);
2368  right.getAttachedBodies(right_attached);
2369  if (left_attached.size() != right_attached.size())
2370  {
2371  ROS_DEBUG_STREAM(prefix << "different number of objects");
2372  return false;
2373  }
2374 
2375  for (const moveit::core::AttachedBody* left_object : left_attached)
2376  {
2377  auto it = std::find_if(right_attached.cbegin(), right_attached.cend(),
2378  [left_object](const moveit::core::AttachedBody* object) {
2379  return object->getName() == left_object->getName();
2380  });
2381  if (it == right_attached.cend())
2382  {
2383  ROS_DEBUG_STREAM(prefix << "object missing: " << left_object->getName());
2384  return false;
2385  }
2386  const moveit::core::AttachedBody* right_object = *it;
2387  if (left_object->getAttachedLink() != right_object->getAttachedLink())
2388  {
2389  ROS_DEBUG_STREAM(prefix << "different attach links: " << left_object->getName() << " attached to "
2390  << left_object->getAttachedLinkName() << " / " << right_object->getAttachedLinkName());
2391  return false; // links not matching
2392  }
2393  if (left_object->getShapes().size() != right_object->getShapes().size())
2394  {
2395  ROS_DEBUG_STREAM(prefix << "different object shapes: " << left_object->getName());
2396  return false; // shapes not matching
2397  }
2398 
2399  auto left_it = left_object->getShapePosesInLinkFrame().cbegin();
2400  auto left_end = left_object->getShapePosesInLinkFrame().cend();
2401  auto right_it = right_object->getShapePosesInLinkFrame().cbegin();
2402  for (; left_it != left_end; ++left_it, ++right_it)
2403  if (!(left_it->matrix() - right_it->matrix()).isZero(1e-4))
2404  {
2405  ROS_DEBUG_STREAM(prefix << "different pose of attached object shape: " << left_object->getName());
2406  return false; // transforms do not match
2407  }
2408  }
2409  return true;
2410 }
2411 
2412 } // end of namespace core
2413 } // end of namespace moveit
moveit::core::RobotState::dropAccelerations
void dropAccelerations()
Remove accelerations from this state (this differs from setting them to zero)
Definition: robot_state.cpp:336
moveit::core::LinkModel::getJointOriginTransform
const Eigen::Isometry3d & getJointOriginTransform() const
When transforms are computed for this link, they are usually applied to the link's origin....
Definition: link_model.h:142
moveit::core::JointModelGroup::hasLinkModel
bool hasLinkModel(const std::string &link) const
Check if a link is part of this group.
Definition: joint_model_group.cpp:354
moveit::core::LinkModel
A link from the robot. Contains the constant transform applied to the link and its geometry.
Definition: link_model.h:71
moveit::core
Core components of MoveIt.
Definition: kinematics_base.h:83
moveit::core::RobotState::checkJointTransforms
bool checkJointTransforms(const JointModel *joint) const
This function is only called in debug mode.
Definition: robot_state.cpp:254
moveit::core::GroupStateValidityCallbackFn
boost::function< bool(RobotState *robot_state, const JointModelGroup *joint_group, const double *joint_group_variable_values)> GroupStateValidityCallbackFn
Signature for functions that can verify that if the group joint_group in robot_state is set to joint_...
Definition: robot_state.h:136
moveit::core::JointModelGroup::getActiveJointModels
const std::vector< const JointModel * > & getActiveJointModels() const
Get the active joints in this group (that have controllable DOF). This does not include mimic joints.
Definition: joint_model_group.h:222
moveit::core::RobotState::setJointPositions
void setJointPositions(const std::string &joint_name, const double *position)
Definition: robot_state.h:581
moveit::core::RobotState::operator=
RobotState & operator=(const RobotState &other)
Copy operator.
Definition: robot_state.cpp:208
moveit::core::RobotState::distance
double distance(const RobotState &other) const
Return the sum of joint distances to "other" state. Only considers active joints.
Definition: robot_state.h:1533
moveit::core::RobotState::dirtyJointTransform
bool dirtyJointTransform(const JointModel *joint) const
Definition: robot_state.h:1505
moveit::core::RobotState::setVariablePositions
void setVariablePositions(const double *position)
It is assumed positions is an array containing the new positions for all variables in this state....
Definition: robot_state.cpp:443
shapes
EigenSTL::vector_Isometry3d
std::vector< Eigen::Isometry3d, Eigen::aligned_allocator< Eigen::Isometry3d > > vector_Isometry3d
moveit::core::operator<<
std::ostream & operator<<(std::ostream &out, const VariableBounds &b)
Operator overload for printing variable bounds to a stream.
Definition: joint_model.cpp:309
moveit::core::RobotState::harmonizePosition
void harmonizePosition(const JointModel *joint)
Definition: robot_state.h:1606
moveit::core::RobotState::getVariableCount
std::size_t getVariableCount() const
Get the number of variables that make up this state.
Definition: robot_state.h:176
moveit::core::RobotState::setJointGroupVelocities
void setJointGroupVelocities(const std::string &joint_group_name, const double *gstate)
Given velocities for the variables that make up a group, in the order found in the group (including v...
Definition: robot_state.h:814
moveit::core::JointModelGroup::getActiveVariableCount
unsigned int getActiveVariableCount() const
Get the number of variables that describe the active joints in this joint group. This excludes variab...
Definition: joint_model_group.h:482
moveit::core::JointModel::PLANAR
@ PLANAR
Definition: joint_model.h:182
moveit::core::JointModelGroup::getVariableIndexList
const std::vector< int > & getVariableIndexList() const
Get the index locations in the complete robot state for all the variables in this group.
Definition: joint_model_group.h:351
moveit::core::RobotState::velocity_
double * velocity_
Definition: robot_state.h:1976
moveit::core::JointModelGroup
Definition: joint_model_group.h:134
moveit::core::VariableBounds
Definition: joint_model.h:118
moveit::core::LinkModel::getChildJointModels
const std::vector< const JointModel * > & getChildJointModels() const
A link may have 0 or more child joints. From those joints there will certainly be other descendant li...
Definition: link_model.h:127
moveit::core::RobotState::setFromIKSubgroups
bool setFromIKSubgroups(const JointModelGroup *group, const EigenSTL::vector_Isometry3d &poses, const std::vector< std::string > &tips, const std::vector< std::vector< double >> &consistency_limits, double timeout=0.0, const GroupStateValidityCallbackFn &constraint=GroupStateValidityCallbackFn(), const kinematics::KinematicsQueryOptions &options=kinematics::KinematicsQueryOptions())
setFromIK for multiple poses and tips (end effectors) when no solver exists for the jmg that can solv...
moveit::core::RobotState::getStateTreeJointString
void getStateTreeJointString(std::ostream &ss, const JointModel *jm, const std::string &pfx0, bool last) const
Definition: robot_state.cpp:2393
moveit::core::JointModel::getDescendantLinkModels
const std::vector< const LinkModel * > & getDescendantLinkModels() const
Get all the link models that descend from this joint, in the kinematic tree.
Definition: joint_model.h:476
tf2_eigen.h
tf2::fromMsg
void fromMsg(const A &, B &b)
moveit::core::RobotState::setVariableVelocities
void setVariableVelocities(const double *velocity)
Given an array with velocity values for all variables, set those values as the velocities in this sta...
Definition: robot_state.h:319
s
XmlRpcServer s
moveit::core::RobotState::getFrameInfo
const Eigen::Isometry3d & getFrameInfo(const std::string &frame_id, const LinkModel *&robot_link, bool &frame_found) const
Get the transformation matrix from the model frame (root of model) to the frame identified by frame_i...
Definition: robot_state.cpp:1211
moveit::core::RobotState::knowsFrameTransform
bool knowsFrameTransform(const std::string &frame_id) const
Check if a transformation matrix from the model frame (root of model) to frame frame_id is known.
Definition: robot_state.cpp:1259
moveit::core::RobotState::zeroAccelerations
void zeroAccelerations()
Set all accelerations to 0.0.
Definition: robot_state.cpp:319
moveit::core::RobotState::getJacobian
bool getJacobian(const JointModelGroup *group, const LinkModel *link, const Eigen::Vector3d &reference_point_position, Eigen::MatrixXd &jacobian, bool use_quaternion_representation=false) const
Compute the Jacobian with reference to a particular point on a given link, for a specified group.
Definition: robot_state.cpp:1374
moveit::core::RobotState::getLinkModel
const LinkModel * getLinkModel(const std::string &link) const
Get the model of a particular link.
Definition: robot_state.h:188
moveit::core::RobotState::copyFrom
void copyFrom(const RobotState &other)
Definition: robot_state.cpp:215
getName
ROSCONSOLE_CONSOLE_IMPL_DECL std::string getName(void *handle)
moveit::core::RobotState::dropDynamics
void dropDynamics()
Reduce RobotState to kinematic information (remove velocity, acceleration and effort,...
Definition: robot_state.cpp:346
check_isometry.h
inverse
TF2SIMD_FORCE_INLINE Quaternion inverse(const Quaternion &q)
moveit::core::AttachedBody::getShapePosesInLinkFrame
const EigenSTL::vector_Isometry3d & getShapePosesInLinkFrame() const
Get the fixed transforms (the transforms to the shapes of this body, relative to the link)....
Definition: attached_body.h:195
backtrace.h
moveit::core::RobotState::updateLinkTransformsInternal
void updateLinkTransformsInternal(const JointModel *start)
Definition: robot_state.cpp:784
moveit::core::PrismaticJointModel
A prismatic joint.
Definition: prismatic_joint_model.h:110
moveit::core::RobotState::getJointTransform
const Eigen::Isometry3d & getJointTransform(const std::string &joint_name)
Definition: robot_state.h:1477
moveit::core::JointModel::getName
const std::string & getName() const
Get the name of the joint.
Definition: joint_model.h:196
moveit::core::RobotState::markAcceleration
void markAcceleration()
Definition: robot_state.cpp:293
moveit::core::RobotState::setJointGroupActivePositions
void setJointGroupActivePositions(const JointModelGroup *group, const std::vector< double > &gstate)
Given positions for the variables of active joints that make up a group, in the order found in the gr...
Definition: robot_state.cpp:609
moveit::core::LinkModel::getParentJointModel
const JointModel * getParentJointModel() const
Get the joint model whose child this link is. There will always be a parent joint.
Definition: link_model.h:107
shape_operations.h
moveit::core::RobotState::getAttachedBody
const AttachedBody * getAttachedBody(const std::string &name) const
Get the attached body named name. Return NULL if not found.
Definition: robot_state.cpp:1075
ROS_ERROR_NAMED
#define ROS_ERROR_NAMED(name,...)
moveit::core::RobotState
Representation of a robot's state. This includes position, velocity, acceleration and effort.
Definition: robot_state.h:155
moveit::core::RobotState::copyJointGroupPositions
void copyJointGroupPositions(const std::string &joint_group_name, std::vector< double > &gstate) const
For a given group, copy the position values of the variables that make up the group into another loca...
Definition: robot_state.h:757
moveit::core::RobotState::attached_body_map_
std::map< std::string, std::unique_ptr< AttachedBody > > attached_body_map_
All attached bodies that are part of this state, indexed by their name.
Definition: robot_state.h:1995
moveit::core::RobotState::getGlobalLinkTransform
const Eigen::Isometry3d & getGlobalLinkTransform(const std::string &link_name)
Get the link transform w.r.t. the root link (model frame) of the RobotModel. This is typically the ro...
Definition: robot_state.h:1423
moveit::core::RobotState::setFromIK
bool setFromIK(const JointModelGroup *group, const geometry_msgs::Pose &pose, double timeout=0.0, const GroupStateValidityCallbackFn &constraint=GroupStateValidityCallbackFn(), const kinematics::KinematicsQueryOptions &options=kinematics::KinematicsQueryOptions())
If the group this state corresponds to is a chain and a solver is available, then the joint values ca...
Definition: robot_state.cpp:1630
moveit::core::RobotState::setToRandomPositions
void setToRandomPositions()
Set all joints to random values. Values will be within default bounds.
Definition: robot_state.cpp:353
moveit::core::RobotState::getJacobianDerivative
bool getJacobianDerivative(const JointModelGroup *group, const LinkModel *link, const Eigen::Vector3d &reference_point_position, Eigen::MatrixXd &jacobian, Eigen::MatrixXd &jacobian_derivative) const
Compute the time derivative of the Jacobian with reference to a particular point on a given link,...
Definition: robot_state.cpp:1482
moveit::core::RobotState::computeVariableVelocity
void computeVariableVelocity(const JointModelGroup *jmg, Eigen::VectorXd &qdot, const Eigen::VectorXd &twist, const LinkModel *tip) const
Given a twist for a particular link (tip), compute the corresponding velocity for every variable and ...
Definition: robot_state.cpp:1570
step
unsigned int step
transform
template Halfspace< double > transform(const Halfspace< double > &a, const Transform3< double > &tf)
moveit::core::JointModel::PRISMATIC
@ PRISMATIC
Definition: joint_model.h:181
kinematics::KinematicsBase::IKCallbackFn
boost::function< void(const geometry_msgs::Pose &, const std::vector< double > &, moveit_msgs::MoveItErrorCodes &)> IKCallbackFn
Signature for a callback to validate an IK solution. Typically used for collision checking.
Definition: kinematics_base.h:153
moveit::core::RobotState::setAttachedBodyUpdateCallback
void setAttachedBodyUpdateCallback(const AttachedBodyCallback &callback)
Definition: robot_state.cpp:1065
moveit::core::RobotState::setToIKSolverFrame
bool setToIKSolverFrame(Eigen::Isometry3d &pose, const kinematics::KinematicsBaseConstPtr &solver)
Transform pose from the robot model's base frame to the reference frame of the IK solver.
Definition: robot_state.cpp:1692
MOVEIT_CONSOLE_COLOR_RESET
#define MOVEIT_CONSOLE_COLOR_RESET
Definition: console_colors.h:39
ROS_DEBUG_STREAM
#define ROS_DEBUG_STREAM(args)
get
def get(url)
uintptr_t
std::uintptr_t uintptr_t
moveit::core::RobotState::printStatePositions
void printStatePositions(std::ostream &out=std::cout) const
Definition: robot_state.cpp:2203
moveit::core::RobotState::getMinDistanceToPositionBounds
std::pair< double, const JointModel * > getMinDistanceToPositionBounds() const
Get the minimm distance from this state to the bounds. The minimum distance and the joint for which t...
Definition: robot_state.cpp:965
moveit::core::RobotState::getRobotMarkers
void getRobotMarkers(visualization_msgs::MarkerArray &arr, const std::vector< std::string > &link_names, const std_msgs::ColorRGBA &color, const std::string &ns, const ros::Duration &dur, bool include_attached=false) const
Get a MarkerArray that fully describes the robot markers for a given robot.
Definition: robot_state.cpp:1280
moveit::core::RobotState::checkCollisionTransforms
bool checkCollisionTransforms() const
This function is only called in debug mode.
Definition: robot_state.cpp:274
del
ROSCPP_DECL bool del(const std::string &key)
moveit::core::RobotState::clearAttachedBodies
void clearAttachedBodies()
Clear all attached bodies. This calls delete on the AttachedBody instances, if needed.
Definition: robot_state.cpp:1137
moveit::core::JointModel::REVOLUTE
@ REVOLUTE
Definition: joint_model.h:180
moveit::core::RobotState::getMissingKeys
void getMissingKeys(const std::map< std::string, double > &variable_map, std::vector< std::string > &missing_variables) const
Definition: robot_state.cpp:467
moveit::core::RobotState::getStateTreeString
std::string getStateTreeString() const
Definition: robot_state.cpp:2368
moveit::core::AttachedBody
Object defining bodies that can be attached to robot links.
Definition: attached_body.h:121
moveit::core::RobotState::copyJointGroupAccelerations
void copyJointGroupAccelerations(const std::string &joint_group_name, std::vector< double > &gstate) const
For a given group, copy the acceleration values of the variables that make up the group into another ...
Definition: robot_state.h:957
moveit::core::RobotState::getRigidlyConnectedParentLinkModel
const moveit::core::LinkModel * getRigidlyConnectedParentLinkModel(const std::string &frame, Eigen::Isometry3d *transform=nullptr, const moveit::core::JointModelGroup *jmg=nullptr) const
Get the latest link upwards the kinematic tree which is only connected via fixed joints.
Definition: robot_state.cpp:875
moveit::core::RobotState::harmonizePositions
void harmonizePositions()
Call harmonizePosition() for all joints / all joints in group / given joint.
Definition: robot_state.cpp:953
transforms.h
moveit::core::RobotState::getRandomNumberGenerator
random_numbers::RandomNumberGenerator & getRandomNumberGenerator()
Return the instance of a random number generator.
Definition: robot_state.h:1787
moveit::core::JointModelGroup::getName
const std::string & getName() const
Get the name of the joint group.
Definition: joint_model_group.h:185
moveit::core::RobotState::memory_
void * memory_
Definition: robot_state.h:1973
moveit::core::RobotState::printDirtyInfo
void printDirtyInfo(std::ostream &out=std::cout) const
Definition: robot_state.cpp:2262
profiler.h
moveit::core::RobotState::RobotState
RobotState(const RobotModelConstPtr &robot_model)
A state can be constructed from a specified robot model. No values are initialized....
Definition: robot_state.cpp:125
moveit::core::JointModelGroup::getVariableDefaultPositions
bool getVariableDefaultPositions(const std::string &name, std::map< std::string, double > &values) const
Get the values that correspond to a named state as read from the URDF. Return false on failure.
Definition: joint_model_group.cpp:512
moveit::core::JointModel::getParentLinkModel
const LinkModel * getParentLinkModel() const
Get the link that this joint connects to. The robot is assumed to start with a joint,...
Definition: joint_model.h:213
moveit::core::RobotState::markDirtyJointTransforms
void markDirtyJointTransforms(const JointModel *joint)
Definition: robot_state.h:1900
moveit::core::RobotState::markEffort
void markEffort()
Definition: robot_state.cpp:303
moveit::core::RobotState::printTransform
void printTransform(const Eigen::Isometry3d &transform, std::ostream &out=std::cout) const
Definition: robot_state.cpp:2318
moveit::core::RobotState::dirtyLinkTransforms
bool dirtyLinkTransforms() const
Definition: robot_state.h:1510
moveit::core::RobotState::update
void update(bool force=false)
Update all transforms.
Definition: robot_state.cpp:729
name
std::string name
kinematics::KinematicsBase
Provides an interface for kinematics solvers.
Definition: kinematics_base.h:145
moveit::core::JointModel::Bounds
std::vector< VariableBounds > Bounds
The datatype for the joint bounds.
Definition: joint_model.h:188
ROS_DEBUG_NAMED
#define ROS_DEBUG_NAMED(name,...)
bound
template Interval< double > bound(const Interval< double > &i, const Interval< double > &other)
y
double y
ros::WallTime::now
static WallTime now()
ROS_ERROR_STREAM_NAMED
#define ROS_ERROR_STREAM_NAMED(name, args)
moveit::core::RobotState::dropVelocities
void dropVelocities()
Remove velocities from this state (this differs from setting them to zero)
Definition: robot_state.cpp:331
moveit::core::RobotState::dirty_link_transforms_
const JointModel * dirty_link_transforms_
Definition: robot_state.h:1983
moveit::core::RobotState::printTransforms
void printTransforms(std::ostream &out=std::cout) const
Definition: robot_state.cpp:2336
ASSERT_ISOMETRY
#define ASSERT_ISOMETRY(transform)
moveit::core::RobotState::getRobotModel
const RobotModelConstPtr & getRobotModel() const
Get the robot model this state is constructed for.
Definition: robot_state.h:170
MOVEIT_CONSOLE_COLOR_RED
#define MOVEIT_CONSOLE_COLOR_RED
Definition: console_colors.h:41
moveit::core::RobotState::attachBody
void attachBody(std::unique_ptr< AttachedBody > attached_body)
Add an attached body to this state.
Definition: robot_state.cpp:1087
moveit::core::RobotState::getVariablePosition
double getVariablePosition(const std::string &variable) const
Get the position of a particular variable. An exception is thrown if the variable is not known.
Definition: robot_state.h:273
moveit::core::LinkModel::getAssociatedFixedTransforms
const LinkTransformMap & getAssociatedFixedTransforms() const
Get the set of links that are attached to this one via fixed transforms. The returned transforms are ...
Definition: link_model.h:198
moveit::core::RobotState::position_
double * position_
Definition: robot_state.h:1975
moveit::core::RobotState::setToDefaultValues
void setToDefaultValues()
Set all joints to their default positions. The default position is 0, or if that is not within bounds...
Definition: robot_state.cpp:434
console_colors.h
moveit::core::RobotState::setVariableEffort
void setVariableEffort(const double *effort)
Given an array with effort values for all variables, set those values as the effort in this state.
Definition: robot_state.h:511
cartesian_interpolator.h
moveit::core::RobotState::setToRandomPositionsNearBy
void setToRandomPositionsNearBy(const JointModelGroup *group, const RobotState &seed, double distance)
Set all joints in group to random values near the value in seed. distance is the maximum amount each ...
Definition: robot_state.cpp:405
moveit::core::RobotState::global_link_transforms_
Eigen::Isometry3d * global_link_transforms_
Transforms from model frame to link frame for each link.
Definition: robot_state.h:1990
moveit::core::RobotState::updateMimicJoints
void updateMimicJoints(const JointModelGroup *group)
Update all mimic joints within group.
Definition: robot_state.h:1946
moveit::core::RobotState::computeAABB
void computeAABB(std::vector< double > &aabb) const
Compute an axis-aligned bounding box that contains the current state. The format for aabb is (minx,...
Definition: robot_state.cpp:2168
setup.d
d
Definition: setup.py:8
moveit::core::RobotState::setJointEfforts
void setJointEfforts(const JointModel *joint, const double *effort)
Definition: robot_state.cpp:576
moveit::core::RobotState::allocMemory
void allocMemory()
Definition: robot_state.cpp:159
moveit::core::RobotState::rng_
random_numbers::RandomNumberGenerator * rng_
For certain operations a state needs a random number generator. However, it may be slightly expensive...
Definition: robot_state.h:2006
moveit::core::RobotState::getAttachedBodies
void getAttachedBodies(std::vector< const AttachedBody * > &attached_bodies) const
Get all bodies attached to the model corresponding to this state.
Definition: robot_state.cpp:1113
moveit::core::AttachedBodyCallback
boost::function< void(AttachedBody *body, bool attached)> AttachedBodyCallback
Definition: attached_body.h:115
moveit::core::RobotState::has_acceleration_
bool has_acceleration_
Definition: robot_state.h:1980
moveit::core::RobotState::setFromDiffIK
bool setFromDiffIK(const JointModelGroup *group, const Eigen::VectorXd &twist, const std::string &tip, double dt, const GroupStateValidityCallbackFn &constraint=GroupStateValidityCallbackFn())
Set the joint values from a Cartesian velocity applied during a time dt.
Definition: robot_state.cpp:1554
shapes::constructMarkerFromShape
bool constructMarkerFromShape(const Shape *shape, visualization_msgs::Marker &mk, bool use_mesh_triangle_list=false)
moveit::core::FixedTransformsMap
std::map< std::string, Eigen::Isometry3d, std::less< std::string >, Eigen::aligned_allocator< std::pair< const std::string, Eigen::Isometry3d > > > FixedTransformsMap
Map frame names to the transformation matrix that can transform objects from the frame name to the pl...
Definition: transforms.h:117
moveit::core::JointModel::getJointIndex
int getJointIndex() const
Get the index of this joint within the robot model.
Definition: joint_model.h:279
moveit::core::LOGNAME
const std::string LOGNAME
Definition: joint_model_group.cpp:165
moveit::core::AttachedBody::getAttachedLink
const LinkModel * getAttachedLink() const
Get the model of the link this body is attached to.
Definition: attached_body.h:162
moveit::core::RobotState::printStatePositionsWithJointLimits
void printStatePositionsWithJointLimits(const moveit::core::JointModelGroup *jmg, std::ostream &out=std::cout) const
Output to console the current state of the robot's joint limits.
Definition: robot_state.cpp:2210
moveit::core::LinkTransformMap
std::map< const LinkModel *, Eigen::Isometry3d, std::less< const LinkModel * >, Eigen::aligned_allocator< std::pair< const LinkModel *const, Eigen::Isometry3d > > > LinkTransformMap
Map from link model instances to Eigen transforms.
Definition: link_model.h:68
ros::WallTime
aabb.h
moveit::core::RobotState::global_collision_body_transforms_
Eigen::Isometry3d * global_collision_body_transforms_
Transforms from model frame to collision bodies.
Definition: robot_state.h:1991
moveit::core::RobotState::variable_joint_transforms_
Eigen::Isometry3d * variable_joint_transforms_
Local transforms of all joints.
Definition: robot_state.h:1989
moveit::core::RobotState::~RobotState
~RobotState()
Definition: robot_state.cpp:151
r
S r
pr2_arm_kinematics::NO_IK_SOLUTION
static const int NO_IK_SOLUTION
Definition: pr2_arm_kinematics_plugin.h:95
moveit::core::Transforms::sameFrame
static bool sameFrame(const std::string &frame1, const std::string &frame2)
Check if two frames end up being the same once the missing / are added as prefix (if they are missing...
Definition: transforms.cpp:122
moveit::core::RobotState::effort_
double * effort_
Definition: robot_state.h:1978
random_numbers::RandomNumberGenerator
point
std::chrono::system_clock::time_point point
moveit::core::RobotState::has_velocity_
bool has_velocity_
Definition: robot_state.h:1979
moveit::core::RobotState::updateLinkTransforms
void updateLinkTransforms()
Update the reference frame transforms for links. This call is needed before using the transforms of l...
Definition: robot_state.cpp:770
moveit::core::RobotState::integrateVariableVelocity
bool integrateVariableVelocity(const JointModelGroup *jmg, const Eigen::VectorXd &qdot, double dt, const GroupStateValidityCallbackFn &constraint=GroupStateValidityCallbackFn())
Given the velocities for the variables in this group (qdot) and an amount of time (dt),...
Definition: robot_state.cpp:1611
moveit::core::RobotState::getVariablePositions
double * getVariablePositions()
Get a raw pointer to the positions of the variables stored in this state. Use carefully....
Definition: robot_state.h:213
start
ROSCPP_DECL void start()
moveit::core::JointModelGroup::getDefaultIKTimeout
double getDefaultIKTimeout() const
Get the default IK timeout.
Definition: joint_model_group.h:622
moveit::core::RobotState::getFrameTransform
const Eigen::Isometry3d & getFrameTransform(const std::string &frame_id, bool *frame_found=nullptr)
Get the transformation matrix from the model frame (root of model) to the frame identified by frame_i...
Definition: robot_state.cpp:1191
moveit::core::JointModel::computeTransform
virtual void computeTransform(const double *joint_values, Eigen::Isometry3d &transf) const =0
Given the joint values for a joint, compute the corresponding transform. The computed transform is gu...
moveit::core::LinkModel::getLinkIndex
int getLinkIndex() const
The index of this joint when traversing the kinematic tree in depth first fashion.
Definition: link_model.h:86
moveit::core::RobotState::updateCollisionBodyTransforms
void updateCollisionBodyTransforms()
Update the transforms for the collision bodies. This call is needed before calling collision checking...
Definition: robot_state.cpp:742
moveit::core::RobotState::zeroEffort
void zeroEffort()
Set all effort values to 0.0.
Definition: robot_state.cpp:325
moveit::core::RobotState::zeroVelocities
void zeroVelocities()
Set all velocities to 0.0.
Definition: robot_state.cpp:313
moveit::core::RobotState::getJacobianColumnPartialDerivative
static Eigen::Matrix< double, 6, 1 > getJacobianColumnPartialDerivative(const Eigen::MatrixXd &jacobian, int column_index, int joint_index)
Compute the partial derivative of a column of the Jacobian wrt a single joint.
Definition: robot_state.cpp:1530
moveit::core::RobotState::checkLinkTransforms
bool checkLinkTransforms() const
This function is only called in debug mode.
Definition: robot_state.cpp:264
ros::Time
moveit
Main namespace for MoveIt.
Definition: background_processing.h:46
values
std::vector< double > values
kinematics::KinematicsQueryOptions
A set of options for the kinematics solver.
Definition: kinematics_base.h:109
moveit::core::JointModelGroup::getSolverInstance
const kinematics::KinematicsBaseConstPtr getSolverInstance() const
Definition: joint_model_group.h:602
moveit::core::RobotState::clearAttachedBody
bool clearAttachedBody(const std::string &id)
Remove the attached body named id. Return false if the object was not found (and thus not removed)....
Definition: robot_state.cpp:1177
moveit::core::RobotState::getJointPositions
const double * getJointPositions(const std::string &joint_name) const
Definition: robot_state.h:623
moveit::core::RobotState::dirty_joint_transforms_
unsigned char * dirty_joint_transforms_
Definition: robot_state.h:1992
moveit::core::RobotState::invertVelocity
void invertVelocity()
Invert velocity if present.
Definition: robot_state.cpp:567
moveit::core::RobotState::satisfiesBounds
bool satisfiesBounds(double margin=0.0) const
Definition: robot_state.cpp:921
moveit::core::AttachedBody::getAttachedLinkName
const std::string & getAttachedLinkName() const
Get the name of the link this body is attached to.
Definition: attached_body.h:156
moveit::core::RobotState::copyJointGroupVelocities
void copyJointGroupVelocities(const std::string &joint_group_name, std::vector< double > &gstate) const
For a given group, copy the velocity values of the variables that make up the group into another loca...
Definition: robot_state.h:857
moveit::core::RobotState::attached_body_update_callback_
AttachedBodyCallback attached_body_update_callback_
This event is called when there is a change in the attached bodies for this state; The event specifie...
Definition: robot_state.h:1999
moveit::core::AttachedBody::getShapes
const std::vector< shapes::ShapeConstPtr > & getShapes() const
Get the shapes that make up this attached body.
Definition: attached_body.h:168
moveit::core::RobotState::interpolate
void interpolate(const RobotState &to, double t, RobotState &state) const
Definition: robot_state.cpp:1044
moveit::core::RobotState::initTransforms
void initTransforms()
Definition: robot_state.cpp:189
ROS_WARN_NAMED
#define ROS_WARN_NAMED(name,...)
index
unsigned int index
moveit::core::RobotState::setJointGroupAccelerations
void setJointGroupAccelerations(const std::string &joint_group_name, const double *gstate)
Given accelerations for the variables that make up a group, in the order found in the group (includin...
Definition: robot_state.h:914
tf2::toMsg
B toMsg(const A &a)
moveit::core::RobotState::robot_model_
RobotModelConstPtr robot_model_
Definition: robot_state.h:1972
moveit::core::RobotState::setVariableAccelerations
void setVariableAccelerations(const double *acceleration)
Given an array with acceleration values for all variables, set those values as the accelerations in t...
Definition: robot_state.h:414
x
double x
shapes::computeShapeExtents
Eigen::Vector3d computeShapeExtents(const Shape *shape)
moveit::core::RevoluteJointModel
A revolute joint.
Definition: revolute_joint_model.h:110
moveit::core::JointModelGroup::getKinematicsSolverJointBijection
const std::vector< unsigned int > & getKinematicsSolverJointBijection() const
Return the mapping between the order of the joints in this group and the order of the joints in the k...
Definition: joint_model_group.h:634
moveit::core::RobotState::updateStateWithLinkAt
void updateStateWithLinkAt(const std::string &link_name, const Eigen::Isometry3d &transform, bool backward=false)
Update the state after setting a particular link to the input global transform pose.
Definition: robot_state.h:1396
moveit::core::RobotState::acceleration_
double * acceleration_
Definition: robot_state.h:1977
moveit::core::JointModelGroup::getVariableCount
unsigned int getVariableCount() const
Get the number of variables that describe this joint group. This includes variables necessary for mim...
Definition: joint_model_group.h:475
moveit::core::JointModel::FLOATING
@ FLOATING
Definition: joint_model.h:183
moveit::core::LinkModel::getName
const std::string & getName() const
The name of this link.
Definition: link_model.h:80
moveit::Exception
This may be thrown if unrecoverable errors occur.
Definition: exceptions.h:84
aabb
SaPCollisionManager< S >::SaPAABB * aabb
moveit::core::RobotState::setJointGroupPositions
void setJointGroupPositions(const std::string &joint_group_name, const double *gstate)
Given positions for the variables that make up a group, in the order found in the group (including va...
Definition: robot_state.h:671
moveit::core::RobotState::has_effort_
bool has_effort_
Definition: robot_state.h:1981
moveit::core::haveSameAttachedObjects
bool haveSameAttachedObjects(const RobotState &left, const RobotState &right, const std::string &logprefix="")
Definition: robot_state.cpp:2429
extents
std::array< S, 6 > & extents()
moveit::core::RobotState::printStateInfo
void printStateInfo(std::ostream &out=std::cout) const
Definition: robot_state.cpp:2275
checkIsometry
bool checkIsometry(const Eigen::Isometry3d &transform, const double precision=CHECK_ISOMETRY_PRECISION, const bool printError=true)
moveit::core::checkInterpolationParamBounds
static void checkInterpolationParamBounds(const char LOGNAME[], double t)
Definition: robot_model.h:132
moveit::core::JointModel::FIXED
@ FIXED
Definition: joint_model.h:184
moveit::core::RobotState::isValidVelocityMove
bool isValidVelocityMove(const RobotState &other, const JointModelGroup *group, double dt) const
Check that the time to move between two waypoints is sufficient given velocity limits and time step.
Definition: robot_state.cpp:1012
moveit::core::RobotState::markVelocity
void markVelocity()
Definition: robot_state.cpp:284
pr2_arm_kinematics::distance
double distance(const urdf::Pose &transform)
Definition: pr2_arm_ik.h:86
ros::Duration
z
double z
moveit::core::RobotState::enforceBounds
void enforceBounds()
Definition: robot_state.cpp:939
robot_state.h
t
geometry_msgs::TransformStamped t
moveit::core::RobotState::dropEffort
void dropEffort()
Remove effort values from this state (this differs from setting them to zero)
Definition: robot_state.cpp:341
moveit::core::JointModel
A joint from the robot. Models the transform that this joint applies in the kinematic chain....
Definition: joint_model.h:173
moveit::core::RobotState::updateMimicJoint
void updateMimicJoint(const JointModel *joint)
Definition: robot_state.h:1920
moveit::core::RobotState::dirtyCollisionBodyTransforms
bool dirtyCollisionBodyTransforms() const
Definition: robot_state.h:1515
moveit::core::RobotState::hasAttachedBody
bool hasAttachedBody(const std::string &id) const
Check if an attached body named id exists in this state.
Definition: robot_state.cpp:1070
moveit::core::RobotState::getJointVelocities
const double * getJointVelocities(const std::string &joint_name) const
Definition: robot_state.h:633
moveit::core::JointModelGroup::isContiguousWithinState
bool isContiguousWithinState() const
Definition: joint_model_group.h:523
moveit::core::LinkModel::getParentLinkModel
const LinkModel * getParentLinkModel() const
Get the link model whose child this link is (through some joint). There may not always be a parent li...
Definition: link_model.h:116
fcl::Vector3d
Vec3fX< details::Vec3Data< double > > Vector3d
Definition: fcl_compat.h:89
ros::Time::now
static Time now()
moveit::core::RobotState::dirty_collision_body_transforms_
const JointModel * dirty_collision_body_transforms_
Definition: robot_state.h:1984


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Sun Feb 9 2025 03:25:07