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

A sampleable goal region for OMPL for a set of TSRs. Samples goals in a separate thread using a clone of the world. More...

#include <robot.h>

+ Inheritance diagram for robowflex::darts::Robot:

Public Types

using GroupsMap = std::map< std::string, std::vector< std::string > >
 A map of group name to member joints. More...
 
using NamedStatesMap = std::map< std::string, std::map< std::string, Eigen::VectorXd > >
 A map of group name to a map of state name to configurations. More...
 

Public Member Functions

Constructors
 Robot (const std::string &name)
 Construct an empty robot. More...
 
 Robot (robowflex::RobotPtr robot)
 Convert a robowflex::Robot into a Dart robot. More...
 
 Robot (const std::string &name, const ScenePtr &scene)
 Convert a robowflex::Scene into a Dart robot. More...
 
RobotPtr cloneRobot (const std::string &newName) const
 Clone this robot with a new name. More...
 
File Loading
bool loadURDF (const std::string &urdf)
 Load a URDF into this robot. More...
 
bool loadSRDF (const std::string &srdf)
 Load a SRDF into this robot. More...
 
State Operations
void setStateFromMoveItMsg (const moveit_msgs::RobotState &msg)
 Set the current state of this robot from a MoveIt message. More...
 
void setMoveItMsgFromState (moveit_msgs::RobotState &msg) const
 Set a MoveIt message from the current state of this robot. More...
 
void setStateFromMoveItState (const robot_state::RobotState &state)
 Set the current state of this robot from a MoveIt robot state. More...
 
void setMoveItStateFromState (robot_state::RobotState &state) const
 Set a MoveIt robot state from the current state of this robot. More...
 
void setStateFromMoveItJMG (const std::string &jmg, const std::vector< double > &joints)
 Set the state using a MoveIt Joint Group. More...
 
void setStateFromMoveItJMG (const std::string &jmg, const Eigen::Ref< const Eigen::VectorXd > &vec)
 Set the state using a MoveIt Joint Group. More...
 
void setMoveItJMGFromState (const std::string &jmg, std::vector< double > &joints) const
 Set a MoveIt Joint Group state from the current state of the robot. More...
 
void setMoveItJMGFromState (const std::string &jmg, Eigen::Ref< Eigen::VectorXd > vec) const
 Set a MoveIt Joint Group state from the current state of the robot. More...
 
Group Operations
void setGroups (const GroupsMap &newGroups)
 Get the groups currently in the robot. A map of group name to a list of all joints in the group. More...
 
const GroupsMap & getGroups () const
 Get the groups currently in the robot. A map of group name to a list of all joints in the group. More...
 
std::vector< std::string > & getGroupJointNames (const std::string &group)
 Get the joint names in a group. More...
 
const std::vector< std::string > & getGroupJointNamesConst (const std::string &group) const
 Get the joint names in a group. More...
 
std::vector< dart::dynamics::Joint * > getGroupJoints (const std::string &group) const
 Get the joints for a group. More...
 
std::pair< std::size_t, dart::dynamics::Joint * > getGroupJoint (const std::string &group, const std::string &joint) const
 Get a joint in a group along with its index in the group. More...
 
const std::vector< std::size_t > & getGroupIndices (const std::string &group) const
 Get the indices of joints corresponding to a group. More...
 
bool isGroup (const std::string &name) const
 Checks if a group exists. More...
 
std::size_t getNumDofsGroup (const std::string &group) const
 Gets the number of DoFs controlled by a group. More...
 
void getGroupState (const std::string &group, Eigen::Ref< Eigen::VectorXd > q) const
 Get the current state of the joints of a group. More...
 
void setGroupState (const std::string &group, const Eigen::Ref< const Eigen::VectorXd > &q)
 Set the current state of the joints of a group. More...
 
Constructing Groups
bool addJointToGroup (const std::string &group, const std::string &joint_name)
 Add a joint to a group. More...
 
bool addLinkToGroup (const std::string &group, const std::string &link_name)
 Add a the parent joint of a link to a group. More...
 
bool addChainToGroup (const std::string &group, const std::string &tip, const std::string &base)
 Add all the joints between two frames in a chain to a group. More...
 
bool addGroupToGroup (const std::string &group, const std::string &other)
 Add all the joints in another group to this group. More...
 
Named States
void setNamedGroupStates (const NamedStatesMap &states)
 Set the named states map. More...
 
const NamedStatesMap & getNamedGroupStates () const
 Get the named states map. More...
 
std::vector< std::string > getNamedGroupStates (const std::string &group) const
 Get all names for named states for a group. More...
 
bool getNamedGroupState (const std::string &group, const std::string &name, Eigen::Ref< Eigen::VectorXd > q) const
 Get the configuration of a named group state. More...
 
