Skip to content

URDF Overview and XML Syntax Guide: From robot, link, and joint Trees to origin Rotations and xacro

Understand URDF XML syntax for ROS 2 Jazzy, including robot link and joint trees, visual vs collision geometry, radian rpy rotations, xacro macros, and check_urdf.

Contents

Key takeaways

  1. URDF is not merely a 3D mesh file; it is the kinematic and dynamic contract (Single Source of Truth) shared by RViz2 visualization, TF2 coordinate transforms, and physics simulators.
  2. Every URDF model must form a strict directed tree starting from a single root link connected via parent-to-child joints; closed kinematic loops cannot be represented natively in URDF.
  3. Each link separates visual appearance (visual), simplified contact boundaries (collision), and mass/inertia properties (inertial) so physics engines run stably at real-time speed.
  4. All origin xyz offsets use meters and rpy rotations use fixed-axis (X→Y→Z) radians; repetitive symmetric structures should be parameterized with xacro macros and verified with check_urdf.

Imagine opening RViz2 and seeing a cleanly rendered mobile robot, only to spawn that exact same robot in a physics simulator and watch it fall straight through the floor—or drive into walls during autonomous navigation because its laser scanner frame points backward. In nearly every case, the problem is not the 3D CAD mesh file (.stl or .dae), but the numbers and tags inside the URDF (Unified Robot Description Format) file. While a 3D mesh merely says “this part looks like these triangles,” a URDF file acts as a structural contract stating “this rigid body sits at this coordinate offset, rotates around this unit vector, and carries this exact mass and inertia tensor.”

With a containerized workspace ready—as configured in reproducible ROS 2 Jazzy environments with Docker and VS Code Dev Containers—the next step is defining the robot’s physical skeleton in code. This guide explains what URDF defines (and what it cannot represent), previews the complete 13-link tree of the myros_sketch mobile robot, breaks down <link> attributes (visual, collision, inertial) and <joint> types (fixed, continuous, revolute), derives <origin> radian rotations and <axis> conventions, and demonstrates how to refactor repetitive XML into xacro macros verified with check_urdf.

What URDF Defines: The Single Source of Truth in ROS 2

As outlined in the official ROS 2 Jazzy URDF tutorials, URDF is an XML schema that describes a robot’s physical structure. If a visualization tool, a coordinate transform publisher, and a physics engine each read separate configuration files, frame offsets inevitably drift apart. ROS 2 avoids this by treating the URDF model as the Single Source of Truth shared across three core subsystems:

URDF XML ElementPhysical or Geometric MeaningSubsystem Consuming This Data in ROS 2
<link>A single rigid body with its own local coordinate framerobot_state_publisher (TF2 frames), physics rigid bodies
<joint>Parent-to-child frame transform and kinematic degree of freedomStatic/dynamic TF2 transforms, ros2_control actuator interfaces
<visual>Surface geometry and color (<material>) for renderingrviz2 display, Gazebo camera rendering pipelines
<collision>Simplified bounding volume for contact and obstacle checksGazebo physics contact solver, MoveIt2 collision avoidance
<inertial>Mass (kg), center of mass (<origin>), and 3×3 inertia matrixDynamic simulation of gravity, wheel slip, torque, and acceleration

Understanding what standard URDF cannot do is equally important when deciding how classical robot modeling fits into modern learning pipelines, a trade-off examined in when and how deep to learn ROS 2 for Physical AI:

  • No closed kinematic loops: Every URDF must form a strict tree where each link has at most one parent link. Four-bar linkages, parallel manipulators, and closed suspension loops cannot be expressed natively in pure URDF and require SDF or custom gazebo plugins.
  • No deformable bodies: Every <link> is modeled as a strictly rigid body; soft robotics, cables, and fluids are outside the specification.
  • No sensor physics or controller gains: LiDAR scan rates, camera distortion coefficients, surface friction (mu1, mu2), and motor PID loops live inside <gazebo> extension blocks or ros2_control YAML files rather than core URDF tags.

