Ask Your Question
2

Roslaunch XML boolean operators

asked 2013-01-05 04:28:57 -0600

Arrakis gravatar image

I am currently using a conditional line in a roslaunch file as shown below:

<arg name="cond1" value="true"/>
<node pkg="PKG" type="TYPE" name="NAME" unless="$(arg cond1)">
...

However I wish to have this node not load if EITHER cond1 or cond2 is set. No combination of

<arg name="cond2" value="false"/>
unless="$(arg cond1 or cond2)"
unless="$(arg cond1) or $(arg cond2)"

seems to work, returning the error:

$(arg var) may only specify one arg

How do I use boolean operators (AND or OR) in the roslaunch XML syntax?

Many thanks

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
1

answered 2013-01-05 08:34:13 -0600

I think the only way to do that is construct another arg that represents the condition you want using the unless/if attribute to create it.

edit flag offensive delete link more
5

answered 2018-01-24 04:56:09 -0600

Maverobot gravatar image

updated 2018-01-24 08:19:31 -0600

Use eval keyword if you are using ROS Kinetic or newer version. See documentation.

This is a very neat solution for boolean operators in roslaunch file. An example for an "or" operation:

<arg name="cond_1" default="false"/> 
<arg name="cond_2" default="false"/>
<node pkg="PKG" type="TYPE" name="NAME" if="$(eval arg('cond_1) or arg('cond_2'))" />

This syntax can of course also be applied to including a launch file.

Thanks to @gvhoorn's: $(eval <expression>) allows to evaluate arbitrary complex python expressions.

edit flag offensive delete link more

Comments

1

This is neat, but note it's really almost arbitrary Python you can use in eval. It's not custom expressions in there.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-24 04:58:32 -0600 )edit
2

answered 2017-02-28 15:16:26 -0600

AMatt gravatar image

Adding this because I couldn't easily find it anywhere:

    <arg name="foo" default="false" />
    <group if="$(arg foo)">
        <!--do some stuff-->
    </group>
    <group unless="$(arg foo)">
        <!--do some different stuff-->
    </group>
edit flag offensive delete link more

Comments

Here's another example if anyone's needs it

abhishek47 gravatar image abhishek47  ( 2021-02-10 01:32:29 -0600 )edit
1

answered 2013-01-07 03:38:09 -0600

Arrakis gravatar image

The above suggestion will work, as well as the following. However both seem like hacks to me and I would love to hear if anyone knows of if/when proper boolean operators will be added to the roslaunch XML syntax

<group unless="$(arg cond1)">
    <node pkg="PKG" type="TYPE" name="NAME" unless="$(arg cond2)" />
</group>
edit flag offensive delete link more

Comments

2

Thanks for adding a code snippet - that pretty much what I had in mind for making an arg. There's a roslaunch SIG (http://www.ros.org/wiki/hydro/Planning/roslaunch) for hydro which might be a good place to bring this up.

Dan Lazewatsky gravatar image Dan Lazewatsky  ( 2013-01-07 05:32:46 -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: 2013-01-05 04:28:57 -0600

Seen: 7,314 times

Last updated: Jan 24 '18