Robowflex  v0.1
Making MoveIt Easy
robowflex::darts::Structure Class Reference

Wrapper class for a dart::dynamics::Skeleton. More...

#include <structure.h>

+ Inheritance diagram for robowflex::darts::Structure:

Public Member Functions

Constructors
 Structure (const std::string &name)
 Create an empty structure. More...
 
 Structure (const std::string &name, const SceneConstPtr &scene)
 Copy a MoveIt (robowflex::Scene) into a structure. More...
 
virtual ~Structure ()=default
 Destructor. More...
 
StructurePtr cloneStructure (const std::string &newName) const
 Clones this structure with a new name. More...
 
Getters and Setters
const std::string & getName () const
 Get the name of this structure. More...
 
ACMPtr getACM ()
 Get the ACM for the structure. More...
 
const ACMPtr & getACMConst () const
 Get the ACM for the structure. More...
 
void setSkeleton (const dart::dynamics::SkeletonPtr &skeleton)
 Set the skeleton for the structure. More...
 
dart::dynamics::SkeletonPtr & getSkeleton ()
 Get the underlying skeleton for the structure. More...
 
const dart::dynamics::SkeletonPtr & getSkeletonConst () const
 Get the underlying skeleton for the structure. More...
 
void dumpGraphViz (std::ostream &out, bool standalone=true)
 Dumps the structure of the skeleton to a GraphViz file. More...
 
Getting and Setting Configurations
void setJoint (const std::string &name, double value)
 Set the value of a 1-DoF joint in the structure. More...
 
void setJoint (const std::string &name, const Eigen::Ref< const Eigen::VectorXd > &value)
 Set the value of a n-DoF joint in the structure. More...
 
bool solveIK ()
 Solve the current whole-body IK problem imposed on the structure. More...
 
void setDof (unsigned int index, double value)
 Set the DoF at index to value. More...
 
Modifying Frames
std::vector< std::string > getJointNames () const
 Get the joint names for this structure. More...
 
dart::dynamics::Joint * getJoint (const std::string &joint_name) const
 Get a reference to the joint in the structure. More...
 
dart::dynamics::BodyNode * getFrame (const std::string &name="") const
 Get a body node within the structure. More...
 
dart::dynamics::BodyNode * getRootFrame () const
 Get the root frame of this structure. More...
 
void reparentFreeFrame (dart::dynamics::BodyNode *child, const std::string &parent="")
 Reparents the child node to the parent node. More...
 
void setJointParentTransform (const std::string &name, const RobotPose &tf)
 Set the transform from a joint to its parent. More...
 
void updateCollisionObject (const std::string &name, const GeometryPtr &geometry, const robowflex::RobotPose &pose)
 Update or add a collision object. More...
 
Constructing Frames
std::pair< dart::dynamics::RevoluteJoint *, dart::dynamics::BodyNode * > addRevoluteFrame (const dart::dynamics::RevoluteJoint::Properties &properties, const dart::dynamics::ShapePtr &shape, dart::dynamics::BodyNode *parent=nullptr)
 Add a new frame attached to a revolute joint to this structure. More...
 
std::pair< dart::dynamics::PrismaticJoint *, dart::dynamics::BodyNode * > addPrismaticFrame (const dart::dynamics::PrismaticJoint::Properties &properties, const dart::dynamics::ShapePtr &shape, dart::dynamics::BodyNode *parent=nullptr)
 Add a new frame attached to a prismatic joint to this structure. More...
 
std::pair< dart::dynamics::FreeJoint *, dart::dynamics::BodyNode * > addFreeFrame (const dart::dynamics::FreeJoint::Properties &properties, const dart::dynamics::ShapePtr &shape, dart::dynamics::BodyNode *parent=nullptr)
 Add a new frame attached to a free joint to this structure. More...
 
std::pair< dart::dynamics::WeldJoint *, dart::dynamics::BodyNode * > addWeldedFrame (const dart::dynamics::WeldJoint::Properties &properties, const dart::dynamics::ShapePtr &shape, dart::dynamics::BodyNode *parent=nullptr)
 Add a new frame attached to a fixed joint to this structure. More...
 
void addGround (double z=0., double radius=10.)
 Add a ground plane. More...
 

