17 #ifndef NAV2_SMAC_PLANNER__GOAL_MANAGER_HPP_
18 #define NAV2_SMAC_PLANNER__GOAL_MANAGER_HPP_
20 #include <unordered_set>
24 #include "nav2_smac_planner/types.hpp"
25 #include "nav2_smac_planner/node_2d.hpp"
26 #include "nav2_smac_planner/node_hybrid.hpp"
27 #include "nav2_smac_planner/node_lattice.hpp"
28 #include "nav2_smac_planner/node_basic.hpp"
29 #include "nav2_smac_planner/collision_checker.hpp"
32 namespace nav2_smac_planner
39 template<
typename NodeT>
43 typedef NodeT * NodePtr;
44 typedef std::vector<NodePtr> NodeVector;
45 typedef std::unordered_set<NodePtr> NodeSet;
46 typedef std::vector<GoalState<NodeT>> GoalStateVector;
47 typedef typename NodeT::Coordinates Coordinates;
48 typedef typename NodeT::CoordinateVector CoordinateVector;
54 : _goals_set(NodeSet()),
55 _goals_state(GoalStateVector()),
56 _goals_coordinate(CoordinateVector()),
57 _ref_goal_coord(Coordinates())
72 return _goals_state.empty();
81 _goals_state.push_back({goal,
true});
91 _goals_coordinate.clear();
101 NodeVector & coarse_check_goals, NodeVector & fine_check_goals,
102 int coarse_search_resolution)
104 for (
unsigned int i = 0; i < _goals_state.size(); i++) {
105 if (_goals_state[i].is_valid) {
106 if (i % coarse_search_resolution == 0) {
107 coarse_check_goals.push_back(_goals_state[i].goal);
109 fine_check_goals.push_back(_goals_state[i].goal);
125 const float & tolerance,
127 const bool & traverse_unknown)
130 if (!_goals_set.empty() || !_goals_coordinate.empty()) {
131 throw std::runtime_error(
"Goal set should be cleared before calling "
132 "removeinvalidgoals");
134 for (
unsigned int i = 0; i < _goals_state.size(); i++) {
135 if (_goals_state[i].goal->isNodeValid(traverse_unknown, collision_checker) ||
138 _goals_state[i].is_valid =
true;
139 _goals_set.insert(_goals_state[i].goal);
140 _goals_coordinate.push_back(_goals_state[i].goal->pose);
142 _goals_state[i].is_valid =
false;
154 return _goals_set.find(node) != _goals_set.end();
181 return _goals_coordinate;
190 _ref_goal_coord = coord;
206 return _ref_goal_coord != coord;
211 GoalStateVector _goals_state;
212 CoordinateVector _goals_coordinate;
213 Coordinates _ref_goal_coord;
Responsible for managing multiple variables storing information on the goal.
GoalManager()
Constructor: Initializes empty goal state. sets and coordinate lists.
~GoalManager()=default
Destructor for the GoalManager.
void removeInvalidGoals(const float &tolerance, GridCollisionChecker *collision_checker, const bool &traverse_unknown)
Filters and marks invalid goals based on collision checking and tolerance thresholds.
NodeSet & getGoalsSet()
Get pointer reference to goals set vector.
bool hasGoalChanged(const Coordinates &coord)
Checks whether the Reference goal coordinate has changed.
void addGoal(NodePtr &goal)
Adds goal to the goal vector.
void prepareGoalsForAnalyticExpansion(NodeVector &coarse_check_goals, NodeVector &fine_check_goals, int coarse_search_resolution)
Populates coarse and fine goal lists for analytic expansion.
GoalStateVector & getGoalsState()
Get pointer reference to goals state.
void setRefGoalCoordinates(const Coordinates &coord)
Set the Reference goal coordinate.
void clear()
Clears all internal goal data, including goals, states, and coordinates.
bool goalsIsEmpty()
Checks if the goals set is empty.
bool isGoal(const NodePtr &node)
Check if a given node is part of the goal set.
CoordinateVector & getGoalsCoordinates()
Get pointer reference to goals coordinates.
A costmap grid collision checker.