Nav2 Navigation Stack - lyrical  lyrical
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_ros_common/service_server.hpp"
27 #include "nav2_ros_common/lifecycle_node.hpp"
28 #include "nav2_ros_common/node_utils.hpp"
29 #include "nav2_ros_common/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 #include "nav2_ros_common/tf2_factories.hpp"
34 
35 namespace opennav_docking
36 {
42 {
43 public:
47  explicit DockDatabase(std::mutex & mutex);
48 
55  bool initialize(
56  const nav2::LifecycleNode::WeakPtr & parent, nav2::TransformBuffer::SharedPtr tf);
57 
61  ~DockDatabase();
62 
66  void activate();
67 
71  void deactivate();
72 
78  Dock * findDock(const std::string & dock_id);
79 
85  ChargingDock::Ptr findDockPlugin(const std::string & type);
86 
91  unsigned int instance_size() const;
92 
97  unsigned int plugin_size() const;
98 
99 protected:
106  bool getDockPlugins(
107  const nav2::LifecycleNode::SharedPtr & node, nav2::TransformBuffer::SharedPtr tf);
108 
113  bool getDockInstances(const nav2::LifecycleNode::SharedPtr & node);
114 
120  Dock * findDockInstance(const std::string & dock_id);
121 
127  void reloadDbCb(
128  const std::shared_ptr<rmw_request_id_t> request_header,
129  const std::shared_ptr<nav2_msgs::srv::ReloadDockDatabase::Request> request,
130  std::shared_ptr<nav2_msgs::srv::ReloadDockDatabase::Response> response);
131 
132  nav2::LifecycleNode::WeakPtr node_;
133  std::mutex & mutex_; // Don't reload database while actively docking
134  DockPluginMap dock_plugins_;
135  DockMap dock_instances_;
136  pluginlib::ClassLoader<opennav_docking_core::ChargingDock> dock_loader_;
137  nav2::ServiceServer<nav2_msgs::srv::ReloadDockDatabase>::SharedPtr reload_db_service_;
138 };
139 
140 } // namespace opennav_docking
141 
142 #endif // OPENNAV_DOCKING__DOCK_DATABASE_HPP_
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.
Dock * findDockInstance(const std::string &dock_id)
Find a dock instance in the database from ID.
bool getDockPlugins(const nav2::LifecycleNode::SharedPtr &node, nav2::TransformBuffer::SharedPtr tf)
Populate database of dock type plugins.
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.
bool getDockInstances(const nav2::LifecycleNode::SharedPtr &node)
Populate database of dock instances.
void activate()
An activation method.
DockDatabase(std::mutex &mutex)
A constructor for opennav_docking::DockDatabase.
bool initialize(const nav2::LifecycleNode::WeakPtr &parent, nav2::TransformBuffer::SharedPtr tf)
A setup function to populate database.
Definition: types.hpp:33