Protected Member Functions

void createShapeNode (dart::dynamics::BodyNode *body, const dart::dynamics::ShapePtr &shape)
 Create a shape node on a body. More...
 

Protected Attributes

const std::string name_ {"robot"}
 Name of the structure. More...
 
dart::dynamics::SkeletonPtr skeleton_ {nullptr}
 Underlying skeleton. More...
 
ACMPtr acm_
 ACM for structure. More...
 

Detailed Description

Wrapper class for a dart::dynamics::Skeleton.

Definition at line 52 of file structure.h.

Constructor & Destructor Documentation

◆ Structure() [1/2]

Structure::Structure ( const std::string &  name)

Create an empty structure.

Parameters
[in]nameName of the structure.

Structure

Definition at line 26 of file structure.cpp.

27  : name_(name), skeleton_(dart::dynamics::Skeleton::create(name_)), acm_(std::make_shared<ACM>(this))
28 {
29  skeleton_->setSelfCollisionCheck(true);
30 }
ACMPtr acm_
ACM for structure.
Definition: structure.h:262
dart::dynamics::SkeletonPtr skeleton_
Underlying skeleton.
Definition: structure.h:261
const std::string name_
Name of the structure.
Definition: structure.h:260

◆ Structure() [2/2]

Structure::Structure ( const std::string &  name,
const SceneConstPtr &  scene 
)

Copy a MoveIt (robowflex::Scene) into a structure.

Parameters
[in]nameName of the structure.
[in]sceneScene to copy.

Definition at line 32 of file structure.cpp.

32  : Structure(name)
33 {
34  dart::dynamics::WeldJoint::Properties properties;
35  dart::dynamics::BodyNode::Properties node;
36 
37  node.mName = properties.mName = "root";
38  properties.mT_ParentBodyToJoint = robowflex::TF::identity();
39  const auto &pair =
40  skeleton_->createJointAndBodyNodePair<dart::dynamics::WeldJoint>(nullptr, properties, node);
41  const auto &root = pair.second;
42 
43  const auto &objects = scene->getCollisionObjects();
44  for (const auto &object : objects)
45  {
46  const auto &geometry = scene->getObjectGeometry(object);
47  const auto &pose = scene->getObjectPose(object);
48 
49  dart::dynamics::FreeJoint::Properties joint;
50  joint.mName = object;
51  joint.mT_ParentBodyToJoint = robowflex::TF::identity();
52 
53  auto shape = makeGeometry(geometry);
54 
55  auto pair = addFreeFrame(joint, shape, root);
56  setJointParentTransform(object, pose);
57  setColor(pair.second, dart::Color::Blue(0.2));
58  }
59 
60  const auto &acm = scene->getACMConst();
62  acm.getAllEntryNames(names);
63 
65  for (const auto &name1 : names)
66  for (const auto &name2 : names)
67  if (acm.getEntry(name1, name2, type))
68  {
70  acm_->enableCollision(name1, name2);
72  acm_->disableCollision(name1, name2);
73  }
74 }
void setJointParentTransform(const std::string &name, const RobotPose &tf)
Set the transform from a joint to its parent.
Definition: structure.cpp:314
Structure(const std::string &name)
Create an empty structure.
Definition: structure.cpp:26
std::pair< dart::dynamics::FreeJoint *, dart::dynamics::BodyNode * > addFreeFrame(const dart::dynamics::FreeJoint::Properties &properties, const dart::dynamics::ShapePtr &shape, dart::dynamics::BodyNode *parent=nullptr)
Add a new frame attached to a free joint to this structure.
Definition: structure.cpp:212
RobotPose identity()
Creates the Identity pose.
Definition: tf.cpp:9
void setColor(dart::dynamics::BodyNode *node, const Eigen::Vector4d &color)
Sets the color of the shapes on a body node.
Definition: structure.cpp:550
dart::dynamics::ShapePtr makeGeometry(const GeometryPtr &geometry)
Convert a robowflex::Geometry to a Dart Shape.
Definition: structure.cpp:348
Functions for loading and animating scenes in Blender.

◆ ~Structure()

virtual robowflex::darts::Structure::~Structure ( )
virtualdefault

Destructor.

Member Function Documentation

