eval command isn't working in arg tag inside roslaunch
I am using ROS Melodic and trying to use eval command inside arg with a decision-making statement. Please see the following code snippet from roslaunch file:
<arg name="mode" default="sim" doc="operating mode of the system. only real and sim are supported." />
<arg if="$(eval mode == 'sim')" name="robot_ip" value="127.0.0.1" />
<arg unless="$(eval mode == 'real')" name="robot_ip" value="192.168.10.10" />
The above roslaunch is not working and throwing an exception by saying that robot_ip must be defined.
In contrast, if we have a boolean, it can be used easily as shown below:
<arg name="debug" default="false" />
<arg if="$(arg debug)" name="launch_prefix" value="gdb -ex run --args" />
<arg unless="$(arg debug)" name="launch_prefix" value="" />
Any workaround for using non-boolean variable, please?
Asked by ravijoshi on 2021-12-10 10:43:44 UTC
Answers
You could refactor the statements to move the $(eval ...)
into the value property. We use this in melodic, so I know it is supported.
Also, your launch file code is just wrong if you intended to implement:
if mode == 'sim' then IP1 else IP2
Asked by Mike Scheutzow on 2021-12-11 09:16:29 UTC
Comments
Thanks a lot. As you figured it out, the roslaunch was invalid and it throws exception saying robot_ip must be defined. By the way, can you please tell how to move $(eval ...)
into the value ?
Asked by ravijoshi on 2021-12-11 10:22:43 UTC
This is untested:
<arg name="robot_ip" value="$(eval '127.0.0.1' if mode == 'sim' else '192.168.10.10' )" />
Asked by Mike Scheutzow on 2021-12-11 10:51:34 UTC
It works fine. However, I wanted to use mode == 'real'
as well.
Asked by ravijoshi on 2021-12-13 04:43:03 UTC
Comments
I just realized a mistake in above code. All I need to do is change to
unless
toif
like the following<arg unless="$(eval mode == 'real')"
and it works well. Thank you very much.Asked by ravijoshi on 2021-12-13 04:44:22 UTC