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

If condition in ROS2 launch xml

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

adityakamath gravatar image

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

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

Comments

1

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 -0500 )edit

Yep, that's what I eventually did.

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

3 Answers

Sort by ยป oldest newest most voted
0

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

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

Comments

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

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

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

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

edit flag offensive delete link more
0

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

adityakamath gravatar image

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

edit flag offensive delete link more

Question Tools

1 follower

Stats

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

Seen: 2,083 times

Last updated: Feb 07 '23