Nav2 Navigation Stack - kilted  kilted
ROS 2 Navigation Stack
behavior_server.hpp
1 // Copyright (c) 2018 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 
16 #include <chrono>
17 #include <string>
18 #include <memory>
19 #include <vector>
20 
21 #include "nav2_util/lifecycle_node.hpp"
22 #include "tf2_ros/transform_listener.h"
23 #include "tf2_ros/create_timer_ros.h"
24 #include "pluginlib/class_loader.hpp"
25 #include "pluginlib/class_list_macros.hpp"
26 #include "nav2_core/behavior.hpp"
27 
28 #ifndef NAV2_BEHAVIORS__BEHAVIOR_SERVER_HPP_
29 #define NAV2_BEHAVIORS__BEHAVIOR_SERVER_HPP_
30 
31 namespace behavior_server
32 {
33 
39 {
40 public:
45  explicit BehaviorServer(const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
46  ~BehaviorServer();
47 
48 protected:
53  bool loadBehaviorPlugins();
54 
59 
67  nav2_util::CallbackReturn on_configure(const rclcpp_lifecycle::State & state) override;
68 
72  nav2_util::CallbackReturn on_activate(const rclcpp_lifecycle::State & state) override;
73 
77  nav2_util::CallbackReturn on_deactivate(const rclcpp_lifecycle::State & state) override;
78 
82  nav2_util::CallbackReturn on_cleanup(const rclcpp_lifecycle::State & state) override;
83 
87  nav2_util::CallbackReturn on_shutdown(const rclcpp_lifecycle::State & state) override;
88 
89  std::shared_ptr<tf2_ros::Buffer> tf_;
90  std::shared_ptr<tf2_ros::TransformListener> transform_listener_;
91 
92  // Plugins
93  pluginlib::ClassLoader<nav2_core::Behavior> plugin_loader_;
94  std::vector<pluginlib::UniquePtr<nav2_core::Behavior>> behaviors_;
95  std::vector<std::string> default_ids_;
96  std::vector<std::string> default_types_;
97  std::vector<std::string> behavior_ids_;
98  std::vector<std::string> behavior_types_;
99 
100  // Utilities
101  std::unique_ptr<nav2_costmap_2d::CostmapSubscriber> local_costmap_sub_;
102  std::unique_ptr<nav2_costmap_2d::FootprintSubscriber> local_footprint_sub_;
103  std::shared_ptr<nav2_costmap_2d::CostmapTopicCollisionChecker> local_collision_checker_;
104 
105  std::unique_ptr<nav2_costmap_2d::CostmapSubscriber> global_costmap_sub_;
106  std::unique_ptr<nav2_costmap_2d::FootprintSubscriber> global_footprint_sub_;
107  std::shared_ptr<nav2_costmap_2d::CostmapTopicCollisionChecker> global_collision_checker_;
108 };
109 
110 } // namespace behavior_server
111 
112 #endif // NAV2_BEHAVIORS__BEHAVIOR_SERVER_HPP_
An server hosting a map of behavior plugins.
nav2_util::CallbackReturn on_cleanup(const rclcpp_lifecycle::State &state) override
Cleanup lifecycle server.
BehaviorServer(const rclcpp::NodeOptions &options=rclcpp::NodeOptions())
A constructor for behavior_server::BehaviorServer.
nav2_util::CallbackReturn on_deactivate(const rclcpp_lifecycle::State &state) override
Deactivate lifecycle server.
nav2_util::CallbackReturn on_activate(const rclcpp_lifecycle::State &state) override
Activate lifecycle server.
void configureBehaviorPlugins()
configures behavior plugins
nav2_util::CallbackReturn on_shutdown(const rclcpp_lifecycle::State &state) override
Shutdown lifecycle server.
void setupResourcesForBehaviorPlugins()
configures behavior plugins
nav2_util::CallbackReturn on_configure(const rclcpp_lifecycle::State &state) override
Configure lifecycle server.
bool loadBehaviorPlugins()
Loads behavior plugins from parameter file.
A lifecycle node wrapper to enable common Nav2 needs such as manipulating parameters.