PickNikRobotics / generate_parameter_library

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

Add ability for param_listener to load values from yaml dictionary #211

Closed MarqRazz closed 1 month ago

MarqRazz commented 1 month ago

This PR makes it so the parameter_listener can refresh it's copy of parameters with ones specified in a yaml dictionary and would close #208.

To load and the get the parameters

        self.param_listener = my_param_namespace.ParamListener(self.node)
        path_to_config = os.path.dirname(__file__) + '/config/my_config_file.yaml'
        with open(path_to_config) as file:
            configParamsFromYaml = yaml.safe_load(file)['my_param_namespace']['ros__parameters']

        self.param_listener.set_params_from_dict(configParamsFromYaml)
        self.test_params = self.param_listener.get_params()
MarqRazz commented 1 month ago

Note this design was heavily influenced by rclpy.parameter.py's unpack_parameter_dict()

What do you think about supporting the yaml loading like they do in parameter_dict_from_yaml_file(). I tried to use this functionality but it's not in Humble and returns a Dict[str, ParameterMsg] where generate_parameter's update() takes a list of rclpy.parameter.Parameter's. Personally I think it's fine for the user to have to load the dictionary from the correct namespace with yaml.safe_load(file)['my_param_namespace']['ros__parameters']

MarqRazz commented 1 month ago

@pac48 do you have any thoughts about this approach? Is there anything I can do to help get this across the finish line?

pac48 commented 1 month ago

@MarqRazz I added a small comment, otherwise looks good.

MarqRazz commented 1 month ago

How does that look?

MarqRazz commented 1 month ago

@pac48 can we run the tests?