ROS -- Create Basic URDF Model


Unified Robot Description Format (URDF)

URDF is an XML format for representing a robot model.

graph TD A[URDF] --> B[Link]; B --> C[Visual]; B --> D[Collision]; B --> E[Inertial]; A --> F[Joint]; A --> G[Material]; A --> H[Gazebo];

XACRO

Xacro (XML Macros) allows user to construct shorter, reusable and more readable XML files by using macros that expand to larger XML expressions.

Structure

robot.urdf

<?xml version="1.0" ?>
<robot name="my_robot" xmlns:xacro="http://www.ros.org/wiki/xacro">
  <link name="link_chassis">

    <pose>0 0 0.1 0 0 0</pose>

    <inertial>
      <mass value="5"/>
      <origin xyz="0 0 0.1" rpy="0 0 0"/>
      <inertia ixx="0.0395416666667" ixy="0" ixz="0" 
               iyy="0.106208333333" iyz="0"
               izz="0.106208333333"/>
    </inertial>
    
    <collision name="collision_chassis">
      <geometry>
        <box size="1 1 2"/>
      </geometry>
    </collision>

    <visual>
      <origin xyz="0 0 0.1" rpy="0 0 0"/>
      <geometry>
        <box size="1 1 2"/>
      </geometry>
    </visual>


  </link>
</robot>
    
spawn.launch

<?xml version="1.0" encoding="UTF-8"?>
<launch>
  <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find my_package)/urdf/robot.urdf'"/>
  
  <arg name="x" default="0"/>
  <arg name="y" default="0"/>
  <arg name="z" default="1.5"/>

  <node name="my_robot_spawn" pkg="gazebo_ros" type="spawn_model" output="screen"
        args="-urdf -param robot_description -model my_robot -x $(arg x) -y $(arg y) -z $(arg z)"/>

</launch>
    
rviz.launch

<?xml version="1.0"?>
<launch>

  <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find my_package)/urdf/robot.urdf'"/>

  <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher">
    <param name="use_gui" value="False"/>
  </node>

  <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher"/>

  <node name="rviz" pkg="rviz" type="rviz"/>

</launch>
    

Steps

  1. Start roscore.
  2. Create package in source folder of your workspace. catkin_create_pkg my_package urdf
  3. Create urdf and launch folders.
  4. Place the scripts above to the respective folders.
  5. Open gazebo. roslaunch gazebo_ros empty_world.launch
  6. Run spawn. roslaunch my_package spawn.launch
  7. Run rviz. roslaunch my_package rviz.launch
  8. In rviz UI, Add RobotModel and change the fixed frame as link_chassis.

References


  1. Youtube [Gazebo in 5 minutes] 008 - How to visualize a robot URDF using RVIZ
  2. urdf/Tutorials
  3. xacro Package Summary
  4. Creating and Spawning Custom URDF Objects in Simulation
  5. Adding Physical and Collision Properties to a URDF Model
  6. Make a Mobile Robot
  7. Add a Sensor to a Robot
  8. Youtube - [Exploring ROS using a 2 Wheeled Robot] #1: Basics of Robot Modeling using URDF
  9. ROS Answers -- Adding a camera to a model in Gazebo? (Beginner)