Skip to content

Commit

Permalink
remove exceptions from navigator onLoop (ros-navigation#4341)
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Wake <[email protected]>
  • Loading branch information
aosmw committed Sep 13, 2024
1 parent 0970a7b commit 5ef6f46
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "rclcpp_action/rclcpp_action.hpp"
#include "geometry_msgs/msg/pose_stamped.hpp"
#include "nav2_core/behavior_tree_navigator.hpp"
#include "nav2_core/navigator_exceptions.hpp"
#include "nav2_msgs/action/navigate_through_poses.hpp"
#include "nav_msgs/msg/path.hpp"
#include "nav2_util/robot_utils.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "rclcpp_action/rclcpp_action.hpp"
#include "geometry_msgs/msg/pose_stamped.hpp"
#include "nav2_core/behavior_tree_navigator.hpp"
#include "nav2_core/navigator_exceptions.hpp"
#include "nav2_msgs/action/navigate_to_pose.hpp"
#include "nav2_util/geometry_utils.hpp"
#include "nav2_util/robot_utils.hpp"
Expand Down
31 changes: 6 additions & 25 deletions nav2_bt_navigator/src/navigators/navigate_through_poses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <memory>
#include <limits>
#include "nav2_bt_navigator/navigators/navigate_through_poses.hpp"
#include "nav2_core/navigator_exceptions.hpp"

namespace nav2_bt_navigator
{
Expand Down Expand Up @@ -122,17 +121,14 @@ NavigateThroughPosesNavigator::onLoop()
feedback_utils_.global_frame, feedback_utils_.robot_frame,
feedback_utils_.transform_tolerance))
{
throw nav2_core::NavigatorPoseNotAvailable("Robot pose is not available.");
// Robot pose is not yet available, no feedback
return;
}

try {
// Get current path points
nav_msgs::msg::Path current_path;
if (!blackboard->get(path_blackboard_id_, current_path) || current_path.poses.size() == 0u) {
// If no path set yet or not meaningful, can't compute ETA or dist remaining yet.
throw nav2_core::NavigatorInvalidPath("no valid path available");
}

// Get current path points
nav_msgs::msg::Path current_path;
res = blackboard->get(path_blackboard_id_, current_path);
if (res && current_path.poses.size() > 0u) {
// Find the closest pose to current pose on global path
auto find_closest_pose_idx =
[&current_pose, &current_path]() {
Expand Down Expand Up @@ -169,21 +165,6 @@ NavigateThroughPosesNavigator::onLoop()

feedback_msg->distance_remaining = distance_remaining;
feedback_msg->estimated_time_remaining = estimated_time_remaining;
} catch (const nav2_core::NavigatorPoseNotAvailable & ex) {
current_error_code_ = ActionT::Result::POSE_NOT_AVAILABLE;
current_error_msg_ = ex.what();
RCLCPP_ERROR(logger_, current_error_msg_.c_str());
// Returning since no point attempting recovery or publishing
// feedback until robot pose is available.
return;
} catch (const nav2_core::NavigatorInvalidPath & ex) {
current_error_code_ = ActionT::Result::NO_VALID_PATH;
current_error_msg_ = ex.what();
// Ignore ??
} catch (const std::runtime_error & ex) {
current_error_code_ = ActionT::Result::UNKNOWN;
current_error_msg_ = ex.what();
// Ignore ??
}

int recovery_count = 0;
Expand Down
33 changes: 7 additions & 26 deletions nav2_bt_navigator/src/navigators/navigate_to_pose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <memory>
#include <limits>
#include "nav2_bt_navigator/navigators/navigate_to_pose.hpp"
#include "nav2_core/navigator_exceptions.hpp"

namespace nav2_bt_navigator
{
Expand Down Expand Up @@ -124,19 +123,16 @@ NavigateToPoseNavigator::onLoop()
feedback_utils_.global_frame, feedback_utils_.robot_frame,
feedback_utils_.transform_tolerance))
{
throw nav2_core::NavigatorPoseNotAvailable("Robot pose is not available.");
RCLCPP_ERROR(logger_, "Robot pose is not available.");
return;
}

auto blackboard = bt_action_server_->getBlackboard();

try {
// Get current path points
nav_msgs::msg::Path current_path;
if (!blackboard->get(path_blackboard_id_, current_path) || current_path.poses.size() == 0u) {
// If no path set yet or not meaningful, can't compute ETA or dist remaining yet.
throw nav2_core::NavigatorInvalidPath("no valid path available");
}

// Get current path points
nav_msgs::msg::Path current_path;
[[maybe_unused]] auto res = blackboard->get(path_blackboard_id_, current_path);
if (current_path.poses.size() > 0u) {
// Find the closest pose to current pose on global path
auto find_closest_pose_idx =
[&current_pose, &current_path]() {
Expand Down Expand Up @@ -173,25 +169,10 @@ NavigateToPoseNavigator::onLoop()

feedback_msg->distance_remaining = distance_remaining;
feedback_msg->estimated_time_remaining = estimated_time_remaining;
} catch (const nav2_core::NavigatorPoseNotAvailable & ex) {
current_error_code_ = ActionT::Result::POSE_NOT_AVAILABLE;
current_error_msg_ = ex.what();
RCLCPP_ERROR(logger_, current_error_msg_.c_str());
// Returning since no point attempting recovery or publishing
// feedback until robot pose is available.
return;
} catch (const nav2_core::NavigatorInvalidPath & ex) {
current_error_code_ = ActionT::Result::NO_VALID_PATH;
current_error_msg_ = ex.what();
// Ignore ??
} catch (const std::runtime_error & ex) {
current_error_code_ = ActionT::Result::UNKNOWN;
current_error_msg_ = ex.what();
// Ignore ??
}

int recovery_count = 0;
[[maybe_unused]] auto res = blackboard->get("number_recoveries", recovery_count);
res = blackboard->get("number_recoveries", recovery_count);
feedback_msg->number_of_recoveries = recovery_count;
feedback_msg->current_pose = current_pose;
feedback_msg->navigation_time = clock_->now() - start_time_;
Expand Down
47 changes: 0 additions & 47 deletions nav2_core/include/nav2_core/navigator_exceptions.hpp

This file was deleted.

1 change: 0 additions & 1 deletion nav2_msgs/action/NavigateThroughPoses.action
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ uint16 NONE=0
uint16 FAILED_TO_LOAD_BEHAVIOR_TREE=901
uint16 TF_ERROR=902
uint16 POSE_NOT_AVAILABLE=912
uint16 NO_VALID_PATH=913
uint16 UNKNOWN=999

uint16 error_code
Expand Down
1 change: 0 additions & 1 deletion nav2_msgs/action/NavigateToPose.action
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ uint16 NONE=0
uint16 FAILED_TO_LOAD_BEHAVIOR_TREE=901
uint16 TF_ERROR=902
uint16 POSE_NOT_AVAILABLE=912
uint16 NO_VALID_PATH=913
uint16 UNKNOWN=999

uint16 error_code
Expand Down

0 comments on commit 5ef6f46

Please sign in to comment.