Skip to content

Commit

Permalink
Address review comments. (#4704)
Browse files Browse the repository at this point in the history
* remove comments.
* Use RCLCPP_DEBUG instead of INFO for low level messages.
* Add test for trying to access parameters that are not declared.

Signed-off-by: Mike Wake <[email protected]>
  • Loading branch information
aosmw committed Oct 8, 2024
1 parent 7e9304b commit 7cb8ef5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void ParametersHandler::getParam(

if (param_type == ParameterType::Dynamic) {
if (verbose_) {
RCLCPP_INFO(node->get_logger(), "setDynamicParamCallback for %s", name.c_str());
RCLCPP_DEBUG(node->get_logger(), "setDynamicParamCallback for %s", name.c_str());

Check warning on line 214 in nav2_mppi_controller/include/nav2_mppi_controller/tools/parameters_handler.hpp

View check run for this annotation

Codecov / codecov/patch

nav2_mppi_controller/include/nav2_mppi_controller/tools/parameters_handler.hpp#L214

Added line #L214 was not covered by tests
}
setDynamicParamCallback(setting, name);
} else {
Expand Down
4 changes: 0 additions & 4 deletions nav2_mppi_controller/src/parameters_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ void ParametersHandler::start()
{
auto node = node_.lock();

// Register the special case "verbose" parameter before registering dynamicParamsCallback
auto get_param = getParamGetter(node_name_);
get_param(verbose_, "verbose", false);

Expand Down Expand Up @@ -70,11 +69,8 @@ ParametersHandler::dynamicParamsCallback(
callback->second(param);
} else {
if (verbose_) {
// Expected if static parameter, ie one with no registered callback is attempted
// to be changed
RCLCPP_WARN(logger_, "Parameter callback func for '%s' not found", param_name.c_str());
}
// success = true; // Decision ??? Still return true to avoid exception ???
success = false;
}
}
Expand Down
33 changes: 33 additions & 0 deletions nav2_mppi_controller/test/parameter_handler_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,36 @@ TEST(ParameterHandlerTest, DynamicAndStaticParametersNotVerboseTest)
EXPECT_EQ(p1, 10);
EXPECT_EQ(p2, 7);
}

TEST(ParameterHandlerTest, DynamicAndStaticParametersNotDeclaredTest)
{
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node");

node->declare_parameter("dynamic_int", rclcpp::ParameterValue(7));
node->declare_parameter("static_int", rclcpp::ParameterValue(7));
ParametersHandlerWrapper handler(node);
handler.start();

// Set verbose true to get more information about bad parameter usage
auto getParamer = handler.getParamGetter("");
auto rec_param = std::make_shared<rclcpp::AsyncParametersClient>(
node->get_node_base_interface(), node->get_node_topics_interface(),
node->get_node_graph_interface(),
node->get_node_services_interface());

auto results = rec_param->set_parameters_atomically(
{
rclcpp::Parameter("my_node.verbose", true),
});

rclcpp::spin_until_future_complete(
node->get_node_base_interface(),
results);

// Try to access some parameters that have not been declared
int p1 = 0, p2 = 0;
EXPECT_THROW(getParamer(p1, "not_declared", 8, ParameterType::Dynamic),
rclcpp::exceptions::InvalidParameterValueException);
EXPECT_THROW(getParamer(p2, "not_declared2", 9, ParameterType::Static),
rclcpp::exceptions::InvalidParameterValueException);
}

0 comments on commit 7cb8ef5

Please sign in to comment.