Ask Your Question
0

Help with using parameters in included Xacro Macro

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

Chuples gravatar image

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

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="http://ros.org/wiki/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"/>
</robot>

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">
        <visual>
            <geometry>
                <!-- TODO: replace with the actual mesh here -->
                <box size="0.083  0.058  0.020"/>
            </geometry>
            <origin xyz="0 0 0" rpy="0 0 0"/>
        </visual>
        <collision>
            <geometry>
                <box size="0.083  0.058  0.020"/>
            </geometry>
            <origin xyz="0 0 0" rpy="0 0 0"/>
        </collision>
        <inertial>
            <mass value="0.038"/>
            <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0" />
        </inertial>
    </link>
    <!-- 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"/>
    </joint>
</xacro:macro>

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 xacro.py 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 http://wiki.ros.org/xacro#Processing_Order
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

Comments

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 imagegvdhoorn ( 2018-07-23 13:54:46 -0600 )edit

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

Chuples gravatar imageChuples ( 2018-07-23 14:05:05 -0600 )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 imagegvdhoorn ( 2018-07-23 14:13:07 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

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

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="http://wiki.ros.org/xacro">
</robot>

to be the root element of the file.

edit flag offensive delete link more

Comments

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.

Cheers

Chuples gravatar imageChuples ( 2018-07-23 14:09:14 -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

Stats

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

Seen: 626 times

Last updated: Jul 23 '18