Using xacro for robot description does not work
Hi, I defined a model using the urdf and everything works fine. However, when I replace one of the links with a macro, the link is not built to form the tree.
the xacro file: links_joints.xacro`
<?xml version="1.0" ?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
<xacro:macro name="m_link_box" params="name origin_xyz origin_rpy size">
<link name="${name}">
<!--<inertial>
<mass value="${mass}" />
<origin rpy="${origin_rpy}" xyz="${origin_xyz}" />
<inertia ixx="${ixx}" ixy="${ixy}" ixz="${ixz}" iyy="${iyy}" iyz="${iyz}" izz="${izz}" />
</inertial>
<collision>
<origin rpy="${origin_rpy}" xyz="${origin_xyz}" />
<geometry>
<box size="${size}" />
</geometry>
</collision>-->
<visual>
<origin rpy="${origin_rpy}" xyz="${origin_xyz}" />
<geometry>
<box size="${size}" />
</geometry>
</visual>
</link>
</xacro:macro>
</robot>
`
Using this file works: mrm.xacro`
<?xml version="1.0"?>
<robot name="mrm" xmlns:xacro="https://www.ros.org/wiki/xacro">
<xacro:include filename="$(find mrm_description)/urdf/links_joints.xacro" />
<link name="base_link">
<visual>
<origin rpy="0 0 0" xyz="0 0 0 "/>
<geometry>
<box size="1 1 1"/>
</geometry>
</visual>
</link>
<joint name="base_link__link_01" type="revolute">
<axis xyz="0 0 1"/>
<limit effort="0.0" lower="-3.14" upper="3.14" velocity="0.5"/>
<origin rpy="0 0 0" xyz="0 0 0.5"/>
<parent link="base_link"/>
<child link="link_01"/>
</joint>
<link name="link_01">
<visual>
<origin rpy="0 0 0" xyz="0 0 0.2 "/>
<geometry>
<cylinder radius="0.35" length="0.4" />
</geometry>
</visual>
</link>
</robot>
`
But replacing first link with the macro fails to build the tree: `
<?xml version="1.0"?>
<robot name="mrm" xmlns:xacro="https://www.ros.org/wiki/xacro">
<xacro:include filename="$(find mrm_description)/urdf/links_joints.xacro" />
<m_link_box name="base_link"
origin_rpy="0 0 0" origin_xyz="0 0 0"
size="1 1 1" />
<joint name="base_link__link_01" type="revolute">
<axis xyz="0 0 1"/>
<limit effort="0.0" lower="-3.14" upper="3.14" velocity="0.5"/>
<origin rpy="0 0 0" xyz="0 0 0.5"/>
<parent link="base_link"/>
<child link="link_01"/>
</joint>
<link name="link_01">
<visual>
<origin rpy="0 0 0" xyz="0 0 0.2 "/>
<geometry>
<cylinder radius="0.35" length="0.4" />
</geometry>
</visual>
</link>
</robot>
`
I am using rviz to visualize the urdf. The error says "Failed to parse URDF". Any help would be appreciated. Thanks
Use
check_urdf <urdf file name>
to check for errors first.Check this tutorial and one observation there are less chances to have errors if you use the open and close tags, as it make it easier to find if something is missing.
In the first example that 'works' you are not using macro, the xacro:include even if it doesn't work it's not being used.