Skip to content

Commit 5008ceb

Browse files
committed
Bond support + fixing various action server issues (#1894)
* prototype of lifecycle bond system * adding more structure to get around weak ptr issue * working prototype for manager * adding some ns -> s conversions * changing to service node * adding bond connections to all servers * update logs * fixing review comments * fix types * remove extraneous functions * make linters happy * simplifications * adding spinner to get working but now unstable * moving bond connections to activate state * adding defaults * working complete prototype for review * update dependencies * adding connection logging * remove accidental file * fix server side timeout for heartbeats * adding complete unit coverage of bond support * fixing lifecycle test * trying to activate since autostart was removed
1 parent 5f7bf97 commit 5008ceb

File tree

25 files changed

+553
-39
lines changed

25 files changed

+553
-39
lines changed

doc/parameters/param_list.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ When `controller_plugins`\`progress_checker_plugin`\`goal_checker_plugin` parame
400400
| ----------| --------| ------------|
401401
| node_names | N/A | Ordered list of node names to bringup through lifecycle transition |
402402
| autostart | false | Whether to transition nodes to active state on startup |
403+
| bond_timeout_ms | 4000 | Timeout for bond to fail if no heartbeat can be found, in milliseconds. If set to 0, it will be disabled. Must be larger than 300ms for stable bringup. |
403404

404405
# map_server
405406

nav2_amcl/src/amcl_node.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ AmclNode::on_activate(const rclcpp_lifecycle::State & /*state*/)
300300
handleInitialPose(last_published_pose_);
301301
}
302302

303+
// create bond connection
304+
createBond();
305+
303306
return nav2_util::CallbackReturn::SUCCESS;
304307
}
305308

@@ -315,6 +318,9 @@ AmclNode::on_deactivate(const rclcpp_lifecycle::State & /*state*/)
315318
particlecloud_pub_->on_deactivate();
316319
particle_cloud_pub_->on_deactivate();
317320

321+
// destroy bond connection
322+
destroyBond();
323+
318324
return nav2_util::CallbackReturn::SUCCESS;
319325
}
320326

nav2_bt_navigator/src/bt_navigator.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ BtNavigator::on_configure(const rclcpp_lifecycle::State & /*state*/)
108108
get_node_clock_interface(),
109109
get_node_logging_interface(),
110110
get_node_waitables_interface(),
111-
"navigate_to_pose", std::bind(&BtNavigator::navigateToPose, this), false);
111+
"navigate_to_pose", std::bind(&BtNavigator::navigateToPose, this));
112112

113113
// Get the libraries to pull plugins from
114114
plugin_lib_names_ = get_parameter("plugin_lib_names").as_string_array();
@@ -133,11 +133,6 @@ BtNavigator::on_configure(const rclcpp_lifecycle::State & /*state*/)
133133
// Get the BT filename to use from the node parameter
134134
get_parameter("default_bt_xml_filename", default_bt_xml_filename_);
135135

136-
if (!loadBehaviorTree(default_bt_xml_filename_)) {
137-
RCLCPP_ERROR(get_logger(), "Error loading XML file: %s", default_bt_xml_filename_.c_str());
138-
return nav2_util::CallbackReturn::FAILURE;
139-
}
140-
141136
return nav2_util::CallbackReturn::SUCCESS;
142137
}
143138

@@ -176,8 +171,16 @@ BtNavigator::on_activate(const rclcpp_lifecycle::State & /*state*/)
176171
{
177172
RCLCPP_INFO(get_logger(), "Activating");
178173

174+
if (!loadBehaviorTree(default_bt_xml_filename_)) {
175+
RCLCPP_ERROR(get_logger(), "Error loading XML file: %s", default_bt_xml_filename_.c_str());
176+
return nav2_util::CallbackReturn::FAILURE;
177+
}
178+
179179
action_server_->activate();
180180

181+
// create bond connection
182+
createBond();
183+
181184
return nav2_util::CallbackReturn::SUCCESS;
182185
}
183186

@@ -188,6 +191,9 @@ BtNavigator::on_deactivate(const rclcpp_lifecycle::State & /*state*/)
188191

189192
action_server_->deactivate();
190193

194+
// destroy bond connection
195+
destroyBond();
196+
191197
return nav2_util::CallbackReturn::SUCCESS;
192198
}
193199

@@ -332,7 +338,7 @@ BtNavigator::initializeGoalPose()
332338
blackboard_->set<int>("number_recoveries", 0); // NOLINT
333339

334340
// Update the goal pose on the blackboard
335-
blackboard_->set("goal", goal->pose);
341+
blackboard_->set<geometry_msgs::msg::PoseStamped>("goal", goal->pose);
336342
}
337343

338344
void

nav2_controller/src/nav2_controller.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ ControllerServer::on_configure(const rclcpp_lifecycle::State & state)
7272

7373
RCLCPP_INFO(get_logger(), "Configuring controller interface");
7474

75+
7576
get_parameter("progress_checker_plugin", progress_checker_id_);
7677
if (progress_checker_id_ == default_progress_checker_id_) {
7778
nav2_util::declare_parameter_if_not_declared(
@@ -93,6 +94,7 @@ ControllerServer::on_configure(const rclcpp_lifecycle::State & state)
9394
rclcpp::ParameterValue(default_types_[i]));
9495
}
9596
}
97+
9698
controller_types_.resize(controller_ids_.size());
9799

