PickNikRobotics / generate_parameter_library

Declarative ROS 2 Parameters
BSD 3-Clause "New" or "Revised" License
240 stars 45 forks source link

Question: how to handle an array of custom data structures? #179

Closed reinzor closed 7 months ago

reinzor commented 7 months ago

Hi,

Thanks for sharing this library! I have a question about using this library with an array of parameters of custom data structures. e.g.

plugins:
  - {plugin: pluginA, enabled: true}
  - {plugin: pluginB, enabled: true}

As far as I know, this is not supported by the ROS2 parameter system since every parameter need an unique key: so arrays of complex types are not supported.

In the nav2 system, this problem is solved as follows:

https://github.com/ros-planning/navigation2/blob/654e7e0d39c515612713c7426a30b2a219ae477a/nav2_bringup/params/nav2_params.yaml#L191

So we have an additional parameter that specifies the keys of the complex data structures:

plugins: ["pluginA", "pluginB"]
pluginA: {} # Complex data structure

How should we address this problem when using this library?

Thanks!

christophfroehlich commented 7 months ago

for reference https://github.com/PickNikRobotics/generate_parameter_library/issues/140

but maybe you have found a workaround?

reinzor commented 7 months ago

Thanks for the reference. So out of this I can conclude that this is not supported? This could be realized by introducing an additional feature that supports variables in parameter keys. Any thought about this by any of the creators, maintainers?

christophfroehlich commented 7 months ago

but how does nav2 declare the parameters? or do they use allow_undeclared_parameters and parse it based on the data from plugins?

reinzor commented 7 months ago

Every parameter is declared in code. The plugins parameter is declared here. Based on the value of this parameter, the other variables are declared [here]. And then the plugin specific parameters are declared here. So the parameter keys depend on the values of the plugins parameter.

reinzor commented 7 months ago

This pattern is also described here: https://github.com/mikeferguson/ros2_cookbook/blob/b7250b3270a8399f5fa2b894472b591f6a6914c8/rclcpp/parameters.md?plain=1#L93

reinzor commented 7 months ago

I have been reading to the README.md a bit more but shouldn;t this feature be used for this: https://github.com/PickNikRobotics/generate_parameter_library?tab=readme-ov-file#mapped-parameters ?

reinzor commented 7 months ago

That worked.