At its core, writing a URDF file means dividing a robot into distinct rigid bodies (<link>) and connecting each body to its parent through a kinematic constraint (<joint>). In our differential-drive educational robot myros_sketch, the kinematic tree starts at the ground projection frame (base_footprint) and branches outward through base_link and chassis to the wheels, casters, compute boards, and sensors:

base_footprint (ground-plane projection reference)
  └── [base_joint: fixed] ──> base_link (kinematic center reference)
        └── [chassis_joint: fixed] ──> chassis (main robot body box)
              ├── [left_wheel_joint: continuous]  ──> left_wheel (left drive wheel)
              ├── [right_wheel_joint: continuous] ──> right_wheel (right drive wheel)
              ├── [front_caster_joint: fixed]     ──> front_caster (front support caster)
              ├── [rear_caster_joint: fixed]      ──> rear_caster (rear support caster)
              ├── [esp32s3_joint: fixed]          ──> esp32s3_frame (MCU board)
              ├── [imu_joint: fixed]              ──> imu_link (inertial measurement unit)
              ├── [rpi_base_joint: fixed]         ──> rpi_base ──> rpi_frame (onboard SBC)
              ├── [lidar_base_joint: fixed]       ──> lidar_base_frame ──> laser_frame (2D LiDAR)
              └── [camera_joint: fixed]           ──> camera_link ──> camera_link_optical (camera)
Subsystem GroupComponent Links in myros_sketchJoint Type UsedKey Modeling Role
Base Coordinate Framesbase_footprint, base_link, chassisfixedEstablishes ground clearance (z) and chassis center offset
Differential Drive Wheelsleft_wheel, right_wheelcontinuousUnbounded rotation around the Y-axis (0 1 0)
Passive Support Castersfront_caster, rear_casterfixedKeeps the chassis level against the ground plane
Compute and Sensor Framesesp32s3_frame, imu_link, rpi_frame, laser_frame, camera_link_opticalfixedPublishes exact TF2 coordinate origins matching sensor frame_id headers

Notice that links such as base_link, laser_frame, or camera_link_optical can be declared as empty elements (<link name="laser_frame"/>) without any <visual> geometry at all. In ROS 2, a <link> is fundamentally a 3D coordinate frame, not a graphical mesh; even if it is invisible in RViz2, robot_state_publisher publishes its TF2 transform so LiDAR scans and camera point clouds align properly in space.

According to the official ROS Wiki URDF XML specification, a complete physical <link> contains three child blocks: <visual>, <collision>, and <inertial>. Below is a minimal, self-contained URDF model that passes check_urdf and loads cleanly into both RViz2 and Gazebo:

<?xml version="1.0"?>
<robot name="myros_sketch">
  <material name="dark_grey">
    <color rgba="0.3 0.3 0.3 1.0"/>
  </material>

  <link name="base_link"/>

  <link name="chassis">
    <visual>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <geometry>
        <box size="0.20 0.15 0.05"/>
      </geometry>
      <material name="dark_grey"/>
    </visual>

    <collision>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <geometry>
        <box size="0.20 0.15 0.05"/>
      </geometry>
    </collision>

    <inertial>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <mass value="0.45"/>
      <inertia ixx="9.375e-4" ixy="0.0" ixz="0.0"
               iyy="1.594e-3" iyz="0.0" izz="2.344e-3"/>
    </inertial>
  </link>

  <joint name="chassis_joint" type="fixed">
    <parent link="base_link"/>
    <child link="chassis"/>
    <origin xyz="0 0 0.05" rpy="0 0 0"/>
  </joint>
</robot>

1. Separating visual, collision, and inertial Properties

