To create a URDF file follow the below command:

touch my_robot.urdf

Now we will just create a base link for our robot. We will start by creating a box.

This is the URDF file for the box:

<?xml version="1.0"?>
<robot name="my_robot">
    <link name="base_link">
        <visual>
            <geometry>
                <box size="0.6 0.4 0.2" />
            </geometry>
            <origin xyz="0 0 0.1" rpy="0 0 0" />
        </visual>
    </link>
</robot>

Explanation of the code:

Position (xyz):

In this case, the geometry is raised by 0.1 meters above the link's local origin, ensuring the box isn't placed directly on the ground but is instead centered slightly above the link's origin.

If z = 0 meters, the box would appear below the ground in the RViz simulation. Therefore, it is considered best practice to set the z-axis value to half of the box's height to ensure it rests on the ground properly.

Orientation (rpy):


Launch The URDF File

To launch the URDF file follow the below command in the terminal:

ros2 launch urdf_tutorial display.launch.py model:=/home/sahel/my_robot.urdf