Ask Your Question
1

Problem with xacro:if value="${model_type == A_model_type}"

asked 2014-12-22 10:22:31 -0500

corb gravatar image

updated 2014-12-22 10:24:10 -0500

I'm trying to set up a Xacro where one section is based on a Model type passed as an argument (the first line below would be an external argument). No matter what model_type is set to, model A, B and C get included. I can get this to work by having a separate variable set to true/false for each model, but it's ugly. The following always loads all three models. I'm using Indigo.

<!-- The model we want loaded -->
<xacro:property name="model_type" value="3"/>

<!-- The different possibilities -->
<xacro:property name="A_model_type" value="2"/>
<xacro:property name="B_model_type" value="3"/>
<xacro:property name="C_model_type" value="4"/>

 <!-- Only load the specified model -->
<xacro:if value="${model_type == A_model_type}">
<xacro:include filename="/urdf/A_model.xacro"/>
</xacro:if>

<xacro:if value="${model_type == B_model_type}">
<xacro:include filename="/urdf/B_model.xacro"/>
</xacro:if>

<xacro:if value="${model_type == C_model_type}">
<xacro:include filename="/urdf/C_model.xacro"/>
</xacro:if>
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-06-19 21:54:36 -0500

130s gravatar image

updated 2018-08-08 05:09:10 -0500

I can think of a couple of "clean" ways to do this.

I do not know which way is better. There should be other ways to achieve this as well. With Option-1, child_X.xacro can be very small, and is dependent on parent.xacro. In Option-2, each xacro file is not inter-dependent. wholerobot_model_X.xacro can be a little larger than Option-1 but still concise enough.

Option-1. Split xacro files into "parent/abstract" and "child/concrete" files.

parent.xacro:

:
<!-- Only load the specified model -->
<xacro:macro name="model_to_be_inserted" params="modelfile_path">
  <xacro:include filename="${modelfile_path}"/>
</xacro:macro>
:

child_a.xacro

:
<xacro:include filename="parent.xacro" />
:
<xacro:model_to_be_inserted modelfile_path="A_model_type" />
:

Option-2. Split your robot definition into smaller components as xacro files, then "assemble" them in another xacro for the specific design.

Say, split components of upper-body humanoid into {head, torso, left_arm, left_hand, right_arm, right_hand}.xacro, and you want to switch with customize hands.

wholerobot_model_A.xacro

:
<xacro:include filename="head.xacro"/>
<xacro:include filename="torso.xacro"/>
<xacro:include filename="left_arm.xacro"/>
<xacro:include filename="A_model_type_l.xacro"/>
<xacro:include filename="right_arm.xacro"/>
<xacro:include filename="A_model_type_r.xacro"/>
:
edit flag offensive delete link more

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: 2014-12-22 10:22:31 -0500

Seen: 847 times

Last updated: Aug 08 '18