Introduction to xacro
The first challenge is model description. ROS2 and Ignition Gazebo use different formats for robot description. ROS2 uses URDF and Gazebo uses SDF. Many solutions exist to deal with this issue. One can keep both URDF and SDF files at cost of maintaining two different files that need to be in sync. If we modify one of the files, the other one needs to be updated accordingly. Another approach is to use conversion tools. However, this dependency on external tools can be a blocker when we run into corner cases which are not covered by the tools.
In this tutorial, we will show how to leverage xacro to generate both URDF and SDF files from a single source.
We will walk you through how to create xacro file to describe our robot.
First, create the name space and give our robot a name.
For this source file is used to generate two different files, we need a way to distinguish the two cases. This can be achieved by introducing a sim_gazebo
flag:
Let's add a link. A typical link definition in URDF files looks similar to the one below:
And a typical link definition in SDF looks like the following:
It's unfortunate that the syntax is similar but not exactly the same. To deal with different format, we will parameterize these blocks and leverage the macro.
Last updated