Skip to content

Any reason why examples use a timer instead of ParameterEventHandler? #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
danielcranston opened this issue Apr 24, 2025 · 1 comment

Comments

@danielcranston
Copy link

Seems like a lost opportunity to showcase best practices. Using a ParameterEventHandler (C++/Python) seems like a nicer fit when checking for updates instead of using a timer that polls for changes every x seconds.

I'd be happy to make a PR, just want check in case there's a reason behind it I'm not aware of.

@amarburg
Copy link

amarburg commented May 3, 2025

+1 It would be good to have a canonical code sample / example for receiving a callback on a parameter change and using this package (for the validation, etc).

Best I have so far is something like

...
param_listener_ =  std::make_shared<ParamListener>(get_node_parameters_interface());
callback_handle_ = this->add_on_set_parameters_callback(std::bind(
        &MyNode::parametersCallback, this, std::placeholders::_1));
...


rcl_interfaces::msg::SetParametersResult parametersCallback(
      const std::vector<rclcpp::Parameter> &parameters) {

    param_listener_->update(parameters);
    auto params = param_listener_->get_params();

    // use params
}

This is functional, but doesn't sit right, as the listener is update()'ed twice, once here and once in the internal callback within the ParamListener?

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

No branches or pull requests

2 participants