◆ addFreeFrame()

std::pair< dart::dynamics::FreeJoint *, dart::dynamics::BodyNode * > Structure::addFreeFrame ( const dart::dynamics::FreeJoint::Properties &  properties,
const dart::dynamics::ShapePtr &  shape,
dart::dynamics::BodyNode *  parent = nullptr 
)

Add a new frame attached to a free joint to this structure.

Parameters
[in]propertiesJoint properties to use for joint.
[in]shapeShape to attach to frame.
[in]parentParent frame to attach new joint to.
Returns
The created joint and body node.

Definition at line 212 of file structure.cpp.

215 {
216  dart::dynamics::BodyNode::Properties node;
217  node.mName = properties.mName;
218 
219  auto pair = skeleton_->createJointAndBodyNodePair<dart::dynamics::FreeJoint>(parent, properties, node);
220  createShapeNode(pair.second, shape);
221 
222  pair.first->setPositionLimitEnforced(true);
223  return pair;
224 }
void createShapeNode(dart::dynamics::BodyNode *body, const dart::dynamics::ShapePtr &shape)
Create a shape node on a body.
Definition: structure.cpp:150

◆ addGround()

void Structure::addGround ( double  z = 0.,
double  radius = 10. 
)

Add a ground plane.

Parameters
[in]zZ- height of the plane.
[in]radiusX- and Y- width of the plane.

Definition at line 240 of file structure.cpp.

241 {
242  const double thickness = 0.01;
243 
244  dart::dynamics::WeldJoint::Properties joint;
245  joint.mName = "ground";
246  joint.mT_ParentBodyToJoint.translation() = Eigen::Vector3d(0, 0, z - thickness);
247 
248  auto ground = makeBox(radius, radius, thickness);
249  auto pair = addWeldedFrame(joint, ground);
250 
251  setColor(pair.second, dart::Color::Blue(0.2));
252 }
std::pair< dart::dynamics::WeldJoint *, dart::dynamics::BodyNode * > addWeldedFrame(const dart::dynamics::WeldJoint::Properties &properties, const dart::dynamics::ShapePtr &shape, dart::dynamics::BodyNode *parent=nullptr)
Add a new frame attached to a fixed joint to this structure.
Definition: structure.cpp:227
std::shared_ptr< dart::dynamics::BoxShape > makeBox(const Eigen::Ref< const Eigen::Vector3d > &v)
Create a box.
Definition: structure.cpp:370

◆ addPrismaticFrame()

std::pair< dart::dynamics::PrismaticJoint *, dart::dynamics::BodyNode * > Structure::addPrismaticFrame ( const dart::dynamics::PrismaticJoint::Properties &  properties,
const dart::dynamics::ShapePtr &  shape,
dart::dynamics::BodyNode *  parent = nullptr 
)

Add a new frame attached to a prismatic joint to this structure.

Parameters
[in]propertiesJoint properties to use for joint.
[in]shapeShape to attach to frame.
[in]parentParent frame to attach new joint to.
Returns
The created joint and body node.

Definition at line 196 of file structure.cpp.

199 {
200  dart::dynamics::BodyNode::Properties node;
201  node.mName = properties.mName;
202 
203  auto pair =
204  skeleton_->createJointAndBodyNodePair<dart::dynamics::PrismaticJoint>(parent, properties, node);
205  createShapeNode(pair.second, shape);
206 
207  pair.first->setPositionLimitEnforced(true);
208  return pair;
209 }

◆ addRevoluteFrame()

std::pair< dart::dynamics::RevoluteJoint *, dart::dynamics::BodyNode * > Structure::addRevoluteFrame ( const dart::dynamics::RevoluteJoint::Properties &  properties,
const dart::dynamics::ShapePtr &  shape,
dart::dynamics::BodyNode *  parent = nullptr 
)

Add a new frame attached to a revolute joint to this structure.

Parameters
[in]propertiesJoint properties to use for joint.
[in]shapeShape to attach to frame.
[in]parentParent frame to attach new joint to.
Returns
The created joint and body node.

Definition at line 180 of file structure.cpp.

