Ask Your Question

[YAML parser] ROS2 get parameters from sequences

asked 2018-12-20 04:39:38 -0500

sam_123 gravatar image

updated 2018-12-20 04:47:28 -0500

I give a yaml file as a parameter to a ROS2 (crystal) node and want to read a sequence.

Is it possible to read parameters from a yaml sequence? I found that there is a test case rcl/rcl_yaml_param_parser/test/seq_map1.yaml. But I couldn't figure out how to do it.

I tried it with this parameter file:

    test_int: 4
      - item: 1
      - item: 2
      - item: 3

And with this variations in code. None of them seem to work.

int item;
node->get_parameter("test_list/[0]/item", item);
node->get_parameter("test_list/0/item", item);
node->get_parameter("test_list[0]/item", item);
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-06-20 19:48:44 -0500

Christian Rauch gravatar image

To read a regular standard variable type:

int item;
this->get_parameter_or<int>("test_int", item, <default_int_value>);

For a sequence, you need to iterate through the test_list namespace like:

static const std::string param_list = "test_list";
auto parameters_and_prefixes = list_parameters({param_list}, 2);
for (const std::string &name : parameters_and_prefixes.names) {
    std::cout << name.substr(param_list.size()+1, name.size()) << " : " << get_parameter(name).get_value<int>() << std::endl;

This has changed from dashing on. You need to declare all parameters beforehand:

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



Asked: 2018-12-20 04:39:38 -0500

Seen: 547 times

Last updated: Jun 20 '19