[Documentation] [TitleIndex] [WordIndex


The urdfdom_py package provides the urdf_parser_py Python module providing both functions to parse an URDF model from a file or the parameter server and Python classes mapping the URDF information to a Python structure.

The display_urdf script allows the user to display the parsing result. It can be used either with a path to an URDF file (i.e. rosrun urdf_parser_py display_urdf /tmp/robot.urdf) or without any argument. In this case, it connects to the parameter server to retrieve the robot configuration.

   1 # Display the PR-2 model.
   2 rosrun urdf_parser_py display_urdf `rospack find pr2_mechanism_model`/pr2.urdf


This package comes from the following prior packages: urdfpy, urdf_python, urdf_parser_python, and robot_model_py.

urdf_parser_py presently has its own package page, which redirects here.

Python API

Here is a brief example showing the different ways to load/parse a URDF model.

   1 # Load the urdf_parser_py manifest, you use your own package
   2 # name on the condition but in this case, you need to depend on
   3 # urdf_parser_py.
   4 import roslib; roslib.load_manifest('urdfdom_py')
   5 import rospy
   7 # Import the module
   9 from urdf_parser_py.urdf import URDF
  11 # 1. Parse a string containing the robot description in URDF.
  12 # Pro: no need to have a roscore running.
  13 # Cons: n/a
  14 # Note: it is rare to receive the robot model as a string.
  15 robot = URDF.from_xml_string("<robot name='myrobot'></robot>")
  17 # - OR -
  19 # 2. Load the module from a file.
  20 # Pro: no need to have a roscore running.
  21 # Cons: using hardcoded file location is not portable.
  22 robot = URDF.from_xml_file()
  24 # - OR -
  26 # 3. Load the module from the parameter server.
  27 # Pro: automatic, no arguments are needed, consistent
  28 #      with other ROS nodes.
  29 # Cons: need roscore to be running and the parameter to
  30 #      to be set beforehand (through a roslaunch file for
  31 #      instance).
  32 robot = URDF.from_parameter_server()
  34 # Print the robot
  35 print(robot)

Once you have retrieved the robot object, please consult the package Python API to know how to browse the structure.

2024-06-15 13:48