$\color{white}\colorbox{FE9227}{Building a solid foundation and deepening understanding!}$

$$▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░ 42.9%


Using the XACRO package can make life much easier when writing your robot urdfs. To use XACRO, you would replace your main robot urdf file with a xacro file, and then include secondary XACRO files that would describe different aspects of your robot. Let's look at some key features and attributes of a XACRO file.

Table of Contents

1. Initializing XACRO file

To initialize your XACRO file, you first need to declare the syntax language of the file, include the XACRO repository, and declare your robot namespace. This is done within the first lines of your robot.xacro file.

<?xml version="1.0"?>
<robot xmlns:xacro="<http://www.ros.org/wiki/xacro>" name="robot" >

<!--- DESCRIPTIONS -->

</robot>

Next, we are going to cover some of the key XACRO attributes.

2. Properties

Setting properties is a lot like declaring a variable in a script. This allows you to give a numerical or mathematical value to a string and then call on that string later to populate urdf tags. There are two types of values you can give to a xacro:property: a Constant or a Math.

a. Constant

For this example, let’s look at a simple base_link with some visual and collision geometry.

	<link name="base_link">
    <visual>
      <geometry>
        <cylinder length="0.6" radius="0.2"/>
      </geometry>
      <material name="blue"/>
    </visual>
    <collision>
      <geometry>
        <cylinder length="0.6" radius="0.2"/>
      </geometry>
    </collision>
  </link>

It’s clear that there is some redundant information present here. The cylinder tag has its length and radius defined with the same values twice. Not only is this redundant information, but if you wanted to change the size of the cylinder, you would have to change it in two different places.

Using XACRO, you can specify constants outside of your link definitions and then call on them within the tags. This allows you to only have to change values in one place if you wanted to alter the geometry of the link.

<xacro:property name="width" value="0.2" />
<xacro:property name="bodylen" value="0.6" />
<link name="base_link">
    <visual>
        <geometry>
            <cylinder radius="${width}" length="${bodylen}"/>
        </geometry>
        <material name="blue"/>
    </visual>
    <collision>
        <geometry>
            <cylinder radius="${width}" length="${bodylen}"/>
        </geometry>
    </collision>
</link>

To call on properties within links, use the ${} syntax, where any value within the curly brackets ‘ {} ’ will be replaced with their value. Because only the value within the curly brackets are replaced, you can combine those values with other text to create an attribute.

<xacro:property name="robotname" value="marvin" />
<link name="${robotname}s_leg" />

This will generate: