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

nested substitution args in launch files

asked 2012-05-30 11:41:46 -0500

somudrog gravatar image

updated 2012-05-30 15:37:24 -0500

joq gravatar image

Hi,

I'm writing a launch file and I want to pass a package name as an argument. The launch file should then look for the appropriate package. I wrote the following:

<arg name="robot" default="mh5_mesh" />
<include file="$(find $(arg robot) ... />

But when I run this, roslaunch complains: Dollar signs '$' cannot be inside of substitution args

Is there any way around this? How else can I pass a variable to $(find)? Is there some other method I should be using?

Thanks!

edit retag flag offensive close merge delete

Comments

I updated the correct answer as there has been new solutions developed since this question has been asked.

Procópio gravatar image Procópio  ( 2019-07-11 05:09:36 -0500 )edit

3 Answers

Sort by » oldest newest most voted
6

answered 2016-06-03 18:56:57 -0500

juztamau5 gravatar image

A solution to this problem has been added to roslaunch version 1.12.1, released on April 18, 2016. (ATM the debian repos are at version 1.12.0, so you'll either have to wait or download the github sources)

roslaunch 1.12.1 adds support for evaluation of arbitrary python expressions using the syntax $(eval <expression>). With this change, the following is possible:

<arg name="robot" default="mh5_mesh" />
<include file="$(eval find(arg('robot')) + '...')"/>

args are available as python variables, so the following is equivalent:

<arg name="robot" default="mh5_mesh" />
<include file="$(eval find(robot) + '...')"/>
edit flag offensive delete link more
1

answered 2012-05-31 06:45:58 -0500

I cannot see an easy solution to your problem. I recommend supplying the absolute path of the file at command line. For instace:

roslaunch package file.launch robot:=`rospack find package_2`/relative/path/to/file

And using it directly as $(arg robot) in your launch file.

Depending on your exact application, there might be a better solution.

edit flag offensive delete link more
4

answered 2017-11-15 10:26:29 -0500

ninja777 gravatar image

In case someone is stuck with older versions of roslaunch due to other dependencies, here is a workaround:

<arg name="robot"  default="mh5_mesh" />

<arg name="path"   value="(find $(arg robot)...)" />
<arg name="dollar" value="$" />

<include file="$(arg dollar)$(arg path)"  />

In my case I needed it to call the appropriate moveit_config file based on the robot and this hack works fine on ROS indigo

edit flag offensive delete link more

Comments

Thanks for this genius solution! Also i can confirm it working on ros kinetic.

wsneijers gravatar image wsneijers  ( 2018-01-23 06:11:39 -0500 )edit

Question Tools

Stats

Asked: 2012-05-30 11:41:46 -0500

Seen: 3,565 times

Last updated: Nov 15 '17