void setNamedGroupState (const std::string &group, const std::string &name, const Eigen::Ref< const Eigen::VectorXd > &q)
 Set or create a named group state. More...
 
- Public Member Functions inherited from robowflex::darts::Structure
 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...
 
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...
 
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...
 
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...
 
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...
 

Private Member Functions

bool addNameToGroup (const std::string &group, const std::string &name)
 Adds a name to the group. More...
 
void processGroup (const std::string &group)
 Process the members of a group to generate the set of indices. More...
 

Private Attributes

std::map< std::string, std::vector< std::string > > groups_
 Map of group names to joint names. More...
 
std::map< std::string, std::map< std::string, Eigen::VectorXd > > group_states_
 
std::map< std::string, std::vector< std::size_t > > group_indices_
 Indices of group joints. More...
 
robowflex::RobotPtr robot_ {nullptr}
 Robowflex robot. More...
 

Additional Inherited Members

- Protected Member Functions inherited from robowflex::darts::Structure
void createShapeNode (dart::dynamics::BodyNode *body, const dart::dynamics::ShapePtr &shape)
 Create a shape node on a body. More...
 
- Protected Attributes inherited from robowflex::darts::Structure
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

A sampleable goal region for OMPL for a set of TSRs. Samples goals in a separate thread using a clone of the world.

Definition at line 40 of file robowflex_dart/include/robowflex_dart/robot.h.

Member Typedef Documentation

◆ GroupsMap

A map of group name to member joints.

Definition at line 45 of file robowflex_dart/include/robowflex_dart/robot.h.

◆ NamedStatesMap

A map of group name to a map of state name to configurations.

Definition at line 49 of file robowflex_dart/include/robowflex_dart/robot.h.

Constructor & Destructor Documentation

◆ Robot() [1/3]

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

Construct an empty robot.

Parameters
[in]nameName of the robot.

Robot

Definition at line 24 of file robowflex_dart/src/robot.cpp.

24  : Structure(name)
25 {
26 }
Structure(const std::string &name)
Create an empty structure.
Definition: structure.cpp:26

◆ Robot() [2/3]

Robot::Robot ( robowflex::RobotPtr  robot)

Convert a robowflex::Robot into a Dart robot.

Parameters
[in]robotRobot to convert.

Definition at line 28 of file robowflex_dart/src/robot.cpp.

28  : Structure(robot->getName()), robot_(robot)
29 {
30  std::ofstream urdf_file;
31  std::string urdf_filename = robowflex::IO::createTempFile(urdf_file);
32 
33  std::ofstream srdf_file;
34  std::string srdf_filename = robowflex::IO::createTempFile(srdf_file);
35 
36  urdf_file << robot->getURDFString();
37  urdf_file.close();
38 
39  srdf_file << robot->getSRDFString();
40  srdf_file.close();
41 
42  loadURDF(urdf_filename);
43  loadSRDF(srdf_filename);
44 
45  robowflex::IO::deleteFile(urdf_filename);
46  robowflex::IO::deleteFile(srdf_filename);
47 }
bool loadSRDF(const std::string &srdf)
Load a SRDF into this robot.
robowflex::RobotPtr robot_
Robowflex robot.
bool loadURDF(const std::string &urdf)
Load a URDF into this robot.
T close(T... args)
Functions for loading and animating robots in Blender.
void deleteFile(const std::string &file)
Deletes a file.
std::string createTempFile(std::ofstream &out)
Creates a temporary file and opens an output stream.

◆ Robot() [3/3]

Robot::Robot ( const std::string &  name,
const ScenePtr &  scene 
)

Convert a robowflex::Scene into a Dart robot.

Parameters
[in]nameName of the robot.
[in]sceneScene to convert.

Definition at line 49 of file robowflex_dart/src/robot.cpp.

49  : Structure(name, scene)
50 {
51 }
Functions for loading and animating scenes in Blender.

Member Function Documentation

◆ addChainToGroup()

bool Robot::addChainToGroup ( const std::string &  group,
const std::string &  tip,
const std::string &  base 
)

Add all the joints between two frames in a chain to a group.

Parameters
[in]groupGroup to add joint to.
[in]tipTip of the chain.
[in]baseBase of the chain.
Returns
True on success, false on failure.

Definition at line 135 of file robowflex_dart/src/robot.cpp.

