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/publisher.hpp"
29 #include "nav2_ros_common/service_server.hpp"
30 #include "rclcpp/rclcpp.hpp"
31 #include "std_msgs/msg/bool.hpp"
32 #include "std_srvs/srv/empty.hpp"
33 #include "nav2_msgs/srv/manage_lifecycle_nodes.hpp"
34 #include "std_srvs/srv/trigger.hpp"
35 #include "bondcpp/bond.hpp"
36 #include "diagnostic_updater/diagnostic_updater.hpp"
37 #include "nav2_ros_common/lifecycle_node.hpp"
40 namespace nav2_lifecycle_manager
42 using namespace std::chrono_literals;
44 using nav2_msgs::srv::ManageLifecycleNodes;
69 explicit LifecycleManager(
const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
77 rclcpp::CallbackGroup::SharedPtr callback_group_;
78 std::unique_ptr<nav2::NodeThread> service_thread_;
81 nav2::ServiceServer<ManageLifecycleNodes>::SharedPtr manager_srv_;
82 nav2::ServiceServer<std_srvs::srv::Trigger>::SharedPtr is_active_srv_;
85 nav2::Publisher<std_msgs::msg::Bool>::SharedPtr is_active_pub_;
94 const std::shared_ptr<rmw_request_id_t> request_header,
95 const std::shared_ptr<ManageLifecycleNodes::Request> request,
96 std::shared_ptr<ManageLifecycleNodes::Response> response);
104 void isActiveCallback(
105 const std::shared_ptr<rmw_request_id_t> request_header,
106 const std::shared_ptr<std_srvs::srv::Trigger::Request> request,
107 std::shared_ptr<std_srvs::srv::Trigger::Response> response);
134 bool reset(
bool hard_reset =
false);
151 void onRclPreshutdown();
157 void createLifecycleServiceClients();
163 void createLifecycleServiceServers();
169 void createLifecyclePublishers();
175 void shutdownAllNodes();
179 void destroyLifecycleServiceClients();
183 void destroyLifecyclePublishers();
189 void createBondTimer();
195 bool createBondConnection(
const std::string & node_name);
201 void destroyBondTimer();
208 void checkBondConnections();
215 void checkBondRespawnConnection();
220 bool changeStateForNode(
221 const std::string & node_name,
222 std::uint8_t transition);
227 bool changeStateForAllNodes(std::uint8_t transition,
bool hard_change =
false);
233 void message(
const std::string & msg);
239 void CreateDiagnostic(diagnostic_updater::DiagnosticStatusWrapper & stat);
247 void registerRclPreshutdownCallback();
252 void setState(
const NodeState & state);
262 void publishIsActiveState();
265 rclcpp::TimerBase::SharedPtr init_timer_;
266 rclcpp::TimerBase::SharedPtr bond_timer_;
267 rclcpp::TimerBase::SharedPtr bond_respawn_timer_;
268 std::chrono::milliseconds bond_timeout_;
269 std::chrono::milliseconds service_timeout_;
272 std::map<std::string, std::shared_ptr<bond::Bond>> bond_map_;
275 std::map<std::string, std::shared_ptr<nav2_util::LifecycleServiceClient>> node_map_;
277 std::map<std::uint8_t, std::string> transition_label_map_;
280 std::unordered_map<std::uint8_t, std::uint8_t> transition_state_map_;
283 std::vector<std::string> node_names_;
287 bool attempt_respawn_reconnection_;
289 NodeState managed_nodes_state_{NodeState::UNCONFIGURED};
290 diagnostic_updater::Updater diagnostics_updater_;
292 rclcpp::Time bond_respawn_start_time_{0};
293 rclcpp::Duration bond_respawn_max_duration_{10s};
Implements service interface to transition the lifecycle nodes of Nav2 stack. It receives transition ...