ROS2 how a node can be notified if one of its own parameters is updated?

asked 2019-07-30 08:59:57 -0600

alsora gravatar image

In ROS2 each node has its own Parameter Server.

Assume that I have a node that hosts several parameters: PARAM_A, PARAM_B... Other nodes can modify these parameters.

The node can register a callback using set_on_parameters_set_callback in order to validate parameter changes. Moreover it can also subscribe to the parameter_events topic.

The node has some functions that have to be called every time a parameter is changed. These functions may be different depending on which parameter has been changed.

Where should these function be called? To me it looks like set_on_parameters_set_callback should only take care of validate changes. A callback to parameter_events topic may look the correct place, however, this would be triggered also for events not related with this node, potentially being a waste of resources.

edit retag flag offensive close merge delete


I am also curious about the recommended approach to this.

The callback set_on_parameters_set_callback cannot be used, because changes might be rejected after this has been called; e.g. if the new value is outside a required range.

To me the main issue is to update local copies of the parameters. It would be possible to always use the parameters through Node::get_parameter instead of storing a local copy. However, this is not very efficient, as it both requires locking a mutex and looking up in a std::map.

rasmusan- gravatar image rasmusan-  ( 2021-01-07 08:15:17 -0600 )edit