Skip to content

Commit

Permalink
Fix bt_navigator crashes when restarted (ros-navigation#3546)
Browse files Browse the repository at this point in the history
* Update bt_navigator.cpp

* Clean uncrestify

* Use declare_parameter_if_not_declared
  • Loading branch information
BriceRenaudeau authored and jwallace42 committed May 9, 2023
1 parent fdfcb86 commit 3269ada
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions nav2_bt_navigator/src/bt_navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
#include <vector>

#include "nav2_util/geometry_utils.hpp"
#include "nav2_util/node_utils.hpp"
#include "nav2_util/robot_utils.hpp"
#include "nav2_behavior_tree/bt_conversions.hpp"

using nav2_util::declare_parameter_if_not_declared;

namespace nav2_bt_navigator
{

Expand Down Expand Up @@ -137,11 +140,15 @@ BtNavigator::on_configure(const rclcpp_lifecycle::State & /*state*/)
};

std::vector<std::string> navigator_ids;
declare_parameter("navigators", default_navigator_ids);
declare_parameter_if_not_declared(
node, "navigators",
rclcpp::ParameterValue(default_navigator_ids));
get_parameter("navigators", navigator_ids);
if (navigator_ids == default_navigator_ids) {
for (size_t i = 0; i < default_navigator_ids.size(); ++i) {
declare_parameter(default_navigator_ids[i] + ".plugin", default_navigator_types[i]);
declare_parameter_if_not_declared(
node, default_navigator_ids[i] + ".plugin",
rclcpp::ParameterValue(default_navigator_types[i]));
}
}

Expand Down

0 comments on commit 3269ada

Please sign in to comment.