19
19
#include < vector>
20
20
21
21
#include " lifecycle_msgs/msg/state.hpp"
22
+ #include " nav2_util/node_utils.hpp"
22
23
23
24
namespace nav2_util
24
25
{
@@ -35,6 +36,10 @@ LifecycleNode::LifecycleNode(
35
36
rclcpp::Parameter (
36
37
bond::msg::Constants::DISABLE_HEARTBEAT_TIMEOUT_PARAM, true ));
37
38
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
+
38
43
printLifecycleNodeNotification ();
39
44
40
45
register_rcl_preshutdown_callback ();
@@ -55,16 +60,18 @@ LifecycleNode::~LifecycleNode()
55
60
56
61
void LifecycleNode::createBond ()
57
62
{
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 ());
59
65
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 ());
64
70
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
+ }
68
75
}
69
76
70
77
void LifecycleNode::runCleanups ()
@@ -110,10 +117,12 @@ void LifecycleNode::register_rcl_preshutdown_callback()
110
117
111
118
void LifecycleNode::destroyBond ()
112
119
{
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 ());
114
122
115
- if (bond_) {
116
- bond_.reset ();
123
+ if (bond_) {
124
+ bond_.reset ();
125
+ }
117
126
}
118
127
}
119
128
0 commit comments