ROS2: How to tell service clients that a provided service cannot be executed?

asked 2020-05-01 10:43:22 -0600

thebyohazard gravatar image

Back in ROS1, when a node provided a service, the wiki says that the callback signature of a service is

 bool callback(MReq& request, MRes& response);

It further explains that

A return value of true means the service succeeded, and the response object has been filled with the necessary data. A return value of false means the call has failed and the response object will not be sent to the caller.

But in ROS2, the API shows the callback function type for a service is

std::function< void(const std::shared_ptr< typename ServiceT::Request >, std::shared_ptr< typename ServiceT::Response >)>

So in ROS2, if it is impossible to execute the service, how does the service provider indicate to the caller that it is impossible for a response to be created if the return type of the callback is void? It looks like a default response is always sent, but if the service was unable to be executed, then that default response will most likely be wrong.

I guess you could add a bool field indicating success to each service type that needs it, as in the SetBool.srv of ROS2 std_srvs. But there is also an Empty.srvthere that I see no use for anymore if you can't know that it actually worked. In ROS1, you could use an Empty service as kind of a trigger that you know got to its intended destination: the fact that you even got a response means that the service server at least received your trigger successfully.

I tried throwing a std::exception thinking they might be caught, but they are not. Anyway, I'm hoping there's just something I missed. Thanks!

edit retag flag offensive close merge delete


I am facing the same issue. Did you find the solution ? Please let me know.

Prabeen gravatar image Prabeen  ( 2020-07-07 01:57:56 -0600 )edit