Skip to main content

Gazebo

URDF, XACRO, and SDF in Gazebo: Core Robot Modeling Formats

1. URDF (Unified Robot Description Format):

Definition: URDF is an XML format used in ROS (Robot Operating System) to describe the three-dimensional structure, joint connections, and kinematic characteristics of a robot. It was developed by the ROS community and is widely used in robot simulation and control.

Core components and application
  1. Key Elements
    • Link: defines the rigid components of the robot, including geometric shape (such as box, cylinder, mesh), mass, inertia matrix and other physical properties.
    • Joint: Connects two links, supports revolute, prismatic, fixed and other motion types, and can set the range of motion and dynamic parameters.
    • Visual model: describes the appearance of the connecting rod and is used for simulation visualization.
    • Collision (collision model): defines the collision shape of the connecting rod for physics engine calculation.
  2. Example snippet
<robot name="my_robot">
<link name="base_link">
<inertial>
<mass value="1.0"/>
<!-- 惯性矩阵省略 -->
</inertial>
<visual>
<geometry><box size="0.2 0.2 0.1"/></geometry>
</visual>
<collision>
<geometry><box size="0.2 0.2 0.1"/></geometry>
</collision>
</link>
<joint name="base_to_wheel" type="revolute">
<parent link="base_link"/>
<child link="wheel_link"/>
<axis xyz="0 1 0"/>
</joint>
</robot>
  1. Advantages and Disadvantages
    • Advantages: Simple structure, deep integration with the ROS ecosystem, suitable for describing the kinematic model of rigid robots.
    • Disadvantages: Lack of description of simulation environment elements such as sensors and lights, and cumbersome writing of complex models.

2. XACRO (XML Macro): Advanced Extension

Definition: XACRO is a macro language based on URDF. It simplifies the writing of complex robot models through variable definition, parametric modeling and module reuse. It is essentially a preprocessing format of URDF.

Core Features and
  1. Key Features
    • Variables and parameterization: <property> Define <param> reusable values (such as length and mass) to avoid repetitive writing.
    • Macro definition: Encapsulate repeated modules as macros, such as defining a wheel model and instantiating it multiple times:
      <macro name="wheel" params="name xyz rpy">
      <!-- 轮子模型定义 -->
      </macro>
      <wheel name="left_wheel" xyz="0.1 0.05 0" rpy="0 0 0"/>
    • Conditional compilation: <if> <else> Dynamically generates models based on parameters, suitable for multi-version robot configuration.
  2. Advantages
    • Code reuse: Reduce duplication of code. For example, the four legs of a quadruped robot can be instantiated through macros, and only the parameters need to be modified.
    • Maintainability: Centrally manage global parameters (such as robot height and joint limits), and modify one place to apply to the entire model.

3. SDF (Simulation Description Format): Gazebo’s proprietary simulation

Definition: SDF is the scene description format used by the Gazebo physics engine. It supports the complete definition of robot models, environmental elements (such as terrain, light sources), sensors, and physical rules. It was developed by Open Robotics.

Core components and Gazebo
  1. Key Elements (Compared to URDF)
    • World: Contains multiple models, physics engine configuration (such as gravity, friction coefficient), and environmental properties (such as skybox and wind speed).
    • Model: It can contain multiple Links and Joints. It is similar to the URDF structure, but extends sensors (such as Camera, LiDAR) and dynamic properties (such as joint motor control parameters).
    • Plugin: Extend functions through C++/Python plug-ins, such as defining joint controllers and sensor data output interfaces.
  2. Relationship between SDF and URDF
    • Compatibility and extension: SDF can directly import URDF models, but the sensor and physics engine parameters that URDF lacks need to be supplemented in SDF.
    • Example comparison: URDF defines the robot structure, and SDF adds Gazebo-specific simulation parameters (such as joint damping and sensor noise model) on this basis.
  3. Typical structure
<sdf version="1.9">
<world name="default">
<include>
<uri>model://my_robot</uri> <!-- 引用机器人模型 -->
</include>
<physics name="default_physics">
<gravity>0 0 -9.81</gravity>
<ode>
<solver>
<type>quick</type>
</solver>
</ode>
</physics>
<model name="my_robot">
<!-- 机器人Link和Joint定义,类似URDF -->
<sensor name="camera_sensor" type="camera">
<pose>0 0 0.5 0 0 0</pose>
<camera>
<horizontal_fov>1.57</horizontal_fov>
<image>
<width>640</width>
<height>480</height>
</image>
</camera>
</sensor>
</model>
</world>
</sdf>

4.

FormatCore FeaturesApplicable ScenariosRelationship with Gazebo
URDFRobot kinematics and structural descriptionROS robot control and motion planningCan be imported into Gazebo, but lacks simulation details
BREAKING NEWSURDF parameterization and modularization toolsComplex robot model development and multi-version configurationPreprocess to URDF and import into Gazebo
SDFComplete simulation scene description (including physics engine parameters)Gazebo simulation, sensor simulation, and environment constructionGazebo native support, recommended for simulation

5. Practical Application Process (Taking Gazebo Simulation as an Example

  1. Use XACRO to write parameterized URDF models to define the robot structure (such as robotic arm links and joints).
  2. Generate standard URDF through XACRO preprocessing, or directly reference URDF model in SDF.
  3. Add Gazebo-specific elements to SDF:
    • Physics engine configuration (such as ODE, Bullet), sensor model (such as lidar, IMU).
    • Add environment models (such as ground, obstacles) and plugins (such as joint position controllers).
  4. Start Gazebo and load the SDF file to realize the physical simulation and interaction of the robot in the virtual environment.

6.

By flexibly combining URDF, XACRO, and SDF, you can efficiently build simple to complex robot simulation systems to meet the needs of scientific research, education, and engineering development.