Reference: http://wiki.ros.org/xacro
<aside> 💡 Xacro (XML Macros) Xacro is an XML macro language. With xacro, you can construct shorter and more readable XML files by using macros that expand to larger XML expressions
</aside>
URDF 작성시 대부분 링크, 조인트, 링크, 조인트 등의 반복입니다. 또 로봇의 생김새에 따라 좌우 대칭인 경우도 있고, 수치를 그때그때 변경해줘야 하는 경우도 있습니다. 해당 수치들이 어나 하나의 변수에 연동해서 변경되는 경우도 있고요.
Property and Property Blocks
<xacro:property name="the_radius" value="2.1" />
<xacro:property name="the_length" value="4.5" />
<geometry type="cylinder" radius="${the_radius}" length="${the_length}" />
<xacro:property name="front_left_origin">
<origin xyz="0.3 0 0" rpy="0 0 0" />
</xacro:property>
<pr2_wheel name="front_left_wheel">
<xacro:insert_block name="front_left_origin" />
</pr2_wheel>
Conditional Blocks
<xacro:property name="var" value="useit"/>
<xacro:if value="${var == 'useit'}"/>
<xacro:if value="${var.startswith('use') and var.endswith('it')}"/>
<xacro:property name="allowed" value="${[1,2,3]}"/>
<xacro:if value="${1 in allowed}"/>
Including other xacro files
<xacro:include filename="$(find package)/other_file.xacro" />
<xacro:include filename="other_file.xacro" />
<xacro:include filename="$(cwd)/other_file.xacro" />
Math expressions
<xacro:property name="radius" value="4.3" />
<circle diameter="${2 * radius}" />
Macros
<xacro:macro name="pr2_caster" params="suffix *origin **content **anothercontent">
<joint name="caster_${suffix}_joint">
<axis xyz="0 0 1" />
</joint>
<link name="caster_${suffix}">
<xacro:insert_block name="origin" />
<xacro:insert_block name="content" />
<xacro:insert_block name="anothercontent" />
</link>
</xacro:macro>
<xacro:pr2_caster suffix="front_left">
<pose xyz="0 1 0" rpy="0 0 0" />
<container>
<color name="yellow"/>
<mass>0.1</mass>
</container>
<another>
<inertial>
<origin xyz="0 0 0.5" rpy="0 0 0"/>
<mass value="1"/>
<inertia ixx="100" ixy="0" ixz="0" iyy="100" iyz="0" izz="100" />
</inertial>
</another>
</xacro:pr2_caster>