Skip to main content

URDF and SDF: Bridging Robot Description and Simulation

Overview​

In the previous sections, we learned about digital twins and setting up physics simulation with Gazebo. Now, we'll dive deeper into the core technologies that describe and simulate robots: URDF (Unified Robot Description Format) for general robot description and SDF (Simulation Description Format) for simulation-specific details.

This chapter will provide a comprehensive understanding of how these formats work together to create accurate robot simulations that can be used for development, testing, and validation before deploying to physical robots.

Learning Objectives​

After completing this chapter, you will be able to:

  1. Explain the differences and relationships between URDF and SDF
  2. Create and modify URDF files to describe robot kinematics and dynamics
  3. Understand SDF extensions and how they enhance simulation capabilities
  4. Convert between URDF and SDF formats for different use cases
  5. Implement sensor configurations in both formats for accurate simulation

URDF: The Robot Description Foundation​

What is URDF?​

URDF (Unified Robot Description Format) is an XML-based format used to describe robots in ROS. It defines the physical properties of robots, including:

  • Links (rigid bodies)
  • Joints (constraints between links)
  • Visual and collision properties
  • Inertial properties
  • Sensors and actuators

Basic URDF Structure​

A typical URDF file follows this structure:

<?xml version="1.0"?>
<robot name="robot_name">
<!-- Links define rigid bodies -->
<link name="base_link">
<visual>
<geometry>
<cylinder length="0.6" radius="0.2"/>
</geometry>
<material name="blue">
<color rgba="0 0 0.8 1"/>
</material>
</visual>
<collision>
<geometry>
<cylinder length="0.6" radius="0.2"/>
</geometry>
</collision>
<inertial>
<mass value="10"/>
<inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>
</inertial>
</link>

<!-- Joints define constraints between links -->
<joint name="base_to_wheel" type="continuous">
<parent link="base_link"/>
<child link="wheel_link"/>
<origin xyz="0 0.5 0" rpy="0 0 0"/>
<axis xyz="0 1 0"/>
</joint>

<link name="wheel_link">
<visual>
<geometry>
<cylinder length="0.1" radius="0.3"/>
</geometry>
<material name="black">
<color rgba="0 0 0 1"/>
</material>
</visual>
</link>
</robot>

Key URDF Elements​

  1. Links: Represent rigid bodies of the robot

    • Visual: Defines how the link appears visually
    • Collision: Defines collision detection properties
    • Inertial: Defines mass and inertia properties
  2. Joints: Define kinematic and dynamic relationships between links

    • Fixed: No relative motion between parent and child
    • Revolute: Single-axis rotation joint with limits
    • Continuous: Single-axis rotation joint without limits
    • Prismatic: Single-axis sliding joint with limits
    • Floating: No constraints between parent and child
    • Planar: Motion limited to a plane

SDF: Simulation-Specific Details​

What is SDF?​

SDF (Simulation Description Format) is also an XML-based format, but specifically designed for simulation environments like Gazebo. It provides additional capabilities beyond URDF:

  • Physics engine properties
  • Sensor models and plugins
  • Controller configurations
  • Simulation-specific parameters
  • World environment descriptions

Basic SDF Structure​

An SDF file structure looks like this:

<sdf version="1.7">
<world name="default">
<light name="sun" type="directional">
<cast_shadows>true</cast_shadows>
<pose>0 0 10 0 0 0</pose>
<diffuse>0.8 0.8 0.8 1</diffuse>
<specular>0.2 0.2 0.2 1</specular>
<attenuation>
<range>1000</range>
<constant>0.9</constant>
<linear>0.01</linear>
<quadratic>0.001</quadratic>
</attenuation>
<direction>-0.0 0.0 -1</direction>
</light>

<model name="my_robot">
<link name="chassis">
<pose>0 0 0.1 0 0 0</pose>
<collision name="collision">
<geometry>
<box>
<size>1.0 0.5 0.2</size>
</box>
</geometry>
</collision>
<visual name="visual">
<geometry>
<box>
<size>1.0 0.5 0.2</size>
</box>
</geometry>
</visual>
<inertial>
<mass>1.0</mass>
<inertia>
<ixx>1.0</ixx>
<ixy>0.0</ixy>
<ixz>0.0</ixz>
<iyy>1.0</iyy>
<iyz>0.0</iyz>
<izz>1.0</izz>
</inertia>
</inertial>
</link>
</model>

