20 #include "rclcpp/node.hpp"
21 #include "rclcpp/utilities.hpp"
22 #include "nav2_util/lifecycle_service_client.hpp"
25 using namespace std::chrono_literals;
26 using namespace nav2_util;
30 cerr <<
"Invalid command line.\n\n";
31 cerr <<
"This command will take a set of unconfigured lifecycle nodes through the\n";
32 cerr <<
"CONFIGURED to the ACTIVATED state\n";
33 cerr <<
"The nodes are brought up in the order listed on the command line\n\n";
35 cerr <<
" > lifecycle_startup <node name> ...\n";
39 #define RETRY(fn, retries) \
46 } catch (const std::runtime_error & e) { \
48 if (count > (retries)) { \
54 inline void startupLifecycleNode(
55 rclcpp::Node::SharedPtr node,
56 const std::string & node_name,
57 const std::chrono::seconds service_call_timeout,
66 sc.change_state(lifecycle_msgs::msg::Transition::TRANSITION_CONFIGURE, service_call_timeout),
69 sc.change_state(lifecycle_msgs::msg::Transition::TRANSITION_ACTIVATE, service_call_timeout),
73 inline void startup_lifecycle_nodes(
74 rclcpp::Node::SharedPtr node,
75 const std::vector<std::string> & node_names,
76 const std::chrono::seconds service_call_timeout,
77 const int retries = 3)
79 for (
const auto & node_name : node_names) {
80 startupLifecycleNode(node, node_name, service_call_timeout, retries);
85 int main(
int argc,
char * argv[])
90 rclcpp::init(0,
nullptr);
91 auto node = std::make_shared<rclcpp::Node>(
"lifecycle_bringup_client");
92 startup_lifecycle_nodes(
94 std::vector<std::string>(argv + 1, argv + argc),
Helper functions to interact with a lifecycle node.