Wait for multiple services to appear

asked 2018-09-06 17:28:47 -0600

alsora gravatar image

updated 2018-09-06 17:31:07 -0600

I'm using ROS2 Bouncy.

I have a node which has to send multiple service requests. Before starting the execution loop I want the node to find all the services it needs. My problem is that the node waits only for 2 out of 3 services.

This is how I'm initializing it.

auto node = rclcpp::Node::make_shared("my_client_node") ;
auto client_1 = node->create_client<Service1>("get_service_1") ;
auto client_2 =  node->create_client<Service2>("get_service_2") ;
auto client_3 =  node->create_client<Service3>("get_service_3") ;

while (!client_1->wait_for_service(std::chrono::seconds(1)) && 
       !client_2->wait_for_service(std::chrono::seconds(1)) && 
    ) {
    if (!rclcpp::ok()) {
        RCLCPP_ERROR(node->get_logger(), "ros client interrupted while waiting for services to appear.") ;
        return ;
    RCLCPP_INFO(node->get_logger(), "waiting for service to appear...") ;

//Start loop... do stuff with the clients...

Besides this node there are other 2 nodes, one provides 2 services and the other the remaining service. I noticed that the while condition is not verified if the node with 2 services is on, even if the other is not running.

Is there something wrong in this code ?

edit retag flag offensive close merge delete