Skip to content
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

Dynamic params redesign #256

Merged
merged 9 commits into from
Oct 31, 2018

Conversation

bpwilcox
Copy link

This PR addresses some issues for redesign mentioned in the README of PR #196.

In particular, this PR modifies and adds the following features:

  • events are now filtered within the DynamicParamsClient internal callback
  • dynamic parameters are now added (and intialized in the cached map) via add_parameters()
  • user callbacks are now only called for parameters in the cached parameter map
  • user callbacks are now initialized immediately via a forced "empty" event
  • also added an example of adding a custom verification callback to DynamicParamsValidator

nav2_costmap_2d/src/costmap_2d_ros.cpp Outdated Show resolved Hide resolved
for (auto & client : parameters_clients_) {
auto sub = client->on_parameter_event(callback);
event_subscriptions_.push_back(sub);
user_callback_ = callback;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment about how to properly use the init_callback feature would be helpful.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

}
return false;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see some comments about these member variables. In general, there could be more comments to help the reader of this code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, I added comments to the class now.

@@ -32,29 +33,29 @@ int main(int argc, char ** argv)

// Add Dynamic Reconfigure Client

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend changing the "Add parameters to server" comment to "Set parameters on the node". This avoids a potential misunderstanding about a "parameter server"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@crdelsey crdelsey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make the example for a custom validator easier to read?

@@ -120,9 +120,9 @@ void StaticLayer::onInitialize()
}

dynamic_param_client_ = new nav2_dynamic_params::DynamicParamsClient(node_);
dynamic_param_client_->add_parameters({"enabled_static_layer"});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have an add_parameters variant that takes a string, so we can drop the initializer list in the case of a single parameter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the variant in latest commit. When overloading with a string argument, I was getting that the call was ambiguous (assuming users call function like add_parameters("enabled_static_layer") and add_parameters({"foo", "bar"})) so I ended up passing a character array instead.

@@ -64,22 +65,53 @@ int main(int argc, char ** argv)
param_validator->add_param("foo", rclcpp::ParameterType::PARAMETER_DOUBLE);
param_validator->add_param("bar", rclcpp::ParameterType::PARAMETER_INTEGER, {0, 10});

// Create a custom validation callback
std::function<rcl_interfaces::msg::SetParametersResult(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do something to make this line easier to read? It took me at least a minute or two to parse this statement.

Use some using directives to shorten the type names so you can break the line at better points

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In latest commit, I added the using directives

const std::vector<rclcpp::Parameter> &)> custom_validation_callback = [node](
const std::vector<rclcpp::Parameter> & parameters)
-> rcl_interfaces::msg::SetParametersResult
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long functions like this a better as named functions, not lambdas.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I made them functions outside of main

@bpwilcox bpwilcox force-pushed the dynamic_params-redesign branch from 52d3bb3 to 61ce69d Compare October 31, 2018 19:54
@bpwilcox bpwilcox merged commit a1ea922 into ros-navigation:master Oct 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants