16 #ifndef NAV2_LIFECYCLE_MANAGER__LIFECYCLE_MANAGER_HPP_
17 #define NAV2_LIFECYCLE_MANAGER__LIFECYCLE_MANAGER_HPP_
23 #include <unordered_map>
26 #include "nav2_util/lifecycle_service_client.hpp"
27 #include "nav2_util/node_thread.hpp"
28 #include "rclcpp/rclcpp.hpp"
29 #include "std_srvs/srv/empty.hpp"
30 #include "nav2_msgs/srv/manage_lifecycle_nodes.hpp"
31 #include "std_srvs/srv/trigger.hpp"
32 #include "bondcpp/bond.hpp"
33 #include "diagnostic_updater/diagnostic_updater.hpp"
36 namespace nav2_lifecycle_manager
38 using namespace std::chrono_literals;
40 using nav2_msgs::srv::ManageLifecycleNodes;
65 explicit LifecycleManager(
const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
73 rclcpp::CallbackGroup::SharedPtr callback_group_;
74 std::unique_ptr<nav2_util::NodeThread> service_thread_;
77 rclcpp::Service<ManageLifecycleNodes>::SharedPtr manager_srv_;
78 rclcpp::Service<std_srvs::srv::Trigger>::SharedPtr is_active_srv_;
86 const std::shared_ptr<rmw_request_id_t> request_header,
87 const std::shared_ptr<ManageLifecycleNodes::Request> request,
88 std::shared_ptr<ManageLifecycleNodes::Response> response);
96 void isActiveCallback(
97 const std::shared_ptr<rmw_request_id_t> request_header,
98 const std::shared_ptr<std_srvs::srv::Trigger::Request> request,
99 std::shared_ptr<std_srvs::srv::Trigger::Response> response);
126 bool reset(
bool hard_reset =
false);
143 void onRclPreshutdown();
149 void createLifecycleServiceClients();
155 void shutdownAllNodes();
159 void destroyLifecycleServiceClients();
165 void createBondTimer();
171 bool createBondConnection(
const std::string & node_name);
177 void destroyBondTimer();
184 void checkBondConnections();
191 void checkBondRespawnConnection();
196 bool changeStateForNode(
197 const std::string & node_name,
198 std::uint8_t transition);
203 bool changeStateForAllNodes(std::uint8_t transition,
bool hard_change =
false);
209 void message(
const std::string & msg);
215 void CreateDiagnostic(diagnostic_updater::DiagnosticStatusWrapper & stat);
223 void registerRclPreshutdownCallback();
231 rclcpp::TimerBase::SharedPtr init_timer_;
232 rclcpp::TimerBase::SharedPtr bond_timer_;
233 rclcpp::TimerBase::SharedPtr bond_respawn_timer_;
234 std::chrono::milliseconds bond_timeout_;
237 std::map<std::string, std::shared_ptr<bond::Bond>> bond_map_;
240 std::map<std::string, std::shared_ptr<nav2_util::LifecycleServiceClient>> node_map_;
242 std::map<std::uint8_t, std::string> transition_label_map_;
245 std::unordered_map<std::uint8_t, std::uint8_t> transition_state_map_;
248 std::vector<std::string> node_names_;
252 bool attempt_respawn_reconnection_;
254 NodeState managed_nodes_state_{NodeState::UNCONFIGURED};
255 diagnostic_updater::Updater diagnostics_updater_;
257 rclcpp::Time bond_respawn_start_time_{0};
258 rclcpp::Duration bond_respawn_max_duration_{10s};
Implements service interface to transition the lifecycle nodes of Nav2 stack. It receives transition ...