Ask Your Question

How to use substitution args in a yaml file?

asked 2012-10-19 04:10:09 -0500

Benoit Larochelle gravatar image

updated 2012-10-19 04:11:14 -0500

I have a yaml file that is used by many launch files. I centralized most of the parameters in the yaml file, but those with substitution arguments do not get properly evaluated. Instead, they get passed in literally (verbatim) to the node. For example:

# params.yaml
showRobotModel: true
folderNameForSnapshots: $(find ocu)/snapshots
robot_description: cat $(find ocu)/media/robot_model/NIFTi.urdf

How could I avoid copy-pasting the more complex parameters in each launch file? Can they be interpreted somehow in the yaml file?

edit retag flag offensive close merge delete



I'm asking the same question 5 years later, but it appears there is no solution.

Nikola Malešević gravatar image Nikola Malešević  ( 2017-10-24 14:49:44 -0500 )edit

YAML is just a markup language and doesn't have a concept of paths or includes. As @dornhenge said, the better way to do this is by creating a launch file which does the substitution and sets the desired parameters.

ahendrix gravatar image ahendrix  ( 2017-10-24 14:58:53 -0500 )edit

I do not agree. My case is that I have other package's large YAML in which I need to change only one parameter depending on the scenario. Having an arg substitution there would be fantastic. There is an open request here:

Nikola Malešević gravatar image Nikola Malešević  ( 2017-10-24 15:04:36 -0500 )edit

2 Answers

Sort by » oldest newest most voted

answered 2012-10-19 04:37:25 -0500

dornhege gravatar image

updated 2012-10-19 05:01:24 -0500

I think the best way is to set those parameter directly from the launch file instead of loading the yaml. If want to keep it separated make a params.launch from params.yaml and include that.

The way to specific package relative paths would be to use: package://ocu/bla syntax, but afaik the node needs to support that, i.e. call the proper ROS api functions.

edit flag offensive delete link more


This workaround works in simple cases, but not always. This comes back to another question that I posted, but I need these parameters inside a node with an anonymous name. I am allowed to place <rosparam load params.yaml> inside my <node> tag, but not <include params.launch>.

Benoit Larochelle gravatar image Benoit Larochelle  ( 2012-10-21 21:51:49 -0500 )edit

The result is that I must include params.launch outside of the <node> tag, but then the parameters are not in the anonymous namespace.

Benoit Larochelle gravatar image Benoit Larochelle  ( 2012-10-21 21:53:12 -0500 )edit

answered 2018-06-18 10:23:15 -0500

Great news for any one still trying to do this. This feature was added recently to Ros Lunar. Check out this PR. There is also talk of back porting to kinetic.

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

1 follower


Asked: 2012-10-19 04:10:09 -0500

Seen: 6,969 times

Last updated: Jun 18 '18