Nav2 Navigation Stack - kilted  kilted
ROS 2 Navigation Stack
dock_database.hpp
1 // Copyright (c) 2024 Open Navigation LLC
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.
14 
15 #ifndef OPENNAV_DOCKING__DOCK_DATABASE_HPP_
16 #define OPENNAV_DOCKING__DOCK_DATABASE_HPP_
17 
18 #include <vector>
19 #include <memory>
20 #include <string>
21 #include <mutex>
22 
23 #include "rclcpp/rclcpp.hpp"
24 #include "pluginlib/class_loader.hpp"
25 #include "pluginlib/class_list_macros.hpp"
26 #include "nav2_util/service_server.hpp"
27 #include "nav2_util/lifecycle_node.hpp"
28 #include "nav2_util/node_utils.hpp"
29 #include "nav2_util/simple_action_server.hpp"
30 #include "opennav_docking/utils.hpp"
31 #include "opennav_docking/types.hpp"
32 #include "nav2_msgs/srv/reload_dock_database.hpp"
33 
34 namespace opennav_docking
35 {
41 {
42 public:
46  explicit DockDatabase(std::shared_ptr<std::mutex> mutex = std::make_shared<std::mutex>());
47 
54  bool initialize(
55  const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent, std::shared_ptr<tf2_ros::Buffer> tf);
56 
60  ~DockDatabase();
61 
65  void activate();
66 
70  void deactivate();
71 
77  Dock * findDock(const std::string & dock_id);
78 
84  ChargingDock::Ptr findDockPlugin(const std::string & type);
85 
90  unsigned int instance_size() const;
91 
96  unsigned int plugin_size() const;
97 
98 protected:
105  bool getDockPlugins(
106  const rclcpp_lifecycle::LifecycleNode::SharedPtr & node, std::shared_ptr<tf2_ros::Buffer> tf);
107 
112  bool getDockInstances(const rclcpp_lifecycle::LifecycleNode::SharedPtr & node);
113 
119  Dock * findDockInstance(const std::string & dock_id);
120 
126  void reloadDbCb(
127  const std::shared_ptr<rmw_request_id_t> request_header,
128  const std::shared_ptr<nav2_msgs::srv::ReloadDockDatabase::Request> request,
129  std::shared_ptr<nav2_msgs::srv::ReloadDockDatabase::Response> response);
130 
131  rclcpp_lifecycle::LifecycleNode::WeakPtr node_;
132  std::shared_ptr<std::mutex> mutex_; // Don't reload database while actively docking
133  DockPluginMap dock_plugins_;
134  DockMap dock_instances_;
135  pluginlib::ClassLoader<opennav_docking_core::ChargingDock> dock_loader_;
136  nav2_util::ServiceServer<nav2_msgs::srv::ReloadDockDatabase,
137  std::shared_ptr<rclcpp_lifecycle::LifecycleNode>>::SharedPtr reload_db_service_;
138 };
139 
140 } // namespace opennav_docking
141 
142 #endif // OPENNAV_DOCKING__DOCK_DATABASE_HPP_
A simple wrapper on ROS2 services server.
An object to contain docks and docking plugins.
Dock * findDock(const std::string &dock_id)
Find a dock instance & plugin in the databases from ID.
bool getDockInstances(const rclcpp_lifecycle::LifecycleNode::SharedPtr &node)
Populate database of dock instances.
Dock * findDockInstance(const std::string &dock_id)
Find a dock instance in the database from ID.
bool initialize(const rclcpp_lifecycle::LifecycleNode::WeakPtr &parent, std::shared_ptr< tf2_ros::Buffer > tf)
A setup function to populate database.
ChargingDock::Ptr findDockPlugin(const std::string &type)
Find a dock plugin to use for a given type.
void reloadDbCb(const std::shared_ptr< rmw_request_id_t > request_header, const std::shared_ptr< nav2_msgs::srv::ReloadDockDatabase::Request > request, std::shared_ptr< nav2_msgs::srv::ReloadDockDatabase::Response > response)
Service request to reload database of docks.
void deactivate()
An deactivation method.
unsigned int plugin_size() const
Get the number of dock types in the database.
~DockDatabase()
A destructor for opennav_docking::DockDatabase.
unsigned int instance_size() const
Get the number of docks in the database.
DockDatabase(std::shared_ptr< std::mutex > mutex=std::make_shared< std::mutex >())
A constructor for opennav_docking::DockDatabase.
void activate()
An activation method.
bool getDockPlugins(const rclcpp_lifecycle::LifecycleNode::SharedPtr &node, std::shared_ptr< tf2_ros::Buffer > tf)
Populate database of dock type plugins.
Definition: types.hpp:33