Overview
URDF (Unified Robot Description Format) is an XML format for describing robot physical structure, including links (rigid bodies), joints (connections), and visual/collision geometry. Xacro (XML Macros) extends URDF with programming features like variables, macros, and math expressions for more maintainable robot descriptions.Robot Structure
Define links, joints, and kinematic chains
Visualization
Render robot in RViz and Gazebo simulation
URDF Basics
Links
Links represent rigid bodies (chassis, wheels, sensors):simple_link.urdf
Joints
Joints connect links and define motion:simple_joint.urdf
fixed: No movement (sensors, brackets)revolute: Rotation with limits (servo, arm)continuous: Unlimited rotation (wheels)prismatic: Linear motion (elevator, gripper)floating: 6-DOF (rarely used)planar: 2D motion in plane
Xacro: URDF with Macros
Xacro adds programming to URDF for reusability:Variables
mecanum_robot.urdf.xacro
Macros
wheel_macro.xacro
Math Expressions
Complete Mecanum Robot Example
mecanum_robot.urdf.xacro
Viewing URDF in RViz
Launch File
display.launch.py
Best Practices
Organization
urdf/directory for robot modelsmeshes/for STL/DAE files- Split into files:
chassis.xacro,wheels.xacro,sensors.xacro - Main file includes all:
mecanum_robot.urdf.xacro
Coordinate Frames
base_link: Center of robot, ground level- Follow REP-103: X forward, Y left, Z up
- Match physical robot mounting positions
- Use TF tree tool to verify:
ros2 run tf2_tools view_frames
Mesh Files
- Use STL for simple geometry, DAE for colors
- Export from CAD (Fusion 360, SolidWorks)
- Optimize: reduce polygon count for performance
- Scale correctly: check units (mm vs m)
Validation
- Check URDF syntax:
check_urdf robot.urdf - Convert xacro to URDF:
xacro robot.urdf.xacro -o robot.urdf - Visualize TF tree:
ros2 run tf2_tools view_frames - Test in RViz before Gazebo
Troubleshooting
Robot not visible in RViz
Robot not visible in RViz
Solutions:
- Add RobotModel display in RViz
- Set Fixed Frame to
base_link - Check
robot_state_publisheris running: - Verify
robot_descriptionparameter:
Xacro processing error
Xacro processing error
Symptoms:
xacro: error: invalid macro nameSolutions:-
Check macro syntax:
-
Ensure namespace declared:
-
Test xacro conversion manually:
TF transform errors
TF transform errors
Solutions:
- Verify all joints have parent and child links
- Check for duplicate link/joint names
- View TF tree:
- Ensure
base_linkexists (required root)
Next Steps
TF Transforms
Coordinate frame transformations and TF tree
Gazebo Simulation
Add physics simulation and sensors
Robot Description
Full mecanum robot URDF tutorial
ros2_control
Integrate hardware interfaces