Overview
URDF (Unified Robot Description Format) is an XML-based format for describing a robot’s physical structure. It defines links (rigid bodies), joints (connections), and properties like mass, inertia, and visual geometry.Why URDF? ROS2 needs to know your robot’s physical structure for:
- Coordinate frame transforms (TF)
- Visualization in RViz
- Simulation in Gazebo
- Collision detection
- Motion planning
URDF Purpose in ROS2
Visualization
RViz displays your robot’s 3D model exactly as defined in URDF, showing sensor positions and orientations.
Coordinate Transforms
TF2 system uses URDF joint definitions to compute transforms between robot parts (e.g., base_link → wheel_link).
Simulation
Gazebo uses URDF for physics simulation, including masses, inertias, and collision geometries.
Motion Planning
Nav2 and MoveIt use URDF to understand robot dimensions for collision-free path planning.
URDF Concepts
Links
Links are rigid bodies (physical parts of robot):- Robot base
- Wheels
- Sensor mounts
- Camera/LiDAR bodies
Joints
Joints connect links and define motion constraints:- Fixed: No movement (e.g., sensor rigidly mounted to base)
- Revolute: Rotation around axis (e.g., steering wheel)
- Continuous: Unlimited rotation (e.g., drive wheels)
- Prismatic: Linear sliding (e.g., elevator)
Coordinate Frames
Each link has a coordinate frame (origin + orientation):- X-axis: Forward (red in RViz)
- Y-axis: Left (green in RViz)
- Z-axis: Up (blue in RViz)
ROS Convention (REP-103):
- X: forward
- Y: left
- Z: up
- Rotation: right-hand rule
Basic URDF Structure
Minimal URDF Example
Simple Box Robot
simple_box.urdf
Visualize in RViz
Link Elements
Visual (Appearance)
Collision (Physics)
Inertial (Dynamics)
- Box
- Cylinder
- Sphere
Joint Types
Fixed Joint
No motion allowed:Continuous Joint
Unlimited rotation:Revolute Joint
Limited rotation:Prismatic Joint
Linear motion:Origin: Position and Orientation
Position (xyz)
- X: forward/backward (m)
- Y: left/right (m)
- Z: up/down (m)
Orientation (rpy)
Roll-Pitch-Yaw in radians:- Roll (R): Rotation around X-axis
- Pitch (P): Rotation around Y-axis
- Yaw (Y): Rotation around Z-axis
- 90° = 1.5708 rad (
π/2) - 180° = 3.1416 rad (
π) - 270° = 4.7124 rad (
3π/2)
URDF Best Practices
Use Xacro for Modularity
Use Xacro for Modularity
Problem: URDF is verbose and repetitive (4 wheels = lots of copy-paste).Solution: Use Xacro (XML Macros):We’ll use Xacro extensively for Mecanum robot!
- Define reusable macros (e.g., wheel macro)
- Use variables for dimensions
- Include external files
Start Simple, Add Complexity
Start Simple, Add Complexity
- Step 1: Base link only (box)
- Step 2: Add wheels (cylinders)
- Step 3: Add sensors (simple shapes)
- Step 4: Replace with detailed meshes
- Step 5: Add inertia and collision
Test in RViz Frequently
Test in RViz Frequently
After each change:Check:
- Links appear at correct positions
- Joints rotate correctly (use GUI sliders)
- Coordinate frames (TF) are logical
Follow Naming Conventions
Follow Naming Conventions
Links:
base_link(root, always)base_footprint(projection on ground)wheel_FL,wheel_FR,wheel_RL,wheel_RRlidar_link,imu_link,camera_link
base_to_wheel_FLbase_to_lidar
Validate URDF Syntax
Validate URDF Syntax
- Unclosed tags
- Invalid joint parent/child references
- Duplicate link names
URDF to Robot State Publisher
Once URDF is created, robot_state_publisher node publishes TF transforms:- Reads URDF from
robot_descriptionparameter - Publishes static transforms for fixed joints
- Subscribes to
/joint_statesfor movable joints - Publishes complete TF tree
Visualization Tools
RViz
- 3D visualization
- TF frame axes (RGB = XYZ)
- Joint state sliders (for revolute/continuous joints)
View Frames
URDF to Graphviz
Common URDF Mistakes
| Mistake | Symptom | Fix |
|---|---|---|
| Missing base_link | TF errors, no root | Always have base_link as root |
| Wrong origin | Parts floating/misaligned | Double-check xyz values |
| Wrong axis | Joint rotates wrong way | Verify axis direction (X/Y/Z) |
| Missing inertia | Gazebo crashes | Add <inertial> to all links |
| Negative mass | Physics explosion | Use positive mass values |
| Collision = Visual | Slow simulation | Simplify collision geometry |
| Large mesh scale | Giant robot in RViz | Adjust scale in mesh |
URDF Resources
File Locations (ROS2 Package)
Typical Launch File
Next Steps
Mecanum URDF
Create complete URDF for Mecanum wheel robot
URDF Visualization
Visualize and test URDF in RViz
Xacro Tutorial
Learn Xacro macros for modular URDF
TF2 Transforms
Understand coordinate frame transforms