Skip to content

Add parameter callbacks#611

Open
azerupi wants to merge 1 commit intoros2-rust:mainfrom
azerupi:parameter_callback_v2
Open

Add parameter callbacks#611
azerupi wants to merge 1 commit intoros2-rust:mainfrom
azerupi:parameter_callback_v2

Conversation

@azerupi
Copy link

@azerupi azerupi commented Mar 8, 2026

Adds three new capabilities to the parameter API:

  1. ParameterBuilder::validate() to register a callback that can reject parameter changes. Called during declaration (for the initial value) and on every subsequent set, both programmatic and via service calls. Runs after range checks, before the value is written.
  2. MandatoryParameter::on_change() / OptionalParameter::on_change() to register a callback invoked after a parameter value is successfully changed. Intended for side effects (reconfiguring algorithms, logging, etc.). Callbacks are invoked outside the parameter map lock to avoid deadlocks.
  3. MandatoryParameter::subscribe() / OptionalParameter::subscribe() that return a ParameterSubscription for async notification of changes via tokio::sync::watch. Supports changed(), get(), and wait_for(predicate). The naming might be slightly confusing with subscribers already being a foundational ROS 2 concept, let me know if there are better naming ideas.

Also adds ValidationFailed and InitialValueRejected error variants to ParameterValueError and DeclarationError respectively.

Examples can be found here: https://github.com/azerupi/ros2_rust_examples/tree/parameter_callback_v2


Disclaimer AI was used to help write this PR

@azerupi azerupi force-pushed the parameter_callback_v2 branch from 087e9fe to 04d7f5e Compare March 8, 2026 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant