Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LifecycleNode] add bond_heartbeat_period #4342

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nav2_util/include/nav2_util/lifecycle_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class LifecycleNode : public rclcpp_lifecycle::LifecycleNode

// Connection to tell that server is still up
std::unique_ptr<bond::Bond> bond_{nullptr};
double bond_heartbeat_period;
};

} // namespace nav2_util
Expand Down
31 changes: 20 additions & 11 deletions nav2_util/src/lifecycle_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <vector>

#include "lifecycle_msgs/msg/state.hpp"
#include "nav2_util/node_utils.hpp"

namespace nav2_util
{
Expand All @@ -35,6 +36,10 @@ LifecycleNode::LifecycleNode(
rclcpp::Parameter(
bond::msg::Constants::DISABLE_HEARTBEAT_TIMEOUT_PARAM, true));

nav2_util::declare_parameter_if_not_declared(
this, "bond_heartbeat_period", rclcpp::ParameterValue(0.1));
this->get_parameter("bond_heartbeat_period", bond_heartbeat_period);

printLifecycleNodeNotification();

register_rcl_preshutdown_callback();
Expand All @@ -55,16 +60,18 @@ LifecycleNode::~LifecycleNode()

void LifecycleNode::createBond()
{
RCLCPP_INFO(get_logger(), "Creating bond (%s) to lifecycle manager.", this->get_name());
if (bond_heartbeat_period > 0.0) {
RCLCPP_INFO(get_logger(), "Creating bond (%s) to lifecycle manager.", this->get_name());

bond_ = std::make_unique<bond::Bond>(
std::string("bond"),
this->get_name(),
shared_from_this());
bond_ = std::make_unique<bond::Bond>(
std::string("bond"),
this->get_name(),
shared_from_this());

bond_->setHeartbeatPeriod(0.10);
bond_->setHeartbeatTimeout(4.0);
bond_->start();
bond_->setHeartbeatPeriod(bond_heartbeat_period);
bond_->setHeartbeatTimeout(4.0);
bond_->start();
}
}

void LifecycleNode::runCleanups()
Expand Down Expand Up @@ -110,10 +117,12 @@ void LifecycleNode::register_rcl_preshutdown_callback()

void LifecycleNode::destroyBond()
{
RCLCPP_INFO(get_logger(), "Destroying bond (%s) to lifecycle manager.", this->get_name());
if (bond_heartbeat_period > 0.0) {
RCLCPP_INFO(get_logger(), "Destroying bond (%s) to lifecycle manager.", this->get_name());

if (bond_) {
bond_.reset();
if (bond_) {
bond_.reset();
}
}
}

Expand Down
Loading