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

rosparam load only part of yaml

asked 2019-05-22 12:34:09 -0500

vbs gravatar image

updated 2019-05-24 13:49:42 -0500

Hi,

Is it possible to load only part of yaml file into the parameter server?

My reason for wanting to do this is, suppose you have a properties.yaml file as follows:

sensors: &COMMON_PROPERTIES
    common_property1: bla
    common_property2: ble

sensor1:
    <<: *COMMON_PROPERTIES
    specific_property1: foo
    specific_property2: bar
        .
        .
        .

sensor2:
    <<: *COMMON_PROPERTIES
    specific_property1: foo
    specific_prop2erty: baz
.
.
.

Now, from my launch file, I would like to do:

<node pkg="sensor_pkg" type="sensor_node" name="sensor1">
    <rosparam command="load" file="properties.yaml['sensor1']"/>
</node>

<node pkg="sensor_pkg" type="sensor_node" name="sensor2">
    <rosparam command="load" file="properties.yaml['sensor2']"/>
</node>

Similar to what you can do in xacro. Is it possible?

edit retag flag offensive close merge delete

Comments

Anyone? :|

vbs gravatar image vbs  ( 2019-05-24 04:24:34 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-05-24 05:08:10 -0500

gvdhoorn gravatar image

updated 2019-05-28 09:55:35 -0500

No, this is not supported.


Edit: so if you want to keep the ability to use anchors and aliases, and your setup is as you show it in your question, then I believe there is no need to load "parts of a yaml file".

The .launch file example you show starts two nodes: sensor1 and sensor2.

The .yaml you show has -- ultimately -- two sections: sensor1 and sensor2.

Private parameters don't necessarily need to be loaded by a rosparam node that is a child of a node to become private parameters. They just need to be loaded in a namespace that corresponds to the name of the node.

So if the private parameters of node sensor1 are loaded from a .yaml file that contains a section called sensor1 and the .yaml file is loaded into the global namespace, the end result will be that the parameters end up in the sensor1 namespace, making them private parameters of the sensor1 node.

The .yaml file doesn't need to be loaded in parts -- in this specific example.

As to a more generic case: I would still recommend using a small Python script for this, as I wrote in my comment.

But I'm in Kinetic and from what I understand support for the yaml type was only added in Lunar.

yes, that is true. So that wouldn't work under Kinetic unfortunately.

edit flag offensive delete link more

Comments

1

You could potentially use the command variant of param and write a short Python script that dump(..)s a subsection of a yaml.safe_load(..)ed .yaml file to stdout. That would then be parsed as a set of parameters. Not sure if that works though (as I just made that up).

You'd have to use the yaml type, otherwise it'll just be considered text.

gvdhoorn gravatar image gvdhoorn  ( 2019-05-24 05:09:53 -0500 )edit

Thanks! But I'm in Kinetic and from what I understand support for the yaml type was only added in Lunar.

vbs gravatar image vbs  ( 2019-05-24 12:10:02 -0500 )edit

But this seemed to me like a direct approach to a common use case and as such I thought it would have natural ROS support. Am I missing a simpler way to implement this?

vbs gravatar image vbs  ( 2019-05-24 12:15:02 -0500 )edit
1

Am I missing a simpler way to implement this?

yes. Using multiple files.

gvdhoorn gravatar image gvdhoorn  ( 2019-05-24 13:23:09 -0500 )edit

But then you lose the ability of using YAML anchors and aliases. I've edited my question to illustrate.

vbs gravatar image vbs  ( 2019-05-24 13:51:23 -0500 )edit
1

Well, your original question did not mention that was one of your requirements. Please do not post incomplete questions.

gvdhoorn gravatar image gvdhoorn  ( 2019-05-24 14:32:57 -0500 )edit

Well, being the first time using the feature, I couldn't foresee what would or not be exactly relevant for the question; and was trying to put together a minimal case example in order to gather more viewers for possible help. I thought this was good practice, no?

vbs gravatar image vbs  ( 2019-05-28 08:13:52 -0500 )edit

Honestly, I think the example was perfectly fine to illustrate the question until I had to address your comment suggesting to separate the thing into multiple files. And then I addressed it. What's wrong with that?

vbs gravatar image vbs  ( 2019-05-28 08:15:59 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2019-05-22 12:34:09 -0500

Seen: 1,039 times

Last updated: May 28 '19