Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
obstacle_heuristic.hpp
1 // Copyright (c) 2026, Open Navigation LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License. Reserved.
14 
15 #ifndef NAV2_SMAC_PLANNER__OBSTACLE_HEURISTIC_HPP_
16 #define NAV2_SMAC_PLANNER__OBSTACLE_HEURISTIC_HPP_
17 
18 #include <utility>
19 #include <vector>
20 #include <memory>
21 #include "nav2_smac_planner/constants.hpp"
22 #include "nav2_smac_planner/types.hpp"
23 #include "nav2_costmap_2d/costmap_2d_ros.hpp"
24 
25 namespace nav2_smac_planner
26 {
27 
28 typedef std::pair<float, uint64_t> ObstacleHeuristicElement;
30 {
31  bool operator()(const ObstacleHeuristicElement & a, const ObstacleHeuristicElement & b) const
32  {
33  return a.first > b.first;
34  }
35 };
36 
37 typedef std::vector<ObstacleHeuristicElement> ObstacleHeuristicQueue;
38 
44 {
45 public:
50 
55 
62  std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros_i,
63  const unsigned int & start_x, const unsigned int & start_y,
64  const unsigned int & goal_x, const unsigned int & goal_y,
65  const bool downsample_obstacle_heuristic);
66 
74  const Coordinates & node_coords,
75  const float & cost_penalty,
76  const bool use_quadratic_cost_penalty,
77  const bool downsample_obstacle_heuristic);
78 
79  inline float distanceHeuristic2D(
80  const uint64_t idx, const unsigned int size_x,
81  const unsigned int target_x, const unsigned int target_y)
82  {
83  int dx = static_cast<int>(idx % size_x) - static_cast<int>(target_x);
84  int dy = static_cast<int>(idx / size_x) - static_cast<int>(target_y);
85  return std::sqrt(dx * dx + dy * dy);
86  }
87 
88 protected:
89  LookupTable obstacle_heuristic_lookup_table_;
90  ObstacleHeuristicQueue obstacle_heuristic_queue_;
91  std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros;
92 };
93 
94 } // namespace nav2_smac_planner
95 
96 #endif // NAV2_SMAC_PLANNER__OBSTACLE_HEURISTIC_HPP_
Obstacle Heuristic implementation for graph, Hybrid-A*.
ObstacleHeuristic()
A constructor for nav2_smac_planner::ObstacleHeuristic.
float getObstacleHeuristic(const Coordinates &node_coords, const float &cost_penalty, const bool use_quadratic_cost_penalty, const bool downsample_obstacle_heuristic)
Compute the Obstacle heuristic.
void resetObstacleHeuristic(std::shared_ptr< nav2_costmap_2d::Costmap2DROS > costmap_ros_i, const unsigned int &start_x, const unsigned int &start_y, const unsigned int &goal_x, const unsigned int &goal_y, const bool downsample_obstacle_heuristic)
Compute the wavefront heuristic.
~ObstacleHeuristic()
A destructor for nav2_smac_planner::ObstacleHeuristic.
Implementation of coordinate2d structure.
Definition: types.hpp:224