136 {
137  auto *node = skeleton_->getBodyNode(tip);
138  if (not node)
139  {
140  RBX_ERROR("Tip link %1% not in skeleton.", tip);
141  return false;
142  }
143 
145  while (node and node->getName() != base)
146  {
147  const auto &joint = node->getParentJoint();
148  if (not joint)
149  {
150  RBX_ERROR("Link %1% has no parent joint", node->getName());
151  return false;
152  }
153 
154  if (joint->getNumDofs() > 0)
155  names.emplace_back(joint->getName());
156 
157  node = joint->getParentBodyNode();
158  }
159 
160  if (not node)
161  {
162  RBX_ERROR("Base link %1% not parent of tip link %2%", base, tip);
163  return false;
164  }
165 
166  for (const auto &name : names)
167  addNameToGroup(group, name);
168 
169  processGroup(group);
170  return true;
171 }
bool addNameToGroup(const std::string &group, const std::string &name)
Adds a name to the group.
void processGroup(const std::string &group)
Process the members of a group to generate the set of indices.
dart::dynamics::SkeletonPtr skeleton_
Underlying skeleton.
Definition: structure.h:261
T emplace_back(T... args)
#define RBX_ERROR(fmt,...)
Output a error logging message.
Definition: log.h:102

◆ addGroupToGroup()

bool Robot::addGroupToGroup ( const std::string &  group,
const std::string &  other 
)

Add all the joints in another group to this group.

Parameters
[in]groupGroup to add other to.
[in]otherOther group to add.
Returns
True on success, false on failure.

Definition at line 173 of file robowflex_dart/src/robot.cpp.

174 {
175  if (not isGroup(other))
176  {
177  RBX_ERROR("Group %1% does not exist", other);
178  return false;
179  }
180 
181  for (const auto &name : getGroupJointNamesConst(other))
182  addNameToGroup(group, name);
183 
184  processGroup(group);
185  return true;
186 }
const std::vector< std::string > & getGroupJointNamesConst(const std::string &group) const
Get the joint names in a group.
bool isGroup(const std::string &name) const
Checks if a group exists.

◆ addJointToGroup()

bool Robot::addJointToGroup ( const std::string &  group,
const std::string &  joint_name 
)

Add a joint to a group.

Parameters
[in]groupGroup to add joint to.
[in]joint_nameJoint name to add.
Returns
True on success, false on failure.

Definition at line 92 of file robowflex_dart/src/robot.cpp.

93 {
94  const auto &joint = skeleton_->getJoint(joint_name);
95  if (not joint)
96  {
97  RBX_ERROR("Joint %1% not in skeleton.", joint_name);
98  return false;
99  }
100 
101  if (joint->getNumDofs() > 0)
102  addNameToGroup(group, joint_name);
103 
104  processGroup(group);
105  return true;
106 }

◆ addLinkToGroup()

bool Robot::addLinkToGroup ( const std::string &  group,
const std::string &  link_name 
)

Add a the parent joint of a link to a group.

Parameters
[in]groupGroup to add joint to.
[in]link_nameLink to add.
Returns
True on success, false on failure.

Definition at line 108 of file robowflex_dart/src/robot.cpp.

109 {
110  const auto &node = skeleton_->getBodyNode(link_name);
111  if (not node)
112  {
113  RBX_ERROR("Link %1% not in skeleton.", link_name);
114  return false;
115  }
116 
117  const auto &joint = node->getParentJoint();
118  if (not joint)
119  {
120  RBX_ERROR("Link %1% has no parent joint", link_name);
121  return false;
122  }
123 
124  if (joint->getName() == "rootJoint")
125  return false;
126 
127  // Only include mobile joints
128  if (joint->getNumDofs() > 0)
129  addNameToGroup(group, joint->getName());
130 
131  processGroup(group);
132  return true;
133 }

◆ addNameToGroup()

bool Robot::addNameToGroup ( const std::string &  group,
const std::string &  name 
)
private

Adds a name to the group.

Parameters
[in]groupGroup to add name to.
[in]nameName to add to group.
Returns
True on success, false on failure.

Definition at line 72 of file robowflex_dart/src/robot.cpp.

73 {
74  if (not isGroup(group))
75  {
76  RBX_DEBUG("Adding joint %1% to group %2%.", name, group);
78  return true;
79  }
80 
81  auto &names = getGroupJointNames(group);
82 
83  for (const auto &item : names)
84  if (item == name)
85  return false;
86 
87  RBX_DEBUG("Adding joint %1% to group %2%.", name, group);
88  names.emplace_back(name);
89  return true;
90 }
std::vector< std::string > & getGroupJointNames(const std::string &group)
Get the joint names in a group.
std::map< std::string, std::vector< std::string > > groups_
Map of group names to joint names.
T emplace(T... args)
#define RBX_DEBUG(fmt,...)
Output a debug logging message.
Definition: log.h:126

◆ cloneRobot()

RobotPtr Robot::cloneRobot ( const std::string &  newName) const

Clone this robot with a new name.

Parameters
[in]newNameName for cloned robot.
Returns
Cloned robot.

Definition at line 53 of file robowflex_dart/src/robot.cpp.

