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

If condition in ROS2 launch xml

asked 2022-08-14 12:23:03 -0600

adityakamath gravatar image

updated 2022-09-03 23:24:36 -0600

ravijoshi gravatar image

I am migrating one of my ROS 1 launch files to ROS 2 launch.xml, and I need help implementing an if condition.

I want to implement a condition such as the following:

<param name="x"   value="0.0" if="$(var condition)" />

But this is not working with ROS 2 launch.xml. The ROS 2 design documents mentions the eval expression, but there is no documentation on how to use it.

edit retag flag offensive close merge delete



A launch file in ROS 2 can be written in Python, XML, or YAML. So, a workaround is to rewrite your launch file in Python. Please read the documentation for more information.

ravijoshi gravatar image ravijoshi  ( 2022-09-03 23:27:00 -0600 )edit

Yep, that's what I eventually did.

adityakamath gravatar image adityakamath  ( 2022-09-04 02:57:39 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2023-02-07 07:06:20 -0600

verybadtype gravatar image

A workaround that can be used in the XML format is the tag <let>. This tag works in galactic with the argument "if". Your launchfile would then look like this:

<let name="x" value="true" if="$(var condition)"/>
<let name="x" value="false" unless="$(var condition)"/>

<node .......>
  <param name="x" value="$(var x)"/>

It uses a little bit more lines but I think it's a useful method if you don't want to rewrite all of the file in Python

edit flag offensive delete link more

answered 2023-02-07 07:18:59 -0600

ljaniec gravatar image

For others - there is a nice new tutorial about ROS 1/2 launch files, called rosetta_launch.

ROS1 - XML, ROS2 - Python.

It can be helpful with transition from XML to Python launchers.

edit flag offensive delete link more


I saw this yesterday, it's indeed a wonderful resource :)

adityakamath gravatar image adityakamath  ( 2023-02-07 07:25:17 -0600 )edit

answered 2022-09-03 14:21:28 -0600

adityakamath gravatar image

It is currently not possible, there is an issue in the ros2 git repo:

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2022-08-14 12:23:03 -0600

Seen: 1,848 times

Last updated: Feb 07