15 #include "nav2_util/lifecycle_node.hpp"
21 #include "lifecycle_msgs/msg/state.hpp"
27 const std::string & node_name,
28 const std::string & ns,
29 const rclcpp::NodeOptions & options)
33 this->declare_parameter(bond::msg::Constants::DISABLE_HEARTBEAT_TIMEOUT_PARAM,
true);
36 bond::msg::Constants::DISABLE_HEARTBEAT_TIMEOUT_PARAM,
true));
43 LifecycleNode::~LifecycleNode()
45 RCLCPP_INFO(get_logger(),
"Destroying");
49 if (rcl_preshutdown_cb_handle_) {
50 rclcpp::Context::SharedPtr context = get_node_base_interface()->get_context();
51 context->remove_pre_shutdown_callback(*(rcl_preshutdown_cb_handle_.get()));
52 rcl_preshutdown_cb_handle_.reset();
58 RCLCPP_INFO(get_logger(),
"Creating bond (%s) to lifecycle manager.", this->get_name());
60 bond_ = std::make_unique<bond::Bond>(
65 bond_->setHeartbeatPeriod(0.10);
66 bond_->setHeartbeatTimeout(4.0);
77 if (get_current_state().
id() ==
78 lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE)
83 if (get_current_state().
id() ==
84 lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE)
93 get_logger(),
"Running Nav2 LifecycleNode rcl preshutdown (%s)",
103 rclcpp::Context::SharedPtr context = get_node_base_interface()->get_context();
105 rcl_preshutdown_cb_handle_ = std::make_unique<rclcpp::PreShutdownCallbackHandle>(
106 context->add_pre_shutdown_callback(
113 RCLCPP_INFO(get_logger(),
"Destroying bond (%s) to lifecycle manager.", this->get_name());
124 "\n\t%s lifecycle node launched. \n"
125 "\tWaiting on external lifecycle transitions to activate\n"
126 "\tSee https://design.ros2.org/articles/node_lifecycle.html for more information.", get_name());
A lifecycle node wrapper to enable common Nav2 needs such as manipulating parameters.
void register_rcl_preshutdown_callback()
LifecycleNode(const std::string &node_name, const std::string &ns="", const rclcpp::NodeOptions &options=rclcpp::NodeOptions())
A lifecycle node constructor.
void printLifecycleNodeNotification()
Print notifications for lifecycle node.
std::shared_ptr< nav2_util::LifecycleNode > shared_from_this()
Get a shared pointer of this.
virtual void on_rcl_preshutdown()
Perform preshutdown activities before our Context is shutdown. Note that this is related to our Conte...
void createBond()
Create bond connection to lifecycle manager.
void destroyBond()
Destroy bond connection to lifecycle manager.