Introduction

URDF file

URDF, or Unified Robot Description Format, is an XML file format used in ROS to describe the physical structure of a robot, including its links, joints, and sensors. URDF files are used by ROS to understand the structure of a robot and its movements, allowing ROS to control and visualize the robot. In this article, we will cover the basics of URDF files and how to define a robot model using an URDF file.

Create a new package

Create a new ROS package that depends on rviz, urdf, xacro, sensor_msgs, and geometry_msgs.

cd ~/blog_ws/src
catkin_create_pkg my_robot rviz urdf xacro sensor_msgs geometry_msgs
cd my_robot
mkdir urdf
gedit urdf/<filename>.urdf

Save your URDF file inside urdf subdirectory. Yon can name the subdirectory as you want. The path should be like this: '~/workspace_name/src/package_name/urdf/filename.urdf'

How to define a robot model using an URDF file

Defining a robot model using an URDF file involves creating an XML file that describes the robot's structure, including its links, joints, and sensors. It is important to have a good understanding of the structure of your robot, including the link and joint relationships, to create an accurate URDF file.

Here is an example of a simple URDF file for a robot with two links (base_link and end_effector) and one joint (joint1) connecting them:

<?xml version="1.0"?>
<robot name="my_robot">
  <link name="base_link"/>
  <link name="head"/>
  <joint name="base_link_head_joint" type="fixed">
    <parent link="base_link"/>
    <child link="head"/>
  </joint>
</robot>

In this example, the URDF file defines a robot with two links, "base_link" and "end_effector", and one joint, "joint1". The joint is defined as a continuous joint, meaning that it can rotate indefinitely. The parent link is set as "base_link" and the child link is set as "end_effector", connecting the two links together.

Once you have created the URDF file, you can validate it by running the command:

check_urdf <path-to-urdf-file>

This command will check for the consistency and the errors in your URDF file and if there are no errors, you are good to go. If check_urdf is not installed, use the following command to install it.

sudo apt install liburdfdom-dev liburdfdom-tools ros-noetic-urdfdom-py

Conclusion

URDF files are an essential part of ROS, as they allow ROS to understand the structure of a robot and its movements. By understanding how to define a robot model using an URDF file, you will be able to more effectively work with ROS and control and visualize your robot.

Check my next article about customizing and visualizing your robot HERE.