0
$\begingroup$

Rosanswers logo

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


Originally posted by Arrakis on ROS Answers with karma: 163 on 2013-01-05

Post score: 2

$\endgroup$

4 Answers 4

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Dan Lazewatsky with karma: 9115 on 2013-01-05

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

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>

Originally posted by Arrakis with karma: 163 on 2013-01-07

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by Dan Lazewatsky on 2013-01-07:
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.

$\endgroup$
0
$\begingroup$

Rosanswers logo

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>

Originally posted by AMatt with karma: 11 on 2017-02-28

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by abhishek47 on 2021-02-10:
Here's another example if anyone's needs it

$\endgroup$
0
$\begingroup$

Rosanswers logo

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.


Originally posted by Maverobot with karma: 66 on 2018-01-24

This answer was NOT ACCEPTED on the original site

Post score: 5


Original comments

Comment by gvdhoorn on 2018-01-24:
This is neat, but note it's really almost arbitrary Python you can use in eval. It's not custom expressions in there.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.