54 {
55  auto robot = std::make_shared<Robot>(newName);
56  robot->setSkeleton(skeleton_->cloneSkeleton(newName));
57 
58  for (const auto &pair : acm_->getDisabledPairsConst())
59  robot->getACM()->disableCollision(pair.first, pair.second);
60 
61  robot->setGroups(groups_);
62  robot->setNamedGroupStates(group_states_);
63 
64  return robot;
65 }
std::map< std::string, std::map< std::string, Eigen::VectorXd > > group_states_
ACMPtr acm_
ACM for structure.
Definition: structure.h:262

◆ getGroupIndices()

const std::vector< std::size_t > & Robot::getGroupIndices ( const std::string &  group) const

Get the indices of joints corresponding to a group.

Parameters
[in]groupGroup to get indices for.
Returns
The indices of the joints in a group.

Definition at line 381 of file robowflex_dart/src/robot.cpp.

382 {
383  return group_indices_.find(group)->second;
384 }
std::map< std::string, std::vector< std::size_t > > group_indices_
Indices of group joints.
T find(T... args)

◆ getGroupJoint()

std::pair< std::size_t, dart::dynamics::Joint * > Robot::getGroupJoint ( const std::string &  group,
const std::string &  joint 
) const

Get a joint in a group along with its index in the group.

Parameters
[in]groupGroup to search.
[in]jointJoint to find in group.
Returns
The index of the joint and the joint in the group. {0, nullptr} if it does not exist.

Definition at line 366 of file robowflex_dart/src/robot.cpp.

368 {
369  std::size_t i = 0;
370  for (const auto &dof : getGroupJoints(group))
371  {
372  if (dof->getName() == joint)
373  return {i, dof};
374 
375  i += dof->getNumDofs();
376  }
377 
378  return {0, nullptr};
379 }
std::vector< dart::dynamics::Joint * > getGroupJoints(const std::string &group) const
Get the joints for a group.

◆ getGroupJointNames()

std::vector< std::string > & Robot::getGroupJointNames ( const std::string &  group)

Get the joint names in a group.

Parameters
[in]groupGroup to get joint names for.
Returns
The list of joint names.

Definition at line 347 of file robowflex_dart/src/robot.cpp.

348 {
349  return groups_.find(group)->second;
350 }

◆ getGroupJointNamesConst()

const std::vector< std::string > & Robot::getGroupJointNamesConst ( const std::string &  group) const

Get the joint names in a group.

Parameters
[in]groupGroup to get joint names for.
Returns
The list of joint names.

Definition at line 352 of file robowflex_dart/src/robot.cpp.

353 {
354  return groups_.find(group)->second;
355 }

◆ getGroupJoints()

std::vector< dart::dynamics::Joint * > Robot::getGroupJoints ( const std::string &  group) const

Get the joints for a group.

Parameters
[in]groupGroup to get joint names for.
Returns
The list of joints.

Definition at line 357 of file robowflex_dart/src/robot.cpp.

358 {
360  for (const auto &dof : groups_.find(group)->second)
361  joints.emplace_back(skeleton_->getJoint(dof));
362 
363  return joints;
364 }

◆ getGroups()

const Robot::GroupsMap & Robot::getGroups ( ) const

Get the groups currently in the robot. A map of group name to a list of all joints in the group.

Returns
The groups in the robot.

Definition at line 342 of file robowflex_dart/src/robot.cpp.

343 {
344  return groups_;
345 }

◆ getGroupState()

void Robot::getGroupState ( const std::string &  group,
Eigen::Ref< Eigen::VectorXd >  q 
) const

Get the current state of the joints of a group.

Parameters
[in]groupGroup to get state for.
[out]qConfiguration of the group.

Definition at line 391 of file robowflex_dart/src/robot.cpp.

392 {
393  q = skeleton_->getPositions(getGroupIndices(group));
394 }
const std::vector< std::size_t > & getGroupIndices(const std::string &group) const
Get the indices of joints corresponding to a group.

◆ getNamedGroupState()

bool Robot::getNamedGroupState ( const std::string &  group,
const std::string &  name,
Eigen::Ref< Eigen::VectorXd >  q 
) const

Get the configuration of a named group state.

Parameters
[in]groupGroup of the named state.
[in]nameName of the state to get.
[out]qConfiguration to fill with named state.
Returns
True if state exists, false if not.

Definition at line 423 of file robowflex_dart/src/robot.cpp.

425 {
426  auto gsit = group_states_.find(group);
427  if (gsit != group_states_.end())
428  {
429  auto it = gsit->second.find(name);
430  if (it != gsit->second.end())
431  {
432  q = it->second;
433  return true;
434  }
435 
436  return false;
437  }
438 
439  return false;
440 }
T end(T... args)

◆ getNamedGroupStates() [1/2]

const Robot::NamedStatesMap & Robot::getNamedGroupStates ( ) const

Get the named states map.

Returns
The map of named states.

Definition at line 406 of file robowflex_dart/src/robot.cpp.

407 {
408  return group_states_;
409 }

◆ getNamedGroupStates() [2/2]

std::vector< std::string > Robot::getNamedGroupStates ( const std::string &  group) const

Get all names for named states for a group.

Parameters
[in]groupGroup to get named states for.
Returns
List of all named states.

Definition at line 411 of file robowflex_dart/src/robot.cpp.

412 {
414  for (const auto &group : group_states_)
415  {
416  for (const auto &state : group.second)
417  names.emplace_back(state.first);
418  }
419 
420  return names;
421 }

◆ getNumDofsGroup()

std::size_t Robot::getNumDofsGroup ( const std::string &  group) const

Gets the number of DoFs controlled by a group.

Parameters
[in]groupGroup to get DoFs for.
Returns
The number of DoFs in the group.

Definition at line 386 of file robowflex_dart/src/robot.cpp.

387 {
388  return getGroupIndices(group).size();
389 }
T size(T... args)

◆ isGroup()

bool Robot::isGroup ( const std::string &  name) const

Checks if a group exists.

Parameters
[in]nameName of group to check.
Returns
True if the group exists, false otherwise.

Definition at line 330 of file robowflex_dart/src/robot.cpp.

331 {
332  return groups_.find(name) != groups_.end();
333 }

◆ loadSRDF()

bool Robot::loadSRDF ( const std::string &  srdf)

Load a SRDF into this robot.

Parameters
[in]srdfSRDF filename to load. Can be package URI.
Returns
True on success, false on failure.

Definition at line 188 of file robowflex_dart/src/robot.cpp.

189 {
190  const auto &file = IO::getPackageFile(srdf);
191  if (file.empty())
192  {
193  RBX_ERROR("File %1% cannot be found!", srdf);
194  return false;
195  }
196 
197  tinyxml2::XMLDocument doc;
198  doc.LoadFile(file.c_str());
199 
200  tinyxml2::XMLElement *root = doc.FirstChildElement();
201  if (not root)
202  {
203  RBX_ERROR("No child element in SRDF");
204  return false;
205  }
206 
207  // parse virtual joints
208  tinyxml2::XMLElement *vj = root->FirstChildElement("virtual_joint");
209  while (vj != nullptr)
210  {
211  std::string name = vj->Attribute("name");
212  std::string type = vj->Attribute("type");
213  std::string parent = vj->Attribute("parent_frame");
214  std::string child = vj->Attribute("child_link");
215 
216  dart::dynamics::BodyNode *pnode = nullptr;
217  if (parent != "world")
218  {
219  pnode = skeleton_->getBodyNode(parent);
220  if (not pnode)
221  RBX_ERROR("Couldn't find %s for virtual joint!", parent);
222  }
223 
224  auto *cnode = skeleton_->getBodyNode(child);
225  if (cnode)
226  {
227  if (type == "floating")
228  {
229  dart::dynamics::FreeJoint::Properties joint;
230  joint.mName = name;
231 
232  cnode->moveTo<dart::dynamics::FreeJoint>(pnode, joint);
233  }
234  }
235 
236  vj = vj->NextSiblingElement("virtual_joint");
237  }
238 
239  // Parse groups
240  tinyxml2::XMLElement *group = root->FirstChildElement("group");
241  while (group != nullptr)
242  {
243  const auto &group_name = group->Attribute("name");
244 
245  tinyxml2::XMLElement *joints = group->FirstChildElement("joint");
246  while (joints != nullptr)
247  {
248  const auto &joint_name = joints->Attribute("name");
249  addJointToGroup(group_name, joint_name);
250 
251  joints = joints->NextSiblingElement("joint");
252  }
253 
254  tinyxml2::XMLElement *links = group->FirstChildElement("link");
255  while (links != nullptr)
256  {
257  const auto &link_name = links->Attribute("name");
258  addLinkToGroup(group_name, link_name);
259 
260  links = links->NextSiblingElement("link");
261  }
262 
263  tinyxml2::XMLElement *chains = group->FirstChildElement("chain");
264  while (chains != nullptr)
265  {
266  const auto &base_link = chains->Attribute("base_link");
267  const auto &tip_link = chains->Attribute("tip_link");
268  addChainToGroup(group_name, tip_link, base_link);
269 
270  chains = chains->NextSiblingElement("chain");
271  }
272 
273  tinyxml2::XMLElement *groups = group->FirstChildElement("group");
274  while (groups != nullptr)
275  {
276  const auto &other_name = groups->Attribute("name");
277  addGroupToGroup(group_name, other_name);
278 
279  groups = groups->NextSiblingElement("group");
280  }
281 
282  group = group->NextSiblingElement("group");
283  }
284 
285  // Parse allowed collisions
286  tinyxml2::XMLElement *dc = root->FirstChildElement("disable_collisions");
287  while (dc != nullptr)
288  {
289  const auto &l1 = dc->Attribute("link1");
290  const auto &l2 = dc->Attribute("link2");
291 
292  acm_->disableCollision(l1, l2);
293 
294  dc = dc->NextSiblingElement("disable_collisions");
295  }
296 
297  // Parse named group states
298  tinyxml2::XMLElement *gs = root->FirstChildElement("group_state");
299  while (gs != nullptr)
300  {
301  const auto &group = gs->Attribute("group");
302  const auto &name = gs->Attribute("name");
303 
304  Eigen::VectorXd state = Eigen::VectorXd::Zero(getNumDofsGroup(group));
305 
306  tinyxml2::XMLElement *js = gs->FirstChildElement("joint");
307  while (js != nullptr)
308  {
309  const auto &value = js->Attribute("value");
310  const auto &jname = js->Attribute("name");
311 
312  auto values = robowflex::IO::tokenize<double>(value, " ");
313  auto joint = getGroupJoint(group, jname);
314  if (joint.second != nullptr)
315  {
316  for (std::size_t i = 0; i < values.size(); ++i)
317  state[joint.first + i] = values[i];
318  }
319 
320  js = js->NextSiblingElement("joint");
321  }
322 
323  setNamedGroupState(group, name, state);
324  gs = gs->NextSiblingElement("group_state");
325  }
326 
327  return true;
328 }
std::size_t getNumDofsGroup(const std::string &group) const
Gets the number of DoFs controlled by a group.
bool addGroupToGroup(const std::string &group, const std::string &other)
Add all the joints in another group to this group.
void setNamedGroupState(const std::string &group, const std::string &name, const Eigen::Ref< const Eigen::VectorXd > &q)
Set or create a named group state.
bool addJointToGroup(const std::string &group, const std::string &joint_name)
Add a joint to a group.
bool addChainToGroup(const std::string &group, const std::string &tip, const std::string &base)
Add all the joints between two frames in a chain to a group.
std::pair< std::size_t, dart::dynamics::Joint * > getGroupJoint(const std::string &group, const std::string &joint) const
Get a joint in a group along with its index in the group.
bool addLinkToGroup(const std::string &group, const std::string &link_name)
Add a the parent joint of a link to a group.
std::string getPackageFile(const std::string &uri)
Get the filename for a package URI using Dart's lookup.

