Skip to content

Commit f5543c3

Browse files
Feat/smac planner include orientation flexibility (#4127)
* include functionality to allow multiple goal heading for smac planner Signed-off-by: stevedanomodolor <stevedan.o.omodolor@gmail.com> * include missing parameter inclusion Signed-off-by: stevedanomodolor <stevedan.o.omodolor@gmail.com> * increase test coverage Signed-off-by: stevedanomodolor <stevedan.o.omodolor@gmail.com> --------- Signed-off-by: stevedanomodolor <stevedan.o.omodolor@gmail.com>
1 parent b6a5387 commit f5543c3

24 files changed

+5193
-160
lines changed

nav2_smac_planner/include/nav2_smac_planner/a_star.hpp

+30-17
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "nav2_smac_planner/node_hybrid.hpp"
3333
#include "nav2_smac_planner/node_lattice.hpp"
3434
#include "nav2_smac_planner/node_basic.hpp"
35+
#include "nav2_smac_planner/goal_manager.hpp"
3536
#include "nav2_smac_planner/types.hpp"
3637
#include "nav2_smac_planner/constants.hpp"
3738

@@ -54,6 +55,9 @@ class AStarAlgorithm
5455
typedef typename NodeT::CoordinateVector CoordinateVector;
5556
typedef typename NodeVector::iterator NeighborIterator;
5657
typedef std::function<bool (const uint64_t &, NodeT * &)> NodeGetter;
58+
typedef GoalManager<NodeT> GoalManagerT;
59+
typedef std::vector<GoalState<NodeT>> GoalStateVector;
60+
5761

5862
/**
5963
* @struct nav2_smac_planner::NodeComparator
@@ -90,6 +94,8 @@ class AStarAlgorithm
9094
* or planning time exceeded
9195
* @param max_planning_time Maximum time (in seconds) to wait for a plan, createPath returns
9296
* false after this timeout
97+
* @param lookup_table_size Size of the lookup table to store heuristic values
98+
* @param dim_3_size Number of quantization bins
9399
*/
94100
void initialize(
95101
const bool & allow_unknown,
@@ -125,11 +131,15 @@ class AStarAlgorithm
125131
* @param mx The node X index of the goal
126132
* @param my The node Y index of the goal
127133
* @param dim_3 The node dim_3 index of the goal
134+
* @param goal_heading_mode The goal heading mode to use
135+
* @param coarse_search_resolution The resolution to search for goal heading
128136
*/
129137
void setGoal(
130138
const float & mx,
131139
const float & my,
132-
const unsigned int & dim_3);
140+
const unsigned int & dim_3,
141+
const GoalHeadingMode & goal_heading_mode = GoalHeadingMode::DEFAULT,
142+
const int & coarse_search_resolution = 1);
133143

134144
/**
135145
* @brief Set the starting pose for planning, as a node index
@@ -154,12 +164,6 @@ class AStarAlgorithm
154164
*/
155165
NodePtr & getStart();
156166

157-
/**
158-
* @brief Get pointer reference to goal node
159-
* @return Node pointer reference to goal node
160-
*/
161-
NodePtr & getGoal();
162-
163167
/**
164168
* @brief Get maximum number of on-approach iterations after within threshold
165169
* @return Reference to Maximum on-approach iterations parameter
@@ -190,6 +194,18 @@ class AStarAlgorithm
190194
*/
191195
unsigned int & getSizeDim3();
192196

197+
/**
198+
* @brief Get the resolution of the coarse search
199+
* @return Size of the goals to expand
200+
*/
201+
unsigned int getCoarseSearchResolution();
202+
203+
/**
204+
* @brief Get the goals manager class
205+
* @return Goal manager class
206+
*/
207+
GoalManagerT getGoalManager();
208+
193209
protected:
194210
/**
195211
* @brief Get pointer to next goal in open set
@@ -210,13 +226,6 @@ class AStarAlgorithm
210226
*/
211227
inline NodePtr addToGraph(const uint64_t & index);
212228

213-
/**
214-
* @brief Check if this node is the goal node
215-
* @param node Node pointer to check if its the goal node
216-
* @return if node is goal
217-
*/
218-
inline bool isGoal(NodePtr & node);
219-
220229
/**
221230
* @brief Get cost of heuristic of node
222231
* @param node Node pointer to get heuristic for
@@ -240,6 +249,11 @@ class AStarAlgorithm
240249
*/
241250
inline void clearGraph();
242251

252+
/**
253+
* @brief Check if node has been visited
254+
* @param current_node Node to check if visited
255+
* @return if node has been visited
256+
*/
243257
inline bool onVisitationCheckNode(const NodePtr & node);
244258

245259
/**
@@ -260,12 +274,11 @@ class AStarAlgorithm
260274
unsigned int _x_size;
261275
unsigned int _y_size;
262276
unsigned int _dim3_size;
277+
unsigned int _coarse_search_resolution;
263278
SearchInfo _search_info;
264279

265-
Coordinates _goal_coordinates;
266280
NodePtr _start;
267-
NodePtr _goal;
268-
281+
GoalManagerT _goal_manager;
269282
Graph _graph;
270283
NodeQueue _queue;
271284

nav2_smac_planner/include/nav2_smac_planner/analytic_expansion.hpp

+27-6
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ class AnalyticExpansion
3535
{
3636
public:
3737
typedef NodeT * NodePtr;
38+
typedef std::vector<NodePtr> NodeVector;
3839
typedef typename NodeT::Coordinates Coordinates;
3940
typedef std::function<bool (const uint64_t &, NodeT * &)> NodeGetter;
41+
typedef typename NodeT::CoordinateVector CoordinateVector;
4042

4143
/**
4244
* @struct nav2_smac_planner::AnalyticExpansion::AnalyticExpansionNodes
@@ -79,17 +81,22 @@ class AnalyticExpansion
7981
/**
8082
* @brief Attempt an analytic path completion
8183
* @param node The node to start the analytic path from
82-
* @param goal The goal node to plan to
84+
* @param coarse_check_goals Coarse list of goals nodes to plan to
85+
* @param fine_check_goals Fine list of goals nodes to plan to
86+
* @param goals_coords vector of goal coordinates to plan to
8387
* @param getter Gets a node at a set of coordinates
8488
* @param iterations Iterations to run over
85-
* @param best_cost Best heuristic cost to propertionally expand more closer to the goal
86-
* @return Node pointer reference to goal node if successful, else
87-
* return nullptr
89+
* @param closest_distance Closest distance to goal
90+
* @return Node pointer reference to goal node with the best score out of the goals node if
91+
* successful, else return nullptr
8892
*/
8993
NodePtr tryAnalyticExpansion(
9094
const NodePtr & current_node,
91-
const NodePtr & goal_node,
92-
const NodeGetter & getter, int & iterations, int & best_cost);
95+
const NodeVector & coarse_check_goals,
96+
const NodeVector & fine_check_goals,
97+
const CoordinateVector & goals_coords,
98+
const NodeGetter & getter, int & iterations,
99+
int & closest_distance);
93100

