Performance: Xacro macros for URDF
This affects the robot model loading time and parsing speed in ROS visualization and simulation tools.
Jump into concepts and practice - no test required
<xacro:macro name="wheel" params="name"> <link name="${name}">...</link> </xacro:macro> <xacro:wheel name="wheel1"/> <xacro:wheel name="wheel2"/>
<link name="wheel1">...</link> <link name="wheel2">...</link> <link name="wheel3">...</link>
| Pattern | File Size | Parsing Time | Memory Usage | Verdict |
|---|---|---|---|---|
| Repeated XML blocks | Large | High | High | [X] Bad |
| Xacro macros reuse | Smaller | Lower | Lower | [OK] Good |
xacro:macro in a URDF file?xacro:macro doesxacro:macro lets you define a piece of robot description once and reuse it multiple times with different settings.wheel with a parameter radius in Xacro?<xacro:macro> tag and parameters are listed in the params attribute as a space-separated string.<xacro:macro name="wheel" params="radius">...</xacro:macro> correctly uses params="radius" inside <xacro:macro> tag.<xacro:macro name="link_with_length" params="length">
<link name="link_${length}">
<visual>
<geometry>
<box size="${length} 0.1 0.1"/>
</geometry>
</visual>
</link>
</xacro:macro>
<xacro:link_with_length length="2.0"/>${length} to insert the parameter value into the link name and box size.length="2.0", so link_${length} becomes link_2.0.<xacro:link_with_length length=""/>
length parameter?length="", which is empty and not a valid number.${length} for box size, so empty string leads to invalid or zero size, causing errors or unexpected behavior.