Skip to content

Commit e434ad8

Browse files
authored
backport ispathvalid improvements (#5428)
Signed-off-by: Siddarth Calidas <calidas.siddarth@gmail.com>
1 parent 4cefd25 commit e434ad8

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

nav2_planner/include/nav2_planner/planner_server.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "tf2_ros/transform_listener.h"
3636
#include "tf2_ros/create_timer_ros.h"
3737
#include "nav2_costmap_2d/costmap_2d_ros.hpp"
38+
#include "nav2_costmap_2d/footprint_collision_checker.hpp"
3839
#include "pluginlib/class_loader.hpp"
3940
#include "pluginlib/class_list_macros.hpp"
4041
#include "nav2_core/global_planner.hpp"
@@ -244,6 +245,8 @@ class PlannerServer : public nav2_util::LifecycleNode
244245
std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros_;
245246
std::unique_ptr<nav2_util::NodeThread> costmap_thread_;
246247
nav2_costmap_2d::Costmap2D * costmap_;
248+
std::unique_ptr<nav2_costmap_2d::FootprintCollisionChecker<nav2_costmap_2d::Costmap2D *>>
249+
collision_checker_;
247250

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

nav2_planner/src/planner_server.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "nav2_util/node_utils.hpp"
3131
#include "nav2_util/geometry_utils.hpp"
3232
#include "nav2_costmap_2d/cost_values.hpp"
33+
#include "nav2_costmap_2d/footprint_collision_checker.hpp"
3334

3435
#include "nav2_planner/planner_server.hpp"
3536

@@ -83,6 +84,12 @@ PlannerServer::on_configure(const rclcpp_lifecycle::State & /*state*/)
8384
costmap_ros_->configure();
8485
costmap_ = costmap_ros_->getCostmap();
8586

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

@@ -585,16 +592,35 @@ void PlannerServer::isPathValid(
585592
std::unique_lock<nav2_costmap_2d::Costmap2D::mutex_t> lock(*(costmap_->getMutex()));
586593
unsigned int mx = 0;
587594
unsigned int my = 0;
595+
596+
bool use_radius = costmap_ros_->getUseRadius();
597+
598+
unsigned int cost = nav2_costmap_2d::FREE_SPACE;
599+
588600
for (unsigned int i = closest_point_index; i < request->path.poses.size(); ++i) {
589-
costmap_->worldToMap(
590-
request->path.poses[i].pose.position.x,
591-
request->path.poses[i].pose.position.y, mx, my);
592-
unsigned int cost = costmap_->getCost(mx, my);
601+
auto & position = request->path.poses[i].pose.position;
602+
if (use_radius) {
603+
if (costmap_->worldToMap(position.x, position.y, mx, my)) {
604+
cost = costmap_->getCost(mx, my);
605+
} else {
606+
cost = nav2_costmap_2d::LETHAL_OBSTACLE;
607+
}
608+
} else {
609+
nav2_costmap_2d::Footprint footprint = costmap_ros_->getRobotFootprint();
610+
auto theta = tf2::getYaw(request->path.poses[i].pose.orientation);
611+
cost = static_cast<unsigned int>(collision_checker_->footprintCostAtPose(
612+
position.x, position.y, theta, footprint));
613+
}
593614

594-
if (cost == nav2_costmap_2d::LETHAL_OBSTACLE ||
595-
cost == nav2_costmap_2d::INSCRIBED_INFLATED_OBSTACLE)
615+
if (use_radius &&
616+
(cost == nav2_costmap_2d::LETHAL_OBSTACLE ||
617+
cost == nav2_costmap_2d::INSCRIBED_INFLATED_OBSTACLE))
596618
{
597619
response->is_valid = false;
620+
break;
621+
} else if (cost == nav2_costmap_2d::LETHAL_OBSTACLE) {
622+
response->is_valid = false;
623+
break;
598624
}
599625
}
600626
}

0 commit comments

Comments
 (0)