◆ loadURDF()

bool Robot::loadURDF ( const std::string &  urdf)

Load a URDF into this robot.

Parameters
[in]urdfURDF filename to load. Can be package URI.
Returns
True on success, false on failure.

Definition at line 67 of file robowflex_dart/src/robot.cpp.

68 {
69  return IO::loadURDF(*this, urdf);
70 }
bool loadURDF(Robot &robot, const std::string &urdf)
Loads a URDF at urdf into a robot.

◆ processGroup()

void Robot::processGroup ( const std::string &  group)
private

Process the members of a group to generate the set of indices.

Parameters
[in]groupGroup to process.

Definition at line 568 of file robowflex_dart/src/robot.cpp.

569 {
570  std::vector<std::size_t> indices;
571 
572  auto joints = getGroupJoints(group);
573  for (const auto &joint : joints)
574  {
575  for (std::size_t i = 0; i < joint->getNumDofs(); ++i)
576  indices.emplace_back(joint->getDof(i)->getIndexInSkeleton());
577  }
578 
579  auto it = group_indices_.find(group);
580  if (it == group_indices_.end())
581  group_indices_.emplace(group, indices);
582  else
583  it->second = indices;
584 }

◆ setGroups()

void Robot::setGroups ( const GroupsMap &  newGroups)

Get the groups currently in the robot. A map of group name to a list of all joints in the group.

Returns
The groups in the robot.

Definition at line 335 of file robowflex_dart/src/robot.cpp.

336 {
337  groups_ = newGroups;
338  for (const auto &pair : groups_)
339  processGroup(pair.first);
340 }

◆ setGroupState()

void Robot::setGroupState ( const std::string &  group,
const Eigen::Ref< const Eigen::VectorXd > &  q 
)

Set the current state of the joints of a group.

Parameters
[in]groupGroup to set state for.
[out]qConfiguration to set the group.

Definition at line 396 of file robowflex_dart/src/robot.cpp.

397 {
398  skeleton_->setPositions(getGroupIndices(group), q);
399 }

◆ setMoveItJMGFromState() [1/2]

void Robot::setMoveItJMGFromState ( const std::string &  jmg,
Eigen::Ref< Eigen::VectorXd >  vec 
) const

Set a MoveIt Joint Group state from the current state of the robot.

Parameters
[in]jmgName of joint group.
[out]vecJoint values to set.

