- http://wiki.ros.org/xacro
- http://wiki.ros.org/urdf/Tutorials/Using%20Xacro%20to%20Clean%20Up%20a%20URDF%20File
- Frames of Reference, Links Configuration and Appearance
-
Properties act like constants, they are global in your xacro file (they're
also (most likely, haven't tested) seen by the xacro files that you include in
this
xacrofile - They can be defined before or after the point they're used.
- Properties are local if defined inside of a xacro:macro
<xacro:property name="width" value="0.2" />
<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>
We first define a macro, then call it
<xacro:macro name="default_origin">
<origin xyz="0 0 0" rpy="0 0 0"/>
</xacro:macro>
<xacro:default_origin />
This will generate: <origin rpy="0 0 0" xyz="0 0 0"/>
If the xacro with a specified name is not found, it will not be expanded and
will NOT generate an error.
wtf?
<xacro:macro name="default_inertial" params="mass">
<inertial>
<mass value="${mass}" />
<inertia ixx="1.0" ixy="0.0" ixz="0.0"
iyy="1.0" iyz="0.0"
izz="1.0" />
</inertial>
</xacro:macro>
Then call it like this:
<xacro:default_inertial mass="10"/>
For block parameters of a xacro macro, prefix with an asterisk, *.
<xacro:macro name="blue_shape" params="name *shape">
<link name="${name}">
<visual>
<geometry>
<xacro:insert_block name="shape" />
</geometry>
<material name="blue"/>
</visual>
<collision>
<geometry>
<xacro:insert_block name="shape" />
</geometry>
</collision>
</link>
</xacro:macro>
Then call it like:
<xacro:blue_shape name="base_link">
<cylinder radius=".42" length=".01" />
</xacro:blue_shape>
<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>
- Multiple blocks will be processed in the specified order
<xacro:macro name="pr2_arm" params="suffix parent reflect">
<pr2_upperarm suffix="${suffix}" reflect="${reflect}" parent="${parent}" />
<pr2_forearm suffix="${suffix}" reflect="${reflect}" parent="elbow_flex_${suffix}" />
</xacro:macro>
<xacro:pr2_arm suffix="left" reflect="1" parent="torso" />
<xacro:pr2_arm suffix="right" reflect="-1" parent="torso" />
-
Failed to find root link: Two root links found
- Each URDF / Xacro file must have a single root link
-
A root link is denoted as
<link name="base_footprint"/>