URDF: Mapping Real & Simulated Robots
Learning Objectives
- Understand the role of URDF in connecting real and simulated robots
- Create URDF files that accurately represent physical robot hardware
- Map URDF parameters to real robot specifications and constraints
- Implement URDF for both simulation and real robot deployment
- Handle differences between simulated and real robot behaviors
Prerequisites: This chapter builds on the ROS 2 concepts covered in Module 1: The Robotic Nervous System and the robot structure fundamentals from Module 2: Robot Links, Joints, and Coordinate Frames and Forward and Inverse Kinematics. Understanding robot structure and kinematics is essential for creating accurate URDF models.
Introduction to URDF in Real-Simulated Integration
The Unified Robot Description Format (URDF) serves as the critical bridge between simulated and real robotic systems. A well-constructed URDF enables seamless transition between simulation environments like Gazebo and real hardware, allowing developers to test algorithms in simulation before deploying to physical robots.
Key Concept: URDF provides a common language for describing robot geometry, kinematics, and dynamics that can be interpreted by both simulation engines and real robot controllers, enabling the "simulate, test, deploy" workflow that is fundamental to modern robotics development.
Understanding the Real-Simulated Mapping Challenge
Physical vs. Virtual Representations
Real robots and simulated robots differ in several key aspects that must be accounted for in URDF:
Inertial Properties
Real robots have manufacturing tolerances, component variations, and assembly imperfections that affect their actual inertial properties. Simulated models often use idealized values that must be calibrated to match reality.
Joint Dynamics
Real joints have friction, backlash, and compliance that may not be fully captured in simulation. The URDF should include realistic joint limits and dynamics that reflect the physical constraints.
Sensor Characteristics
Physical sensors have noise, latency, and accuracy limitations that differ from idealized simulation models. The URDF describes the physical mounting and placement but simulation parameters may need adjustment.
Calibration Requirements
Accurate mapping between real and simulated robots often requires:
- Kinematic Calibration: Adjusting link lengths, joint offsets, and coordinate frame positions
- Dynamic Calibration: Tuning mass, center of mass, and inertia parameters
- Joint Calibration: Verifying joint limits, velocities, and effort constraints
Creating URDF for Real Robots
Physical Measurement and Documentation
The foundation of an accurate URDF for a real robot begins with precise physical measurements:
Link Dimensions
- Measure actual link lengths, widths, and heights
- Document geometric shapes (cylinders, boxes, meshes)
- Account for mounting points and connection interfaces
Joint Specifications
- Document actual joint types (revolute, prismatic, fixed)
- Measure joint limits from physical constraints
- Record gear ratios and transmission characteristics
Mass Properties
- Weigh each physical link
- Determine center of mass through physical measurement or CAD analysis
- Calculate or measure inertia tensors where possible
URDF Structure for Real Hardware
<?xml version="1.0"?>
<robot name="example_real_robot">
<!-- Base Link Definition -->
<link name="base_link">
<inertial>
<mass value="5.0"/>
<origin xyz="0 0 0.1" rpy="0 0 0"/>
<inertia ixx="0.1" ixy="0.0" ixz="0.0"
iyy="0.1" iyz="0.0" izz="0.2"/>
</inertial>
<visual>
<origin xyz="0 0 0.1" rpy="0 0 0"/>
<geometry>
<mesh filename="package://robot_description/meshes/base_link.dae"/>
</geometry>
</visual>
<collision>
<origin xyz="0 0 0.1" rpy="0 0 0"/>
<geometry>
<mesh filename="package://robot_description/meshes/base_link_collision.stl"/>
</geometry>
</collision>
</link>
<!-- Joint Definition -->
<joint name="joint_1" type="revolute">
<parent link="base_link"/>
<child link="link_1"/>
<origin xyz="0 0 0.2" rpy="0 0 0"/>
<axis xyz="0 0 1"/>
<limit lower="-2.5" upper="2.5" effort="100" velocity="2.0"/>
<dynamics friction="0.1" damping="0.5"/>
</joint>
<!-- Additional links and joints -->
<link name="link_1">
<inertial>
<mass value="2.0"/>
<origin xyz="0 0 0.15" rpy="0 0 0"/>
<inertia ixx="0.05" ixy="0.0" ixz="0.0"
iyy="0.05" iyz="0.0" izz="0.1"/>
</inertial>
<visual>
<origin xyz="0 0 0.15" rpy="0 0 0"/>
<geometry>
<mesh filename="package://robot_description/meshes/link_1.dae"/>
</geometry>
</visual>
<collision>
<origin xyz="0 0 0.15" rpy="0 0 0"/>
<geometry>
<mesh filename="package://robot_description/meshes/link_1_collision.stl"/>
</geometry>
</collision>
</link>
</robot>
Incorporating Real Hardware Specifications
Motor and Actuator Parameters
Real URDF files must accurately represent the capabilities of physical actuators:
- Effort limits: Based on actual motor torque capabilities
- Velocity limits: Based on gear ratios and motor speed
- Control characteristics: PID parameters and control modes
Sensor Integration
Physical sensors should be properly positioned in the URDF:
- Camera mounting positions and orientations
- IMU placements for accurate state estimation
- Range sensor positions for perception tasks
Adapting URDF for Simulation
Simulation-Specific Considerations
While the basic URDF structure remains the same, simulation environments may require additional elements:
Gazebo-Specific Tags
<gazebo reference="link_1">
<material>Gazebo/Blue</material>
<mu1>0.2</mu1>
<mu2>0.2</mu2>
<kp>1000000.0</kp>
<kd>100.0</kd>
</gazebo>
<gazebo reference="joint_1">
<implicitSpringDamper>1</implicitSpringDamper>
</gazebo>
Physics Parameters
Simulation physics engines require specific parameters that may differ from real robot specifications:
- Contact properties: Friction coefficients, restitution
- Damping values: To simulate real-world energy loss
- Stiffness parameters: For joint and link behavior
Collision and Visual Separation
In simulation, it's often beneficial to have different collision and visual models:
- Visual models: Detailed meshes for rendering
- Collision models: Simplified geometries for physics calculations
- Level of detail: Different meshes for different simulation requirements
Bridging Simulation and Reality
Domain Randomization Techniques
To improve transfer from simulation to reality, domain randomization can be applied:
Physical Parameter Variation
- Randomly vary mass, friction, and damping parameters during training
- Add noise to sensor readings and actuator responses
- Vary environmental conditions (gravity, lighting)
URDF Parameterization
Using Xacro (XML Macros) to create parameterized URDFs that can be easily modified:
<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="parameterized_robot">
<xacro:property name="base_mass" value="5.0"/>
<xacro:property name="base_length" value="0.2"/>
<xacro:property name="joint_friction" value="0.1"/>
<link name="base_link">
<inertial>
<mass value="${base_mass}"/>
<origin xyz="0 0 0.1" rpy="0 0 0"/>
<inertia ixx="0.1" ixy="0.0" ixz="0.0"
iyy="0.1" iyz="0.0" izz="0.2"/>
</inertial>
<!-- Visual and collision elements -->
</link>
<joint name="joint_1" type="revolute">
<parent link="base_link"/>
<child link="link_1"/>
<origin xyz="0 0 ${base_length}" rpy="0 0 0"/>
<axis xyz="0 0 1"/>
<limit lower="-2.5" upper="2.5" effort="100" velocity="2.0"/>
<dynamics friction="${joint_friction}" damping="0.5"/>
</joint>
</robot>
Hardware Interface Mapping
Joint State Publishers
The URDF must align with the actual hardware interface:
<!-- Transmission elements for hardware interface -->
<transmission name="tran1">
<type>transmission_interface/SimpleTransmission</type>
<joint name="joint_1">
<hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
</joint>
<actuator name="motor1">
<hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
<mechanicalReduction>1</mechanicalReduction>
</actuator>
</transmission>
Controller Configuration
Controllers must be configured to work with both simulated and real hardware:
# Controller configuration
joint_state_controller:
type: joint_state_controller/JointStateController
publish_rate: 50
position_trajectory_controller:
type: position_controllers/JointTrajectoryController
joints:
- joint_1
- joint_2
constraints:
goal_time: 0.6
stopped_velocity_tolerance: 0.05
joint_1:
trajectory: 0.05
goal: 0.01
joint_2:
trajectory: 0.05
goal: 0.01
Calibration and Validation Process
Kinematic Calibration
Measurement-Based Calibration
- Pose Measurement: Use external measurement systems (motion capture, laser trackers) to measure actual robot poses
- Parameter Identification: Use optimization algorithms to identify kinematic parameters that minimize pose errors
- Validation: Test calibrated parameters across the robot's workspace
Calibration Tools
ROS provides several tools for kinematic calibration:
kdl_calibration: Uses KDL for kinematic parameter identificationrobot_calibration: More comprehensive calibration framework- Custom optimization routines using the robot's forward kinematics
Dynamic Parameter Tuning
System Identification
For accurate dynamic simulation, parameters must be identified through system identification:
- Excitation Trajectories: Apply known inputs to the real robot and measure responses
- Parameter Estimation: Use optimization to find parameters that best match real behavior
- Validation: Compare simulation and real robot responses to various inputs
Friction Modeling
Real robots exhibit complex friction behaviors that must be modeled:
- Coulomb friction: Constant friction opposing motion
- Viscous friction: Velocity-dependent friction
- Stribeck effect: Complex low-velocity friction characteristics
Troubleshooting Real-Simulated Mapping Issues
Common Mapping Problems
Kinematic Discrepancies
- Issue: Robot in simulation doesn't match real robot's kinematic behavior
- Solutions:
- Verify link lengths and joint axis orientations
- Check joint limits and home positions
- Validate coordinate frame definitions
- Use calibration tools to identify errors
Dynamic Differences
- Issue: Robot moves differently in simulation vs. reality
- Solutions:
- Tune inertial parameters through system identification
- Add friction and damping parameters that match real behavior
- Account for actuator limitations in simulation
- Consider environmental factors (floor friction, air resistance)
Control Performance Gaps
- Issue: Controllers that work in simulation fail on real robot
- Solutions:
- Add realistic sensor noise and latency to simulation
- Model actuator dynamics and limitations
- Implement domain randomization during training
- Use robust control techniques
Validation Techniques
Forward Kinematics Validation
- Command known joint angles and compare end-effector positions
- Use external measurement systems to verify accuracy
- Test across the entire workspace
Inverse Kinematics Validation
- Command known end-effector poses and verify joint solutions
- Check that solutions are physically achievable
- Validate joint limit compliance
Dynamic Response Validation
- Apply step inputs and compare response times
- Test frequency response characteristics
- Validate stability margins
Best Practices for URDF Mapping
Design Principles
Modularity
- Create reusable URDF components that can be assembled differently
- Use Xacro for parameterized designs
- Separate visual and collision models appropriately
Accuracy vs. Performance
- Balance model complexity with simulation performance
- Use simplified collision models where precision isn't critical
- Implement level-of-detail switching for different simulation needs
Documentation
- Include clear comments in URDF files
- Document measurement sources and calibration procedures
- Maintain version control for URDF changes
Testing Strategies
Simulation-Only Testing
- Verify kinematic and dynamic properties in simulation
- Test controllers and algorithms in virtual environment
- Validate safety constraints before real robot deployment
Gradual Transfer
- Start with simple tasks in simulation
- Gradually increase complexity when real robot testing begins
- Maintain simulation models that can be updated based on real robot performance
Hands-On Exercises
Exercise 1: URDF Creation from Physical Measurements
Objective: Create a URDF file for a simple robot based on physical measurements.
Instructions:
- Measure the physical dimensions of a simple robot or robot arm
- Determine mass properties using scales and measurement techniques
- Identify joint types and measure joint limits
- Create a URDF file with appropriate visual and collision models
- Validate the URDF using check_urdf tool
Expected Outcome: A complete URDF file that accurately represents the physical robot.
Exercise 2: Simulation to Reality Transfer
Objective: Test a simple movement in simulation and transfer to a real robot.
Instructions:
- Create a simulation environment with your robot URDF
- Implement a simple trajectory controller
- Test the controller in simulation
- Deploy the same controller to a real robot with identical URDF
- Compare and analyze differences in behavior
Expected Outcome: Understanding of the differences between simulated and real robot behavior.
"Try This" Experiments
Experiment 1: URDF Parameterization
- Take an existing URDF and convert it to Xacro format
- Parameterize key dimensions and properties
- Create multiple variants by changing parameter values
- Test how parameter changes affect simulation behavior
- Consider how this approach could be used for robot families
Experiment 2: Calibration Validation
- Create a simple 2-DOF manipulator URDF
- Introduce small errors in link lengths or joint angles
- Compare forward kinematics results with ideal model
- Use inverse kinematics to see how errors propagate
- Consider how calibration could correct these errors
Experiment 3: Domain Randomization
- Create a parameterized URDF with variable friction coefficients
- Run the same simulation multiple times with different parameter values
- Observe how parameter variations affect robot behavior
- Consider how this approach could improve real-world performance
Real-World Connections
Industrial Applications
- Manufacturing: URDF enables offline programming and simulation of industrial robots
- Quality Control: Simulation helps verify robot programs before deployment
- Safety: Virtual testing ensures safe robot operation in complex environments
Research Applications
- Robot Learning: Simulation provides safe environment for learning algorithms
- Human-Robot Interaction: Virtual environments enable safe HRI research
- Multi-Robot Systems: Simulation allows testing of complex coordination algorithms
Service Robotics
- Navigation: URDF models help robots understand their physical constraints
- Manipulation: Accurate models enable precise object interaction
- Adaptation: Real-simulated mapping enables robots to adapt to new environments
Summary
URDF serves as the critical link between simulated and real robotic systems, enabling the development and testing of algorithms in virtual environments before deployment to physical robots. Creating accurate URDF models requires careful attention to physical measurements, dynamic properties, and hardware interfaces. The mapping process involves not just creating geometric models, but also capturing the dynamic and control characteristics that determine how robots actually behave. Through proper calibration, validation, and domain randomization techniques, developers can create simulation environments that closely match real-world behavior, enabling safer and more efficient robot development workflows.