Child BlockFunctional PurposeUsed by RViz2?Used by Gazebo Physics?Recommended Authoring Practice
<visual>Renders external shape and <material> color (rgba)Yes (default view)Only for simulated optical camerasDetailed STL/DAE meshes or composed primitives
<collision>Defines contact surfaces for physics and motion planningOptional toggleYes (every physics solver step)Always prefer simple box, cylinder, or sphere primitives
<inertial>Specifies mass (kg), center of mass, and 3×3 rotational inertiaOptional gizmoYes (mandatory for dynamic links)Never leave mass at 0; compute positive diagonal moments (ixx, iyy, izz)

Beginners frequently define <visual> blocks and skip <collision> and <inertial>. While the model looks fine in RViz2, spawning it in Gazebo causes the physics engine to either ignore the zero-mass link or let the robot drop straight through the ground plane. Conversely, pasting a 500,000-vertex CAD .stl mesh into <collision> forces the physics engine to test hundreds of thousands of triangles every millisecond, cutting the simulation Real Time Factor in half.

2. The Four Geometry Primitives and REP-0103 SI Units

Per REP-0103 (Standard Units of Measure and Coordinate Conventions), every URDF file uses meters (m) for length, kilograms (kg) for mass, and radians (rad) for angles, following the right-handed coordinate convention (+X forward, +Y left, +Z up). Writing radius="32.5" instead of radius="0.0325" creates a wheel 65 meters tall.

Geometry TagXML Syntax ExampleParameter Meaning (Units: meters)Typical Robot Component
<box><box size="0.30 0.20 0.06"/>Full length along X, width along Y, height along ZMain chassis, Raspberry Pi board, battery pack
<cylinder><cylinder radius="0.0325" length="0.026"/>radius (m) and full length along the local Z-axisDrive wheels, cylindrical 2D LiDAR turrets
<sphere><sphere radius="0.015"/>radius (m) from the local originPassive ball casters, spherical joints
<mesh><mesh filename="package://my_pkg/meshes/body.stl" scale="0.001 0.001 0.001"/>Package URI and per-axis scale (0.001 converts mm STL to m)Complex 3D-printed shells and sensor brackets

Anatomy of a joint Element: Types, origin Radian Rotations, and axis Vectors

A <joint> connects a <parent> link to a <child> link and defines how the child coordinate frame moves relative to the parent frame. The ROS Wiki urdf/XML/joint specification defines six joint types:

Joint TypeDegrees of Freedom (DOF)Requires <limit> Tag?Kinematic Behavior and Typical Application
fixed0NoRigidly welds child to parent (sensor mounts, chassis-to-base offsets)
continuous1 (rotational)No angle bounds (effort/velocity advised)Unbounded rotation around <axis> (differential-drive wheels)
revolute1 (rotational)Yes (lower, upper, effort, velocity)Hinged rotation within strict angle limits (robot arm joints, steering servos)
prismatic1 (translational)Yes (lower, upper, effort, velocity)Linear sliding motion along <axis> within bounds (elevators, parallel grippers)
floating6 (3 linear + 3 angular)NoUnconstrained 6-DOF body in 3D space (specialized free-body simulations)
planar3 (2 linear + 1 angular)NoMotion constrained to a 2D surface plane (rarely used in standard robots)

Why wheels must use continuous rather than revolute is straightforward: a revolute joint enforces hard <limit lower="..." upper="..."/> stops, meaning a wheel would physically slam to a halt once its accumulated rotation reached the upper angle limit. For articulated robot arms where revolute and prismatic joints chain together to position an end-effector, see the robot arm kinematics and pick-and-place minimum math guide.

1. Understanding origin xyz Offsets and Fixed-Axis rpy Radian Rotations

Inside a <joint> (or inside a link’s <visual>/<collision> block), <origin xyz="x y z" rpy="roll pitch yaw"/> defines the pose of the child frame expressed in the parent frame. xyz specifies translation in meters, while rpy specifies Euler rotations in radians applied around the fixed axes in X (roll) → Y (pitch) → Z (yaw) order:

R=Rz(yaw)⋅Ry(pitch)⋅Rx(roll)R = R_z(\text{yaw}) \cdot R_y(\text{pitch}) \cdot R_x(\text{roll})

