PickNikRobotics / generate_parameter_library

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

Allow nested map definitions #191

Open Kotochleb opened 5 months ago

Kotochleb commented 5 months ago

Currently, the library allows only top level map definitions. Something that would be nice is the option to create parameters in a following way.

With this yaml:

my_node:
  my_params:
    params_to_be_mapped: {
      type: string_array,
    }
    __map_params_to_mapped:
      in_map_param: {
        type: bool,
      }

When attempting to do so, the current Jinja template will create the following code:

# declare any new dynamic parameters
for value_1 in updated_params.params_to_mapped:
  updated_params.my_params.add_entry(value_1)

# ...

for value_1 in updated_params.params_to_mapped:
  param_name = f"{self.prefix_}my_params.{value_1}.in_map_param"

# ...

# declare and set all dynamic parameters
for value_1 in updated_params.params_to_mapped:
  updated_params.my_params.add_entry(value_1)

While the expected output is:

# declare any new dynamic parameters
for value_1 in updated_params.my_params.params_to_mapped:
  updated_params.my_params.add_entry(value_1)

# ...

for value_1 in updated_params.my_params.params_to_mapped:
  param_name = f"{self.prefix_}my_params.{value_1}.in_map_param"

# ...

# declare and set all dynamic parameters
for value_1 in updated_params.my_params.params_to_mapped:
  updated_params.my_params.add_entry(value_1)

Namespace of my_params is not taken into account in for loops of the mapped values.

Topic initially started in https://github.com/PickNikRobotics/generate_parameter_library/pull/183.

BrunoB81HK commented 4 months ago

Is there any plan to implement this feature? This would be very useful since a mapped parameters is not necessarily a global one.

@pac48 suggested to use the following key format and I think this is the way to go: __map_my_params.params_to_mapped

pac48 commented 4 months ago

@BrunoB81HK I am working on a branch here https://github.com/PickNikRobotics/generate_parameter_library/tree/pr-allow-mapped-sub-parameter but it is not ready yet.

BrunoB81HK commented 4 months ago

@pac48 Great! Thanks a lot for your work!