98100
get_parameter("controller_frequency", controller_frequency_);
@@ -172,6 +174,9 @@ ControllerServer::on_activate(const rclcpp_lifecycle::State & state)
172174
vel_publisher_->on_activate();
173175
action_server_->activate();
174176

177+
// create bond connection
178+
createBond();
179+
175180
return nav2_util::CallbackReturn::SUCCESS;
176181
}
177182

@@ -190,6 +195,9 @@ ControllerServer::on_deactivate(const rclcpp_lifecycle::State & state)
190195
publishZeroVelocity();
191196
vel_publisher_->on_deactivate();
192197

198+
// destroy bond connection
199+
destroyBond();
200+
193201
return nav2_util::CallbackReturn::SUCCESS;
194202
}
195203

nav2_lifecycle_manager/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ find_package(rclcpp REQUIRED)
1313
find_package(std_msgs REQUIRED)
1414
find_package(std_srvs REQUIRED)
1515
find_package(tf2_geometry_msgs REQUIRED)
16+
find_package(bondcpp REQUIRED)
1617

1718
nav2_package()
1819

@@ -38,6 +39,7 @@ set(dependencies
3839
std_msgs
3940
std_srvs
4041
tf2_geometry_msgs
42+
bondcpp
4143
)
4244

4345
ament_target_dependencies(${library_name}

nav2_lifecycle_manager/include/nav2_lifecycle_manager/lifecycle_manager.hpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
#include <vector>
2323

2424
#include "nav2_util/lifecycle_service_client.hpp"
25+
#include "nav2_util/node_thread.hpp"
2526
#include "rclcpp/rclcpp.hpp"
2627
#include "std_srvs/srv/empty.hpp"
2728
#include "nav2_msgs/srv/manage_lifecycle_nodes.hpp"
2829
#include "std_srvs/srv/trigger.hpp"
30+
#include "bondcpp/bond.hpp"
2931

3032
namespace nav2_lifecycle_manager
3133
{
@@ -52,6 +54,8 @@ class LifecycleManager : public rclcpp::Node
5254
protected:
5355
// The ROS node to use when calling lifecycle services
5456
rclcpp::Node::SharedPtr service_client_node_;
57+
rclcpp::Node::SharedPtr bond_client_node_;
58+
std::unique_ptr<nav2_util::NodeThread> bond_node_thread_;
5559

5660
// The services provided by this node
5761
rclcpp::Service<ManageLifecycleNodes>::SharedPtr manager_srv_;
@@ -121,10 +125,37 @@ class LifecycleManager : public rclcpp::Node
121125
*/
122126
void destroyLifecycleServiceClients();
123127

128+
// Support function for creating bond timer
129+
/**
130+
* @brief Support function for creating bond timer
131+
*/
132+
void createBondTimer();
133+
134+
// Support function for creating bond connection
135+
/**
136+
* @brief Support function for creating bond connections
137+
*/
138+
bool createBondConnection(const std::string & node_name);
139+
140+
// Support function for killing bond connections
141+
/**
142+
* @brief Support function for killing bond connections
143+
*/
144+
void destroyBondTimer();
145+
146+
// Support function for checking on bond connections
147+
/**
148+
* @ brief Support function for checking on bond connections
149+
* will take down system if there's something non-responsive
150+
*/
151+
void checkBondConnections();
152+
124153
/**
125154
* @brief For a node, transition to the new target state
126155
*/
127-
bool changeStateForNode(const std::string & node_name, std::uint8_t transition);
156+
bool changeStateForNode(
157+
const std::string & node_name,
158+
std::uint8_t transition);
128159

129160
/**
130161
* @brief For each node in the map, transition to the new target state
@@ -137,6 +168,13 @@ class LifecycleManager : public rclcpp::Node
137168
*/
138169
void message(const std::string & msg);
139170

171+
// Timer thread to look at bond connections
172+
rclcpp::TimerBase::SharedPtr bond_timer_;
173+
std::chrono::milliseconds bond_timeout_;
174+
175+
// A map of all nodes to check bond connection
176+
std::map<std::string, std::shared_ptr<bond::Bond>> bond_map_;
177+
140178
// A map of all nodes to be controlled
141179
std::map<std::string, std::shared_ptr<nav2_util::LifecycleServiceClient>> node_map_;
142180

nav2_lifecycle_manager/package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<build_depend>std_msgs</build_depend>
1919
<build_depend>std_srvs</build_depend>
2020
<build_depend>tf2_geometry_msgs</build_depend>
21+
<build_depend>bondcpp</build_depend>
2122
<build_depend>nav2_common</build_depend>
2223

2324
<exec_depend>geometry_msgs</exec_depend>
@@ -28,6 +29,7 @@
2829
<exec_depend>rclcpp_lifecycle</exec_depend>
2930
<exec_depend>std_msgs</exec_depend>
3031
<exec_depend>std_srvs</exec_depend>
32+
<exec_depend>bondcpp</exec_depend>
3133
<exec_depend>tf2_geometry_msgs</exec_depend>
3234

3335
<test_depend>ament_lint_auto</test_depend>

0 commit comments

Comments
 (0)