Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
lifecycle_manager_client.hpp
1 // Copyright (c) 2019 Intel Corporation
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 NAV2_LIFECYCLE_MANAGER__LIFECYCLE_MANAGER_CLIENT_HPP_
16 #define NAV2_LIFECYCLE_MANAGER__LIFECYCLE_MANAGER_CLIENT_HPP_
17 
18 #include <memory>
19 #include <string>
20 
21 #include "nav2_msgs/action/navigate_to_pose.hpp"
22 #include "rclcpp/logger.hpp"
23 #include "rclcpp/node.hpp"
24 #include "std_srvs/srv/empty.hpp"
25 #include "nav2_msgs/srv/manage_lifecycle_nodes.hpp"
26 #include "std_srvs/srv/trigger.hpp"
27 #include "nav2_ros_common/lifecycle_node.hpp"
28 #include "nav2_ros_common/service_client.hpp"
29 
30 namespace nav2_lifecycle_manager
31 {
36 enum class SystemStatus {ACTIVE, INACTIVE, TIMEOUT};
43 {
44 public:
50  template<typename NodeT>
52  const std::string & name,
53  NodeT parent_node)
54  {
55  manage_service_name_ = name + std::string("/manage_nodes");
56  active_service_name_ = name + std::string("/is_active");
57 
58  // Use parent node for service call and logging
59  logger_ = parent_node->get_logger();
60 
61  // Create the service clients
62  // Could be using a user rclcpp::Node, so need to use the Nav2 factory to create the
63  // subscription to convert nav2::LifecycleNode, rclcpp::Node or rclcpp_lifecycle::LifecycleNode
64  manager_client_ = nav2::interfaces::create_client<ManageLifecycleNodes>(
65  parent_node, manage_service_name_, true /*creates and spins an internal executor*/);
66  is_active_client_ = nav2::interfaces::create_client<std_srvs::srv::Trigger>(
67  parent_node, active_service_name_, true /*creates and spins an internal executor*/);
68  }
69 
70  // Client-side interface to the Nav2 lifecycle manager
75  bool startup(const std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
80  bool shutdown(const std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
85  bool pause(const std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
90  bool resume(const std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
95  bool reset(const std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
100  bool configure(const std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
105  bool cleanup(const std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
110  SystemStatus is_active(const std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
111 
112 protected:
113  using ManageLifecycleNodes = nav2_msgs::srv::ManageLifecycleNodes;
114 
119  bool callService(
120  uint8_t command,
121  const std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
122 
123  // The node to use for the service call
124  rclcpp::Node::SharedPtr node_; // nosemgrep
125  rclcpp::Logger logger_{rclcpp::get_logger("nav2_lifecycle_manager_client")};
126 
127  nav2::ServiceClient<ManageLifecycleNodes>::SharedPtr manager_client_;
128  nav2::ServiceClient<std_srvs::srv::Trigger>::SharedPtr is_active_client_;
129  std::string manage_service_name_;
130  std::string active_service_name_;
131 };
132 
133 } // namespace nav2_lifecycle_manager
134 
135 #endif // NAV2_LIFECYCLE_MANAGER__LIFECYCLE_MANAGER_CLIENT_HPP_
bool cleanup(const std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
Make cleanup service call.
LifecycleManagerClient(const std::string &name, NodeT parent_node)
A constructor for LifeCycleMangerClient.
bool pause(const std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
Make pause service call.
SystemStatus is_active(const std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
Check if lifecycle node manager server is active.
bool shutdown(const std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
Make shutdown service call.
bool reset(const std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
Make reset service call.
bool startup(const std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
Make start up service call.
bool configure(const std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
Make configure service call.
bool callService(uint8_t command, const std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
A generic method used to call startup, shutdown, etc.
bool resume(const std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
Make resume service call.