Skip to main content

URDF to SDF Conversion

Learning Objectives

After completing this chapter, you will be able to:

  • Convert URDF robot descriptions to SDF for Gazebo simulation
  • Add Gazebo-specific extensions to robot models
  • Configure physics properties for accurate simulation
  • Integrate sensors and actuators in simulated robots

Introduction

The conversion from URDF (Unified Robot Description Format) to SDF (Simulation Description Format) is a critical step in preparing robots for Gazebo simulation. While URDF is the standard format for describing robots in ROS, Gazebo operates with SDF, which includes additional elements and properties specifically designed for physics simulation and rendering. Understanding this conversion process is essential for creating accurate and functional robot simulations in the Physical AI & Humanoid Robotics pipeline.

The conversion process involves not just translating the kinematic structure but also adding simulation-specific elements like collision properties, friction parameters, and sensor configurations. For humanoid robots with complex kinematics, this process becomes even more important as their many degrees of freedom require careful physics modeling to ensure realistic behavior in simulation.

Core Concepts

URDF and SDF are both XML-based formats but serve different purposes. URDF focuses on the geometric and kinematic description of robots, while SDF extends this to include physics properties, visual effects, and simulation-specific elements. The conversion process typically involves:

URDF to SDF Translation

The basic elements of a robot (links, joints) translate directly from URDF to SDF. However, SDF requires additional information for simulation, such as material properties, friction coefficients, and collision parameters.

Gazebo-Specific Extensions

URDF supports Gazebo-specific extensions using the <gazebo> tag. These extensions allow you to add simulation-specific properties without changing the core URDF, which may be used by real hardware controllers as well.

Physics Configuration

For accurate simulation, physics properties like mass, inertia, friction, and damping must be properly defined. For humanoid robots, these properties are critical for achieving realistic movement patterns and ensuring stability during simulation.

Hands-on Examples

Let's demonstrate the URDF to SDF conversion process:

<?xml version="1.0"?>
<robot name="simple_humanoid">
<!-- Base link -->
<link name="base_link">
<visual>
<geometry>
<box size="0.2 0.1 0.2"/>
</geometry>
<material name="blue">
<color rgba="0 0 0.8 1"/>
</material>
</visual>
<collision>
<geometry>
<box size="0.2 0.1 0.2"/>
</geometry>
</collision>
<inertial>
<mass value="10"/>
<inertia ixx="0.1" ixy="0" ixz="0" iyy="0.1" iyz="0" izz="0.1"/>
</inertial>
</link>

<!-- Torso -->
<joint name="base_to_torso" type="fixed">
<parent link="base_link"/>
<child link="torso"/>
<origin xyz="0 0 0.15"/>
</joint>

<link name="torso">
<visual>
<geometry>
<box size="0.3 0.2 0.5"/>
</geometry>
<material name="grey">
<color rgba="0.5 0.5 0.5 1"/>
</material>
</visual>
<collision>
<geometry>
<box size="0.3 0.2 0.5"/>
</geometry>
</collision>
<inertial>
<mass value="15"/>
<inertia ixx="0.2" ixy="0" ixz="0" iyy="0.2" iyz="0" izz="0.2"/>
</inertial>
</link>

<!-- Example leg joint -->
<joint name="torso_to_hip" type="revolute">
<parent link="torso"/>
<child link="left_hip"/>
<origin xyz="-0.1 0.0 -0.25"/>
<axis xyz="0 0 1"/>
<limit lower="-1.57" upper="1.57" effort="100" velocity="1"/>
<dynamics damping="1.0" friction="0.1"/>
</joint>

<link name="left_hip">
<visual>
<geometry>
<cylinder radius="0.05" length="0.15"/>
</geometry>
<material name="red">
<color rgba="0.8 0 0 1"/>
</material>
</visual>
<collision>
<geometry>
<cylinder radius="0.05" length="0.15"/>
</geometry>
</collision>
<inertial>
<mass value="3"/>
<inertia ixx="0.01" ixy="0" ixz="0" iyy="0.01" iyz="0" izz="0.01"/>
</inertial>
</link>

<!-- Gazebo-specific extensions -->
<gazebo reference="base_link">
<material>Gazebo/Blue</material>
</gazebo>

<gazebo reference="torso">
<material>Gazebo/Grey</material>
</gazebo>

<gazebo reference="left_hip">
<material>Gazebo/Red</material>
</gazebo>

<!-- Gazebo controller plugin -->
<gazebo>
<plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
<robotNamespace>/simple_humanoid</robotNamespace>
</plugin>
</gazebo>
</robot>

Expected Output:

Converted robot.urdf to robot.sdf

Exercises

Complete the following exercises to reinforce your understanding:

  1. Complete Robot Model: Convert a full humanoid robot URDF to SDF

    • Extend the example to include all humanoid joints (arms, legs, head)
    • Add appropriate physical properties for each link
    • Validate that the converted SDF works in Gazebo
    • Test that the robot maintains its kinematic structure
  2. Sensor Integration: Add simulated sensors to the converted robot

    • Add camera sensors to the robot's head
    • Include IMU sensors on the torso
    • Add contact sensors to feet for balance control
    • Verify that sensor data is published correctly in ROS 2

Common Pitfalls and Solutions

  • Pitfall 1: Incorrect mass properties - Using unrealistic mass or inertia values
    • Solution: Calculate values based on CAD models or estimate based on volume and material density
  • Pitfall 2: Missing collision geometry - Links without collision elements causing physics errors
    • Solution: Ensure every visual element has a corresponding collision element
  • Pitfall 3: Joint limit mismatches - Joint limits in URDF not matching SDF
    • Solution: Carefully convert all joint limits and safety margins
  • Pitfall 4: Controller plugin issues - ROS control not working in simulation
    • Solution: Verify plugin configuration and namespace matches ROS nodes

Summary

  • URDF to SDF conversion is essential for Gazebo simulation
  • Gazebo extensions in URDF allow simulation-specific properties
  • Physics properties must be carefully defined for realistic behavior
  • Conversion scripts can automate the process for standard robots
  • Validation is critical to ensure proper simulation behavior

Further Reading