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_ros_common/node_thread.hpp"
28 #include "nav2_ros_common/service_server.hpp"
29 #include "rclcpp/rclcpp.hpp"
30 #include "std_srvs/srv/empty.hpp"
31 #include "nav2_msgs/srv/manage_lifecycle_nodes.hpp"
32 #include "std_srvs/srv/trigger.hpp"
33 #include "bondcpp/bond.hpp"
34 #include "diagnostic_updater/diagnostic_updater.hpp"
35 #include "nav2_ros_common/lifecycle_node.hpp"
38 namespace nav2_lifecycle_manager
40 using namespace std::chrono_literals;
42 using nav2_msgs::srv::ManageLifecycleNodes;
67 explicit LifecycleManager(
const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
75 rclcpp::CallbackGroup::SharedPtr callback_group_;
76 std::unique_ptr<nav2::NodeThread> service_thread_;
79 nav2::ServiceServer<ManageLifecycleNodes>::SharedPtr manager_srv_;
80 nav2::ServiceServer<std_srvs::srv::Trigger>::SharedPtr is_active_srv_;
88 const std::shared_ptr<rmw_request_id_t> request_header,
89 const std::shared_ptr<ManageLifecycleNodes::Request> request,
90 std::shared_ptr<ManageLifecycleNodes::Response> response);
98 void isActiveCallback(
99 const std::shared_ptr<rmw_request_id_t> request_header,
100 const std::shared_ptr<std_srvs::srv::Trigger::Request> request,
101 std::shared_ptr<std_srvs::srv::Trigger::Response> response);
128 bool reset(
bool hard_reset =
false);
145 void onRclPreshutdown();
151 void createLifecycleServiceClients();
157 void createLifecycleServiceServers();
163 void shutdownAllNodes();
167 void destroyLifecycleServiceClients();
173 void createBondTimer();
179 bool createBondConnection(
const std::string & node_name);
185 void destroyBondTimer();
192 void checkBondConnections();
199 void checkBondRespawnConnection();
204 bool changeStateForNode(
205 const std::string & node_name,
206 std::uint8_t transition);
211 bool changeStateForAllNodes(std::uint8_t transition,
bool hard_change =
false);
217 void message(
const std::string & msg);
223 void CreateDiagnostic(diagnostic_updater::DiagnosticStatusWrapper & stat);
231 void registerRclPreshutdownCallback();
239 rclcpp::TimerBase::SharedPtr init_timer_;
240 rclcpp::TimerBase::SharedPtr bond_timer_;
241 rclcpp::TimerBase::SharedPtr bond_respawn_timer_;
242 std::chrono::milliseconds bond_timeout_;
243 std::chrono::milliseconds service_timeout_;
246 std::map<std::string, std::shared_ptr<bond::Bond>> bond_map_;
249 std::map<std::string, std::shared_ptr<nav2_util::LifecycleServiceClient>> node_map_;
251 std::map<std::uint8_t, std::string> transition_label_map_;
254 std::unordered_map<std::uint8_t, std::uint8_t> transition_state_map_;
257 std::vector<std::string> node_names_;
261 bool attempt_respawn_reconnection_;
263 NodeState managed_nodes_state_{NodeState::UNCONFIGURED};
264 diagnostic_updater::Updater diagnostics_updater_;
266 rclcpp::Time bond_respawn_start_time_{0};
267 rclcpp::Duration bond_respawn_max_duration_{10s};
Implements service interface to transition the lifecycle nodes of Nav2 stack. It receives transition ...