Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions urdf_parser/src/link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,44 @@ bool parseCylinder(Cylinder &y, TiXmlElement *c)
return true;
}

bool parseCapsule(Capsule &y, TiXmlElement *c)
{
y.clear();

y.type = Geometry::CAPSULE;
if (!c->Attribute("length") ||
!c->Attribute("radius"))
{
CONSOLE_BRIDGE_logError("Capsule shape must have both length and radius attributes");
return false;
}

try
{
y.length = boost::lexical_cast<double>(c->Attribute("length"));
}
catch (boost::bad_lexical_cast &/*e*/)
{
std::stringstream stm;
stm << "length [" << c->Attribute("length") << "] is not a valid float";
CONSOLE_BRIDGE_logError(stm.str().c_str());
return false;
}

try
{
y.radius = boost::lexical_cast<double>(c->Attribute("radius"));
}
catch (boost::bad_lexical_cast &/*e*/)
{
std::stringstream stm;
stm << "radius [" << c->Attribute("radius") << "] is not a valid float";
CONSOLE_BRIDGE_logError(stm.str().c_str());
return false;
}
return true;
}


bool parseMesh(Mesh &m, TiXmlElement *c)
{
Expand Down Expand Up @@ -254,6 +292,13 @@ GeometrySharedPtr parseGeometry(TiXmlElement *g)
if (parseCylinder(*c, shape))
return geom;
}
else if (type_name == "capsule")
{
Capsule *c = new Capsule();
geom.reset(c);
if (parseCapsule(*c, shape))
return geom;
}
else if (type_name == "mesh")
{
Mesh *m = new Mesh();
Expand Down Expand Up @@ -532,6 +577,16 @@ bool exportCylinder(Cylinder &y, TiXmlElement *xml)
return true;
}

bool exportCapsule(Capsule &y, TiXmlElement *xml)
{
// e.g. add <capsule radius="1"/>
TiXmlElement *capsule_xml = new TiXmlElement("capsule");
capsule_xml->SetAttribute("radius", urdf_export_helpers::values2str(y.radius));
capsule_xml->SetAttribute("length", urdf_export_helpers::values2str(y.length));
xml->LinkEndChild(capsule_xml);
return true;
}

bool exportMesh(Mesh &m, TiXmlElement *xml)
{
// e.g. add <mesh filename="my_file" scale="1 1 1"/>
Expand All @@ -558,6 +613,10 @@ bool exportGeometry(GeometrySharedPtr &geom, TiXmlElement *xml)
{
exportCylinder((*(urdf::dynamic_pointer_cast<Cylinder>(geom).get())), geometry_xml);
}
else if (urdf::dynamic_pointer_cast<Capsule>(geom))
{
exportCapsule((*(urdf::dynamic_pointer_cast<Capsule>(geom).get())), geometry_xml);
}
else if (urdf::dynamic_pointer_cast<Mesh>(geom))
{
exportMesh((*(urdf::dynamic_pointer_cast<Mesh>(geom).get())), geometry_xml);
Expand Down