@@ -52,7 +52,6 @@ PlannerServer::PlannerServer(const rclcpp::NodeOptions & options)
52
52
// Declare this node's parameters
53
53
declare_parameter (" planner_plugins" , default_ids_);
54
54
declare_parameter (" expected_planner_frequency" , 1.0 );
55
-
56
55
declare_parameter (" action_server_result_timeout" , 10.0 );
57
56
58
57
get_parameter (" planner_plugins" , planner_ids_);
@@ -86,6 +85,12 @@ PlannerServer::on_configure(const rclcpp_lifecycle::State & /*state*/)
86
85
costmap_ros_->configure ();
87
86
costmap_ = costmap_ros_->getCostmap ();
88
87
88
+ if (!costmap_ros_->getUseRadius ()) {
89
+ collision_checker_ =
90
+ std::make_unique<nav2_costmap_2d::FootprintCollisionChecker<nav2_costmap_2d::Costmap2D *>>(
91
+ costmap_);
92
+ }
93
+
89
94
// Launch a thread to run the costmap node
90
95
costmap_thread_ = std::make_unique<nav2_util::NodeThread>(costmap_ros_);
91
96
@@ -644,16 +649,34 @@ void PlannerServer::isPathValid(
644
649
std::unique_lock<nav2_costmap_2d::Costmap2D::mutex_t > lock (*(costmap_->getMutex ()));
645
650
unsigned int mx = 0 ;
646
651
unsigned int my = 0 ;
652
+
653
+ bool use_radius = costmap_ros_->getUseRadius ();
654
+
655
+ unsigned int cost = nav2_costmap_2d::FREE_SPACE;
647
656
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
+ }
652
670
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))
655
674
{
656
675
response->is_valid = false ;
676
+ break ;
677
+ } else if (cost == nav2_costmap_2d::LETHAL_OBSTACLE) {
678
+ response->is_valid = false ;
679
+ break ;
657
680
}
658
681
}
659
682
}
0 commit comments