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

[NavFn] Make the 3 parameters changeable at runtime #2181

Merged
merged 5 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions nav2_navfn_planner/include/nav2_navfn_planner/navfn_planner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ class NavfnPlanner : public nav2_core::GlobalPlanner

// Whether to use the astar planner or default dijkstras
bool use_astar_;

// Subscription for parameter change
rclcpp::AsyncParametersClient::SharedPtr parameters_client_;
rclcpp::Subscription<rcl_interfaces::msg::ParameterEvent>::SharedPtr parameter_event_sub_;

/**
* @brief Callback executed when a paramter change is detected
* @param event ParameterEvent message
*/
void on_parameter_event_callback(const rcl_interfaces::msg::ParameterEvent::SharedPtr event);
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace nav2_navfn_planner
Expand Down
35 changes: 35 additions & 0 deletions nav2_navfn_planner/src/navfn_planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

using namespace std::chrono_literals;
using nav2_util::declare_parameter_if_not_declared;
using rcl_interfaces::msg::ParameterType;
using std::placeholders::_1;

namespace nav2_navfn_planner
{
Expand Down Expand Up @@ -88,6 +90,16 @@ NavfnPlanner::configure(
planner_ = std::make_unique<NavFn>(
costmap_->getSizeInCellsX(),
costmap_->getSizeInCellsY());

// Setup callback for changes to parameters.
parameters_client_ = 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());

parameter_event_sub_ = parameters_client_->on_parameter_event(
std::bind(&NavfnPlanner::on_parameter_event_callback, this, _1));
}

void
Expand Down Expand Up @@ -459,6 +471,29 @@ NavfnPlanner::clearRobotCell(unsigned int mx, unsigned int my)
costmap_->setCost(mx, my, nav2_costmap_2d::FREE_SPACE);
}

void
NavfnPlanner::on_parameter_event_callback(
const rcl_interfaces::msg::ParameterEvent::SharedPtr event)
{
for (auto & changed_parameter : event->changed_parameters) {
const auto & type = changed_parameter.value.type;
const auto & name = changed_parameter.name;
const auto & value = changed_parameter.value;

if (type == ParameterType::PARAMETER_DOUBLE) {
if (name == name_ + ".tolerance") {
tolerance_ = value.double_value;
}
} else if (type == ParameterType::PARAMETER_BOOL) {
if (name == name_ + ".use_astar") {
use_astar_ = value.bool_value;
} else if (name == name_ + ".allow_unknown") {
allow_unknown_ = value.bool_value;
}
}
}
}

} // namespace nav2_navfn_planner

#include "pluginlib/class_list_macros.hpp"
Expand Down