94101
/**
95102
* @brief Perform an analytic path expansion to the goal
@@ -103,6 +110,20 @@ class AnalyticExpansion
103110
const NodePtr & node, const NodePtr & goal,
104111
const NodeGetter & getter, const ompl::base::StateSpacePtr & state_space);
105112

113+
/**
114+
* @brief Refined analytic path from the current node to the goal
115+
* @param current_node The node to start the analytic path from
116+
* @param goal_node The goal node to plan to
117+
* @param getter The function object that gets valid nodes from the graph
118+
* @param analytic_nodes The set of analytic nodes to refine
119+
* @return The score of the refined path
120+
*/
121+
float refineAnalyticPath(
122+
const NodePtr & current_node,
123+
const NodePtr & goal_node,
124+
const NodeGetter & getter,
125+
AnalyticExpansionNodes & analytic_nodes);
126+
106127
/**
107128
* @brief Takes final analytic expansion and appends to current expanded node
108129
* @param node The node to start the analytic path from

nav2_smac_planner/include/nav2_smac_planner/constants.hpp

+35
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ enum class MotionModel
2828
STATE_LATTICE = 4,
2929
};
3030

31+
enum class GoalHeadingMode
32+
{
33+
UNKNOWN = 0,
34+
DEFAULT = 1,
35+
BIDIRECTIONAL = 2,
36+
ALL_DIRECTION = 3,
37+
};
38+
3139
inline std::string toString(const MotionModel & n)
3240
{
3341
switch (n) {
@@ -59,6 +67,33 @@ inline MotionModel fromString(const std::string & n)
5967
}
6068
}
6169

70+
inline std::string toString(const GoalHeadingMode & n)
71+
{
72+
switch (n) {
73+
case GoalHeadingMode::DEFAULT:
74+
return "DEFAULT";
75+
case GoalHeadingMode::BIDIRECTIONAL:
76+
return "BIDIRECTIONAL";
77+
case GoalHeadingMode::ALL_DIRECTION:
78+
return "ALL_DIRECTION";
79+
default:
80+
return "Unknown";
81+
}
82+
}
83+
84+
inline GoalHeadingMode fromStringToGH(const std::string & n)
85+
{
86+
if (n == "DEFAULT") {
87+
return GoalHeadingMode::DEFAULT;
88+
} else if (n == "BIDIRECTIONAL") {
89+
return GoalHeadingMode::BIDIRECTIONAL;
90+
} else if (n == "ALL_DIRECTION") {
91+
return GoalHeadingMode::ALL_DIRECTION;
92+
} else {
93+
return GoalHeadingMode::UNKNOWN;
94+
}
95+
}
96+
6297
const float UNKNOWN_COST = 255.0;
6398
const float OCCUPIED_COST = 254.0;
6499
const float INSCRIBED_COST = 253.0;

0 commit comments

Comments
 (0)