ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Help with using parameters in included Xacro Macro

asked 2018-07-23 13:32:52 -0500

Chuples gravatar image

updated 2018-07-23 14:11:46 -0500

Hello all,

I'm trying to do something that I think is very basic but running into all kinds of trouble. System is Ubuntu 16.04 with ROS Kinetic. I want to define my robot (a drone) with the following file: sample_drone.urdf.xacro

<?xml version="1.0"?>

<robot name="test_drone" xmlns:xacro="">
    <!-- Load up the base pieces -->
    <xacro:include filename="xacro_modules/base_link.xacro"/>
    <xacro:include filename="xacro_modules/fiveinch_chasis.xacro"/>
    <!-- Right now just testing having a camera -->
    <xacro:include filename="xacro_modules/orbbec_astra.xacro"/>
    <xacro:orbbec_astra parent="five_inch_chasis" x="0.15" y="0.0" side="1.0"/>

And for reference, the astra file looks like: orbbec_astra.xacro:

<?xml version="1.0"?>
<xacro:macro name="orbbec_astra" params="parent x y side">
    <!-- Actual link -->
    <link name="orbbec_astra">
                <!-- TODO: replace with the actual mesh here -->
                <box size="0.083  0.058  0.020"/>
            <origin xyz="0 0 0" rpy="0 0 0"/>
                <box size="0.083  0.058  0.020"/>
            <origin xyz="0 0 0" rpy="0 0 0"/>
            <mass value="0.038"/>
            <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0" />
    <!-- Connecting Joint -->
    <joint name="${parent}_to_astra" type="fixed">
        <parent link="${parent}"/>
        <child link="orbbec_astra"/>
        <origin xyz="${x} ${y} ${ (0.01 + (drone_thickness/2.0) )*side}" rpy="${ (side-1)*(pi/2.0) } 0 0"/>

I've tried several different tweaks to this, but everything seems to run into some kind of error. Is there any way I can include the orbbec_astra.xacro without having it automatically expand (and thus fail because it has no parameters) and then call the macro with the required parameters?

Edit: For more clarification, I am running

rosrun xacro sample_drone.urdf.xacro > sample_drone.urdf

With the code I've shown above, I get the following errors:

xacro: Traditional processing is deprecated. Switch to --inorder processing!
To check for compatibility of your document, use option --check-order.
For more infos, see
name 'parent' is not defined
when evaluating expression 'parent'
when processing file: sample_drone.urdf.xacro

Which makes sense, because it seems to try expanding the astra macro completely.

Now if I remove the line

<xacro:orbbec_astra parent="five_inch_chasis" x="0.15" y="0.0" side="1.0"/>

from the top-level file and instead try to pass parameters to the include such as like:

<xacro:include filename="xacro_modules/orbbec_astra.xacro" parent="five_inch_chasis"/>

I get errors that parent is not a known parameter (makes sense, that's not what xacro knows about).

Edit: [Answer]: Including the robot tag in the astra macro has resolved the issue.

edit retag flag offensive close merge delete



but everything seems to run into some kind of error

would you agree it would probably be a lot easier for us to help you if we could actually see those errors?

gvdhoorn gravatar image gvdhoorn  ( 2018-07-23 13:54:46 -0500 )edit

I've edited the original message to be more clear.

Chuples gravatar image Chuples  ( 2018-07-23 14:05:05 -0500 )edit

I've re-opened the question: we don't normally close questions here on ROS Answers if they've actually been answered. Ticking the checkmark to the left of the correct answer indicates much more clearly that a question has been answered.

gvdhoorn gravatar image gvdhoorn  ( 2018-07-23 14:13:07 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-07-23 13:59:45 -0500

gvdhoorn gravatar image

As to your problem: I believe your orbbec_astra.xacro is missing some elements. I would expect something like:

<robot xmlns:xacro="">

to be the root element of the file.

edit flag offensive delete link more


That robot tag seems to have resolved it. It seems there is weird behavior when not including the <robot> tag and it automatically expands things in that case. Seems a little odd, but I'll take it.


Chuples gravatar image Chuples  ( 2018-07-23 14:09:14 -0500 )edit

Question Tools


Asked: 2018-07-23 13:32:52 -0500

Seen: 3,937 times

Last updated: Jul 23 '18