Ask Your Question

nested substitution args in launch files

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

somudrog gravatar image

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

joq gravatar image


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?


edit retag flag offensive close merge delete


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

3 Answers

Sort by » oldest newest most voted

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

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

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

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


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

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

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


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

Seen: 2,176 times

Last updated: Nov 15 '17