ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

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

asked 2020-02-28 05:06:36 -0600

jlepers gravatar image

updated 2020-02-28 05:39:46 -0600

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/Tutori...

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-02-28 07:23:22 -0600

marguedas gravatar image

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 /initservice ? If not you need to create a service server similar to this tutorial https://index.ros.org/doc/ros2/Tutori...

edit flag offensive delete link more

Comments

void CanopenChainComponent::handle_recover( const std::shared_ptr<std_srvs::srv::trigger::request> request, std::shared_ptr<std_srvs::srv::trigger::response> response)

jlepers gravatar image jlepers  ( 2020-02-28 07:36:57 -0600 )edit

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 ?

marguedas gravatar image marguedas  ( 2020-02-28 11:04:15 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-02-28 05:06:36 -0600

Seen: 5,377 times

Last updated: Feb 28 '20