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

Pass an argument to a yaml configuration file

asked 2019-12-06 05:21:35 -0500

Choco93 gravatar image

updated 2019-12-06 06:05:04 -0500

I have a configuration file that I am loading in my launch file using rosparam,

rosparam command="load" file="$(find my_pkg)/config/analyzer.yaml"

I want to pass namespace (an arg) arg name="name_space" value="my_robot" into that yaml file when loading it so I don't have to hardcode it within yaml. Any suggestions on how to do it or if it's possible?

EDIT: Following is part of my analyzer.yaml,

analyzers:
  robot:
    type: diagnostic_aggregator/AnalyzerGroup
    path: robot
    analyzers:
      power:
        type: diagnostic_aggregator/GenericAnalyzer
        path: Power
        remove_prefix: namespace/diagnostics
        timeout: 5
        expected:
          - "namespace/diagnostics: Voltage"
          - "namespace/diagnostics: IMU"
          - "namespace/diagnostics: Odom"

I want to read the namespace bit of this yaml file from launch file argument.

edit retag flag offensive close merge delete

Comments

Pass an argument to configuration file

note: while .yaml files are used as configuration files in ROS, not all configuration files are .yaml files.

Your question is very specifically about how to do this with .yaml files. I would suggest to change the title of your question to reflect his.

gvdhoorn gravatar image gvdhoorn  ( 2019-12-06 05:34:53 -0500 )edit

I modified my question, it was a bit confusing I guess

Choco93 gravatar image Choco93  ( 2019-12-06 06:03:58 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-12-06 05:33:51 -0500

gvdhoorn gravatar image

updated 2019-12-06 06:18:49 -0500

Add subst_value="true" to your rosparam element (from wiki/roslaunch/XML/rosparam):

subst_value=true|false (optional)

Allows use of substitution args in the YAML text.

See also the example shown on the same page.


Edit: you really need to use roslaunch substitution args in the yaml, else it won't work. You could do something like this (just showing a single line as an example):

remove_prefix: $(arg name_space)/diagnostics
edit flag offensive delete link more

Comments

I looked at this before but this doesn't solve my problem, I updated my question with more details.

Choco93 gravatar image Choco93  ( 2019-12-06 06:04:51 -0500 )edit

It does, but you'd need to use $(arg ...) notation in your .yaml file.

You cannot replace arbitrary pieces of text. You must use substitution args if you want to do this using regular roslaunch support functionality.

gvdhoorn gravatar image gvdhoorn  ( 2019-12-06 06:08:56 -0500 )edit

Ahh sorry my bad, yep it works. Thanks for your help :)

Choco93 gravatar image Choco93  ( 2019-12-06 06:21:50 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2019-12-06 05:21:35 -0500

Seen: 7,259 times

Last updated: Dec 06 '19