<gravity>0 0 -9.8</gravity>
<magnetic_field>6e-06 2.3e-05 -4.2e-05</magnetic_field>
<atmosphere type="adiabatic"/>
<physics type="ode">
<max_step_size>0.001</max_step_size>
<real_time_factor>1</real_time_factor>
<real_time_update_rate>1000</real_time_update_rate>
</physics>
</world>
</sdf>

URDF to SDF Conversion​

Gazebo uses SDF internally, so when you load a URDF file into Gazebo, it's automatically converted to SDF. However, this conversion has limitations, and for complex simulations, you might need to create native SDF files.

Gazebo-specific URDF Extensions​

You can add Gazebo-specific elements to your URDF files using the <gazebo> tag:

<link name="sensor_link">
<visual>
<geometry>
<box size="0.1 0.1 0.1"/>
</geometry>
</visual>
</link>

<gazebo reference="sensor_link">
<sensor type="camera" name="camera1">
<update_rate>30.0</update_rate>
<camera name="head">
<horizontal_fov>1.3962634</horizontal_fov>
<image>
<width>800</width>
<height>600</height>
<format>R8G8B8</format>
</image>
<clip>
<near>0.02</near>
<far>300</far>
</clip>
</camera>
<plugin name="camera_controller" filename="libgazebo_ros_camera.so">
<camera_name>my_camera</camera_name>
<image_topic_name>image_raw</image_topic_name>
<camera_info_topic_name>camera_info</camera_info_topic_name>
<frame_name>camera_frame</frame_name>
</plugin>
</sensor>
</gazebo>

Advanced Simulation Features with SDF​

Physics Properties​

SDF allows you to fine-tune physics properties at a granular level:

<model name="robot_with_custom_physics">
<link name="custom_link">
<collision name="collision">
<geometry>
<box>
<size>1.0 1.0 1.0</size>
</box>
</geometry>
<!-- Custom surface properties -->
<surface>
<friction>
<ode>
<mu>1.0</mu>
<mu2>1.0</mu2>
</ode>
</friction>
<contact>
<ode>
<kp>1e+16</kp>
<kd>1e+13</kd>
</ode>
</contact>
</surface>
</collision>
</link>
</model>

Sensor Models​

SDF provides more detailed control over sensor models than URDF extensions:

<model name="sensor_mount">
<link name="lidar_link">
<visual>
<geometry>
<cylinder radius="0.05" length="0.1"/>
</geometry>
</visual>
<collision>
<geometry>
<cylinder radius="0.05" length="0.1"/>
</geometry>
</collision>
</link>

<sensor name="3d_lidar" type="ray">
<pose>0 0 0 0 0 0</pose>
<ray>
<scan>
<horizontal>
<samples>640</samples>
<resolution>1</resolution>
<min_angle>-1.396263</min_angle>
<max_angle>1.396263</max_angle>
</horizontal>
<vertical>
<samples>16</samples>
<resolution>1</resolution>
<min_angle>-0.349066</min_angle>
<max_angle>0.349066</max_angle>
</vertical>
</scan>
<range>
<min>0.08</min>
<max>10.0</max>
<resolution>0.01</resolution>
</range>
</ray>
<plugin name="lidar_controller" filename="libgazebo_ros_laser.so">
<topic_name>scan</topic_name>
<frame_name>lidar_link</frame_name>
</plugin>
</sensor>
</model>

Hands-on Lab: Creating a Robot Model with Sensors​

In this lab, you will create a simple wheeled robot model that includes both URDF elements and Gazebo-specific extensions for simulation.

Step 1: Create the Basic URDF Robot Description​

Create a file simple_robot.urdf in your models directory:

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

<!-- Left wheel -->
<link name="left_wheel">
<visual>
<geometry>
<cylinder length="0.05" radius="0.1"/>
</geometry>
<material name="black">
<color rgba="0 0 0 1"/>
</material>
</visual>
<collision>
<geometry>
<cylinder length="0.05" radius="0.1"/>
</geometry>
</collision>
<inertial>
<mass value="1"/>
<inertia ixx="0.1" ixy="0.0" ixz="0.0" iyy="0.1" iyz="0.0" izz="0.1"/>
</inertial>
</link>