183 {
184  dart::dynamics::BodyNode::Properties node;
185  node.mName = properties.mName;
186 
187  auto pair =
188  skeleton_->createJointAndBodyNodePair<dart::dynamics::RevoluteJoint>(parent, properties, node);
189  createShapeNode(pair.second, shape);
190 
191  pair.first->setPositionLimitEnforced(true);
192  return pair;
193 }

◆ addWeldedFrame()

std::pair< dart::dynamics::WeldJoint *, dart::dynamics::BodyNode * > Structure::addWeldedFrame ( const dart::dynamics::WeldJoint::Properties &  properties,
const dart::dynamics::ShapePtr &  shape,
dart::dynamics::BodyNode *  parent = nullptr 
)

Add a new frame attached to a fixed joint to this structure.

Parameters
[in]propertiesJoint properties to use for joint.
[in]shapeShape to attach to frame.
[in]parentParent frame to attach new joint to.
Returns
The created joint and body node.

Definition at line 227 of file structure.cpp.

230 {
231  dart::dynamics::BodyNode::Properties node;
232  node.mName = properties.mName;
233 
234  auto pair = skeleton_->createJointAndBodyNodePair<dart::dynamics::WeldJoint>(parent, properties, node);
235  createShapeNode(pair.second, shape);
236 
237  return pair;
238 }

◆ cloneStructure()

StructurePtr Structure::cloneStructure ( const std::string &  newName) const

Clones this structure with a new name.

Parameters
[in]newNameName for clone of the structure.
Returns
The cloned structure.

Definition at line 76 of file structure.cpp.

77 {
78  auto structure = std::make_shared<Structure>(newName);
79  structure->setSkeleton(skeleton_->cloneSkeleton(newName));
80 
81  for (const auto &pair : acm_->getDisabledPairsConst())
82  structure->getACM()->disableCollision(pair.first, pair.second);
83 
84  return structure;
85 }

◆ createShapeNode()

void Structure::createShapeNode ( dart::dynamics::BodyNode *  body,
const dart::dynamics::ShapePtr &  shape 
)
protected

Create a shape node on a body.

Parameters
[in,out]bodyBody to add shape node to.
[in]shapeShape to add to body.

Definition at line 150 of file structure.cpp.

151 {
152  if (not shape)
153  return;
154 
155  body->createShapeNodeWith<dart::dynamics::VisualAspect, //
156  dart::dynamics::CollisionAspect, //
157  dart::dynamics::DynamicsAspect>(shape);
158 
159  dart::dynamics::Inertia inertia;
160  double mass = magic::DEFAULT_DENSITY * shape->getVolume();
161  if (mass <= 0)
162  mass = 1.;
163 
164  inertia.setMass(mass);
165  inertia.setMoment(shape->computeInertia(mass));
166 
167  if (not inertia.verify(false))
168  inertia = dart::dynamics::Inertia(mass);
169 
170  body->setInertia(inertia);
171  body->setRestitutionCoeff(magic::DEFAULT_RESTITUTION);
172 
173  auto *joint = body->getParentJoint();
174  if (joint)
175  for (std::size_t i = 0; i < joint->getNumDofs(); ++i)
176  joint->getDof(i)->setDampingCoefficient(magic::DEFAULT_DAMPING);
177 }
static const double DEFAULT_RESTITUTION
Definition: structure.h:33
static const double DEFAULT_DAMPING
Definition: structure.h:32
static const double DEFAULT_DENSITY
Definition: structure.h:31

◆ dumpGraphViz()

void Structure::dumpGraphViz ( std::ostream &  out,
bool  standalone = true 
)

Dumps the structure of the skeleton to a GraphViz file.

Parameters
[in]outStream to output to.
[in]standaloneIf false, does not include graph header.

Definition at line 118 of file structure.cpp.

119 {
120  if (standalone)
121  out << "digraph {" << std::endl;
122 
123  const std::string &sname = skeleton_->getName();
124  for (const auto &node : skeleton_->getBodyNodes())
125  {
126  const std::string &name = node->getName();
127  const std::size_t index = node->getIndexInSkeleton();
128 
129  out << sname << "_" << index << "[label=\"" << name << "\"]" << std::endl;
130 
131  const auto &joint = node->getParentJoint();
132  const std::string &jname = joint->getName();
133  const std::string &type = joint->getType();
134 
135  const auto &parent = joint->getParentBodyNode();
136  if (parent)
137  {
138  const auto &pindex = parent->getIndexInSkeleton();
139  out << sname << "_" << pindex << "->" //
140  << sname << "_" << index //
141  << "[label=\"" << jname << std::endl
142  << type << "\"]" << std::endl;
143  }
144  }
145 
146  if (standalone)
147  out << "}" << std::endl;
148 }
T endl(T... args)

