Skip to content

Commit 7647ba7

Browse files
authored
footprint checks (ros-navigation#4030)
* footprint checks Signed-off-by: gg <[email protected]> * lint fix Signed-off-by: gg <[email protected]> --------- Signed-off-by: gg <[email protected]>
1 parent ef0d773 commit 7647ba7

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

nav2_planner/include/nav2_planner/planner_server.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "pluginlib/class_list_macros.hpp"
4040
#include "nav2_core/global_planner.hpp"
4141
#include "nav2_msgs/srv/is_path_valid.hpp"
42+
#include "nav2_costmap_2d/footprint_collision_checker.hpp"
4243
#include "nav2_core/planner_exceptions.hpp"
4344

4445
namespace nav2_planner
@@ -248,6 +249,8 @@ class PlannerServer : public nav2_util::LifecycleNode
248249
std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros_;
249250
std::unique_ptr<nav2_util::NodeThread> costmap_thread_;
250251
nav2_costmap_2d::Costmap2D * costmap_;
252+
std::unique_ptr<nav2_costmap_2d::FootprintCollisionChecker<nav2_costmap_2d::Costmap2D *>>
253+
collision_checker_;
251254

252255
// Publishers for the path
253256
rclcpp_lifecycle::LifecyclePublisher<nav_msgs::msg::Path>::SharedPtr plan_publisher_;

nav2_planner/src/planner_server.cpp

+30-7
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ PlannerServer::PlannerServer(const rclcpp::NodeOptions & options)
5252
// Declare this node's parameters
5353
declare_parameter("planner_plugins", default_ids_);
5454
declare_parameter("expected_planner_frequency", 1.0);
55-
5655
declare_parameter("action_server_result_timeout", 10.0);
5756

5857
get_parameter("planner_plugins", planner_ids_);
@@ -86,6 +85,12 @@ PlannerServer::on_configure(const rclcpp_lifecycle::State & /*state*/)
8685
costmap_ros_->configure();
8786
costmap_ = costmap_ros_->getCostmap();
8887

88+
if (!costmap_ros_->getUseRadius()) {
89+
collision_checker_ =
90+
std::make_unique<nav2_costmap_2d::FootprintCollisionChecker<nav2_costmap_2d::Costmap2D *>>(
91+
costmap_);
92+
}
93+
8994
// Launch a thread to run the costmap node
9095
costmap_thread_ = std::make_unique<nav2_util::NodeThread>(costmap_ros_);
9196

@@ -644,16 +649,34 @@ void PlannerServer::isPathValid(
644649
std::unique_lock<nav2_costmap_2d::Costmap2D::mutex_t> lock(*(costmap_->getMutex()));
645650
unsigned int mx = 0;
646651
unsigned int my = 0;
652+
653+
bool use_radius = costmap_ros_->getUseRadius();
654+
655+
unsigned int cost = nav2_costmap_2d::FREE_SPACE;
647656
for (unsigned int i = closest_point_index; i < request->path.poses.size(); ++i) {
648-
costmap_->worldToMap(
649-
request->path.poses[i].pose.position.x,
650-
request->path.poses[i].pose.position.y, mx, my);
651-
unsigned int cost = costmap_->getCost(mx, my);
657+
auto & position = request->path.poses[i].pose.position;
658+
if (use_radius) {
659+
if (costmap_->worldToMap(position.x, position.y, mx, my)) {
660+
cost = costmap_->getCost(mx, my);
661+
} else {
662+
cost = nav2_costmap_2d::LETHAL_OBSTACLE;
663+
}
664+
} else {
665+
nav2_costmap_2d::Footprint footprint = costmap_ros_->getRobotFootprint();
666+
auto theta = tf2::getYaw(request->path.poses[i].pose.orientation);
667+
cost = static_cast<unsigned int>(collision_checker_->footprintCostAtPose(
668+
position.x, position.y, theta, footprint));
669+
}
652670

653-
if (cost == nav2_costmap_2d::LETHAL_OBSTACLE ||
654-
cost == nav2_costmap_2d::INSCRIBED_INFLATED_OBSTACLE)
671+
if (use_radius &&
672+
(cost == nav2_costmap_2d::LETHAL_OBSTACLE ||
673+
cost == nav2_costmap_2d::INSCRIBED_INFLATED_OBSTACLE))
655674
{
656675
response->is_valid = false;
676+
break;
677+
} else if (cost == nav2_costmap_2d::LETHAL_OBSTACLE) {
678+
response->is_valid = false;
679+
break;
657680
}
658681
}
659682
}

0 commit comments

Comments
 (0)