<!-- Right wheel -->
<link name="right_wheel">
<visual>
<geometry>
<cylinder length="0.05" radius="0.1"/>
</geometry>
<material name="black">
<color rgba="0 0 0 1"/>
</material>
</visual>
<collision>
<geometry>
<cylinder length="0.05" radius="0.1"/>
</geometry>
</collision>
<inertial>
<mass value="1"/>
<inertia ixx="0.1" ixy="0.0" ixz="0.0" iyy="0.1" iyz="0.0" izz="0.1"/>
</inertial>
</link>

<!-- Joints -->
<joint name="left_wheel_joint" type="continuous">
<parent link="base_link"/>
<child link="left_wheel"/>
<origin xyz="0 0.2 0" rpy="1.5708 0 0"/>
<axis xyz="0 0 1"/>
</joint>

<joint name="right_wheel_joint" type="continuous">
<parent link="base_link"/>
<child link="right_wheel"/>
<origin xyz="0 -0.2 0" rpy="1.5708 0 0"/>
<axis xyz="0 0 1"/>
</joint>
</robot>

Step 2: Add Gazebo-Specific Elements​

Add Gazebo plugins and sensors to make the robot functional in simulation:

<!-- Add these Gazebo-specific elements to your URDF -->

<gazebo reference="base_link">
<material>Gazebo/Blue</material>
</gazebo>

<gazebo reference="left_wheel">
<material>Gazebo/Black</material>
</gazebo>

<gazebo reference="right_wheel">
<material>Gazebo/Black</material>
</gazebo>

<!-- Differential drive plugin -->
<gazebo>
<plugin name="differential_drive_controller" filename="libgazebo_ros_diff_drive.so">
<ros>
<namespace>/simple_robot</namespace>
<remapping>cmd_vel:=cmd_vel</remapping>
<remapping>odom:=odom</remapping>
</ros>
<update_rate>30</update_rate>
<left_joint>left_wheel_joint</left_joint>
<right_joint>right_wheel_joint</right_joint>
<wheel_separation>0.4</wheel_separation>
<wheel_diameter>0.2</wheel_diameter>
<max_wheel_torque>20</max_wheel_torque>
<max_wheel_acceleration>1.0</max_wheel_acceleration>
<command_topic>cmd_vel</command_topic>
<odometry_topic>odom</odometry_topic>
<odometry_frame>odom</odometry_frame>
<robot_base_frame>base_link</robot_base_frame>
<publish_odom>true</publish_odom>
<publish_odom_tf>true</publish_odom_tf>
<publish_wheel_tf>true</publish_wheel_tf>
</plugin>
</gazebo>

Step 3: Test the Model in Gazebo​

  1. Launch Gazebo:

    gazebo --verbose
  2. Load your model into Gazebo either through the GUI or using a launch file.

  3. Verify that the robot appears correctly with appropriate colors and can move with the differential drive controller.

Troubleshooting Notes​

  1. Model not appearing in Gazebo: Check that the URDF file is properly loaded and all paths to visual meshes are correct.

  2. Joints not moving: Verify that joint types match your intentions and that controllers are properly configured.

  3. Physics issues: Adjust mass and inertia properties to match real-world values for more accurate simulation.

  4. Plugin errors: Check Gazebo plugin names and parameters match your version of Gazebo and ROS.

Summary​

In this chapter, we've explored the fundamental formats used to describe robots in ROS and Gazebo: URDF for general robot description and SDF for simulation-specific details. We've learned how to create robot models that work effectively in simulation, including how to add sensors and custom physics properties.

Next Steps​

The next chapter will cover sensor simulation in detail, exploring how different types of sensors (LiDAR, cameras, IMUs) can be accurately simulated in Gazebo to provide realistic sensor data for your humanoid robot applications.

References​

  1. ROS URDF Documentation: http://wiki.ros.org/urdf
  2. Gazebo SDF Documentation: http://sdformat.org/
  3. Robot Modeling with URDF Tutorial: http://wiki.ros.org/urdf/Tutorials
  4. Gazebo Robot Simulation: http://gazebosim.org/tutorials?cat=build_robot