Ask Your Question
0

Using xacro for robot description does not work

asked 2021-10-16 15:54:01 -0600

nj08 gravatar image

updated 2021-10-16 16:00:17 -0600

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

edit retag flag offensive close merge delete

Comments

Use check_urdf <urdf file name> to check for errors first.

osilva gravatar image osilva  ( 2021-10-16 16:47:59 -0600 )edit

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.

osilva gravatar image osilva  ( 2021-10-16 16:52:43 -0600 )edit

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.

osilva gravatar image osilva  ( 2021-10-16 16:56:21 -0600 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2021-10-17 09:31:42 -0600

Mike Scheutzow gravatar image

I think the parsing issue is that you have no whitespace around your open and close xml comment tags.

Separate from the above, the modern syntax to create an instance of a macro is <xacro:m_link_box name=...>, but for backward compatibiiity the older style is still supported.

edit flag offensive delete link more

Comments

<xacro:m_link_box name=...> worked. Thank you

nj08 gravatar image nj08  ( 2021-10-18 14:40:56 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2021-10-16 15:54:01 -0600

Seen: 46 times

Last updated: Oct 17 '21