Robotics StackExchange | Archived questions

[ROS2] call service :"waiting for service to become available"

Hi,

I'm using the std_srvs/srv/Trigger service:

 rclcpp::Client<std_srvs::srv::Trigger>::SharedPtr init = node->create_client<std_srvs::srv::Trigger>("/init");

 auto trig = std::make_shared<std_srvs::srv::Trigger::Request>();
 auto trig_result = init->async_send_request(trig);
if (rclcpp::spin_until_future_complete(node, trig_result) ==
                    rclcpp::executor::FutureReturnCode::SUCCESS)
                {
                    RCLCPP_INFO(node->get_logger(),"Init motor succesfull.");
                    rclcpp::sleep_for(sec);
                    state++;
                    break;
                }

First I check if the service is live:

 ros2 service list

I can find the /init service so I want to call it like in following tutorial : https://index.ros.org/doc/ros2/Tutorials/Services/Understanding-ROS2-Services/#ros2-service-call

ros2 service call /init std_srvs/srv/Trigger

The only response I get is:

> waiting for service to become available ...

What am I doing wrong calling or creating this service ?

Thanks

Asked by jlepers on 2020-02-28 06:06:36 UTC

Comments

Answers

You don't seem to be creating a service server anywhere, only a client. This is likely the reason why you get the message "waiting for service to become available ..."

Is there another node in your system providing the /init service ? If not you need to create a service server similar to this tutorial https://index.ros.org/doc/ros2/Tutorials/Writing-A-Simple-Cpp-Service-And-Client/#write-the-service-node

Asked by marguedas on 2020-02-28 08:23:22 UTC

Comments

void CanopenChainComponent::handle_recover( const std::shared_ptr request, std::shared_ptr response)

Asked by jlepers on 2020-02-28 08:36:57 UTC

This is the signature of a service callback without additional context. Could you please edit your question and provide the exact code that you are using? How you are creating the rclcpp::Service etc

Do you succeed to call the service with the C++ snippet code you showed above or does that fail too ?

Asked by marguedas on 2020-02-28 12:04:15 UTC