Skip to content

Commit 2ae649b

Browse files
doisygGuillaume Doisy
andauthored
[LifecycleNode] add bond_heartbeat_period (#4342)
* add bond_heartbeat_period Signed-off-by: Guillaume Doisy <[email protected]> * lint Signed-off-by: Guillaume Doisy <[email protected]> --------- Signed-off-by: Guillaume Doisy <[email protected]> Co-authored-by: Guillaume Doisy <[email protected]>
1 parent 4fa12ac commit 2ae649b

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

nav2_util/include/nav2_util/lifecycle_node.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ class LifecycleNode : public rclcpp_lifecycle::LifecycleNode
205205

206206
// Connection to tell that server is still up
207207
std::unique_ptr<bond::Bond> bond_{nullptr};
208+
double bond_heartbeat_period;
208209
};
209210

210211
} // namespace nav2_util

nav2_util/src/lifecycle_node.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <vector>
2020

2121
#include "lifecycle_msgs/msg/state.hpp"
22+
#include "nav2_util/node_utils.hpp"
2223

2324
namespace nav2_util
2425
{
@@ -35,6 +36,10 @@ LifecycleNode::LifecycleNode(
3536
rclcpp::Parameter(
3637
bond::msg::Constants::DISABLE_HEARTBEAT_TIMEOUT_PARAM, true));
3738

39+
nav2_util::declare_parameter_if_not_declared(
40+
this, "bond_heartbeat_period", rclcpp::ParameterValue(0.1));
41+
this->get_parameter("bond_heartbeat_period", bond_heartbeat_period);
42+
3843
printLifecycleNodeNotification();
3944

4045
register_rcl_preshutdown_callback();
@@ -55,16 +60,18 @@ LifecycleNode::~LifecycleNode()
5560

5661
void LifecycleNode::createBond()
5762
{
58-
RCLCPP_INFO(get_logger(), "Creating bond (%s) to lifecycle manager.", this->get_name());
63+
if (bond_heartbeat_period > 0.0) {
64+
RCLCPP_INFO(get_logger(), "Creating bond (%s) to lifecycle manager.", this->get_name());
5965

60-
bond_ = std::make_unique<bond::Bond>(
61-
std::string("bond"),
62-
this->get_name(),
63-
shared_from_this());
66+
bond_ = std::make_unique<bond::Bond>(
67+
std::string("bond"),
68+
this->get_name(),
69+
shared_from_this());
6470

65-
bond_->setHeartbeatPeriod(0.10);
66-
bond_->setHeartbeatTimeout(4.0);
67-
bond_->start();
71+
bond_->setHeartbeatPeriod(bond_heartbeat_period);
72+
bond_->setHeartbeatTimeout(4.0);
73+
bond_->start();
74+
}
6875
}
6976

7077
void LifecycleNode::runCleanups()
@@ -110,10 +117,12 @@ void LifecycleNode::register_rcl_preshutdown_callback()
110117

111118
void LifecycleNode::destroyBond()
112119
{
113-
RCLCPP_INFO(get_logger(), "Destroying bond (%s) to lifecycle manager.", this->get_name());
120+
if (bond_heartbeat_period > 0.0) {
121+
RCLCPP_INFO(get_logger(), "Destroying bond (%s) to lifecycle manager.", this->get_name());
114122

115-
if (bond_) {
116-
bond_.reset();
123+
if (bond_) {
124+
bond_.reset();
125+
}
117126
}
118127
}
119128

0 commit comments

Comments
 (0)