Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
smoother.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__SMOOTHER_HPP_
16 #define NAV2_SMAC_PLANNER__SMOOTHER_HPP_
17 
18 #include <vector>
19 
20 #include "nav2_costmap_2d/costmap_2d.hpp"
21 #include "nav2_smac_planner/types.hpp"
22 #include "nav2_smac_planner/constants.hpp"
23 #include "nav2_util/geometry_utils.hpp"
24 #include "nav_msgs/msg/path.hpp"
25 #include "ompl/base/StateSpace.h"
26 #include "geometry_msgs/msg/point.hpp"
27 #include "nav2_costmap_2d/footprint_collision_checker.hpp"
28 
29 namespace nav2_smac_planner
30 {
31 
37 {
41  BoundaryPoints(double & x_in, double & y_in, double & theta_in)
42  : x(x_in), y(y_in), theta(theta_in)
43  {}
44 
45  double x;
46  double y;
47  double theta;
48 };
49 
55 {
56  double path_end_idx{0.0};
57  double expansion_path_length{0.0};
58  double original_path_length{0.0};
59  std::vector<BoundaryPoints> pts;
60  bool in_collision{false};
61 };
62 
63 typedef std::vector<BoundaryExpansion> BoundaryExpansions;
64 typedef std::vector<geometry_msgs::msg::PoseStamped>::iterator PathIterator;
65 typedef std::vector<geometry_msgs::msg::PoseStamped>::reverse_iterator ReversePathIterator;
66 
71 class Smoother
72 {
73 public:
77  explicit Smoother(const SmootherParams & params);
78 
82  ~Smoother() {}
83 
89  void initialize(
90  const double & min_turning_radius);
91 
99  bool smooth(
100  nav_msgs::msg::Path & path,
101  const nav2_costmap_2d::Costmap2D * costmap,
102  const double & max_time,
103  const std::vector<geometry_msgs::msg::Point> & footprint =
104  std::vector<geometry_msgs::msg::Point>());
105 
106 protected:
115  bool smoothImpl(
116  nav_msgs::msg::Path & path,
117  bool & reversing_segment,
118  const nav2_costmap_2d::Costmap2D * costmap,
119  const double & max_time,
120  const std::vector<geometry_msgs::msg::Point> & footprint);
121 
128  inline double getFieldByDim(
129  const geometry_msgs::msg::PoseStamped & msg,
130  const unsigned int & dim);
131 
138  inline void setFieldByDim(
139  geometry_msgs::msg::PoseStamped & msg, const unsigned int dim,
140  const double & value);
141 
151  const geometry_msgs::msg::Pose & start_pose,
152  nav_msgs::msg::Path & path,
153  const nav2_costmap_2d::Costmap2D * costmap,
154  const bool & reversing_segment);
155 
165  const geometry_msgs::msg::Pose & end_pose,
166  nav_msgs::msg::Path & path,
167  const nav2_costmap_2d::Costmap2D * costmap,
168  const bool & reversing_segment);
169 
178  unsigned int findShortestBoundaryExpansionIdx(const BoundaryExpansions & boundary_expansions);
179 
189  const geometry_msgs::msg::Pose & start,
190  const geometry_msgs::msg::Pose & end,
191  BoundaryExpansion & expansion,
192  const nav2_costmap_2d::Costmap2D * costmap);
193 
201  template<typename IteratorT>
202  BoundaryExpansions generateBoundaryExpansionPoints(IteratorT start, IteratorT end);
203 
204  double min_turning_rad_, tolerance_, data_w_, smooth_w_;
205  int max_its_, refinement_ctr_, refinement_num_;
206  bool is_holonomic_, do_refinement_;
207  MotionModel motion_model_;
208  ompl::base::StateSpacePtr state_space_;
210  footprint_checker_;
211 };
212 
213 } // namespace nav2_smac_planner
214 
215 #endif // NAV2_SMAC_PLANNER__SMOOTHER_HPP_
A 2D costmap provides a mapping between points in the world and their associated "costs".
Definition: costmap_2d.hpp:69
A Conjugate Gradient 2D path smoother implementation.
void initialize(const double &min_turning_radius)
Initialization of the smoother.
Definition: smoother.cpp:46
bool smoothImpl(nav_msgs::msg::Path &path, bool &reversing_segment, const nav2_costmap_2d::Costmap2D *costmap, const double &max_time, const std::vector< geometry_msgs::msg::Point > &footprint)
Smoother method - does the smoothing on a segment.
Definition: smoother.cpp:112
void enforceStartBoundaryConditions(const geometry_msgs::msg::Pose &start_pose, nav_msgs::msg::Path &path, const nav2_costmap_2d::Costmap2D *costmap, const bool &reversing_segment)
Enforced minimum curvature boundary conditions on plan output the robot is traveling in the same dire...
Definition: smoother.cpp:368
bool smooth(nav_msgs::msg::Path &path, const nav2_costmap_2d::Costmap2D *costmap, const double &max_time, const std::vector< geometry_msgs::msg::Point > &footprint=std::vector< geometry_msgs::msg::Point >())
Smoother API method.
Definition: smoother.cpp:52
double getFieldByDim(const geometry_msgs::msg::PoseStamped &msg, const unsigned int &dim)
Get the field value for a given dimension.
Definition: smoother.cpp:224
~Smoother()
A destructor for nav2_smac_planner::Smoother.
Definition: smoother.hpp:82
void enforceEndBoundaryConditions(const geometry_msgs::msg::Pose &end_pose, nav_msgs::msg::Path &path, const nav2_costmap_2d::Costmap2D *costmap, const bool &reversing_segment)
Enforced minimum curvature boundary conditions on plan output the robot is traveling in the same dire...
Definition: smoother.cpp:414
void setFieldByDim(geometry_msgs::msg::PoseStamped &msg, const unsigned int dim, const double &value)
Set the field value for a given dimension.
Definition: smoother.cpp:236
Smoother(const SmootherParams &params)
A constructor for nav2_smac_planner::Smoother.
Definition: smoother.cpp:35
BoundaryExpansions generateBoundaryExpansionPoints(IteratorT start, IteratorT end)
Generates boundary expansions with end idx at least strategic distances away, using either Reverse or...
Definition: smoother.cpp:331
unsigned int findShortestBoundaryExpansionIdx(const BoundaryExpansions &boundary_expansions)
Given a set of boundary expansion, find the one which is shortest such that it is least likely to con...
Definition: smoother.cpp:249
void findBoundaryExpansion(const geometry_msgs::msg::Pose &start, const geometry_msgs::msg::Pose &end, BoundaryExpansion &expansion, const nav2_costmap_2d::Costmap2D *costmap)
Populate a motion model expansion from start->end into expansion.
Definition: smoother.cpp:271
Boundary expansion state.
Definition: smoother.hpp:55
Set of boundary condition points from expansion.
Definition: smoother.hpp:37
BoundaryPoints(double &x_in, double &y_in, double &theta_in)
A constructor for BoundaryPoints.
Definition: smoother.hpp:41
Parameters for the smoother cost function.