Ask Your Question
1

roslaunch XML "if" comparison

asked 2015-05-26 15:32:45 -0500

Jordan9 gravatar image

updated 2015-05-27 14:57:16 -0500

In the page on roslaunch XML, it discusses the use of "if" and "unless" attributes for tags. In the examples, however, it only shows how to do it if the argument you are checking is a boolean.

I need to do something like this:

<arg name="mode" default="simulate"/> 
<group unless="$(arg mode) == simulate">
     <!-- start a second node -->
</group>

where the "if" attribute is doing a comparison instead of checking a boolean. This syntax throws an error though. Is there an alternative way to do this?

EDIT: To give more info as to why this is complicated, I've edited the code sample a bit. Note that I need to start a new node unless the "mode" argument is of a specific type. That second node requires a whole bunch of arguments and parameters that are defined earlier in the master launch file. This makes the proposed solution of including sub-launch files more complex, because for each one of those files I would have to import a whole array of arguments to start that node, and there are a LOT of modes (and "simulate" is the only one where I don't want to start the second node). The reason I was asking about getting an argument back from a sub-launch file is because then I could just set a simple boolean in each sub-launch file, and in the master file (where all of the many arguments are available) I could start the second node if that boolean is true.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2015-05-26 15:37:15 -0500

ahendrix gravatar image

I don't think the roslaunch XML syntax supports more complex comparisons.

Instead, you could conditionally include a launch file or configuration file with the same name as your mode:

<arg name="mode" default="simulate"/>
<include file="$(find my_package)/launch/modes/$(arg mode).launch"/>
<rosparam command="load" file="$(find my_package)/config/modes/$(arg mode).yaml"/>
edit flag offensive delete link more

Comments

Yep, this could work. Having some difficulty with it though. If I define an argument inside the .launch file that gets included, that argument doesn't seem to be available in the parent .launch file (it just says it "needs to be set"). Also, arguments from the parent aren't available in the child.

Jordan9 gravatar imageJordan9 ( 2015-05-27 11:43:46 -0500 )edit

roslaunch args are not global; you have to explicitly declare them and explicit pass them when you include launch files: http://wiki.ros.org/roslaunch/XML/arg

ahendrix gravatar imageahendrix ( 2015-05-27 12:11:37 -0500 )edit

So I can declare them going into the include file, is there a way to use arguments that are declared in the include file in the parent file? (i.e. the reverse direction)

Jordan9 gravatar imageJordan9 ( 2015-05-27 12:27:51 -0500 )edit

no; you can't use arguments from an included launch file in the outer launch file. It sounds like what you're trying to do is a lot more complex than the simple question you asked...

ahendrix gravatar imageahendrix ( 2015-05-27 14:35:01 -0500 )edit

I updated the OP to explain why it's way more complicated than I originally made it sound.

Jordan9 gravatar imageJordan9 ( 2015-05-27 14:57:34 -0500 )edit
1

I'm not sure of any easy way to implement what you're asking for. Perhaps you just need a separate launch file for simulation, or an explicit boolean parameter indicating if you're running in simulation or not?

ahendrix gravatar imageahendrix ( 2015-06-03 02:47:55 -0500 )edit
-2

answered 2017-10-04 02:06:48 -0500

toblech gravatar image

This is supported as of ROS Kintec.

<group if="$(arg foo)">
  <!-- stuff that will only be evaluated if foo is true -->
</group>

See also http://wiki.ros.org/roslaunch/XML

edit flag offensive delete link more

Comments

This only works for booleans; it doesn't work for the more complex comparisons requested in the initial post.

ahendrix gravatar imageahendrix ( 2017-10-04 15:21:03 -0500 )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

1 follower

Stats

Asked: 2015-05-26 15:32:45 -0500

Seen: 2,865 times

Last updated: Oct 04 '17