As a user of the ROS ecosystem (robot_state_publisher, rviz, etc.), I can currently choose between two file formats to load into a urdf::Model data structure: URDF or Collada.
I propose we add a third valid file format: SDFormat. SDFormat is used by large robotics software projects like Gazebo and Drake. The source code for SDFormat: https://github.com/osrf/sdformat
To be completely clear, this request is not to require urdf::Model to support all of the possible permutations of SDFormat tags and topologies, but whatever subset makes sense to fufill the Model API's.
The plugin structure is already present and available via urdf_parser_plugin. I suggest we add an additional package (very similar to collada_parser) : sdformat_parser

At first glance, it seems this would require a sdformat_parser package to perform the SDFormat file -> urdf::Model validation and API population. This new package would supply a Class Plugin: urdf/SDFormatURDFParser.
Then we would just need to add a small amount of extra logic inside model.cpp's urdf::Model::initString() function to detect the presence of an SDFormat file and invoke the correct plugin class:
|
bool Model::initString(const std::string & xml_string) |
|
{ |
|
urdf::ModelInterfaceSharedPtr model; |
|
|
|
// necessary for COLLADA compatibility |
|
if (IsColladaData(xml_string)) { |
|
ROS_DEBUG("Parsing robot collada xml string"); |
|
|
|
static boost::mutex PARSER_PLUGIN_LOCK; |
|
static boost::scoped_ptr<pluginlib::ClassLoader<urdf::URDFParser> > PARSER_PLUGIN_LOADER; |
|
boost::mutex::scoped_lock _(PARSER_PLUGIN_LOCK); |
|
|
|
try { |
|
if (!PARSER_PLUGIN_LOADER) { |
|
PARSER_PLUGIN_LOADER.reset(new pluginlib::ClassLoader<urdf::URDFParser>("urdf_parser_plugin", "urdf::URDFParser")); |
|
} |
|
const std::vector<std::string> &classes = PARSER_PLUGIN_LOADER->getDeclaredClasses(); |
|
bool found = false; |
|
for (std::size_t i = 0 ; i < classes.size() ; ++i) { |
|
if (classes[i].find("urdf/ColladaURDFParser") != std::string::npos) { |
|
boost::shared_ptr<urdf::URDFParser> instance = PARSER_PLUGIN_LOADER->createInstance(classes[i]); |
|
if (instance) { |
|
model = instance->parse(xml_string); |
|
} |
|
found = true; |
|
break; |
|
} |
|
} |
|
if (!found) { |
|
ROS_ERROR_STREAM("No URDF parser plugin found for Collada files. Did you install the corresponding package?"); |
|
} |
|
} |
|
catch(pluginlib::PluginlibException& ex) { |
|
ROS_ERROR_STREAM("Exception while creating planning plugin loader " << ex.what() << ". Will not parse Collada file."); |
|
} |
|
} else { |
|
ROS_DEBUG("Parsing robot urdf xml string"); |
|
model = parseURDF(xml_string); |
|
} |
|
|
|
// copy data from model into this object |
|
if (model) { |
|
this->links_ = model->links_; |
|
this->joints_ = model->joints_; |
|
this->materials_ = model->materials_; |
|
this->name_ = model->name_; |
|
this->root_link_ = model->root_link_; |
|
return true; |
|
} |
|
return false; |
|
} |
The intent is not to replace URDF or Collada file formats, but to add a third viable file format option for use with urdf::Model. With all that said, it seems we can support SDFormat without being disruptive to the rest of the ROS ecosystem.
As a user of the ROS ecosystem (
robot_state_publisher,rviz, etc.), I can currently choose between two file formats to load into aurdf::Modeldata structure: URDF or Collada.I propose we add a third valid file format: SDFormat. SDFormat is used by large robotics software projects like Gazebo and Drake. The source code for SDFormat: https://github.com/osrf/sdformat
To be completely clear, this request is not to require
urdf::Modelto support all of the possible permutations of SDFormat tags and topologies, but whatever subset makes sense to fufill the Model API's.The plugin structure is already present and available via

urdf_parser_plugin. I suggest we add an additional package (very similar tocollada_parser) :sdformat_parserAt first glance, it seems this would require a
sdformat_parserpackage to perform the SDFormat file ->urdf::Modelvalidation and API population. This new package would supply a Class Plugin:urdf/SDFormatURDFParser.Then we would just need to add a small amount of extra logic inside
model.cpp'surdf::Model::initString()function to detect the presence of anSDFormatfile and invoke the correct plugin class:urdf/urdf/src/model.cpp
Lines 164 to 214 in 4707296
The intent is not to replace URDF or Collada file formats, but to add a third viable file format option for use with
urdf::Model. With all that said, it seems we can support SDFormat without being disruptive to the rest of the ROS ecosystem.