@@ -41,6 +41,9 @@ HybridMotionTable NodeHybrid::motion_table;
4141float NodeHybrid::size_lookup = 25 ;
4242LookupTable NodeHybrid::dist_heuristic_lookup_table;
4343nav2_costmap_2d::Costmap2D * NodeHybrid::sampled_costmap = nullptr ;
44+ std::shared_ptr<nav2_costmap_2d::Costmap2DROS> NodeHybrid::costmap_ros = nullptr ;
45+ std::shared_ptr<nav2_costmap_2d::InflationLayer> NodeHybrid::inflation_layer = nullptr ;
46+
4447CostmapDownsampler NodeHybrid::downsampler;
4548ObstacleHeuristicQueue NodeHybrid::obstacle_heuristic_queue;
4649
@@ -433,8 +436,7 @@ float NodeHybrid::getTraversalCost(const NodePtr & child)
433436
434437float NodeHybrid::getHeuristicCost (
435438 const Coordinates & node_coords,
436- const Coordinates & goal_coords,
437- const nav2_costmap_2d::Costmap2D * /* costmap*/ )
439+ const Coordinates & goal_coords)
438440{
439441 const float obstacle_heuristic =
440442 getObstacleHeuristic (node_coords, goal_coords, motion_table.cost_penalty );
@@ -477,18 +479,20 @@ inline float distanceHeuristic2D(
477479}
478480
479481void NodeHybrid::resetObstacleHeuristic (
480- nav2_costmap_2d::Costmap2D * costmap ,
482+ std::shared_ptr< nav2_costmap_2d::Costmap2DROS> costmap_ros_i ,
481483 const unsigned int & start_x, const unsigned int & start_y,
482484 const unsigned int & goal_x, const unsigned int & goal_y)
483485{
484486 // Downsample costmap 2x to compute a sparse obstacle heuristic. This speeds up
485487 // the planner considerably to search through 75% less cells with no detectable
486488 // erosion of path quality after even modest smoothing. The error would be no more
487489 // than 0.05 * normalized cost. Since this is just a search prior, there's no loss in generality
488- sampled_costmap = costmap;
490+ costmap_ros = costmap_ros_i;
491+ inflation_layer = nav2_costmap_2d::InflationLayer::getInflationLayer (costmap_ros);
492+ sampled_costmap = costmap_ros->getCostmap ();
489493 if (motion_table.downsample_obstacle_heuristic ) {
490494 std::weak_ptr<nav2_util::LifecycleNode> ptr;
491- downsampler.on_configure (ptr, " fake_frame" , " fake_topic" , costmap , 2.0 , true );
495+ downsampler.on_configure (ptr, " fake_frame" , " fake_topic" , sampled_costmap , 2.0 , true );
492496 downsampler.on_activate ();
493497 sampled_costmap = downsampler.downsample (2.0 );
494498 }
@@ -529,13 +533,37 @@ void NodeHybrid::resetObstacleHeuristic(
529533 obstacle_heuristic_lookup_table[goal_index] = -0 .00001f ;
530534}
531535
536+ float NodeHybrid::adjustedFootprintCost (const float & cost)
537+ {
538+ if (!inflation_layer) {
539+ return cost;
540+ }
541+
542+ const auto layered_costmap = costmap_ros->getLayeredCostmap ();
543+ const float scale_factor = inflation_layer->getCostScalingFactor ();
544+ const float min_radius = layered_costmap->getInscribedRadius ();
545+ float dist_to_obj = (scale_factor * min_radius - log (cost) + log (253 .0f )) / scale_factor;
546+
547+ // Subtract minimum radius for edge cost
548+ dist_to_obj -= min_radius;
549+ if (dist_to_obj < 0 .0f ) {
550+ dist_to_obj = 0 .0f ;
551+ }
552+
553+ // Compute cost at this value
554+ return static_cast <float >(
555+ inflation_layer->computeCost (dist_to_obj / layered_costmap->getCostmap ()->getResolution ()));
556+ }
557+
558+
532559float NodeHybrid::getObstacleHeuristic (
533560 const Coordinates & node_coords,
534561 const Coordinates & goal_coords,
535562 const double & cost_penalty)
536563{
537564 // If already expanded, return the cost
538565 const unsigned int size_x = sampled_costmap->getSizeInCellsX ();
566+ const bool is_circular = costmap_ros->getUseRadius ();
539567
540568 // Divided by 2 due to downsampled costmap.
541569 unsigned int start_y, start_x;
@@ -605,7 +633,14 @@ float NodeHybrid::getObstacleHeuristic(
605633 // if neighbor path is better and non-lethal, set new cost and add to queue
606634 if (new_idx < size_x * size_y) {
607635 cost = static_cast <float >(sampled_costmap->getCost (new_idx));
608- if (cost >= INSCRIBED) {
636+
637+ if (!is_circular) {
638+ // Adjust cost value if using SE2 footprint checks
639+ cost = adjustedFootprintCost (cost);
640+ if (cost >= OCCUPIED) {
641+ continue ;
642+ }
643+ } else if (cost >= INSCRIBED) {
609644 continue ;
610645 }
611646
0 commit comments