0
$\begingroup$

Rosanswers logo

In ROS1, you could retrieve a list of parameters

The documentation shows get_parameter returning an ParameterVariant but ParameterVariant doesn't seem to have an as_vector option.


Originally posted by David Lu on ROS Answers with karma: 10932 on 2018-06-27

Post score: 1


Original comments

Comment by William on 2018-06-27:
Do you want a list of parameters in a certain namespace, like /ns/* -> ['value of /ns/foo', 'value of /ns/bar', 'value of /ns/baz'], or do you want one parameter as a vector (e.g. parameter /position -> [1.0, 1.0, 0.0])?

Comment by David Lu on 2018-06-27:
The latter, one parameter name, which is why I figured get_parameters wouldn't work.

Comment by William on 2018-06-27:
We may not have that API yet, but we can certainly add it or whatever the appropriate alternative is. There was some work done on lists in parameters this cycle, but I don't know the state off-hand, let me look it up.

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

For the slightly different case than what @tfoote linked to, here's how to get a single parameter as an array of values.


We recently merged this feature (made by @ayrton04), see:

Looks like there's no documentation yet, but there is an example of setting:

https://github.com/ros2/demos/blob/03ee0e0963ecb0990742eaeee22b334c11b16722/demo_nodes_cpp/src/parameters/set_and_get_parameters.cpp#L47-L48

And you can use get_parameter(s) to get the rclcpp::Parameter for it, and on that class there are as_*_array() methods:

https://github.com/ros2/rclcpp/blob/a49281cff3082410621aeea388944b35ba63f819/rclcpp/include/rclcpp/parameter.hpp#L95-L113

Which return vector<T>.


Originally posted by William with karma: 17335 on 2018-06-27

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Hakaishin on 2020-12-02:
Is there a way to achieve this by just using this->declare_parameter<float>("foo", 15.0); this->get_parameter("foo", foo); syntax? Or in this example how come that the parameter doesn't need to be declared? From reading a long issue involving some 2 booleans with undeclared_auto_param_something_something and another boolean I just got that you always should declare your params, but this example doesn't do that? And is the documentation 2years later still missing?

$\endgroup$
0
$\begingroup$

Rosanswers logo

There's get_parameters() one line above which takes a vector of names and returns a vector of ParameterVariants

Edit:

Sorry I thought you wanted to list multiple parameters. We also support arrays of primatives. It looks like the documentation is not complete.

The ParameterVarient includes ARRAY types natively

The get_value method on the variant will return the vector value. We don't have it in the demos but there are tests covering it you can use as an example, here


Originally posted by tfoote with karma: 58457 on 2018-06-27

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.