ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

If statement in launch file

asked 2015-06-26 15:57:25 -0600

thailor3 gravatar image

I want to cancel the creation of a node in the launch file if a value, which is entered by user in console, equals a certain value. For instance

I am launching a file: roslaunch file attr1:='1' attr2:='2'

and in my launch file i want to do a check. the syntax in any other language would be :

if (attr1 == value){ cancel node};

problem is, in the launch file I tried to use a unless="$(arg attr1)" but it's not a bool because when i enter the value in the console, it is an int. So i realized the unless and if conditionals in the launch file are explicitly looking for a true or false, and that they can't do a comparison:

unless="$(arg attr1 == '1')"

did not work. any suggestions? Any syntax I can use launch file that would make this work?


edit retag flag offensive close merge delete



This question has already been asked at BUT I'm wondering if (and very hopeful that) things have changed in Jade. See my comment on the accepted answer.

thebyohazard gravatar image thebyohazard  ( 2015-06-26 16:42:43 -0600 )edit

2 Answers

Sort by » oldest newest most voted

answered 2015-06-26 16:44:35 -0600

This is just not possible. The arg attr1 has to evaluate to true or false. This post is related:

edit flag offensive delete link more

answered 2017-10-04 02:05:28 -0600

toblech gravatar image

This is supported as of ROS Kinetic.

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

See also

edit flag offensive delete link more



@toblech Your sample code is not an example of the actual problem stated on the question. Also, are you sure is supported in Kinetic? I do not see that in the documentation, and haven't tried if using the new 'eval' works.

Javier V. Gómez gravatar image Javier V. Gómez  ( 2017-10-05 05:33:38 -0600 )edit

Question Tools

1 follower


Asked: 2015-06-26 15:57:25 -0600

Seen: 13,710 times

Last updated: Oct 04 '17