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:
<box size="0.6 0.4 0.2" /> This line specifies the box size in meters. 0.6, 0.4, and 0.2 are the dimensions on the x, y, and z axes respectively.<origin xyz="0 0 0.1" rpy="0 0 0" /> This specifies the position and orientation of the visual geometry relative to the link's frame.Position (xyz):
xyz="0 0 0.1":
This means the center of the box (visual geometry) is located at:
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):
rpy="0 0 0":
This specifies the rotation of the visual geometry using roll, pitch, and yaw angles (in radians):
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