se2ez
robot.cpp
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
3 #include <se2ez/core/log.h>
4 #include <se2ez/core/math.h>
5 #include <se2ez/core/frame.h>
6 #include <se2ez/core/state.h>
7 #include <se2ez/core/collision.h>
8 
9 #include <se2ez/core/robot.h>
10 
11 using namespace se2ez;
12 
13 ///
14 /// FrameMap
15 ///
16 
17 FrameMap::FrameMap(const Robot & /*robot*/)
18 {
19  // TODO: Create map before hand
20 }
21 
22 FrameMap::FrameMap(const RobotPtr & /*robot*/)
23 {
24  // TODO: Create map before hand
25 }
26 
28 {
29  for (auto &frame : frames)
30  {
31  frame.second.dirty = true;
32  frame.second.jc = false;
33  }
34 }
35 
36 void FrameMap::insert(FrameMapPtr other)
37 {
38  for (const auto &frame : frames)
39  other->getEntry(frame.first) = frame.second;
40 }
41 
43 {
44  auto inserted = frames.emplace(frame_name, Value{});
45  return inserted.first->second;
46 }
47 
48 const FrameMap::Value &FrameMap::getEntryConst(const std::string &frame_name) const
49 {
50  const auto &result = frames.find(frame_name);
51  if (result == frames.end())
52  throw std::invalid_argument(log::format("Invalid frame name %1%!", frame_name));
53 
54  return result->second;
55 }
56 
58 {
59  return robot->printTree([&](const Robot::FrameDataPtr &frame) -> std::string {
60  try
61  {
62  const auto &entry = getEntryConst(frame->frame->getName());
63 
65  ss << (entry.dirty ? "D" : "C") << tf::printFrame(entry.pose) << "(";
66  for (const auto &tf : entry.geometry)
67  ss << tf::printFrame(tf);
68  ss << ")";
69 
70  return ss.str();
71  }
72  catch (...)
73  {
74  return "X[ 0, 0, 0 ] ()";
75  }
76  });
77 }
78 
79 ///
80 /// FrameData
81 ///
82 
83 Robot::FrameData::FrameData() : root(true), frame(Frame::getRoot())
84 {
85 }
86 
88 {
89 }
90 
91 Eigen::Ref<Eigen::VectorXd> Robot::FrameData::getValues(Eigen::Ref<Eigen::VectorXd> data) const
92 {
93  return data.segment(index, size);
94 }
95 
96 const Eigen::Ref<const Eigen::VectorXd>
97 Robot::FrameData::getValuesConst(const Eigen::Ref<const Eigen::VectorXd> &data) const
98 {
99  return data.segment(index, size);
100 }
101 
102 ///
103 /// Robot
104 ///
105 
106 Robot::Robot() : acm_(std::make_shared<ACM>())
107 {
108  clear();
109 }
110 
112 {
113  data_.clear();
114  ees_.clear();
115  tree_ = KDL::Tree();
116  data_.emplace("root", std::make_shared<FrameData>());
117  static_.reset();
118 }
119 
120 ///
121 /// Frame / Kinematic Tree Updating
122 ///
123 
124 void Robot::attachFrame(const FramePtr &frame)
125 {
126  attachFrame(frame, "root");
127 }
128 
129 void Robot::attachFrame(const FramePtr &frame, const FramePtr &parent)
130 {
131  attachFrame(frame, parent->getName());
132 }
133 void Robot::attachFrame(const FramePtr &frame, const std::string &parent_name)
134 {
135  if (frame->getName() == "root")
136  throw std::invalid_argument("Cannot add frame named root to tree!");
137 
138  if (!inTree(parent_name))
139  throw std::invalid_argument(log::format("Parent frame %1 not in tree!", parent_name));
140 
141  updateFrame(frame, parent_name);
142 }
143 
144 void Robot::detachFrame(const FramePtr &frame)
145 {
146  detachFrame(frame->getName());
147 }
148 
149 void Robot::detachFrame(const std::string &frame_name)
150 {
151  if (!inTree(frame_name))
152  {
153  SE2EZ_WARN("frame %1 not in tree!", frame_name);
154  return;
155  }
156 
157  auto data = data_[frame_name];
158 
159  if (data->movable)
160  {
161  SE2EZ_WARN("frame %1 is movable thus it cannot be removed", frame_name);
162  return;
163  }
164 
165  // removing all the children of this frame
166  for (const auto &child : data->children)
167  detachFrame(child->frame);
168 
169  removeChild(data->parent, frame_name);
170  data_.erase(frame_name);
171 }
172 
173 void Robot::addFixedRobot(const RobotPtr &frobot, const StatePtr &state, const std::string &scene_name)
174 {
175  for (const auto &fname : frobot->getFrameNames())
176  {
177  if (fname != "root")
178  {
179  // The new frame i namespaced based on the scene
180  auto nframe_name = scene_name + ":" + fname;
181  auto nframe = std::make_shared<Frame>(nframe_name, state->getPose(frobot, fname),
182  frobot->getFrame(fname)->getGeometry());
183  attachFrame(nframe, "root");
184  }
185  }
186 }
187 
188 void Robot::addActiveRobot(const RobotPtr &arobot)
189 {
190  for (const auto &fname : arobot->getFrameNames())
191  {
192  auto oframe = arobot->getFrame(fname);
193 
194  if (fname != "root")
195  {
196  auto nframe = std::make_shared<Frame>(fname, oframe->getTip(), oframe->getJoint().type,
197  oframe->getJoint().lower, oframe->getJoint().upper,
198  arobot->getFrame(fname)->getGeometry());
199 
200  auto parent = arobot->getFrameParent(fname);
201  attachFrame(nframe, parent->getName());
202  }
203  }
204 
205  // Copy the allowable collision matrix
206  setACM(arobot->getACM());
207  // Copy the named states
208  setNamedStates(arobot->getNamedStatesMap());
209 }
210 
211 void Robot::removeChild(FrameDataPtr parent, const std::string &child)
212 {
213  const auto &found =
214  std::find_if(parent->children.begin(), parent->children.end(),
215  [child](const FrameDataPtr &f) -> bool { return f->frame->getName() == child; });
216 
217  if (found == parent->children.end())
218  throw std::invalid_argument(
219  log::format("Child %1% not found in parent %2%", child, parent->frame->getName()));
220 
221  parent->children.erase(found);
222 }
223 
224 void Robot::updateFrame(const FramePtr &frame, const std::string &parent_name)
225 {
226  tree_update_ = true;
227 
228  const auto &frame_name = frame->getName();
229  const auto &new_parent = getFrameDataConst(parent_name);
230 
231  // Frame already existed, need to modify old parent
232  auto inserted = data_.emplace(frame->getName(), std::make_shared<FrameData>(frame, new_parent));
233  FrameDataPtr &data = inserted.first->second;
234 
235  // Emplacement failed due to element already existing
236  if (!inserted.second)
237  {
238  // Remove this frame from old parent's child list
239  const auto &old_parent = data->parent;
240  removeChild(old_parent, frame_name);
241 
242  // Possibly the frame has changed as well?
243  data->frame = frame;
244 
245  // Add this frame's new parent
246  data->parent = new_parent;
247  }
248 
249  // Update new parent's children
250  new_parent->children.emplace_back(data);
251 }
252 
254 {
255  // No work to do
256  if (!tree_update_)
257  return;
258 
259  tree_update_ = false;
260  tree_ = KDL::Tree();
261  names_.clear();
262  ees_.clear();
263  maxDepth_ = 0;
264 
265  const auto &root = getFrameData("root");
266  for (auto &child : root->children)
267  compileTreeRecursive("root", child);
268 
269  joints_.clear();
270  lower_ = Eigen::VectorXd(getNumJoints());
271  upper_ = Eigen::VectorXd(getNumJoints());
272 
273  for (const auto &name : getFrameNames())
274  {
275  const auto &frame = getFrameDataConst(name);
276  auto &joint = frame->frame->getJoint();
277  if (joint.type == Joint::FIXED)
278  continue;
279 
280  joints_.emplace_back(name, frame);
281 
282  const auto &bounds = joint.getBounds();
283  frame->getValues(lower_) = bounds.first;
284  frame->getValues(upper_) = bounds.second;
285  }
286 
287  std::sort(joints_.begin(), joints_.end(),
288  [](const auto &a, const auto &b) { return a.second->index < b.second->index; });
289 
290  jac_ = std::make_shared<KDL::TreeJntToJacSolver>(tree_);
291 
292  staticFK();
294 }
295 
296 void Robot::compileTreeRecursive(const std::string &previous, FrameDataPtr &data, bool movable)
297 {
298  const auto &frame = data->frame;
299  const auto &name = data->frame->getName();
300  auto &children = data->children;
301 
302  const std::string *parent = &previous;
303  const auto &segments = frame->getSegments();
304 
305  // Build up chain that represents frame
306  for (const auto &segment : segments)
307  {
308  tree_.addSegment(segment, *parent);
309  parent = &segment.getName();
310  }
311 
312  const bool isFixed = frame->getJoint().type == Joint::FIXED;
313  data->movable = !isFixed || movable;
314  data->depth = data->parent->depth + 1;
315  if (data->depth > maxDepth_)
316  maxDepth_ = data->depth;
317 
318  names_.emplace_back(name);
319 
320  // Continue tree compilation for children
321  for (auto &child : children)
322  compileTreeRecursive(name, child, data->movable);
323 
324  // Add information about configuration index
325  data->index = GetTreeElementQNr(tree_.getSegment(segments[0].getName())->second);
326  data->size = segments.size() - 1;
327 
328  // If there are no children then we are an end-effector (leaf)!
329  if (children.empty() && data->movable)
330  ees_.emplace_back(name);
331 }
332 
334 {
335  auto map = std::make_shared<FrameMap>(*this);
336  auto state = std::make_shared<State>(*this);
337  for (const auto &data : data_)
338  {
339  const auto &frame = data.second;
340  if (!frame->movable)
341  getPose(frame, state->data, map);
342  }
343 
344  static_ = map;
345 }
346 
348 {
350 
351  for (const auto &joint : this->getJoints())
352  {
353  const auto &jointName = joint.first;
354  const auto &jointType = Joint::typeToString(joint.second->frame->getJoint().type);
355  ss << jointName << "_" << jointType << "_";
356  }
357 
358  signature_ = ss.str();
359 }
360 
361 ///
362 /// Getters and Setters
363 ///
364 
365 unsigned int Robot::getNumJoints() const
366 {
367  return tree_.getNrOfJoints();
368 }
369 
371 {
372  return ees_;
373 }
374 
376 {
377  return names_;
378 }
379 
381 {
382  return getFrameData(name)->frame;
383 }
384 
386 {
387  if (getFrameData(name)->root)
388  SE2EZ_ERROR("Root does not have a parent");
389 
390  return getFrameData(name)->parent->frame;
391 }
392 
393 const FramePtr &Robot::getFrameConst(const std::string &name) const
394 {
395  return getFrameDataConst(name)->frame;
396 }
397 
398 bool Robot::inTree(const std::string &name) const
399 {
400  return data_.count(name) > 0;
401 }
402 
404 {
405  const auto &data = data_.find(frame_name);
406  if (data != data_.end())
407  return data->second;
408 
409  throw std::invalid_argument(log::format("Frame %1% does not exist!", frame_name));
410 }
411 
413 {
414  const auto &data = data_.find(frame_name);
415  if (data != data_.end())
416  return data->second;
417 
418  throw std::invalid_argument(log::format("Frame %1% does not exist!", frame_name));
419 }
420 
422 {
423  return signature_;
424 }
425 
426 void Robot::setNamedState(const std::string &name, const StatePtr &state)
427 {
428  auto entry = named_.find(name);
429  if (entry != named_.end())
430  entry->second->copy(state);
431 
432  else
433  {
434  entry = named_.emplace(name, std::make_shared<State>(*this)).first;
435  entry->second->copy(state);
436  }
437 }
438 
439 void Robot::getNamedState(const std::string &name, StatePtr state)
440 {
441  const auto &entry = named_.find(name);
442  if (entry == named_.end())
443  throw std::invalid_argument(log::format("Named state %1% does not exist!", name));
444 
445  state->copy(entry->second);
446 }
447 
449 {
451  for (const auto &named : named_)
452  names.emplace_back(named.first);
453 
454  return names;
455 }
456 
458 {
459  return named_;
460 }
461 
463 {
464  for (const auto &e : named)
465  setNamedState(e.first, e.second);
466 }
467 
469 {
470  return acm_;
471 }
472 
473 void Robot::setACM(const ACMPtr &acm)
474 {
475  acm_ = acm;
476 }
477 
478 const Eigen::VectorXd Robot::getUpperLimits() const
479 {
480  return upper_;
481 }
482 
483 const Eigen::VectorXd Robot::getLowerLimits() const
484 {
485  return lower_;
486 }
487 
489 {
490  std::vector<bool> conts;
491  for (const auto &joint : joints_)
492  {
493  const auto &j = joint.second->frame->getJoint();
494  if (j.continuous)
495  {
496  for (unsigned int i = 0; i < j.n - 1; ++i)
497  conts.emplace_back(false);
498  conts.emplace_back(true);
499  }
500  else
501  for (unsigned int i = 0; i < j.n; ++i)
502  conts.emplace_back(false);
503  }
504 
505  return conts;
506 }
507 
509 {
510  return joints_;
511 }
512 
513 const KDL::Tree &Robot::getTree() const
514 {
515  return tree_;
516 }
517 
518 ///
519 /// Pose / Configuration Management
520 ///
521 
522 Eigen::Ref<Eigen::VectorXd> Robot::getFrameValues(const std::string &frame_name,
523  Eigen::Ref<Eigen::VectorXd> q) const
524 {
525  return getFrameDataConst(frame_name)->getValues(q);
526 }
527 
528 const Eigen::Ref<const Eigen::VectorXd>
529 Robot::getFrameValuesConst(const std::string &frame_name, const Eigen::Ref<const Eigen::VectorXd> &q) const
530 {
531  return getFrameDataConst(frame_name)->getValuesConst(q);
532 }
533 
534 void Robot::fk(const Eigen::Ref<const Eigen::VectorXd> &q, FrameMapPtr frames) const
535 {
536  for (const auto &ee : ees_)
537  getPose(ee, q, frames);
538 
539  static_->insert(frames);
540 }
541 
542 const FrameMap::Value &Robot::getPose(const std::string &frame_name,
543  const Eigen::Ref<const Eigen::VectorXd> &q, FrameMapPtr frames) const
544 {
545  const auto &entry = getPose(getFrameDataConst(frame_name), q, frames);
546  return entry;
547 }
548 
549 const FrameMap::Value &Robot::getPose(const FrameDataPtr &data, const Eigen::Ref<const Eigen::VectorXd> &q,
550  FrameMapPtr frames) const
551 {
552  const auto &name = data->frame->getName();
553  auto &entry = frames->getEntry(name);
554  if (!entry.dirty)
555  return entry;
556 
557  if (!data->movable && static_)
558  {
559  entry = static_->getEntry(name);
560  return entry;
561  }
562 
563  const auto &values = data->getValuesConst(q);
564  const auto &local = data->frame->getPose(values);
565  const auto &parent = (data->root) ? FrameMap::Value() : getPose(data->parent, q, frames);
566 
567  entry.dirty = false;
568  entry.pose = parent.pose * local;
569  data->frame->getGeometryPoses(entry.pose, entry.geometry);
570 
571  return entry;
572 }
573 
575  const Eigen::Ref<const Eigen::VectorXd> &q,
576  FrameMapPtr frames) const
577 {
578  auto &entry = frames->getEntry(frame_name);
579  if (entry.jc)
580  return entry;
581 
582  KDL::JntArray in(tf::EigenToKDLVec(q));
583  KDL::Jacobian j(q.size());
584  jac_->JntToJac(in, j, frame_name);
585 
586  entry.jc = true;
587 
588  entry.jacobian = Eigen::MatrixXd(3, q.size());
589  entry.jacobian.row(0) = j.data.row(0);
590  entry.jacobian.row(1) = j.data.row(1);
591  entry.jacobian.row(2) = j.data.row(5);
592 
593  return entry;
594 }
595 
596 double Robot::distance(const StatePtr &a, const StatePtr &b, bool weighted) const
597 {
598  double d = 0;
599 
600  const double n = maxDepth_ + 1.;
601  for (const auto &pair : joints_)
602  {
603  const auto &frame = pair.second;
604  const auto &joint = frame->frame->getJoint();
605 
606  const double m = frame->depth;
607  const double weight = (weighted) ? (n - m) / n : 1.;
608 
609  d += weight * joint.distance(frame->getValuesConst(a->data), frame->getValuesConst(b->data));
610  }
611 
612  return d;
613 }
614 
616 {
617  for (const auto &pair : joints_)
618  {
619  const auto &frame = pair.second;
620  const auto &joint = frame->frame->getJoint();
621 
622  joint.enforceBounds(frame->getValues(a->data));
623  }
624 
625  a->dirty = true;
626 }
627 
628 bool Robot::inLimits(const StatePtr &a) const
629 {
630  for (const auto &pair : joints_)
631  {
632  const auto &frame = pair.second;
633  const auto &joint = frame->frame->getJoint();
634 
635  if (!joint.inBounds(frame->getValues(a->data)))
636  return false;
637  }
638 
639  return true;
640 }
641 
642 void Robot::interpolate(const StatePtr &from, const StatePtr &to, double t, StatePtr state) const
643 {
644  for (const auto &pair : joints_)
645  {
646  const auto &frame = pair.second;
647  const auto &joint = frame->frame->getJoint();
648 
649  joint.interpolate(frame->getValuesConst(from->data), frame->getValuesConst(to->data), t,
650  frame->getValues(state->data));
651  }
652 
653  state->dirty = true;
654 }
655 
656 ///
657 /// Informative
658 ///
659 
661 {
663  printTreeRecursive(ss, getFrameDataConst("root"), [&](const Robot::FrameDataPtr &frame) -> std::string {
665 
666  ss << frame->frame->printDebug();
667 
668  for (unsigned int i = 0; i < frame->children.size(); ++i)
669  ss << ((i > 0) ? ", " : " C[") << frame->children[i]->frame->getName();
670 
671  if (frame->parent)
672  ss << log::format("] P[%1%]", frame->parent->frame->getName());
673  else
674  ss << "]";
675 
676  if (frame->frame->getJoint().type != Joint::FIXED)
677  ss << log::format(" [%1%/%2%]", frame->index, frame->size);
678 
679  ss << log::format(" D:%1% M:%2%", frame->depth, frame->movable);
680 
681  return ss.str();
682  });
683 
684  return ss.str();
685 }
686 
688 {
690  printTreeRecursive(ss, getFrameDataConst("root"), function);
691  return ss.str();
692 }
693 
694 void Robot::printTreeRecursive(std::stringstream &ss, const FrameDataPtr &frame, const PrintHelper &function,
695  const std::string &prefix) const
696 {
697  ss << prefix << "\\_ " << frame->frame->getName();
698 
699  if (function)
700  ss << " (" << function(frame) << ")";
701 
702  ss << std::endl;
703 
704  for (unsigned int i = 0; i < frame->children.size(); ++i)
705  printTreeRecursive(ss, frame->children[i], function,
706  prefix + ((i == frame->children.size() - 1) ? " " : "|"));
707 }
const FramePtr & getFrameConst(const std::string &name) const
Get the frame with name name.
Definition: robot.cpp:393
bool inLimits(const StatePtr &a) const
Check if all configuration parameters are within limits.
Definition: robot.cpp:628
Eigen::VectorXd upper_
Upper limits of joints.
Definition: robot.h:564
void detachFrame(const FramePtr &frame)
Detach a frame from a kinematic tree. If frame has children all children will be detached as well...
Definition: robot.cpp:144
const Eigen::VectorXd getUpperLimits() const
Get the upper limits of the joints for this robot.
Definition: robot.cpp:478
A shared pointer wrapper for se2ez::State.
unsigned int size
Number of joint values for this frame.
Definition: robot.h:187
const FrameDataPtr & getFrameDataConst(const std::string &frame_name) const
Retrieves kinematic tree data associated with the frame frame_name.
Definition: robot.cpp:412
tf::EigenHash< std::string, Value > frames
Map of frame name to dirty / transform pairs.
Definition: robot.h:114
double distance(const StatePtr &a, const StatePtr &b, bool weighted=true) const
Compute the distance between two states.
Definition: robot.cpp:596
const Eigen::VectorXd getLowerLimits() const
Get the lower limits of the joints for this robot.
Definition: robot.cpp:483
A shared pointer wrapper for se2ez::Robot::FrameData.
FrameMapPtr static_
Transforms for all non-movable links.
Definition: robot.h:576
static const std::string & typeToString(const Type &type)
Converts a joint type into its string representation.
Definition: joint.cpp:23
std::string printFrame(const Eigen::Isometry2d &frame)
Returns a string "[x, y, t]" of the translation (x, y) and rotation (t) component of a transform...
Definition: math.cpp:79
void interpolate(const StatePtr &from, const StatePtr &to, double t, StatePtr state) const
Interpolate between two states.
Definition: robot.cpp:642
FrameDataPtr getFrameData(const std::string &frame_name)
Retrieves kinematic tree data associated with the frame frame_name.
Definition: robot.cpp:403
const std::vector< bool > getContinuity() const
Returns a vector of booleans. If an entry is true, that index is a continuous joint.
Definition: robot.cpp:488
void generateSignature()
Creates a unique signature (based on active joints).
Definition: robot.cpp:347
std::vector< std::string > getNamedStates() const
Gets the names of all named states.
Definition: robot.cpp:448
T endl(T... args)
void removeChild(FrameDataPtr parent, const std::string &child)
Removes child from the parent in the tree.
Definition: robot.cpp:211
An allowed collision map / matrix for the robot. Stores what frames are allowed to collide with each ...
Definition: collision.h:38
FrameMap(const Robot &robot)
Constructor.
Definition: robot.cpp:17
void fk(const Eigen::Ref< const Eigen::VectorXd > &q, FrameMapPtr frames) const
Compute the forward kinematics of the robot at a state q.
Definition: robot.cpp:534
void insert(FrameMapPtr other)
Inserts all entries in this frame map into another frame map.
Definition: robot.cpp:36
FrameData()
Constructor for the root element.
Definition: robot.cpp:83
std::string printDebug() const
Returns a string of complete robot information for debugging purposes.
Definition: robot.cpp:660
unsigned int maxDepth_
Maximum tree depth.
Definition: robot.h:566
FramePtr getFrame(const std::string &name)
Get the frame with name name.
Definition: robot.cpp:380
void compileTree()
Compiles the underlying kinematic tree representation after a call to attachFrame().
Definition: robot.cpp:253
const FrameMap::Value & getJacobian(const std::string &frame_name, const Eigen::Ref< const Eigen::VectorXd > &q, FrameMapPtr frames) const
Gets the jacobian for frame_name at configuration q.
Definition: robot.cpp:574
Fixed joint, just a rigid transformation.
Definition: joint.h:40
void staticFK()
Compute the transform for all non-movable frames.
Definition: robot.cpp:333
A shared pointer wrapper for se2ez::Frame.
void addFixedRobot(const RobotPtr &frobot, const StatePtr &state, const std::string &scene_name)
add a fixed Robot(frames with all joints fixed) on the current robot. The frame names are namespaced ...
Definition: robot.cpp:173
A representation of a robot (in this case, a kinematic tree in the plane).
Definition: robot.h:119
void printTreeRecursive(std::stringstream &ss, const FrameDataPtr &frame, const PrintHelper &function, const std::string &prefix="") const
Helper function to printTree() that recursively traverses the kinematic tree.
Definition: robot.cpp:694
void getNamedState(const std::string &name, StatePtr state)
Gets a named state.
Definition: robot.cpp:439
ACMPtr getACM()
Gets the robot&#39;s default ACM.
Definition: robot.cpp:468
FramePtr getFrameParent(const std::string &name)
Get the parent of frame with name name. Throws Error if name is root.
Definition: robot.cpp:385
const Eigen::Ref< const Eigen::VectorXd > getFrameValuesConst(const std::string &frame_name, const Eigen::Ref< const Eigen::VectorXd > &q) const
Returns a reference to the underlying subvector of the configuration associated with a specific frame...
Definition: robot.cpp:529
KDL::Tree tree_
Underlying tree representation.
Definition: robot.h:568
const KDL::Tree & getTree() const
Get the underlying KDL tree for this robot.
Definition: robot.cpp:513
const std::map< std::string, StatePtr > & getNamedStatesMap()
Gets the names of all named states.
Definition: robot.cpp:457
void setACM(const ACMPtr &acm)
Sets the robot&#39;s default ACM.
Definition: robot.cpp:473
const std::vector< std::string > & getEEs() const
Gets the names of end-effectors of the tree (leaf nodes).
Definition: robot.cpp:370
const std::vector< std::string > & getFrameNames() const
Get a vector of all the frame names within this robot.
Definition: robot.cpp:375
std::string signature_
A string that represents the current kinematic chain.
Definition: robot.h:573
#define SE2EZ_WARN(fmt,...)
Definition: log.h:41
void dirty()
Dirties all frames within the frame map.
Definition: robot.cpp:27
std::vector< std::string > ees_
End-effectors (leaves) in the kinematic tree that are mobile.
Definition: robot.h:560
void compileTreeRecursive(const std::string &previous, FrameDataPtr &data, bool movable=false)
Helper function to compileTree() that recursively build tree representation.
Definition: robot.cpp:296
T str(T... args)
unsigned int index
Index within tree&#39;s configuration for the frame&#39;s joint values.
Definition: robot.h:186
Eigen::Ref< Eigen::VectorXd > getValues(Eigen::Ref< Eigen::VectorXd > data) const
Returns a reference to the underlying subvector of the configuration associated with this frame...
Definition: robot.cpp:91
A tuple that stores whether a transform is dirty (needs to be updated), the transform itself...
Definition: robot.h:47
const Value & getEntryConst(const std::string &frame_name) const
Gets the entry in the frame map associated with frame_name. Throws error if it does not already exist...
Definition: robot.cpp:48
T clear(T... args)
void setNamedState(const std::string &name, const StatePtr &state)
Sets a named state.
Definition: robot.cpp:426
std::string printFrames(const RobotPtr &robot) const
Prints out all current frame pose information. Attaches "_[ x, y, t ]" to the Robot::printTree(), where &#39;_&#39; is &#39;C&#39; for clean, &#39;D&#39; for dirty, and &#39;X&#39; for uninitialized. "[ x, y, t ]" is the transform of the frame.
Definition: robot.cpp:57
const FrameMap::Value & getPose(const std::string &frame_name, const Eigen::Ref< const Eigen::VectorXd > &q, FrameMapPtr frames) const
Gets the pose of a frame frame_name at a configuration q. Also updates all dependent frames in frames...
Definition: robot.cpp:542
std::map< std::string, StatePtr > named_
Named states.
Definition: robot.h:572
Eigen::VectorXd lower_
Lower limits of joints.
Definition: robot.h:565
A shared pointer wrapper for se2ez::ACM.
void addActiveRobot(const RobotPtr &arobot)
adds an active Robot with all its frames and corresponding joints.
Definition: robot.cpp:188
Representation of a single frame (possibly with a joint) in a kinematic tree.
Definition: frame.h:36
T find_if(T... args)
FrameDataPtr parent
Parent of this frame.
Definition: robot.h:183
Robot()
Constructor. Nothing interesting right now.
Definition: robot.cpp:106
Eigen::Ref< Eigen::VectorXd > getFrameValues(const std::string &frame_name, Eigen::Ref< Eigen::VectorXd > q) const
Returns a reference to the underlying subvector of the configuration associated with a specific frame...
Definition: robot.cpp:522
FramePtr frame
Underlying frame.
Definition: robot.h:181
const Eigen::Ref< const Eigen::VectorXd > getValuesConst(const Eigen::Ref< const Eigen::VectorXd > &data) const
Returns a reference to the underlying subvector of the configuration associated with this frame...
Definition: robot.cpp:97
KDL::JntArray EigenToKDLVec(const Eigen::VectorXd &vec)
Converts an Eigen vector into a KDL vector.
Definition: math.cpp:66
A shared pointer wrapper for se2ez::Robot.
std::string format(const std::string &fmt, Args &&... args)
Definition: log.h:25
bool inTree(const std::string &name) const
Checks if a frame name is in the tree.
Definition: robot.cpp:398
std::vector< std::string > names_
Names of the the kinematic tree frames (ordered).
Definition: robot.h:561
const std::vector< std::pair< std::string, FrameDataPtr > > & getJoints() const
Get the ordered list of active joints in this robot with their associated frame information.
Definition: robot.cpp:508
std::string printTree(const PrintHelper &function={}) const
Returns a string that graphically shows the kinematic structure of the tree. For example: ...
Definition: robot.cpp:687
Value & getEntry(const std::string &frame_name)
Gets the entry in the frame map associated with frame_name. Creates the entry if one does not already...
Definition: robot.cpp:42
void updateFrame(const FramePtr &frame, const std::string &parent_name)
Updates a frame&#39;s entry in the kinematic tree with a possibly new parent parent_name.
Definition: robot.cpp:224
Main namespace.
Definition: collision.h:11
ACMPtr acm_
Default robot ACM.
Definition: robot.h:575
void attachFrame(const FramePtr &frame)
Attach a frame to the root of the kinematic tree. Will detach frame if attached elsewhere already...
Definition: robot.cpp:124
std::map< std::string, FrameDataPtr > data_
Kinematic tree data for all frames.
Definition: robot.h:559
void setNamedStates(const std::map< std::string, StatePtr > &named)
Sets a named state.
Definition: robot.cpp:462
#define SE2EZ_ERROR(fmt,...)
Definition: log.h:39
T sort(T... args)
std::vector< std::pair< std::string, FrameDataPtr > > joints_
Ordered vector of active joints.
Definition: robot.h:563
const std::string & getSignature()
Returns the signature of the robot.
Definition: robot.cpp:421
bool tree_update_
Does the tree need recompiling?
Definition: robot.h:570
std::shared_ptr< KDL::TreeJntToJacSolver > jac_
Underlying tree representation.
Definition: robot.h:569
unsigned int getNumJoints() const
Gets the number of controllable joints within the tree.
Definition: robot.cpp:365
void clear()
Completely clears internal structures, a brand new robot!
Definition: robot.cpp:111
void enforceLimits(StatePtr a) const
Enforce joint limits on a robot and renormalize angles if necessary.
Definition: robot.cpp:615
T emplace_back(T... args)