Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
analytic_expansion.hpp
1 // Copyright (c) 2021, Samsung Research America
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__ANALYTIC_EXPANSION_HPP_
16 #define NAV2_SMAC_PLANNER__ANALYTIC_EXPANSION_HPP_
17 
18 #include <ompl/base/ScopedState.h>
19 #include <ompl/base/spaces/DubinsStateSpace.h>
20 #include <ompl/base/spaces/ReedsSheppStateSpace.h>
21 #include <ompl/config.h>
22 
23 #include <functional>
24 #include <list>
25 #include <memory>
26 #include <string>
27 #include <vector>
28 
29 #include "nav2_smac_planner/node_2d.hpp"
30 #include "nav2_smac_planner/node_hybrid.hpp"
31 #include "nav2_smac_planner/node_lattice.hpp"
32 #include "nav2_smac_planner/types.hpp"
33 #include "nav2_smac_planner/constants.hpp"
34 
35 namespace nav2_smac_planner
36 {
37 
38 template<typename NodeT>
40 {
41 public:
42  typedef NodeT * NodePtr;
43  typedef std::vector<NodePtr> NodeVector;
44  typedef typename NodeT::Coordinates Coordinates;
45  typedef std::function<bool (const uint64_t &, NodeT * &)> NodeGetter;
46  typedef typename NodeT::CoordinateVector CoordinateVector;
47  using NodeContext = typename NodeT::NodeContext;
48 
54  {
56  NodePtr & node_in,
57  Coordinates & initial_coords_in,
58  Coordinates & proposed_coords_in)
59  : node(node_in),
60  initial_coords(initial_coords_in),
61  proposed_coords(proposed_coords_in)
62  {
63  }
64 
65  NodePtr node;
66  Coordinates initial_coords;
67  Coordinates proposed_coords;
68  };
69 
78  {
79  AnalyticExpansionNodes() = default;
80 
81  void add(
82  NodePtr & node,
83  Coordinates & initial_coords,
84  Coordinates & proposed_coords)
85  {
86  nodes.emplace_back(node, initial_coords, proposed_coords);
87  }
88 
89  void setDirectionChanges(int changes)
90  {
91  direction_changes = changes;
92  }
93 
94  std::vector<AnalyticExpansionNode> nodes;
95  int direction_changes{0};
96  };
97 
102  const MotionModel & motion_model,
103  const SearchInfo & search_info,
104  const bool & traverse_unknown,
105  const unsigned int & dim_3_size);
106 
111  void setCollisionChecker(GridCollisionChecker * collision_checker);
112 
117  void setContext(NodeContext * ctx);
118 
131  NodePtr tryAnalyticExpansion(
132  const NodePtr & current_node,
133  const NodeVector & coarse_check_goals,
134  const NodeVector & fine_check_goals,
135  const CoordinateVector & goals_coords,
136  const NodeGetter & getter, int & iterations,
137  int & closest_distance);
138 
148  const NodePtr & node, const NodePtr & goal,
149  const NodeGetter & getter, const ompl::base::StateSpacePtr & state_space);
150 
160  float refineAnalyticPath(
161  NodePtr & node,
162  const NodePtr & goal_node,
163  const NodeGetter & getter,
164  AnalyticExpansionNodes & analytic_nodes);
165 
173  NodePtr setAnalyticPath(
174  const NodePtr & node, const NodePtr & goal,
175  const AnalyticExpansionNodes & expanded_nodes);
176 
182  #if OMPL_VERSION_VALUE >= 2000000 // 2.0.0
183  int countDirectionChanges(const ompl::base::ReedsSheppStateSpace::PathType & path);
184  #else
185  int countDirectionChanges(const ompl::base::ReedsSheppStateSpace::ReedsSheppPath & path);
186  #endif
187 
193  void cleanNode(const NodePtr & nodes);
194 
195 protected:
196  MotionModel _motion_model;
197  SearchInfo _search_info;
198  bool _traverse_unknown;
199  unsigned int _dim_3_size;
200  GridCollisionChecker * _collision_checker;
201  std::list<std::unique_ptr<NodeT>> _detached_nodes;
202  NodeContext * _ctx = nullptr;
203 };
204 
205 } // namespace nav2_smac_planner
206 
207 #include "nav2_smac_planner/analytic_expansion_impl.hpp" // NOLINT
208 
209 #endif // NAV2_SMAC_PLANNER__ANALYTIC_EXPANSION_HPP_
AnalyticExpansionNodes getAnalyticPath(const NodePtr &node, const NodePtr &goal, const NodeGetter &getter, const ompl::base::StateSpacePtr &state_space)
Perform an analytic path expansion to the goal.
NodePtr tryAnalyticExpansion(const NodePtr &current_node, const NodeVector &coarse_check_goals, const NodeVector &fine_check_goals, const CoordinateVector &goals_coords, const NodeGetter &getter, int &iterations, int &closest_distance)
Attempt an analytic path completion.
int countDirectionChanges(const ompl::base::ReedsSheppStateSpace::ReedsSheppPath &path)
Counts the number of direction changes in a Reeds-Shepp path.
void cleanNode(const NodePtr &nodes)
Takes an expanded nodes to clean up, if necessary, of any state information that may be polluting it ...
void setCollisionChecker(GridCollisionChecker *collision_checker)
Sets the collision checker and costmap to use in expansion validation.
AnalyticExpansion(const MotionModel &motion_model, const SearchInfo &search_info, const bool &traverse_unknown, const unsigned int &dim_3_size)
Constructor for analytic expansion object.
float refineAnalyticPath(NodePtr &node, const NodePtr &goal_node, const NodeGetter &getter, AnalyticExpansionNodes &analytic_nodes)
Refined analytic path from the current node to the goal.
void setContext(NodeContext *ctx)
Sets the shared context to use.
NodePtr setAnalyticPath(const NodePtr &node, const NodePtr &goal, const AnalyticExpansionNodes &expanded_nodes)
Takes final analytic expansion and appends to current expanded node.
A costmap grid collision checker.
Analytic expansion nodes and associated metadata.
Search properties and penalties.
Definition: types.hpp:38