# Help with using parameters in included Xacro Macro

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/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">
<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>
<!-- Connecting Joint -->
<joint name="${parent}_to_astra" type="fixed"> <parent link="${parent}"/>
<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.
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 close merge delete

1

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?

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

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

( 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.

( 2018-07-23 14:13:07 -0500 )edit

Sort by » oldest newest most voted

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.

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.

Cheers

( 2018-07-23 14:09:14 -0500 )edit