## page was renamed from kdl_parser/Tutorials/Start using the kdl parser ## For instruction on writing tutorials ## http://www.ros.org/wiki/WritingTutorials #################################### ##FILL ME IN #################################### ## for a custom note with links: ## note = This tutorial assumes you have already [[urdf/Tutorials/Create your own urdf file|created your own URDF file]] or that you are working with the existing PR2 URDF file ## for the canned note of "This tutorial assumes that you have completed the previous tutorials:" just add the links ## note.0= ## descriptive title for the tutorial ## title = Start using the KDL parser ## multi-line description to be displayed in search ## description = This tutorial teaches you how to create a KDL Tree from a [[urdf/XML|URDF]] file ## the next tutorial description (optional) ## next = ## links to next tutorial (optional) ## next.0.link= ## next.1.link= ## what level user is this tutorial for ## level= BeginnerCategory ## keywords = #################################### <> <> == Building the KDL parser == {{{ $ rosdep install kdl_parser }}} This will install all the external dependencies for the `kdl_parser`. To build the package, run: {{{ $ rosmake kdl_parser }}} == Using in your code == First, add the KDL parser as a dependency to your package.xml (in ROS [[fuerte]] or earlier it's `manifest.xml`) file: {{{ ... ... ... }}} To start using the KDL parser in your C++ code, include the following file: {{{#!cplusplus block=action #include }}} Now there are different ways to proceed. You can construct a KDL tree from a urdf in various forms: === From a file === {{{#!cplusplus block=action KDL::Tree my_tree; if (!kdl_parser::treeFromFile("filename", my_tree)){ ROS_ERROR("Failed to construct kdl tree"); return false; } }}} 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 === {{{#!cplusplus block=action KDL::Tree my_tree; ros::NodeHandle node; std::string robot_desc_string; node.param("robot_description", robot_desc_string, std::string()); if (!kdl_parser::treeFromString(robot_desc_string, my_tree)){ ROS_ERROR("Failed to construct kdl tree"); return false; } }}} === From an xml element === {{{#!cplusplus block=action KDL::Tree my_tree; TiXmlDocument xml_doc; xml_doc.Parse(xml_string.c_str()); xml_root = xml_doc.FirstChildElement("robot"); if (!xml_root){ ROS_ERROR("Failed to get robot from xml document"); return false; } if (!kdl_parser::treeFromXml(xml_root, my_tree)){ ROS_ERROR("Failed to construct kdl tree"); return false; } }}} === From a URDF model === {{{#!cplusplus block=action KDL::Tree my_tree; urdf::Model my_model; if (!my_model.initXml(....)){ ROS_ERROR("Failed to parse urdf robot model"); return false; } if (!kdl_parser::treeFromUrdfModel(my_model, my_tree)){ ROS_ERROR("Failed to construct kdl tree"); return false; } }}} For more details, take a look at the [[http://www.ros.org/doc/api/kdl_parser/html/namespacekdl__parser.html|API documentation]]. ## AUTOGENERATED DO NOT DELETE ## TutorialCategory ## FILL IN THE STACK TUTORIAL CATEGORY HERE