|
30 | 30 | #include "nav2_util/node_utils.hpp" |
31 | 31 | #include "nav2_util/geometry_utils.hpp" |
32 | 32 | #include "nav2_costmap_2d/cost_values.hpp" |
| 33 | +#include "nav2_costmap_2d/footprint_collision_checker.hpp" |
33 | 34 |
|
34 | 35 | #include "nav2_planner/planner_server.hpp" |
35 | 36 |
|
@@ -83,6 +84,12 @@ PlannerServer::on_configure(const rclcpp_lifecycle::State & /*state*/) |
83 | 84 | costmap_ros_->configure(); |
84 | 85 | costmap_ = costmap_ros_->getCostmap(); |
85 | 86 |
|
| 87 | + if (!costmap_ros_->getUseRadius()) { |
| 88 | + collision_checker_ = |
| 89 | + std::make_unique<nav2_costmap_2d::FootprintCollisionChecker<nav2_costmap_2d::Costmap2D *>>( |
| 90 | + costmap_); |
| 91 | + } |
| 92 | + |
86 | 93 | // Launch a thread to run the costmap node |
87 | 94 | costmap_thread_ = std::make_unique<nav2_util::NodeThread>(costmap_ros_); |
88 | 95 |
|
@@ -585,16 +592,35 @@ void PlannerServer::isPathValid( |
585 | 592 | std::unique_lock<nav2_costmap_2d::Costmap2D::mutex_t> lock(*(costmap_->getMutex())); |
586 | 593 | unsigned int mx = 0; |
587 | 594 | unsigned int my = 0; |
| 595 | + |
| 596 | + bool use_radius = costmap_ros_->getUseRadius(); |
| 597 | + |
| 598 | + unsigned int cost = nav2_costmap_2d::FREE_SPACE; |
| 599 | + |
588 | 600 | 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 | + } |
593 | 614 |
|
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)) |
596 | 618 | { |
597 | 619 | response->is_valid = false; |
| 620 | + break; |
| 621 | + } else if (cost == nav2_costmap_2d::LETHAL_OBSTACLE) { |
| 622 | + response->is_valid = false; |
| 623 | + break; |
598 | 624 | } |
599 | 625 | } |
600 | 626 | } |
|
0 commit comments