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