Nav2 Navigation Stack - kilted  kilted
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 
22 #include <functional>
23 #include <list>
24 #include <memory>
25 #include <string>
26 #include <vector>
27 
28 #include "nav2_smac_planner/node_2d.hpp"
29 #include "nav2_smac_planner/node_hybrid.hpp"
30 #include "nav2_smac_planner/node_lattice.hpp"
31 #include "nav2_smac_planner/types.hpp"
32 #include "nav2_smac_planner/constants.hpp"
33 
34 namespace nav2_smac_planner
35 {
36 
37 template<typename NodeT>
39 {
40 public:
41  typedef NodeT * NodePtr;
42  typedef std::vector<NodePtr> NodeVector;
43  typedef typename NodeT::Coordinates Coordinates;
44  typedef std::function<bool (const uint64_t &, NodeT * &)> NodeGetter;
45  typedef typename NodeT::CoordinateVector CoordinateVector;
46 
52  {
54  NodePtr & node_in,
55  Coordinates & initial_coords_in,
56  Coordinates & proposed_coords_in)
57  : node(node_in),
58  initial_coords(initial_coords_in),
59  proposed_coords(proposed_coords_in)
60  {
61  }
62 
63  NodePtr node;
64  Coordinates initial_coords;
65  Coordinates proposed_coords;
66  };
67 
76  {
77  AnalyticExpansionNodes() = default;
78 
79  void add(
80  NodePtr & node,
81  Coordinates & initial_coords,
82  Coordinates & proposed_coords)
83  {
84  nodes.emplace_back(node, initial_coords, proposed_coords);
85  }
86 
87  void setDirectionChanges(int changes)
88  {
89  direction_changes = changes;
90  }
91 
92  std::vector<AnalyticExpansionNode> nodes;
93  int direction_changes{0};
94  };
95 
100  const MotionModel & motion_model,
101  const SearchInfo & search_info,
102  const bool & traverse_unknown,
103  const unsigned int & dim_3_size);
104 
109  void setCollisionChecker(GridCollisionChecker * collision_checker);
110 
123  NodePtr tryAnalyticExpansion(
124  const NodePtr & current_node,
125  const NodeVector & coarse_check_goals,
126  const NodeVector & fine_check_goals,
127  const CoordinateVector & goals_coords,
128  const NodeGetter & getter, int & iterations,
129  int & closest_distance);
130 
140  const NodePtr & node, const NodePtr & goal,
141  const NodeGetter & getter, const ompl::base::StateSpacePtr & state_space);
142 
152  float refineAnalyticPath(
153  NodePtr & node,
154  const NodePtr & goal_node,
155  const NodeGetter & getter,
156  AnalyticExpansionNodes & analytic_nodes);
157 
165  NodePtr setAnalyticPath(
166  const NodePtr & node, const NodePtr & goal,
167  const AnalyticExpansionNodes & expanded_nodes);
168 
174  int countDirectionChanges(const ompl::base::ReedsSheppStateSpace::ReedsSheppPath & path);
175 
181  void cleanNode(const NodePtr & nodes);
182 
183 protected:
184  MotionModel _motion_model;
185  SearchInfo _search_info;
186  bool _traverse_unknown;
187  unsigned int _dim_3_size;
188  GridCollisionChecker * _collision_checker;
189  std::list<std::unique_ptr<NodeT>> _detached_nodes;
190 };
191 
192 } // namespace nav2_smac_planner
193 
194 #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.
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:36