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

Expections #3244

Merged
merged 43 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
fdbb761
added result codes for global planner
jwallace42 Aug 23, 2022
6f92768
code review
jwallace42 Aug 24, 2022
4bd5050
code review
jwallace42 Aug 24, 2022
3ccd777
cleanup
jwallace42 Aug 24, 2022
95de2a8
cleanup
jwallace42 Aug 24, 2022
f0a86a0
update smac lattice planner
jwallace42 Aug 24, 2022
af8adbc
update planner instances
jwallace42 Aug 24, 2022
63e5f82
cleanup
jwallace42 Aug 24, 2022
1b92bea
Merge branch 'main' into expections
jwallace42 Aug 25, 2022
7f34be3
updates
jwallace42 Aug 26, 2022
c2221a2
renaming
jwallace42 Aug 26, 2022
915c68f
fixes
jwallace42 Aug 26, 2022
b88ee77
cpplint
jwallace42 Aug 31, 2022
8dc55f2
uncrusitfy
jwallace42 Aug 31, 2022
85493f9
code review
jwallace42 Sep 9, 2022
6612d58
navfn exceptions
jwallace42 Sep 9, 2022
bb5be0a
theta_star_planner
jwallace42 Sep 9, 2022
e553e56
Merge branch 'main' into expections
jwallace42 Sep 12, 2022
ea41362
fix code review
jwallace42 Sep 13, 2022
5b01c2a
wrote timeout exception
jwallace42 Sep 14, 2022
d615e2d
consistent exception throwing across planners
jwallace42 Sep 21, 2022
6377431
code review
jwallace42 Sep 21, 2022
71ae1a8
remove
jwallace42 Sep 21, 2022
1a73968
uncrusitfy
jwallace42 Sep 21, 2022
a97fa2c
uncrusify
jwallace42 Sep 21, 2022
7f1b03e
catch exception
jwallace42 Sep 21, 2022
8eb398f
expect throw
jwallace42 Sep 21, 2022
15867f2
update string of exceptions
jwallace42 Sep 21, 2022
ebf717f
throw with coords
jwallace42 Sep 21, 2022
6d8bb50
removed start == goal error code
jwallace42 Sep 23, 2022
8b23695
code review
jwallace42 Sep 26, 2022
9d0484e
code review
jwallace42 Sep 26, 2022
62ae68c
Merge branch 'main' into expections
jwallace42 Sep 26, 2022
93d98eb
uncrustify
jwallace42 Sep 26, 2022
bf97025
code review
jwallace42 Sep 28, 2022
0234c00
message order
jwallace42 Sep 28, 2022
5ce061f
remove remarks
jwallace42 Sep 28, 2022
7bd09ff
Merge branch 'main' into expections
jwallace42 Sep 28, 2022
9e2c056
update xml
jwallace42 Sep 28, 2022
50e891c
update xml
jwallace42 Sep 28, 2022
91a6253
Update nav2_behavior_tree/nav2_tree_nodes.xml
SteveMacenski Sep 28, 2022
72a8f36
fix
Oct 12, 2022
5c722de
Merge branch 'main' into expections
Oct 12, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class ComputePathToPoseAction : public BtActionNode<nav2_msgs::action::ComputePa
return providedBasicPorts(
{
BT::OutputPort<nav_msgs::msg::Path>("path", "Path created by ComputePathToPose node"),
BT::OutputPort<nav2_msgs::action::ComputePathToPose::Result::_error_code_type>(
"compute_path_to_pose_error_code", "The compute path to pose error code"),
BT::InputPort<geometry_msgs::msg::PoseStamped>("goal", "Destination to plan to"),
BT::InputPort<geometry_msgs::msg::PoseStamped>(
"start", "Start pose of the path if overriding current robot pose"),
Expand Down
1 change: 1 addition & 0 deletions nav2_behavior_tree/nav2_tree_nodes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<input_port name="service_name">Service name</input_port>
<input_port name="server_timeout">Server timeout</input_port>
<output_port name="path">Path created by ComputePathToPose node</output_port>
<output_port name="compute_path_to_pose_error_code">"The compute path to pose error code"</output_port>
</Action>

<Action ID="ComputePathThroughPoses">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,27 @@ void ComputePathToPoseAction::on_tick()
BT::NodeStatus ComputePathToPoseAction::on_success()
{
setOutput("path", result_.result->path);
// Set empty error code, action was successful
result_.result->error_code = nav2_msgs::action::ComputePathToPose::Goal::NONE;
setOutput("compute_path_to_pose_error_code", result_.result->error_code);
return BT::NodeStatus::SUCCESS;
}

BT::NodeStatus ComputePathToPoseAction::on_aborted()
{
nav_msgs::msg::Path empty_path;
setOutput("path", empty_path);
setOutput("compute_path_to_pose_error_code", result_.result->error_code);
return BT::NodeStatus::FAILURE;
}

BT::NodeStatus ComputePathToPoseAction::on_cancelled()
{
nav_msgs::msg::Path empty_path;
setOutput("path", empty_path);
// Set empty error code, action was cancelled
result_.result->error_code = nav2_msgs::action::ComputePathToPose::Goal::NONE;
setOutput("compute_path_to_pose_error_code", result_.result->error_code);
return BT::NodeStatus::SUCCESS;
}

Expand Down
52 changes: 50 additions & 2 deletions nav2_core/include/nav2_core/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,57 @@ namespace nav2_core
class PlannerException : public std::runtime_error
{
public:
explicit PlannerException(const std::string description)
explicit PlannerException(const std::string & description)
: std::runtime_error(description) {}
using Ptr = std::shared_ptr<PlannerException>;
};

class StartOccupied : public PlannerException
{
public:
explicit StartOccupied(const std::string & description)
: PlannerException(description) {}
};

class GoalOccupied : public PlannerException
{
public:
explicit GoalOccupied(const std::string & description)
: PlannerException(description) {}
};

class StartOutsideMapBounds : public PlannerException
{
public:
explicit StartOutsideMapBounds(const std::string & description)
: PlannerException(description) {}
};

class GoalOutsideMapBounds : public PlannerException
{
public:
explicit GoalOutsideMapBounds(const std::string & description)
: PlannerException(description) {}
};

class NoValidPathCouldBeFound : public PlannerException
{
public:
explicit NoValidPathCouldBeFound(const std::string & description)
: PlannerException(description) {}
};

class PlannerTimedOut : public PlannerException
{
public:
explicit PlannerTimedOut(const std::string & description)
: PlannerException(description) {}
};

class PlannerTFError : public PlannerException
{
public:
explicit PlannerTFError(const std::string & description)
: PlannerException(description) {}
};

} // namespace nav2_core
Expand Down
13 changes: 13 additions & 0 deletions nav2_msgs/action/ComputePathToPose.action
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Error codes
# Note: The expected priority order of the errors should match the message order
int16 NONE=0
int16 UNKNOWN=1
int16 TF_ERROR=2
int16 START_OUTSIDE_MAP=3
int16 GOAL_OUTSIDE_MAP=4
int16 START_OCCUPIED=5
int16 GOAL_OCCUPIED=6
int16 TIMEOUT=7
int16 NO_VALID_PATH=8

#goal definition
geometry_msgs/PoseStamped goal
geometry_msgs/PoseStamped start
Expand All @@ -7,5 +19,6 @@ bool use_start # If false, use current robot pose as path start, if true, use st
#result definition
nav_msgs/Path path
builtin_interfaces/Duration planning_time
int16 error_code
---
#feedback definition
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "geometry_msgs/msg/point.hpp"
#include "geometry_msgs/msg/pose_stamped.hpp"
#include "nav2_core/global_planner.hpp"
#include "nav2_core/exceptions.hpp"
#include "nav_msgs/msg/path.hpp"
#include "nav2_navfn_planner/navfn.hpp"
#include "nav2_util/robot_utils.hpp"
Expand Down
61 changes: 29 additions & 32 deletions nav2_navfn_planner/src/navfn_planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,30 @@ nav_msgs::msg::Path NavfnPlanner::createPlan(
#ifdef BENCHMARK_TESTING
steady_clock::time_point a = steady_clock::now();
#endif
unsigned int mx_start, my_start, mx_goal, my_goal;
if (!costmap_->worldToMap(start.pose.position.x, start.pose.position.y, mx_start, my_start)) {
throw nav2_core::StartOutsideMapBounds(
"Start Coordinates of(" + std::to_string(start.pose.position.x) + ", " +
std::to_string(start.pose.position.y) + ") was outside bounds");
}

if (!costmap_->worldToMap(goal.pose.position.x, goal.pose.position.y, mx_goal, my_goal)) {
throw nav2_core::GoalOutsideMapBounds(
"Goal Coordinates of(" + std::to_string(goal.pose.position.x) + ", " +
std::to_string(goal.pose.position.y) + ") was outside bounds");
}

if (costmap_->getCost(mx_start, my_start) == nav2_costmap_2d::LETHAL_OBSTACLE) {
throw nav2_core::StartOccupied(
"Start Coordinates of(" + std::to_string(start.pose.position.x) + ", " +
std::to_string(start.pose.position.y) + ") was in lethal cost");
}

if (tolerance_ == 0 && costmap_->getCost(mx_goal, my_goal) == nav2_costmap_2d::LETHAL_OBSTACLE) {
throw nav2_core::GoalOccupied(
"Goal Coordinates of(" + std::to_string(goal.pose.position.x) + ", " +
std::to_string(goal.pose.position.y) + ") was in lethal cost");
}

// Update planner based on the new costmap size
if (isPlannerOutOfDate()) {
Expand All @@ -148,12 +172,6 @@ nav_msgs::msg::Path NavfnPlanner::createPlan(
if (start.pose.position.x == goal.pose.position.x &&
start.pose.position.y == goal.pose.position.y)
{
unsigned int mx, my;
costmap_->worldToMap(start.pose.position.x, start.pose.position.y, mx, my);
if (costmap_->getCost(mx, my) == nav2_costmap_2d::LETHAL_OBSTACLE) {
RCLCPP_WARN(logger_, "Failed to create a unique pose path because of obstacles");
return path;
}
path.header.stamp = clock_->now();
path.header.frame_id = global_frame_;
geometry_msgs::msg::PoseStamped pose;
Expand All @@ -172,9 +190,8 @@ nav_msgs::msg::Path NavfnPlanner::createPlan(
}

if (!makePlan(start.pose, goal.pose, tolerance_, path)) {
RCLCPP_WARN(
logger_, "%s: failed to create plan with "
"tolerance %.2f.", name_.c_str(), tolerance_);
throw nav2_core::NoValidPathCouldBeFound(
"Failed to create plan with tolerance of: " + std::to_string(tolerance_) );
}


Expand Down Expand Up @@ -221,14 +238,7 @@ NavfnPlanner::makePlan(
start.position.x, start.position.y, goal.position.x, goal.position.y);

unsigned int mx, my;
if (!worldToMap(wx, wy, mx, my)) {
RCLCPP_WARN(
logger_,
"Cannot create a plan: the robot's start position is off the global"
" costmap. Planning will always fail, are you sure"
" the robot has been properly localized?");
return false;
}
worldToMap(wx, wy, mx, my);

// clear the starting cell within the costmap because we know it can't be an obstacle
clearRobotCell(mx, my);
Expand All @@ -251,14 +261,7 @@ NavfnPlanner::makePlan(
wx = goal.position.x;
wy = goal.position.y;

if (!worldToMap(wx, wy, mx, my)) {
RCLCPP_WARN(
logger_,
"The goal sent to the planner is off the global costmap."
" Planning will always fail to this goal.");
return false;
}

worldToMap(wx, wy, mx, my);
int map_goal[2];
map_goal[0] = mx;
map_goal[1] = my;
Expand Down Expand Up @@ -385,13 +388,7 @@ NavfnPlanner::getPlanFromPotential(

// the potential has already been computed, so we won't update our copy of the costmap
unsigned int mx, my;
if (!worldToMap(wx, wy, mx, my)) {
RCLCPP_WARN(
logger_,
"The goal sent to the navfn planner is off the global costmap."
" Planning will always fail to this goal.");
return false;
}
worldToMap(wx, wy, mx, my);

int map_goal[2];
map_goal[0] = mx;
Expand Down
20 changes: 11 additions & 9 deletions nav2_planner/include/nav2_planner/planner_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "pluginlib/class_list_macros.hpp"
#include "nav2_core/global_planner.hpp"
#include "nav2_msgs/srv/is_path_valid.hpp"
#include "nav2_core/exceptions.hpp"

namespace nav2_planner
{
Expand Down Expand Up @@ -152,21 +153,17 @@ class PlannerServer : public nav2_util::LifecycleNode
*/
template<typename T>
bool getStartPose(
std::unique_ptr<nav2_util::SimpleActionServer<T>> & action_server,
typename std::shared_ptr<const typename T::Goal> goal,
geometry_msgs::msg::PoseStamped & start);

/**
* @brief Transform start and goal poses into the costmap
* global frame for path planning plugins to utilize
* @param action_server Action server to terminate if required
* @param start The starting pose to transform
* @param goal Goal pose to transform
* @return bool If successful in transforming poses
*/
template<typename T>
bool transformPosesToGlobalFrame(
std::unique_ptr<nav2_util::SimpleActionServer<T>> & action_server,
geometry_msgs::msg::PoseStamped & curr_start,
geometry_msgs::msg::PoseStamped & curr_goal);

Expand All @@ -180,15 +177,10 @@ class PlannerServer : public nav2_util::LifecycleNode
*/
template<typename T>
bool validatePath(
std::unique_ptr<nav2_util::SimpleActionServer<T>> & action_server,
const geometry_msgs::msg::PoseStamped & curr_goal,
const nav_msgs::msg::Path & path,
const std::string & planner_id);

// Our action server implements the ComputePathToPose action
std::unique_ptr<ActionServerToPose> action_server_pose_;
std::unique_ptr<ActionServerThroughPoses> action_server_poses_;

/**
* @brief The action server callback which calls planner to get the path
* ComputePathToPose
Expand Down Expand Up @@ -216,13 +208,23 @@ class PlannerServer : public nav2_util::LifecycleNode
*/
void publishPlan(const nav_msgs::msg::Path & path);

void exceptionWarning(
const geometry_msgs::msg::PoseStamped & start,
const geometry_msgs::msg::PoseStamped & goal,
const std::string & planner_id,
const std::exception & ex);

/**
* @brief Callback executed when a parameter change is detected
* @param event ParameterEvent message
*/
rcl_interfaces::msg::SetParametersResult
dynamicParametersCallback(std::vector<rclcpp::Parameter> parameters);

// Our action server implements the ComputePathToPose action
std::unique_ptr<ActionServerToPose> action_server_pose_;
std::unique_ptr<ActionServerThroughPoses> action_server_poses_;

// Dynamic parameters handler
rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr dyn_params_handler_;
std::mutex dynamic_params_lock_;
Expand Down
Loading