Definition at line 559 of file robowflex_dart/src/robot.cpp.

560 {
561  if (not robot_)
562  return;
563 
564  setMoveItStateFromState(*robot_->getScratchState()); // copy current state
565  robot_->getScratchState()->copyJointGroupPositions(jmg, vec.data()); // copy JMG state
566 }
void setMoveItStateFromState(robot_state::RobotState &state) const
Set a MoveIt robot state from the current state of this robot.

◆ setMoveItJMGFromState() [2/2]

void Robot::setMoveItJMGFromState ( const std::string &  jmg,
std::vector< double > &  joints 
) const

Set a MoveIt Joint Group state from the current state of the robot.

Parameters
[in]jmgName of joint group.
[out]jointsJoint values to set.

Definition at line 550 of file robowflex_dart/src/robot.cpp.

551 {
552  if (not robot_)
553  return;
554 
555  setMoveItStateFromState(*robot_->getScratchState()); // copy current state
556  robot_->getScratchState()->copyJointGroupPositions(jmg, joints); // copy JMG state
557 }

◆ setMoveItMsgFromState()

void Robot::setMoveItMsgFromState ( moveit_msgs::RobotState &  msg) const

Set a MoveIt message from the current state of this robot.

Parameters
[out]msgMessage to set.

Definition at line 484 of file robowflex_dart/src/robot.cpp.

485 {
486  msg = moveit_msgs::RobotState();
487 
488  for (std::size_t i = 0; i < skeleton_->getNumJoints(); ++i)
489  {
490  auto *joint = skeleton_->getJoint(i);
491 
492  // ignore fixed joints
493  if (joint->getNumDofs() == 0)
494  continue;
495 
496  auto *j = dynamic_cast<dart::dynamics::FreeJoint *>(joint);
497  if (j)
498  {
499  msg.multi_dof_joint_state.joint_names.push_back(joint->getName());
500 
501  auto tf = joint->getRelativeTransform();
502  geometry_msgs::Transform tfmsg;
503  tfmsg.translation = TF::vectorEigenToMsg(tf.translation());
504  tfmsg.rotation = TF::quaternionEigenToMsg(TF::getPoseRotation(tf));
505 
506  msg.multi_dof_joint_state.transforms.push_back(tfmsg);
507  }
508  else
509  {
510  msg.joint_state.name.push_back(joint->getName());
511  msg.joint_state.position.push_back(joint->getPositions()[0]);
512  }
513  }
514 }
geometry_msgs::Vector3 vectorEigenToMsg(const Eigen::Vector3d &vector)
Converts an Eigen::Vector3d to a vector message.
Definition: tf.cpp:104
geometry_msgs::Quaternion quaternionEigenToMsg(const Eigen::Quaterniond &quaternion)
Converts an Eigen::Quaterniond to a quaternion message.
Definition: tf.cpp:140
Eigen::Quaterniond getPoseRotation(const RobotPose &pose)
Get the rotational component of a robot pose.
Definition: tf.cpp:69

◆ setMoveItStateFromState()

void Robot::setMoveItStateFromState ( robot_state::RobotState &  state) const

Set a MoveIt robot state from the current state of this robot.

Parameters
[out]stateMoveIt state to set state to.

Definition at line 523 of file robowflex_dart/src/robot.cpp.

524 {
525  moveit_msgs::RobotState msg;
528 }
void setMoveItMsgFromState(moveit_msgs::RobotState &msg) const
Set a MoveIt message from the current state of this robot.
bool robotStateMsgToRobotState(const Transforms &tf, const moveit_msgs::RobotState &robot_state, RobotState &state, bool copy_attached_bodies=true)

◆ setNamedGroupState()

void Robot::setNamedGroupState ( const std::string &  group,
const std::string &  name,
const Eigen::Ref< const Eigen::VectorXd > &  q 
)

Set or create a named group state.

Parameters
[in]groupGroup of the named state.
[in]nameName of the state to set.
[out]qConfiguration for the named state.

Definition at line 442 of file robowflex_dart/src/robot.cpp.

444 {
445  auto gsit = group_states_.find(group);
446  if (gsit == group_states_.end())
447  {
448  bool r;
450  }
451 
452  auto &names = gsit->second;
453 
454  auto it = names.find(name);
455  if (it == names.end())
456  {
457  bool r;
458  std::tie(it, r) = names.emplace(name, q);
459  }
460  else
461  it->second = q;
462 }
T tie(T... args)

◆ setNamedGroupStates()

void Robot::setNamedGroupStates ( const NamedStatesMap &  states)

Set the named states map.

Parameters
[in]statesNew named states map.

Definition at line 401 of file robowflex_dart/src/robot.cpp.

402 {
403  group_states_ = states;
404 }

◆ setStateFromMoveItJMG() [1/2]

