## page was renamed from kdl_parser/Tutorials/Start using the kdl parser ## ## http://wiki.ros.org/fr/kdl_parser/Tutorials/Start%20using%20the%20KDL%20parser #################################### ## Start using the KDL parser #################################### ## for a custom note with links: ## note = Dans ce tutoriel on considère que vous avez [[fr/urdf/Tutorials/Create your own urdf file|créé votre propre fichier URDF]] ou que vous utilisez un des fichiers urdf existant pour PR2 ## 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 = Démarrer l'utilisation de l'analyseur KDL ## multi-line description to be displayed in search ## description = Ce tutoriel vous apprends comment créer un arbre KDL à partir d'un fichier [[urdf/XML|URDF]] ## 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 = KDL #################################### <> <> == Construire l'analyseur KDL == {{{ $ rosdep install kdl_parser }}} Cela va installer toutes les dépendances externes pour l'analyseur KDL `kdl_parser`. Pour construire le package, lancez: {{{ $ rosmake kdl_parser }}} == L'utiliser dans son code == D'abord, ajoutez l'analyseur KDL (KDL parser) comme dépendances à votre fichire manifest.xml : {{{ ... ... }}} Pour mettre en oeuvre l'analyseur KDL dans votre code C++, ajoutez ces lignes: {{{#!cplusplus block=action #include }}} Maintenant il y a plusieurs manières de procéder. Vous pouvez construire un arbre KDL à partir d'un urdf sous des formes diverses: === A partir d'un fichier === {{{#!cplusplus block=action KDL::Tree my_tree; if (!kdl_parser::treeFromFile("filename", my_tree)){ ROS_ERROR("Failed to construct kdl tree"); return false; } }}} Pour créer le fichier URDF de PR2, lancez la commande suivante: {{{ $ rosrun xacro xacro.py `rospack find pr2_description`/robots/pr2.urdf.xacro > pr2.urdf }}} === A partir du serveur de paramètres === {{{#!cplusplus block=action KDL::Tree my_tree; ros::NodeHandle node; std::string robot_desc_string; node.param("robot_description", robot_desc_string, string()); if (!kdl_parser::treeFromString(robot_desc_string, my_tree)){ ROS_ERROR("Failed to construct kdl tree"); return false; } }}} === A partir d'un élément xml === {{{#!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; } }}} === A partir d'un modèle URDF === {{{#!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; } }}} Pour plus de détails, regardez l'[[http://www.ros.org/doc/api/kdl_parser/html/namespacekdl__parser.html|API documentation]]. ## TutorialCategory ## FILL IN THE STACK TUTORIAL CATEGORY HERE