The single most common syntax error in URDF authoring is typing degrees into rpy. Writing rpy="0 90 0" does not rotate a sensor by 90 degrees—it rotates it by 90 radians (approximately 5,156.6 degrees), leaving the link skewed at an arbitrary angle. Always use radian equivalents:

  • $90^\circ = \frac{\pi}{2} \approx 1.5708\text{ rad}$
  • $-90^\circ = -\frac{\pi}{2} \approx -1.5708\text{ rad}$
  • $180^\circ = \pi \approx 3.14159\text{ rad}$

For example, a <cylinder> primitive stands upright along the local Z-axis by default. To orient that cylinder sideways as a wheel rolling along the Y-axis, apply a 90-degree roll rotation (rpy="1.5708 0 0") inside the wheel’s <visual> and <collision> <origin> tags.

2. The axis Vector and the Right-Hand Rule

<joint name="left_wheel_joint" type="continuous">
  <parent link="chassis"/>
  <child link="left_wheel"/>
  <origin xyz="0 0.08 -0.02" rpy="0 0 0"/>
  <axis xyz="0 1 0"/>
  <limit effort="1.5" velocity="20.0"/>
  <dynamics damping="0.05" friction="0.02"/>
</joint>

The <axis xyz="0 1 0"/> tag specifies the unit vector of rotation in the joint’s local frame (defaulting to 1 0 0 if omitted). Under the right-hand rule with +X pointing forward and +Y pointing left, pointing your right thumb along +Y (0 1 0) curls your fingers from +Z (top of the wheel) toward +X (front of the robot). Consequently, both the left wheel and the right wheel should use <axis xyz="0 1 0"/> so that a positive angular velocity drives both wheels forward. Flipping the right wheel’s axis to 0 -1 0 causes positive motor commands to spin the two wheels in opposite directions.

Eliminating Repetition with xacro Macros and Validating with check_urdf

Writing left and right drive wheels or four identical standoffs in raw URDF duplicates dozens of XML lines that differ only by a + or - sign on the Y-coordinate. Xacro (XML Macros) extends URDF with constants (<xacro:property>), math expressions (${...} including built-in pi), and parameterized blocks (<xacro:macro>):

<?xml version="1.0"?>
<robot name="myros_sketch" xmlns:xacro="http://www.ros.org/wiki/xacro">
  <xacro:property name="wheel_radius" value="0.0325"/>
  <xacro:property name="wheel_length" value="0.026"/>
  <xacro:property name="wheel_separation" value="0.16"/>

  <link name="base_link"/>

  <xacro:macro name="drive_wheel" params="prefix y_reflect">
    <link name="${prefix}_wheel">
      <visual>
        <origin xyz="0 0 0" rpy="${pi/2} 0 0"/>
        <geometry>
          <cylinder radius="${wheel_radius}" length="${wheel_length}"/>
        </geometry>
      </visual>
      <collision>
        <origin xyz="0 0 0" rpy="${pi/2} 0 0"/>
        <geometry>
          <cylinder radius="${wheel_radius}" length="${wheel_length}"/>
        </geometry>
      </collision>
    </link>

    <joint name="${prefix}_wheel_joint" type="continuous">
      <parent link="base_link"/>
      <child link="${prefix}_wheel"/>
      <origin xyz="0 ${y_reflect * wheel_separation / 2} 0" rpy="0 0 0"/>
      <axis xyz="0 1 0"/>
      <limit effort="1.5" velocity="20.0"/>
    </joint>
  </xacro:macro>

  <xacro:drive_wheel prefix="left"  y_reflect="1"/>
  <xacro:drive_wheel prefix="right" y_reflect="-1"/>
</robot>

Verification Commands and Troubleshooting Table

Before launching a complex robot description in Gazebo, validate its XML syntax and kinematic tree topology from the terminal:

