64 if (!
srdf_model_->initString(robot_model, srdf_string))
108 if (!
srdf_model_->initString(robot_model, srdf_string))
110 throw std::runtime_error(
"Unable to update the SRDF Model");
123 return document.SaveFile(file_path);
135 TiXmlPrinter printer;
136 printer.SetIndent(
" ");
137 document.Accept(&printer);
140 return printer.CStr();
148 TiXmlDocument document;
149 TiXmlDeclaration* decl =
new TiXmlDeclaration(
"1.0",
"",
"");
150 document.LinkEndChild(decl);
153 TiXmlComment* comment =
new TiXmlComment(
"This does not replace URDF, and is not an extension of URDF.\n This is " 155 "representing semantic information about the robot structure.\n A URDF " 156 "file must exist for " 157 "this robot as well, where the joints and the links that are referenced are " 159 document.LinkEndChild(comment);
162 TiXmlElement* robot_root =
new TiXmlElement(
"robot");
164 document.LinkEndChild(robot_root);
199 TiXmlComment* comment;
200 comment =
new TiXmlComment(
"GROUPS: Representation of a set of joints and links. This can be useful for specifying " 201 "DOF to plan for, defining arms, end effectors, etc");
202 root->LinkEndChild(comment);
203 comment =
new TiXmlComment(
"LINKS: When a link is specified, the parent joint of that link (if it exists) is " 204 "automatically included");
205 root->LinkEndChild(comment);
206 comment =
new TiXmlComment(
"JOINTS: When a joint is specified, the child link of that joint (which will always " 207 "exist) is automatically included");
208 root->LinkEndChild(comment);
209 comment =
new TiXmlComment(
"CHAINS: When a chain is specified, all the links along the chain (including endpoints) " 210 "are included in the group. Additionally, all the joints that are parents to included " 211 "links are also included. This means that joints along the chain and the parent joint " 212 "of the base link are included in the group");
213 root->LinkEndChild(comment);
214 comment =
new TiXmlComment(
"SUBGROUPS: Groups can also be formed by referencing to already defined group names");
215 root->LinkEndChild(comment);
219 for (std::vector<srdf::Model::Group>::iterator group_it =
groups_.begin(); group_it !=
groups_.end(); ++group_it)
222 TiXmlElement* group =
new TiXmlElement(
"group");
223 group->SetAttribute(
"name", group_it->name_);
224 root->LinkEndChild(group);
227 for (std::vector<std::string>::const_iterator link_it = group_it->links_.begin(); link_it != group_it->links_.end();
230 TiXmlElement* link =
new TiXmlElement(
"link");
231 link->SetAttribute(
"name", *link_it);
232 group->LinkEndChild(link);
236 for (std::vector<std::string>::const_iterator joint_it = group_it->joints_.begin();
237 joint_it != group_it->joints_.end(); ++joint_it)
239 TiXmlElement* joint =
new TiXmlElement(
"joint");
240 joint->SetAttribute(
"name", *joint_it);
241 group->LinkEndChild(joint);
245 for (std::vector<std::pair<std::string, std::string> >::const_iterator chain_it = group_it->chains_.begin();
246 chain_it != group_it->chains_.end(); ++chain_it)
248 TiXmlElement* chain =
new TiXmlElement(
"chain");
249 chain->SetAttribute(
"base_link", chain_it->first);
250 chain->SetAttribute(
"tip_link", chain_it->second);
251 group->LinkEndChild(chain);
255 for (std::vector<std::string>::const_iterator subgroup_it = group_it->subgroups_.begin();
256 subgroup_it != group_it->subgroups_.end(); ++subgroup_it)
258 TiXmlElement* subgroup =
new TiXmlElement(
"group");
259 subgroup->SetAttribute(
"name", *subgroup_it);
260 group->LinkEndChild(subgroup);
274 TiXmlComment* comment =
new TiXmlComment();
275 comment->SetValue(
"COLLISION SPHERES: Purpose: Define a set of spheres that bounds a link.");
276 root->LinkEndChild(comment);
281 if (link_sphere_it->spheres_.empty())
285 TiXmlElement* link =
new TiXmlElement(
"link_sphere_approximation");
286 link->SetAttribute(
"link", link_sphere_it->link_);
287 root->LinkEndChild(link);
290 for (std::vector<srdf::Model::Sphere>::const_iterator sphere_it = link_sphere_it->spheres_.begin();
291 sphere_it != link_sphere_it->spheres_.end(); ++sphere_it)
293 TiXmlElement* sphere =
new TiXmlElement(
"sphere");
294 std::stringstream center;
295 center.precision(20);
296 center << sphere_it->center_x_ <<
" " << sphere_it->center_y_ <<
" " << sphere_it->center_z_;
297 sphere->SetAttribute(
"center", center.str());
298 sphere->SetDoubleAttribute(
"radius", sphere_it->radius_);
299 link->LinkEndChild(sphere);
312 TiXmlComment* comment =
new TiXmlComment();
313 comment->SetValue(
"DISABLE COLLISIONS: By default it is assumed that any link of the robot could potentially come " 314 "into collision with any other link in the robot. This tag disables collision checking between a " 315 "specified pair of links. ");
316 root->LinkEndChild(comment);
319 for (std::vector<srdf::Model::DisabledCollision>::const_iterator pair_it =
disabled_collisions_.begin();
323 TiXmlElement* link_pair =
new TiXmlElement(
"disable_collisions");
324 link_pair->SetAttribute(
"link1", pair_it->link1_);
325 link_pair->SetAttribute(
"link2", pair_it->link2_);
326 link_pair->SetAttribute(
"reason", pair_it->reason_);
328 root->LinkEndChild(link_pair);
340 TiXmlComment* comment =
new TiXmlComment();
341 comment->SetValue(
"GROUP STATES: Purpose: Define a named state for a particular group, in terms of joint values. " 342 "This is useful to define states like 'folded arms'");
343 root->LinkEndChild(comment);
346 for (std::vector<srdf::Model::GroupState>::const_iterator state_it =
group_states_.begin();
350 TiXmlElement* state =
new TiXmlElement(
"group_state");
351 state->SetAttribute(
"name", state_it->name_);
352 state->SetAttribute(
"group", state_it->group_);
353 root->LinkEndChild(state);
356 for (std::map<std::string, std::vector<double> >::const_iterator value_it = state_it->joint_values_.begin();
357 value_it != state_it->joint_values_.end(); ++value_it)
359 TiXmlElement* joint =
new TiXmlElement(
"joint");
360 joint->SetAttribute(
"name", value_it->first);
361 joint->SetDoubleAttribute(
"value", value_it->second[0]);
364 state->LinkEndChild(joint);
377 TiXmlComment* comment =
new TiXmlComment();
378 comment->SetValue(
"END EFFECTOR: Purpose: Represent information about an end effector.");
379 root->LinkEndChild(comment);
382 for (std::vector<srdf::Model::EndEffector>::const_iterator effector_it =
end_effectors_.begin();
386 TiXmlElement* effector =
new TiXmlElement(
"end_effector");
387 effector->SetAttribute(
"name", effector_it->name_);
388 effector->SetAttribute(
"parent_link", effector_it->parent_link_);
389 effector->SetAttribute(
"group", effector_it->component_group_);
390 if (!effector_it->parent_group_.empty())
391 effector->SetAttribute(
"parent_group", effector_it->parent_group_);
392 root->LinkEndChild(effector);
404 TiXmlComment* comment =
new TiXmlComment();
405 comment->SetValue(
"VIRTUAL JOINT: Purpose: this element defines a virtual joint between a robot link and an " 406 "external frame of reference (considered fixed with respect to the robot)");
407 root->LinkEndChild(comment);
410 for (std::vector<srdf::Model::VirtualJoint>::const_iterator virtual_it =
virtual_joints_.begin();
414 TiXmlElement* virtual_joint =
new TiXmlElement(
"virtual_joint");
415 virtual_joint->SetAttribute(
"name", virtual_it->name_);
416 virtual_joint->SetAttribute(
"type", virtual_it->type_);
417 virtual_joint->SetAttribute(
"parent_frame", virtual_it->parent_frame_);
418 virtual_joint->SetAttribute(
"child_link", virtual_it->child_link_);
420 root->LinkEndChild(virtual_joint);
428 TiXmlComment* comment =
new TiXmlComment();
429 comment->SetValue(
"PASSIVE JOINT: Purpose: this element is used to mark joints that are not actuated");
430 root->LinkEndChild(comment);
432 for (std::vector<srdf::Model::PassiveJoint>::const_iterator p_it =
passive_joints_.begin();
436 TiXmlElement* p_joint =
new TiXmlElement(
"passive_joint");
437 p_joint->SetAttribute(
"name", p_it->name_);
438 root->LinkEndChild(p_joint);
void createEndEffectorsXML(TiXmlElement *root)
void createDisabledCollisionsXML(TiXmlElement *root)
Representation of semantic information about the robot.
void createGroupStatesXML(TiXmlElement *root)
void updateSRDFModel(const urdf::ModelInterface &robot_model)
void initModel(const urdf::ModelInterface &robot_model, const srdf::Model &srdf_model)
std::vector< srdf::Model::VirtualJoint > virtual_joints_
void createPassiveJointsXML(TiXmlElement *root)
std::vector< srdf::Model::DisabledCollision > disabled_collisions_
std::vector< srdf::Model::EndEffector > end_effectors_
std::vector< srdf::Model::LinkSpheres > link_sphere_approximations_
void createVirtualJointsXML(TiXmlElement *root)
srdf::ModelSharedPtr srdf_model_
void createLinkSphereApproximationsXML(TiXmlElement *root)
bool writeSRDF(const std::string &file_path)
TiXmlDocument generateSRDF()
void createGroupsXML(TiXmlElement *root)
bool initString(const urdf::ModelInterface &robot_model, const std::string &srdf_string)
std::vector< srdf::Model::Group > groups_
std::string getSRDFString()
std::vector< srdf::Model::GroupState > group_states_
std::vector< srdf::Model::PassiveJoint > passive_joints_