Skip to content

Commit 332304b

Browse files
Remove service nodes in lifecycle_manager (#2267)
* remove service_node from nav2_lifecycle_manager * wait_for_service() returns the value of service_is_ready() * explain wait_for_service return * use timer to trigger init() * init() as lambda function * wait_for_service as void * fix gtest
1 parent e134594 commit 332304b

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

nav2_lifecycle_manager/include/nav2_lifecycle_manager/lifecycle_manager.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ class LifecycleManager : public rclcpp::Node
5252
~LifecycleManager();
5353

5454
protected:
55-
// The ROS node to use when calling lifecycle services
56-
rclcpp::Node::SharedPtr service_client_node_;
55+
// The ROS node to create bond
5756
rclcpp::Node::SharedPtr bond_client_node_;
5857
std::unique_ptr<nav2_util::NodeThread> bond_node_thread_;
5958

@@ -169,6 +168,7 @@ class LifecycleManager : public rclcpp::Node
169168
void message(const std::string & msg);
170169

171170
// Timer thread to look at bond connections
171+
rclcpp::TimerBase::SharedPtr init_timer_;
172172
rclcpp::TimerBase::SharedPtr bond_timer_;
173173
std::chrono::milliseconds bond_timeout_;
174174

nav2_lifecycle_manager/src/lifecycle_manager.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,8 @@ LifecycleManager::LifecycleManager()
5757
get_name() + std::string("/is_active"),
5858
std::bind(&LifecycleManager::isActiveCallback, this, _1, _2, _3));
5959

60-
auto service_options = rclcpp::NodeOptions().arguments(
61-
{"--ros-args", "-r", std::string("__node:=") + get_name() + "_service_client", "--"});
6260
auto bond_options = rclcpp::NodeOptions().arguments(
6361
{"--ros-args", "-r", std::string("__node:=") + get_name() + "_bond_client", "--"});
64-
service_client_node_ = std::make_shared<rclcpp::Node>("_", service_options);
6562
bond_client_node_ = std::make_shared<rclcpp::Node>("_", bond_options);
6663
bond_node_thread_ = std::make_unique<nav2_util::NodeThread>(bond_client_node_);
6764

@@ -79,11 +76,15 @@ LifecycleManager::LifecycleManager()
7976
transition_label_map_[Transition::TRANSITION_UNCONFIGURED_SHUTDOWN] =
8077
std::string("Shutting down ");
8178

82-
createLifecycleServiceClients();
83-
84-
if (autostart_) {
85-
startup();
86-
}
79+
init_timer_ = this->create_wall_timer(
80+
std::chrono::nanoseconds(10),
81+
[this]() -> void {
82+
init_timer_->cancel();
83+
createLifecycleServiceClients();
84+
if (autostart_) {
85+
startup();
86+
}
87+
});
8788
}
8889

8990
LifecycleManager::~LifecycleManager()
@@ -131,7 +132,7 @@ LifecycleManager::createLifecycleServiceClients()
131132
message("Creating and initializing lifecycle service clients");
132133
for (auto & node_name : node_names_) {
133134
node_map_[node_name] =
134-
std::make_shared<LifecycleServiceClient>(node_name, service_client_node_);
135+
std::make_shared<LifecycleServiceClient>(node_name, shared_from_this());
135136
}
136137
}
137138

0 commit comments

Comments
 (0)