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

roslaunch if condition

asked 2012-01-25 13:27:21 -0500

Yogi gravatar image

updated 2021-09-26 18:52:08 -0500

lucasw gravatar image

How can say: run this node if argX==y

The following does not work, and the documentation on this is lacking.

<node pkg="xxx" type="yyy" name="yyy" if="$(arg argX)==y" />
edit retag flag offensive close merge delete

7 Answers

Sort by ยป oldest newest most voted
34

answered 2017-10-09 12:01:24 -0500

updated 2021-05-25 16:41:29 -0500

130s gravatar image

You can do this now in ROS Kinetic using eval:

<arg name="arg_name" default="desired_value"/>

<node pkg="node_pkg" type="node_type" name="node_name" 
      if="$(eval arg('arg_name') == 'desired_value')"/>

The documentation has been updated: http://wiki.ros.org/roslaunch/XML

edit flag offensive delete link more

Comments

2

<arg name="debug" default="0"/>

  <group if="$(eval arg('debug') ==0)">
    <node pkg="xxx" type="yyy" name="yyy">
  </group>
limitless gravatar image limitless  ( 2017-12-02 14:52:22 -0500 )edit

<group if="$(eval arg('image_width') ==640)"> </group>

worked for me. The above did not work for me.

Markus gravatar image Markus  ( 2019-03-15 05:48:32 -0500 )edit
1

Updated the answer's description based on @limitless and @Markus' comments.

130s gravatar image 130s  ( 2021-05-25 16:42:05 -0500 )edit
8

answered 2012-01-25 14:37:19 -0500

kwc gravatar image

The documentation on the roslaunch page for this syntax is complete, i.e. you can't do comparisons or any operators for that matter. You can only test the value itself.

edit flag offensive delete link more

Comments

2

link to the documentation --- http://ros.org/wiki/roslaunch/XML

Kei Okada gravatar image Kei Okada  ( 2012-05-10 03:57:10 -0500 )edit
4

answered 2017-10-04 02:03:44 -0500

toblech gravatar image

This is supported as of ROS Kinetic.

<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 does not answer the question which is about comparing foo to some arbitrary (non-bool) value.

Felix Widmaier gravatar image Felix Widmaier  ( 2018-01-31 03:49:36 -0500 )edit
2

answered 2015-06-25 11:57:15 -0500

thebyohazard gravatar image

updated 2015-06-30 14:16:59 -0500

Is this answer still current? I see that xacro got an upgrade: from http://wiki.ros.org/xacro#Conditional... "The more powerful evaluation capabilities in ROS Jade allow for much more complex expression. Virtually any python expression that evaluates to a Boolean is feasible."

EDIT 2015.6.30:

I found a related ticket suggesting that Ken's answer is probably still current, though I don't yet have jade to check for sure.

edit flag offensive delete link more
0

answered 2021-11-25 17:57:22 -0500

ticotico gravatar image

updated 2021-11-25 18:05:26 -0500

A small addendum from 2021. Embedding the if ...eval statement in a group gives a nice structure. As an example (taken from here):

<arg name="team" default="Red"/>
<arg name="type" default="painter"/>

<group if="$(eval team == 'Red')">
  <group if="$(eval type == 'painter')">
    <param name="robot_description" 
      command="$(find xacro)/xacro $(find robopaint)/urdf/red/paintbot_red.urdf.xacro" />
  </group>
  <group if="$(eval type == 'attacker')">
    <param name="robot_description" 
      command="$(find xacro)/xacro $(find robopaint)/urdf/red/attackbot_red.urdf.xacro" />
  </group>
</group>

<group if="$(eval team == 'Blue')">
  <group if="$(eval type == 'painter')">
    <param name="robot_description" 
      command="$(find xacro)/xacro $(find robopaint)/urdf/blue/paintbot_blue.urdf.xacro" />
  </group>
  <group if="$(eval type == 'attacker')">
    <param name="robot_description" 
      command="$(find xacro)/xacro $(find robopaint)/urdf/blue/attackbot_blue.urdf.xacro" />
  </group>
</group>
edit flag offensive delete link more
0

answered 2022-12-20 01:33:27 -0500

HarshavardhanMV gravatar image

<arg name="mov_b" default="true"/>

<group if="$(eval arg('mov_b') == true)"> <include file="$(find diff_robot)/launch/includes/move_base.launch.xml"/> </group>

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-01-25 13:27:21 -0500

Seen: 42,246 times

Last updated: Nov 25 '21