15 #include "nav2_lifecycle_manager/lifecycle_manager_client.hpp"
22 #include "tf2_geometry_msgs/tf2_geometry_msgs.hpp"
23 #include "nav2_util/geometry_utils.hpp"
25 namespace nav2_lifecycle_manager
27 using nav2_util::geometry_utils::orientationAroundZAxis;
30 const std::string & name,
31 std::shared_ptr<rclcpp::Node> parent_node)
33 manage_service_name_ = name + std::string(
"/manage_nodes");
34 active_service_name_ = name + std::string(
"/is_active");
40 manager_client_ = std::make_shared<nav2_util::ServiceClient<ManageLifecycleNodes>>(
41 manage_service_name_, node_);
42 is_active_client_ = std::make_shared<nav2_util::ServiceClient<std_srvs::srv::Trigger>>(
43 active_service_name_, node_);
49 return callService(ManageLifecycleNodes::Request::STARTUP, timeout);
55 return callService(ManageLifecycleNodes::Request::SHUTDOWN, timeout);
61 return callService(ManageLifecycleNodes::Request::PAUSE, timeout);
67 return callService(ManageLifecycleNodes::Request::RESUME, timeout);
73 return callService(ManageLifecycleNodes::Request::RESET, timeout);
79 auto request = std::make_shared<std_srvs::srv::Trigger::Request>();
80 auto response = std::make_shared<std_srvs::srv::Trigger::Response>();
83 node_->get_logger(),
"Waiting for the %s service...",
84 active_service_name_.c_str());
86 if (!is_active_client_->wait_for_service(std::chrono::seconds(1))) {
87 return SystemStatus::TIMEOUT;
91 node_->get_logger(),
"Sending %s request",
92 active_service_name_.c_str());
95 response = is_active_client_->invoke(request, timeout);
96 }
catch (std::runtime_error &) {
97 return SystemStatus::TIMEOUT;
100 if (response->success) {
101 return SystemStatus::ACTIVE;
103 return SystemStatus::INACTIVE;
110 auto request = std::make_shared<ManageLifecycleNodes::Request>();
111 request->command = command;
114 node_->get_logger(),
"Waiting for the %s service...",
115 manage_service_name_.c_str());
117 while (!manager_client_->wait_for_service(timeout)) {
119 RCLCPP_ERROR(node_->get_logger(),
"Client interrupted while waiting for service to appear");
122 RCLCPP_DEBUG(node_->get_logger(),
"Waiting for service to appear...");
126 node_->get_logger(),
"Sending %s request",
127 manage_service_name_.c_str());
129 auto future_result = manager_client_->invoke(request, timeout);
130 return future_result->success;
131 }
catch (std::runtime_error &) {
LifecycleManagerClient(const std::string &name, std::shared_ptr< rclcpp::Node > 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 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.