Robotics StackExchange | Archived questions

If condition in ROS2 launch xml

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.

Asked by adityakamath on 2022-08-14 12:23:03 UTC

Comments

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.

Asked by ravijoshi on 2022-09-03 23:27:00 UTC

Yep, that's what I eventually did.

Asked by adityakamath on 2022-09-04 02:57:39 UTC

Answers

It is currently not possible, there is an issue in the ros2 git repo: https://github.com/ros2/launch_ros/issues/323

Asked by adityakamath on 2022-09-03 14:21:28 UTC

Comments

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)"/>
</node>

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

Asked by verybadtype on 2023-02-07 08:05:23 UTC

Comments

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.

Asked by ljaniec on 2023-02-07 08:18:59 UTC

Comments

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

Asked by adityakamath on 2023-02-07 08:25:17 UTC