# 1. Expand the xacro file into plain URDF XML to verify macro evaluation
xacro myros_sketch.urdf.xacro > /tmp/myros_sketch.urdf

# 2. Validate tree structure, single root link, and parent-child references
check_urdf /tmp/myros_sketch.urdf

# 3. Export a visual diagram of the link-and-joint hierarchy (requires graphviz)
urdf_to_graphviz /tmp/myros_sketch.urdf

# 4. Inspect visual alignment and test joint sliders interactively in RViz2
ros2 launch urdf_tutorial display.launch.py model:=/tmp/myros_sketch.urdf
Verification Tool or SymptomRoot CauseCorrective Action
check_urdf: Two root links foundAn unattached link exists without a parent jointEnsure every non-root link is referenced as <child> in exactly one <joint>
Link invisible in RViz2Missing <visual>, broken package:// mesh path, or unbuilt packageCheck mesh URI and scale, and run colcon build --symlink-install
Wheel lies flat horizontally instead of standing uprightCylinder default Z-axis was not rotated to align with the Y axleAdd <origin xyz="0 0 0" rpy="${pi/2} 0 0"/> inside the wheel’s <visual> and <collision>
Component twisted at an unexpected angleDegree values (e.g., 90) entered in rpy instead of radiansReplace degree values with radians (1.5708) or xacro expressions (${pi/2})
Robot explodes or sinks through floor in GazeboMissing <collision> or zero/invalid <inertial> mass and inertia tensorAdd <collision> primitives and positive <mass> + diagonal inertia moments (ixx, iyy, izz)

Common mistakes

  • Defining only the visual tag with an STL mesh while omitting collision and inertial blocks, causing the robot to fall straight through the ground plane in Gazebo.
  • Entering degree values such as 90 instead of radians (1.5708) in origin rpy attributes, which rotates the link by 90 radians (roughly 5,157 degrees) and scrambles the geometry.
  • Flipping one wheel’s joint axis to 0 -1 0 in an attempt to mirror left and right sides, causing the two wheels to spin in opposite directions under positive velocity commands.

Pre-flight checklist

  • Confirmed that every rigid body (link) connects back to a single root link without orphan branches or kinematic loops
  • Provided visual, simplified collision primitives, and non-zero inertial tensors for all physically simulated links
  • Verified that all linear dimensions (xyz, size, radius, length) are in meters and all rpy rotations are in radians
  • Assigned continuous joints with proper axis vectors (0 1 0) to endlessly rotating drive wheels and fixed joints to rigid sensor mounts
  • Validated XML structure and tree topology using xacro, check_urdf, and urdf_to_graphviz

Frequently asked questions

How does URDF differ from Gazebo's SDF (Simulation Description Format)?
URDF is the ROS standard for describing a single robot’s kinematic tree, geometry, and rigid-body inertia. SDF is Gazebo’s complete world and simulation format, capable of describing lighting, terrain, friction coefficients, sensor noise plugins, and closed kinematic loops. In ROS 2 projects, robots are typically authored in URDF/xacro and converted into SDF automatically when spawned in Gazebo.
Can I use the same high-resolution STL mesh for both visual and collision tags?
While syntactically valid, using high-polygon STL meshes inside collision blocks severely degrades physics simulation performance because contact detection scales with vertex count. Best practice uses detailed STL/DAE meshes in visual while approximating collision volumes with primitive box, cylinder, or sphere geometries.
When should I switch from plain URDF XML to xacro?
Adopt xacro as soon as a model repeats identical component blocks (such as left/right drive wheels or front/rear casters) or shares geometric constants (such as wheel radius or chassis height) across multiple joint origins. Using xacro properties and macros eliminates copy-paste errors.

Sources & verification

  1. ROS 2 Jazzy — URDF Tutorials
  2. ROS Wiki — urdf/XML Specification
  3. ROS Wiki — urdf/XML/link and joint
  4. REP-0103 — Standard Units of Measure and Coordinate Conventions

Last verified: