Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
nav2_smoother.hpp
1 // Copyright (c) 2021 RoboTech Vision
2 // Copyright (c) 2019 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef NAV2_SMOOTHER__NAV2_SMOOTHER_HPP_
17 #define NAV2_SMOOTHER__NAV2_SMOOTHER_HPP_
18 
19 #include <memory>
20 #include <string>
21 #include <thread>
22 #include <unordered_map>
23 #include <vector>
24 
25 #include "nav2_core/smoother.hpp"
26 #include "nav2_costmap_2d/costmap_2d_ros.hpp"
27 #include "nav2_costmap_2d/costmap_subscriber.hpp"
28 #include "nav2_costmap_2d/costmap_topic_collision_checker.hpp"
29 #include "nav2_costmap_2d/footprint_subscriber.hpp"
30 #include "nav2_msgs/action/smooth_path.hpp"
31 #include "nav2_ros_common/lifecycle_node.hpp"
32 #include "nav2_ros_common/tf2_factories.hpp"
33 #include "nav2_util/robot_utils.hpp"
34 #include "nav2_ros_common/simple_action_server.hpp"
35 #include "pluginlib/class_list_macros.hpp"
36 #include "pluginlib/class_loader.hpp"
37 
38 namespace nav2_smoother
39 {
40 
47 {
48 public:
49  using SmootherMap = std::unordered_map<std::string, nav2_core::Smoother::Ptr>;
50 
55  explicit SmootherServer(const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
60 
61 protected:
72  nav2::CallbackReturn on_configure(const rclcpp_lifecycle::State & state) override;
73 
78  bool loadSmootherPlugins();
79 
88  nav2::CallbackReturn on_activate(const rclcpp_lifecycle::State & state) override;
89 
98  nav2::CallbackReturn on_deactivate(const rclcpp_lifecycle::State & state) override;
99 
108  nav2::CallbackReturn on_cleanup(const rclcpp_lifecycle::State & state) override;
109 
115  nav2::CallbackReturn on_shutdown(const rclcpp_lifecycle::State & state) override;
116 
117  using Action = nav2_msgs::action::SmoothPath;
118  using ActionResult = Action::Result;
120 
126  bool goalReceived(std::shared_ptr<const Action::Goal> goal);
127 
136  void smoothPlan();
137 
145  bool findSmootherId(const std::string & c_name, std::string & name);
146 
152  bool validate(const nav_msgs::msg::Path & path);
153 
154  // Our action server implements the SmoothPath action
155  typename ActionServer::SharedPtr action_server_;
156 
157  // Transforms
158  nav2::TransformBuffer::SharedPtr tf_;
159  nav2::TransformListener::SharedPtr transform_listener_;
160 
161  // Publishers and subscribers
162  nav2::Publisher<nav_msgs::msg::Path>::SharedPtr plan_publisher_;
163 
164  // Smoother Plugins
165  pluginlib::ClassLoader<nav2_core::Smoother> lp_loader_;
166  SmootherMap smoothers_;
167  std::vector<std::string> default_ids_;
168  std::vector<std::string> default_types_;
169  std::vector<std::string> smoother_ids_;
170  std::vector<std::string> smoother_types_;
171  std::string smoother_ids_concat_, current_smoother_;
172 
173  // Utilities
174  std::shared_ptr<nav2_costmap_2d::CostmapSubscriber> costmap_sub_;
175  std::shared_ptr<nav2_costmap_2d::FootprintSubscriber> footprint_sub_;
176  std::shared_ptr<nav2_costmap_2d::CostmapTopicCollisionChecker> collision_checker_;
177 };
178 
179 } // namespace nav2_smoother
180 
181 #endif // NAV2_SMOOTHER__NAV2_SMOOTHER_HPP_
A lifecycle node wrapper to enable common Nav2 needs such as manipulating parameters.
An action server wrapper to make applications simpler using Actions.
This class hosts variety of plugins of different algorithms to smooth or refine a path from the expos...
nav2::CallbackReturn on_deactivate(const rclcpp_lifecycle::State &state) override
Deactivates member variables.
~SmootherServer()
Destructor for nav2_smoother::SmootherServer.
bool loadSmootherPlugins()
Loads smoother plugins from parameter file.
nav2::CallbackReturn on_activate(const rclcpp_lifecycle::State &state) override
Activates member variables.
bool validate(const nav_msgs::msg::Path &path)
Validate that the path contains a meaningful path for smoothing.
SmootherServer(const rclcpp::NodeOptions &options=rclcpp::NodeOptions())
A constructor for nav2_smoother::SmootherServer.
nav2::CallbackReturn on_cleanup(const rclcpp_lifecycle::State &state) override
Calls clean up states and resets member variables.
bool goalReceived(std::shared_ptr< const Action::Goal > goal)
Goal received callback to validate a new goal before acceptance.
nav2::CallbackReturn on_shutdown(const rclcpp_lifecycle::State &state) override
Called when in Shutdown state.
nav2::CallbackReturn on_configure(const rclcpp_lifecycle::State &state) override
Configures smoother parameters and member variables.
bool findSmootherId(const std::string &c_name, std::string &name)
Find the valid smoother ID name for the given request.
void smoothPlan()
SmoothPath action server callback. Handles action server updates and spins server until goal is reach...