◆ getACM()

ACMPtr Structure::getACM ( )

Get the ACM for the structure.

Returns
The ACM.

Definition at line 92 of file structure.cpp.

93 {
94  return acm_;
95 }

◆ getACMConst()

const ACMPtr & Structure::getACMConst ( ) const

Get the ACM for the structure.

Returns
The ACM.

Definition at line 97 of file structure.cpp.

98 {
99  return acm_;
100 }

◆ getFrame()

dart::dynamics::BodyNode * Structure::getFrame ( const std::string &  name = "") const

Get a body node within the structure.

Parameters
[in]nameName of the node to retrieve.
Returns
The body node if it exists, nullptr otherwise. If name is empty, returns root.

Definition at line 292 of file structure.cpp.

293 {
294  return skeleton_->getBodyNode(name);
295 }

◆ getJoint()

dart::dynamics::Joint * Structure::getJoint ( const std::string &  joint_name) const

Get a reference to the joint in the structure.

Parameters
[in]joint_nameName of the joint to retrieve.
Returns
The joint if it exists, nullptr otherwise.

Definition at line 287 of file structure.cpp.

288 {
289  return skeleton_->getJoint(joint_name);
290 }

◆ getJointNames()

std::vector< std::string > Structure::getJointNames ( ) const

Get the joint names for this structure.

Returns
The names of all the joints in this structure.

Definition at line 278 of file structure.cpp.

279 {
281  for (const auto *joint : skeleton_->getJoints())
282  names.emplace_back(joint->getName());
283 
284  return names;
285 }
T emplace_back(T... args)

◆ getName()

const std::string & Structure::getName ( ) const

Get the name of this structure.

Returns
Name of the structure.

Definition at line 87 of file structure.cpp.

88 {
89  return name_;
90 }

◆ getRootFrame()

dart::dynamics::BodyNode * Structure::getRootFrame ( ) const

Get the root frame of this structure.

Returns
The root node.

Definition at line 343 of file structure.cpp.

344 {
345  return skeleton_->getRootBodyNode();
346 }

◆ getSkeleton()

dart::dynamics::SkeletonPtr & Structure::getSkeleton ( )

Get the underlying skeleton for the structure.

Returns
The skeleton.

Definition at line 108 of file structure.cpp.

109 {
110  return skeleton_;
111 }

◆ getSkeletonConst()

const dart::dynamics::SkeletonPtr & Structure::getSkeletonConst ( ) const

Get the underlying skeleton for the structure.

Returns
The skeleton.

Definition at line 113 of file structure.cpp.

114 {
115  return skeleton_;
116 }

◆ reparentFreeFrame()

void Structure::reparentFreeFrame ( dart::dynamics::BodyNode *  child,
const std::string &  parent = "" 
)

Reparents the child node to the parent node.

Parameters
[in]childChild to reparent.
[in]parentName of new parent for the child frame.

Definition at line 297 of file structure.cpp.

298 {
299  auto *frame = getFrame(parent);
300 
301  RobotPose tf;
302  if (frame)
303  tf = child->getTransform(frame);
304  else
305  tf = child->getWorldTransform();
306 
307  dart::dynamics::FreeJoint::Properties joint;
308  joint.mName = child->getName();
309  auto *jt = child->moveTo<dart::dynamics::FreeJoint>(skeleton_, frame, joint);
310 
311  setJointParentTransform(joint.mName, tf);
312 }
dart::dynamics::BodyNode * getFrame(const std::string &name="") const
Get a body node within the structure.
Definition: structure.cpp:292
std::decay< decltype(std::declval< moveit::core::Transforms >().getTransform("")) >::type RobotPose
A pose (point in SE(3)) used in various functions. Defined from what MoveIt! uses.
Definition: adapter.h:24

