Note: This tutorial assumes you have already created your own URDF file or that you are working with the existing PR2 URDF file. |
Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags. |
Exporting URDF to COLLADA
Description: This tutorial teaches you how to export an URDF file to a COLLADA documentTutorial Level: BEGINNER
Contents
Building collada_urdf
$ rosdep install collada_urdf
This will install all the external dependencies for collada_urdf. To build the package, run:
$ rosmake collada_urdf
Using in your code
First, add the package as a dependency to your manifest.xml file:
<package> ... <depend package="collada_urdf" /> ... </package>
To start using the exporter in your C++ code, include the following file:
Now there are different ways to proceed. You can construct a COLLADA Document Object Model (DOM) from URDF in a variety of ways:
From a file
To create the PR2 URDF file, run the following command:
$ rosrun xacro xacro.py `rospack find pr2_description`/robots/pr2.urdf.xacro > pr2.urdf
From the parameter server
From an XML document
1 boost::shared_ptr<DAE> dom;
2 TiXmlDocument xml_doc;
3 xml_doc.Parse(xml_string.c_str());
4 xml_root = xml_doc.FirstChildElement("robot");
5 if (!xml_root) {
6 ROS_ERROR("Failed to find robot element in XML document");
7 return false;
8 }
9 if (!collada_urdf::colladaFromUrdfXml(xml_root, dom)) {
10 ROS_ERROR("Failed to construct COLLADA DOM");
11 return false;
12 }
From an URDF model
Writing COLLADA to file
Once you have your COLLADA document loaded, you can write the document to a file:
1 collada_urdf::colladaToFile(dom, "filename.dae");
For more details, take a look at the API documentation.