Ask Your Question
0

How to get an array of parameters with rclcpp

asked 2018-06-27 16:32:15 -0600

David Lu gravatar image

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.

edit retag flag offensive close merge delete

Comments

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])?

William gravatar imageWilliam ( 2018-06-27 17:18:30 -0600 )edit

The latter, one parameter name, which is why I figured get_parameters wouldn't work.

David Lu gravatar imageDavid Lu ( 2018-06-27 17:51:05 -0600 )edit

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.

William gravatar imageWilliam ( 2018-06-27 17:59:12 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2018-06-27 18:08:33 -0600

William gravatar image

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/03...

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/a...

Which return vector<T>.

edit flag offensive delete link more
1

answered 2018-06-27 16:59:23 -0600

tfoote gravatar image

updated 2018-06-27 18:07:52 -0600

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

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

2 followers

Stats

Asked: 2018-06-27 16:32:15 -0600

Seen: 415 times

Last updated: Jun 27 '18