[YAML parser] ROS2 get parameters from sequences
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:
parametertest: rosparameters: testint: 4 test_list: - item: 1 - item: 2 - item: 3
And with this variations in code. None of them seem to work.
int item; node->getparameter("testlist/[0]/item", item); node->getparameter("testlist/0/item", item); node->getparameter("testlist[0]/item", item);
Asked by sam_123 on 2018-12-20 05:39:38 UTC
Answers
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: http://answers.ros.org/question/325939/declare-nested-parameter/
Asked by Christian Rauch on 2019-06-20 19:48:44 UTC
Comments