5 #include <dart/dynamics/BodyNode.hpp>
6 #include <dart/dynamics/DegreeOfFreedom.hpp>
7 #include <dart/dynamics/Joint.hpp>
36 urdf_file <<
robot->getURDFString();
39 srdf_file <<
robot->getSRDFString();
55 auto robot = std::make_shared<Robot>(newName);
58 for (
const auto &pair :
acm_->getDisabledPairsConst())
59 robot->getACM()->disableCollision(pair.first, pair.second);
76 RBX_DEBUG(
"Adding joint %1% to group %2%.", name, group);
83 for (
const auto &item : names)
87 RBX_DEBUG(
"Adding joint %1% to group %2%.", name, group);
88 names.emplace_back(name);
94 const auto &joint =
skeleton_->getJoint(joint_name);
97 RBX_ERROR(
"Joint %1% not in skeleton.", joint_name);
101 if (joint->getNumDofs() > 0)
110 const auto &node =
skeleton_->getBodyNode(link_name);
113 RBX_ERROR(
"Link %1% not in skeleton.", link_name);
117 const auto &joint = node->getParentJoint();
120 RBX_ERROR(
"Link %1% has no parent joint", link_name);
124 if (joint->getName() ==
"rootJoint")
128 if (joint->getNumDofs() > 0)
137 auto *node =
skeleton_->getBodyNode(tip);
140 RBX_ERROR(
"Tip link %1% not in skeleton.", tip);
145 while (node and node->getName() != base)
147 const auto &joint = node->getParentJoint();
150 RBX_ERROR(
"Link %1% has no parent joint", node->getName());
154 if (joint->getNumDofs() > 0)
157 node = joint->getParentBodyNode();
162 RBX_ERROR(
"Base link %1% not parent of tip link %2%", base, tip);
166 for (
const auto &name : names)
177 RBX_ERROR(
"Group %1% does not exist", other);
193 RBX_ERROR(
"File %1% cannot be found!", srdf);
197 tinyxml2::XMLDocument doc;
198 doc.LoadFile(file.c_str());
200 tinyxml2::XMLElement *root = doc.FirstChildElement();
208 tinyxml2::XMLElement *vj = root->FirstChildElement(
"virtual_joint");
209 while (vj !=
nullptr)
213 std::string parent = vj->Attribute(
"parent_frame");
216 dart::dynamics::BodyNode *pnode =
nullptr;
217 if (parent !=
"world")
221 RBX_ERROR(
"Couldn't find %s for virtual joint!", parent);
224 auto *cnode =
skeleton_->getBodyNode(child);
227 if (type ==
"floating")
229 dart::dynamics::FreeJoint::Properties joint;
232 cnode->moveTo<dart::dynamics::FreeJoint>(pnode, joint);
236 vj = vj->NextSiblingElement(
"virtual_joint");
240 tinyxml2::XMLElement *group = root->FirstChildElement(
"group");
241 while (group !=
nullptr)
243 const auto &group_name = group->Attribute(
"name");
245 tinyxml2::XMLElement *joints = group->FirstChildElement(
"joint");
246 while (joints !=
nullptr)
248 const auto &joint_name = joints->Attribute(
"name");
251 joints = joints->NextSiblingElement(
"joint");
254 tinyxml2::XMLElement *links = group->FirstChildElement(
"link");
255 while (links !=
nullptr)
257 const auto &link_name = links->Attribute(
"name");
260 links = links->NextSiblingElement(
"link");
263 tinyxml2::XMLElement *chains = group->FirstChildElement(
"chain");
264 while (chains !=
nullptr)
266 const auto &base_link = chains->Attribute(
"base_link");
267 const auto &tip_link = chains->Attribute(
"tip_link");
270 chains = chains->NextSiblingElement(
"chain");
273 tinyxml2::XMLElement *groups = group->FirstChildElement(
"group");
274 while (groups !=
nullptr)
276 const auto &other_name = groups->Attribute(
"name");
279 groups = groups->NextSiblingElement(
"group");
282 group = group->NextSiblingElement(
"group");
286 tinyxml2::XMLElement *dc = root->FirstChildElement(
"disable_collisions");
287 while (dc !=
nullptr)
289 const auto &l1 = dc->Attribute(
"link1");
290 const auto &l2 = dc->Attribute(
"link2");
292 acm_->disableCollision(l1, l2);
294 dc = dc->NextSiblingElement(
"disable_collisions");
298 tinyxml2::XMLElement *gs = root->FirstChildElement(
"group_state");
299 while (gs !=
nullptr)
301 const auto &group = gs->Attribute(
"group");
302 const auto &name = gs->Attribute(
"name");
306 tinyxml2::XMLElement *js = gs->FirstChildElement(
"joint");
307 while (js !=
nullptr)
309 const auto &value = js->Attribute(
"value");
310 const auto &jname = js->Attribute(
"name");
312 auto values = robowflex::IO::tokenize<double>(value,
" ");
314 if (joint.second !=
nullptr)
317 state[joint.first + i] = values[i];
320 js = js->NextSiblingElement(
"joint");
324 gs = gs->NextSiblingElement(
"group_state");
338 for (
const auto &pair :
groups_)
360 for (
const auto &dof :
groups_.
find(group)->second)
372 if (dof->getName() == joint)
375 i += dof->getNumDofs();
416 for (
const auto &state : group.second)
424 Eigen::Ref<Eigen::VectorXd> q)
const
429 auto it = gsit->second.find(name);
430 if (it != gsit->second.end())
443 const Eigen::Ref<const Eigen::VectorXd> &q)
452 auto &names = gsit->second;
454 auto it = names.find(name);
455 if (it == names.end())
458 std::tie(it, r) = names.emplace(name, q);
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]);
469 for (
std::size_t i = 0; i < msg.multi_dof_joint_state.joint_names.size(); ++i)
471 auto *joint =
skeleton_->getJoint(msg.multi_dof_joint_state.joint_names[i]);
472 auto *j =
static_cast<dart::dynamics::FreeJoint *
>(joint);
474 auto tfmsg = msg.multi_dof_joint_state.transforms[i];
476 Eigen::Isometry3d tf;
480 j->setRelativeTransform(tf);
486 msg = moveit_msgs::RobotState();
493 if (joint->getNumDofs() == 0)
496 auto *j =
dynamic_cast<dart::dynamics::FreeJoint *
>(joint);
499 msg.multi_dof_joint_state.joint_names.push_back(joint->getName());
501 auto tf = joint->getRelativeTransform();
502 geometry_msgs::Transform tfmsg;
506 msg.multi_dof_joint_state.transforms.push_back(tfmsg);
510 msg.joint_state.name.push_back(joint->getName());
511 msg.joint_state.position.push_back(joint->getPositions()[0]);
518 moveit_msgs::RobotState msg;
525 moveit_msgs::RobotState msg;
536 robot_->getScratchState()->setJointGroupPositions(jmg, joints);
546 robot_->getScratchState()->setJointGroupPositions(jmg, vec.
data());
556 robot_->getScratchState()->copyJointGroupPositions(jmg, joints);
565 robot_->getScratchState()->copyJointGroupPositions(jmg, vec.
data());
573 for (
const auto &joint : joints)
575 for (
std::size_t i = 0; i < joint->getNumDofs(); ++i)
576 indices.
emplace_back(joint->getDof(i)->getIndexInSkeleton());
583 it->second = indices;
589 auto robot = std::make_shared<Robot>(name);
590 robot->loadURDF(urdf);
591 robot->loadSRDF(srdf);
A shared pointer wrapper for robowflex::Robot.
A shared pointer wrapper for robowflex::Scene.
void setStateFromMoveItState(const robot_state::RobotState &state)
Set the current state of this robot from a MoveIt robot state.
std::size_t getNumDofsGroup(const std::string &group) const
Gets the number of DoFs controlled by a group.
const std::vector< std::string > & getGroupJointNamesConst(const std::string &group) const
Get the joint names in a group.
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.
const std::vector< std::size_t > & getGroupIndices(const std::string &group) const
Get the indices of joints corresponding to a group.
bool addGroupToGroup(const std::string &group, const std::string &other)
Add all the joints in another group to this group.
void setGroupState(const std::string &group, const Eigen::Ref< const Eigen::VectorXd > &q)
Set the current state of the joints of a group.
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.
Robot(const std::string &name)
Construct an empty robot.
const NamedStatesMap & getNamedGroupStates() const
Get the named states map.
void setStateFromMoveItJMG(const std::string &jmg, const std::vector< double > &joints)
Set the state using a MoveIt Joint Group.
void setMoveItStateFromState(robot_state::RobotState &state) const
Set a MoveIt robot state from the current state of this robot.
bool getNamedGroupState(const std::string &group, const std::string &name, Eigen::Ref< Eigen::VectorXd > q) const
Get the configuration of a named group state.
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.
void setMoveItMsgFromState(moveit_msgs::RobotState &msg) const
Set a MoveIt message from the current state of this robot.
bool loadSRDF(const std::string &srdf)
Load a SRDF into this robot.
std::map< std::string, std::vector< std::size_t > > group_indices_
Indices of group joints.
void getGroupState(const std::string &group, Eigen::Ref< Eigen::VectorXd > q) const
Get the current state of the joints of a group.
bool isGroup(const std::string &name) const
Checks if a group exists.
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.
robowflex::RobotPtr robot_
Robowflex robot.
bool addNameToGroup(const std::string &group, const std::string &name)
Adds a name to the group.
void setNamedGroupStates(const NamedStatesMap &states)
Set the named states map.
void setStateFromMoveItMsg(const moveit_msgs::RobotState &msg)
Set the current state of this robot from a MoveIt message.
RobotPtr cloneRobot(const std::string &newName) const
Clone this robot with a new name.
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.
void processGroup(const std::string &group)
Process the members of a group to generate the set of indices.
std::vector< std::string > & getGroupJointNames(const std::string &group)
Get the joint names in a group.
std::map< std::string, std::map< std::string, Eigen::VectorXd > > group_states_
std::vector< dart::dynamics::Joint * > getGroupJoints(const std::string &group) const
Get the joints for a group.
void setMoveItJMGFromState(const std::string &jmg, std::vector< double > &joints) const
Set a MoveIt Joint Group state from the current state of the robot.
bool loadURDF(const std::string &urdf)
Load a URDF into this robot.
std::map< std::string, std::vector< std::string > > groups_
Map of group names to joint names.
bool addLinkToGroup(const std::string &group, const std::string &link_name)
Add a the parent joint of a link to a group.
Wrapper class for a dart::dynamics::Skeleton.
void setJoint(const std::string &name, double value)
Set the value of a 1-DoF joint in the structure.
ACMPtr acm_
ACM for structure.
dart::dynamics::SkeletonPtr skeleton_
Underlying skeleton.
T emplace_back(T... args)
#define RBX_ERROR(fmt,...)
Output a error logging message.
#define RBX_DEBUG(fmt,...)
Output a debug logging message.
bool robotStateMsgToRobotState(const Transforms &tf, const moveit_msgs::RobotState &robot_state, RobotState &state, bool copy_attached_bodies=true)
void robotStateToRobotStateMsg(const RobotState &state, moveit_msgs::RobotState &robot_state, bool copy_attached_bodies=true)
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.
geometry_msgs::Vector3 vectorEigenToMsg(const Eigen::Vector3d &vector)
Converts an Eigen::Vector3d to a vector message.
Eigen::Vector3d vectorMsgToEigen(const geometry_msgs::Vector3 &msg)
Converts a vector message to an Eigen::Vector3d.
Eigen::Quaterniond quaternionMsgToEigen(const geometry_msgs::Quaternion &msg)
Converts a quaternion message to Eigen::Quaterniond.
geometry_msgs::Quaternion quaternionEigenToMsg(const Eigen::Quaterniond &quaternion)
Converts an Eigen::Quaterniond to a quaternion message.
Eigen::Quaterniond getPoseRotation(const RobotPose &pose)
Get the rotational component of a robot pose.
std::string getPackageFile(const std::string &uri)
Get the filename for a package URI using Dart's lookup.
bool loadURDF(Robot &robot, const std::string &urdf)
Loads a URDF at urdf into a robot.
DART-based robot modeling and planning.
RobotPtr loadMoveItRobot(const std::string &name, const std::string &urdf, const std::string &srdf)
Load a robot from a URDF and SRDF (i.e., a MoveIt enabled robot).
Functions for loading and animating scenes in Blender.