cmeel-urdfdom: URDF Parser

4.0.1 · active · verified Wed Apr 15

cmeel-urdfdom provides Python bindings for the `urdfdom` C++ library, which is used for parsing Unified Robot Description Format (URDF) XML files. It allows Python applications to load, manipulate, and query robot models defined in URDF. The current version is 4.0.1, with releases typically tracking the underlying `urdfdom` C++ library and often including `cmeel`-specific build suffixes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load a URDF robot model from an XML string using `URDF.load_from_xml_string`. It then shows how to access basic properties like the robot's name, the number of links and joints, and specific details of a link and a joint.

from urdfdom.urdf import URDF

# A simple URDF string for a single link robot
simple_urdf_string = """<?xml version=\"1.0\"?>
<robot name=\"simple_robot\">
  <link name=\"base_link\">
    <visual>
      <geometry>
        <box size=\"1 1 1\"/>
      </geometry>
    </visual>
  </link>
  <joint name=\"fixed_joint\" type=\"fixed\">
    <parent link=\"base_link\"/>
    <child link=\"child_link\"/>
    <origin xyz=\"0 0 1\" rpy=\"0 0 0\"/>
  </joint>
  <link name=\"child_link\">
    <visual>
      <geometry>
        <cylinder radius=\"0.1\" length=\"0.5\"/>
      </geometry>
    </visual>
  </link>
</robot>
"""

try:
    robot = URDF.load_from_xml_string(simple_urdf_string)
    print(f"Successfully loaded robot: {robot.name}")
    print(f"Number of links: {len(robot.links)}")
    print(f"Number of joints: {len(robot.joints)}")

    # Access a link
    if 'base_link' in robot.links:
        print(f"Base link geometry: {robot.links['base_link'].visuals[0].geometry.box.size}")

    # Access a joint
    if 'fixed_joint' in robot.joints:
        joint = robot.joints['fixed_joint']
        print(f"Fixed joint type: {joint.joint_type}")
        print(f"Fixed joint origin: {joint.origin.xyz}")

except Exception as e:
    print(f"Error loading URDF: {e}")

view raw JSON →