0
$\begingroup$

Rosanswers logo

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.


Originally posted by Choco93 on ROS Answers with karma: 685 on 2019-12-06

Post score: 1


Original comments

Comment by gvdhoorn on 2019-12-06:\

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.

Comment by Choco93 on 2019-12-06:
I modified my question, it was a bit confusing I guess

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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

Originally posted by gvdhoorn with karma: 86574 on 2019-12-06

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Choco93 on 2019-12-06:
I looked at this before but this doesn't solve my problem, I updated my question with more details.

Comment by gvdhoorn on 2019-12-06:
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.

Comment by Choco93 on 2019-12-06:
Ahh sorry my bad, yep it works. Thanks for your help :)

$\endgroup$

Your Answer

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