0
$\begingroup$

Rosanswers logo

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!


Originally posted by somudrog on ROS Answers with karma: 55 on 2012-05-30

Post score: 3


Original comments

Comment by Procópio on 2019-07-11:
I updated the correct answer as there has been new solutions developed since this question has been asked.

$\endgroup$

3 Answers 3

0
$\begingroup$

Rosanswers logo

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) + '...')"/>

Originally posted by juztamau5 with karma: 86 on 2016-06-03

This answer was ACCEPTED on the original site

Post score: 6

$\endgroup$
0
$\begingroup$

Rosanswers logo

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.


Originally posted by piyushk with karma: 2871 on 2012-05-31

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

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


Originally posted by ninja777 with karma: 101 on 2017-11-15

This answer was NOT ACCEPTED on the original site

Post score: 4


Original comments

Comment by wsneijers on 2018-01-23:
Thanks for this genius solution! Also i can confirm it working on ros kinetic.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.