void Robot::setStateFromMoveItJMG ( const std::string &  jmg,
const Eigen::Ref< const Eigen::VectorXd > &  vec 
)

Set the state using a MoveIt Joint Group.

Parameters
[in]jmgName of joint group.
[in]vecValue of Joint Group to set.

Definition at line 540 of file robowflex_dart/src/robot.cpp.

541 {
542  if (not robot_)
543  return;
544 
545  setMoveItStateFromState(*robot_->getScratchState()); // copy current state
546  robot_->getScratchState()->setJointGroupPositions(jmg, vec.data()); // set only JMG state
547  setStateFromMoveItState(*robot_->getScratchState()); // copy back
548 }
void setStateFromMoveItState(const robot_state::RobotState &state)
Set the current state of this robot from a MoveIt robot state.

◆ setStateFromMoveItJMG() [2/2]

void Robot::setStateFromMoveItJMG ( const std::string &  jmg,
const std::vector< double > &  joints 
)

Set the state using a MoveIt Joint Group.

Parameters
[in]jmgName of joint group.
[in]jointsValue of Joint Group to set.

Definition at line 530 of file robowflex_dart/src/robot.cpp.

531 {
532  if (not robot_)
533  return;
534 
535  setMoveItStateFromState(*robot_->getScratchState()); // copy current state
536  robot_->getScratchState()->setJointGroupPositions(jmg, joints); // set only JMG state
537  setStateFromMoveItState(*robot_->getScratchState()); // copy back
538 }

◆ setStateFromMoveItMsg()

void Robot::setStateFromMoveItMsg ( const moveit_msgs::RobotState &  msg)

Set the current state of this robot from a MoveIt message.

Parameters
[in]msgMessage to set state to.

Definition at line 464 of file robowflex_dart/src/robot.cpp.

465 {
466  for (std::size_t i = 0; i < msg.joint_state.name.size(); ++i)
467  setJoint(msg.joint_state.name[i], msg.joint_state.position[i]);
468 
469  for (std::size_t i = 0; i < msg.multi_dof_joint_state.joint_names.size(); ++i)
470  {
471  auto *joint = skeleton_->getJoint(msg.multi_dof_joint_state.joint_names[i]);
472  auto *j = static_cast<dart::dynamics::FreeJoint *>(joint);
473 
474  auto tfmsg = msg.multi_dof_joint_state.transforms[i];
475 
476  Eigen::Isometry3d tf;
477  tf.translation() = TF::vectorMsgToEigen(tfmsg.translation);
478  tf.linear() = TF::quaternionMsgToEigen(tfmsg.rotation).toRotationMatrix();
479 
480  j->setRelativeTransform(tf);
481  }
482 }
void setJoint(const std::string &name, double value)
Set the value of a 1-DoF joint in the structure.
Definition: structure.cpp:254
Eigen::Vector3d vectorMsgToEigen(const geometry_msgs::Vector3 &msg)
Converts a vector message to an Eigen::Vector3d.
Definition: tf.cpp:94
Eigen::Quaterniond quaternionMsgToEigen(const geometry_msgs::Quaternion &msg)
Converts a quaternion message to Eigen::Quaterniond.
Definition: tf.cpp:135

◆ setStateFromMoveItState()

void Robot::setStateFromMoveItState ( const robot_state::RobotState &  state)

Set the current state of this robot from a MoveIt robot state.

Parameters
[in]stateMoveIt state to set state to.

Definition at line 516 of file robowflex_dart/src/robot.cpp.

517 {
518  moveit_msgs::RobotState msg;
521 }
void setStateFromMoveItMsg(const moveit_msgs::RobotState &msg)
Set the current state of this robot from a MoveIt message.
void robotStateToRobotStateMsg(const RobotState &state, moveit_msgs::RobotState &robot_state, bool copy_attached_bodies=true)

Member Data Documentation

◆ group_indices_

std::map<std::string, std::vector<std::size_t> > robowflex::darts::Robot::group_indices_
private

Indices of group joints.

Definition at line 304 of file robowflex_dart/include/robowflex_dart/robot.h.

◆ group_states_

std::map<std::string, std::map<std::string, Eigen::VectorXd> > robowflex::darts::Robot::group_states_
private

Map of group names to map of named states.

Definition at line 301 of file robowflex_dart/include/robowflex_dart/robot.h.

◆ groups_

std::map<std::string, std::vector<std::string> > robowflex::darts::Robot::groups_
private

Map of group names to joint names.

Definition at line 300 of file robowflex_dart/include/robowflex_dart/robot.h.

◆ robot_

robowflex::RobotPtr robowflex::darts::Robot::robot_ {nullptr}
private

Robowflex robot.

Definition at line 306 of file robowflex_dart/include/robowflex_dart/robot.h.


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