Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
simple_smoother.hpp
1 // Copyright (c) 2022, 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_SMOOTHER__SIMPLE_SMOOTHER_HPP_
16 #define NAV2_SMOOTHER__SIMPLE_SMOOTHER_HPP_
17 
18 #include <cmath>
19 #include <vector>
20 #include <string>
21 #include <iostream>
22 #include <memory>
23 #include <queue>
24 #include <utility>
25 
26 #include "nav2_core/smoother.hpp"
27 #include "nav2_util/smoother_utils.hpp"
28 #include "nav2_costmap_2d/costmap_2d.hpp"
29 #include "nav2_costmap_2d/cost_values.hpp"
30 #include "nav2_util/geometry_utils.hpp"
31 #include "nav2_ros_common/node_utils.hpp"
32 #include "nav_msgs/msg/path.hpp"
33 #include "angles/angles.h"
34 #include "tf2/utils.hpp"
35 #include "nav2_ros_common/tf2_factories.hpp"
36 #include "nav2_ros_common/lifecycle_node.hpp"
37 
38 namespace nav2_smoother
39 {
40 
46 {
47 public:
51  SimpleSmoother() = default;
52 
56  ~SimpleSmoother() override = default;
57 
58  void configure(
59  const nav2::LifecycleNode::WeakPtr &,
60  std::string name, nav2::TransformBuffer::SharedPtr,
61  std::shared_ptr<nav2_costmap_2d::CostmapSubscriber>,
62  std::shared_ptr<nav2_costmap_2d::FootprintSubscriber>) override;
63 
67  void cleanup() override {costmap_sub_.reset();}
68 
72  void activate() override {}
73 
77  void deactivate() override {}
78 
86  bool smooth(
87  nav_msgs::msg::Path & path,
88  const rclcpp::Duration & max_time) override;
89 
90 protected:
98  void smoothImpl(
99  nav_msgs::msg::Path & path,
100  bool & reversing_segment,
101  const nav2_costmap_2d::Costmap2D * costmap,
102  const double & max_time);
103 
110  inline double getFieldByDim(
111  const geometry_msgs::msg::PoseStamped & msg,
112  const unsigned int & dim);
113 
120  inline void setFieldByDim(
121  geometry_msgs::msg::PoseStamped & msg, const unsigned int dim,
122  const double & value);
123 
124  double tolerance_, data_w_, smooth_w_;
125  int max_its_, refinement_ctr_, refinement_num_;
126  bool do_refinement_, enforce_path_inversion_;
127  std::shared_ptr<nav2_costmap_2d::CostmapSubscriber> costmap_sub_;
128  rclcpp::Logger logger_{rclcpp::get_logger("SimpleSmoother")};
129 };
130 
131 } // namespace nav2_smoother
132 
133 #endif // NAV2_SMOOTHER__SIMPLE_SMOOTHER_HPP_
smoother interface that acts as a virtual base class for all smoother plugins
Definition: smoother.hpp:37
A 2D costmap provides a mapping between points in the world and their associated "costs".
Definition: costmap_2d.hpp:69
A path smoother implementation.
~SimpleSmoother() override=default
A destructor for nav2_smoother::SimpleSmoother.
void setFieldByDim(geometry_msgs::msg::PoseStamped &msg, const unsigned int dim, const double &value)
Set the field value for a given dimension.
void deactivate() override
Method to deactivate smoother and any threads involved in execution.
void activate() override
Method to activate smoother and any threads involved in execution.
SimpleSmoother()=default
A constructor for nav2_smoother::SimpleSmoother.
bool smooth(nav_msgs::msg::Path &path, const rclcpp::Duration &max_time) override
Method to smooth given path.
void smoothImpl(nav_msgs::msg::Path &path, bool &reversing_segment, const nav2_costmap_2d::Costmap2D *costmap, const double &max_time)
Smoother method - does the smoothing on a segment.
double getFieldByDim(const geometry_msgs::msg::PoseStamped &msg, const unsigned int &dim)
Get the field value for a given dimension.
void cleanup() override
Method to cleanup resources.