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

eval command isn't working in arg tag inside roslaunch

asked 2021-12-10 09:43:44 -0500

ravijoshi gravatar image

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?

edit retag flag offensive close merge delete

Comments

I just realized a mistake in above code. All I need to do is change to unless to if like the following <arg unless="$(eval mode == 'real')" and it works well. Thank you very much.

ravijoshi gravatar image ravijoshi  ( 2021-12-13 03:44:22 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-12-11 08:16:29 -0500

Mike Scheutzow gravatar image

updated 2021-12-11 08:20:18 -0500

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
edit flag offensive delete link more

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 ?

ravijoshi gravatar image ravijoshi  ( 2021-12-11 09:22:43 -0500 )edit
1

This is untested:

<arg name="robot_ip" value="$(eval '127.0.0.1' if mode == 'sim' else '192.168.10.10' )" />
Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-12-11 09:51:34 -0500 )edit

It works fine. However, I wanted to use mode == 'real' as well.

ravijoshi gravatar image ravijoshi  ( 2021-12-13 03:43:03 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-12-10 09:43:44 -0500

Seen: 348 times

Last updated: Dec 11 '21