◆ setDof()

void Structure::setDof ( unsigned int  index,
double  value 
)

Set the DoF at index to value.

Parameters
[in]indexIndex of DoF to set.
[in]valueValue to set DoF.

Definition at line 273 of file structure.cpp.

274 {
275  skeleton_->getDof(index)->setPosition(value);
276 }

◆ setJoint() [1/2]

void Structure::setJoint ( const std::string &  name,
const Eigen::Ref< const Eigen::VectorXd > &  value 
)

Set the value of a n-DoF joint in the structure.

Parameters
[in]nameName of joint.
[in]valueValue to set joint.

Definition at line 259 of file structure.cpp.

260 {
261  auto *joint = skeleton_->getJoint(name);
262  joint->setPositions(value);
263 }

◆ setJoint() [2/2]

void Structure::setJoint ( const std::string &  name,
double  value 
)

Set the value of a 1-DoF joint in the structure.

Parameters
[in]nameName of joint.
[in]valueValue to set joint.

Definition at line 254 of file structure.cpp.

255 {
256  setJoint(name, Eigen::VectorXd::Constant(1, value));
257 }
void setJoint(const std::string &name, double value)
Set the value of a 1-DoF joint in the structure.
Definition: structure.cpp:254

◆ setJointParentTransform()

void Structure::setJointParentTransform ( const std::string &  name,
const RobotPose &  tf 
)

Set the transform from a joint to its parent.

Parameters
[in]nameName of joint to set transform of.
[in]tfTransform to set.

Definition at line 314 of file structure.cpp.

315 {
316  auto *joint = skeleton_->getJoint(name);
317  if (joint == nullptr)
318  RBX_ERROR("Cannot find joint named %s to set TF!", name);
319 
320  joint->setTransformFromParentBodyNode(tf);
321 }
#define RBX_ERROR(fmt,...)
Output a error logging message.
Definition: log.h:102

◆ setSkeleton()

void Structure::setSkeleton ( const dart::dynamics::SkeletonPtr &  skeleton)

Set the skeleton for the structure.

Parameters
[in]skeletonThe new skeleton.

Definition at line 102 of file structure.cpp.

103 {
104  skeleton_ = skeleton;
105  skeleton_->setName(name_);
106 }

◆ solveIK()

bool Structure::solveIK ( )

Solve the current whole-body IK problem imposed on the structure.

Returns
Returns true on success false on failure.

Definition at line 265 of file structure.cpp.

266 {
267  auto ik = skeleton_->getIK(true);
268  // ik->getSolver()->setTolerance(1e-9);
269  // ik->getSolver()->setNumMaxIterations(100);
270  return ik->solveAndApply(true);
271 }

◆ updateCollisionObject()

void Structure::updateCollisionObject ( const std::string &  name,
const GeometryPtr &  geometry,
const robowflex::RobotPose &  pose 
)

Update or add a collision object.

Parameters
[in]nameName of object to add.
[in]geometryGeometry of object.
[in]posePose of object to set.

Definition at line 323 of file structure.cpp.

325 {
326  auto nodes = skeleton_->getBodyNodes(name); // Get all nodes with this name
327  if (!nodes.empty())
328  setJointParentTransform(name, pose);
329  else
330  {
331  dart::dynamics::FreeJoint::Properties joint;
332  joint.mName = name;
333  joint.mT_ParentBodyToJoint = robowflex::TF::identity();
334 
335  auto shape = makeGeometry(geometry);
336 
337  auto pair = addFreeFrame(joint, shape);
338  setJointParentTransform(name, pose);
339  setColor(pair.second, dart::Color::Blue(0.2));
340  }
341 }

Member Data Documentation

◆ acm_

ACMPtr robowflex::darts::Structure::acm_
protected

ACM for structure.

Definition at line 262 of file structure.h.

◆ name_

const std::string robowflex::darts::Structure::name_ {"robot"}
protected

Name of the structure.

Definition at line 260 of file structure.h.

◆ skeleton_

dart::dynamics::SkeletonPtr robowflex::darts::Structure::skeleton_ {nullptr}
protected

Underlying skeleton.

Definition at line 261 of file structure.h.


The documentation for this class was generated from the following files: