Introduction
Creating a URDF file for your robot is an essential step in allowing ROS to understand the structure of your robot. However, it's not enough to simply define the links and joints of your robot; you also need to add dimensions and sizes to the links to accurately represent your robot in simulation. In this article, we will cover how to add dimensions and sizes to your URDF links and view your robot in RViz.
Adding Dimensions and Positions to URDF Links
<robot name="my_robot">
<link name="base_link">
<visual>
<!-- Defining the position. !-->
<origin xyz="0.0 0.0 1.0" rpy="0.0 0.0 0.0" />
<!-- Defining the dimensions. !-->
<geometry>
<box size="0.45 0.78 2.0" />
</geometry>
</visual>
</link>
<link name="head">
<visual>
<!-- Defining the relative position from the joint. !-->
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
<!-- Defining the dimensions. !-->
<geometry>
<sphere radius="0.3" />
</geometry>
</visual>
</link>
<joint name="base_link_head_joint" type="fixed">
<parent link="base_link" />
<child link="head" />
<!-- Defining the position of the joint. !-->
<origin xyz="0.0 0.0 2.0" rpy="0.0 0.0 0.0" />
</joint>
</robot>
To add dimensions to your URDF links, you will need to edit the URDF file and include the appropriate measurements. To define the dimensions, the most common way to do this is to add a "visual" element to each link, and within that element, add a "geometry" element. The "geometry" element can be either a "box", "cylinder", "sphere", or "mesh" depending on the shape of the link.
You can add size of the each link in the same way.
In addition to adding dimensions and sizes, it is also important to define the positions of each link. This can be done using the "origin" tag within the "visual" elements of the URDF file. The "origin" tag allows you to specify the position and orientation of the link relative to its parent link.
The "xyz" attribute is used to specify the position of the link in the x, y, and z coordinates and the "rpy" attribute is used to specify the orientation of the link in roll, pitch, and yaw angles.
The official reference for the XML elements and attributes used in URDF can be found HERE.
Viewing Your Robot in RViz
Once you have added dimensions, sizes, and positions to your URDF links, you can view your robot in RViz. RViz is a 3D visualization tool that allows you to visualize your robot and test its movements in a virtual environment.
To view your robot in RViz, you will first need to load your URDF file into RViz by running the following command:
roslaunch urdf_tutorial display.launch model:=<path-to-urdf-file>
For example, "roslaunch urdf_tutorial display.launch model:=my_robot.urdf"
You should now see your robot displayed in RViz. You can use the RViz interface to move the robot and see its movements in the virtual environment.
Conclusion
Creating an accurate URDF file for your robot is essential for representing it in ROS. Adding dimensions and positions to your URDF links is an important step in creating an accurate representation of your robot in the simulation environment. With this knowledge, you can now create a more realistic and accurate simulation of your robot and test it in RViz. Using RViz, you can visualize your robot in a 3D environment, which can help you better understand how your robot will move and interact with its environment.