roslaunch if condition
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" />
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org |
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" />
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
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.
link to the documentation --- http://ros.org/wiki/roslaunch/XML
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
This does not answer the question which is about comparing foo
to some arbitrary (non-bool) value.
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.
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>
<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>
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2012-01-25 13:27:21 -0500
Seen: 39,578 times
Last updated: Nov 25 '21
Get timestamp during roslaunch
Why do I see multiple threads when I do rosrun or roslaunch? [closed]
Add two turtlebot in one .world
Load Parameters using roslaunch saved as .yaml from RQT Dynamic Reconfigure
Multiple Robotino co-ordination
Works with rosrun but not with roslaunch [closed]
roslaunch: [gazebo-2] process has died [pid 7605, exit code 139 [closed]
How does roslaunch determine a remote node's hostname? Can it be overridden?