Ask Your Question
0

service response empty

asked 2018-09-06 14:38:58 -0600

yong gravatar image

The wiki doesn't make it clear if response or request of a ROS service can be empty, and what will happen when either is empty.

I have seen rospy.Service fails if the handler returns None, so I guess ROS services without any response are not supported. Otherwise, what should the handler return?

But I am still not clear if ROS services with empty requests are officially supported. I see services with empty request can be called with no problem, but it would be nice to see this documented, so that when we see some tools cannot work with this case, we know it is a bug and will try fix it.

Best regards, Yong

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2018-09-06 14:45:08 -0600

gvdhoorn gravatar image

updated 2018-09-06 14:50:02 -0600

I have seen rospy.Service fails if the handler returns None, so I guess ROS services without any response are not supported.

None != empty response. None indicates an error on the server side.

See the documentation (wiki/rospy/Overview/Services - Providing services, emphasis mine):

Create a new ROS Service with the specified name, service type (the auto-generated service class), and handler. The handler will be invoked with the service request message and should return the appropriate service response message. If the handler returns None or raises an exception, an error will be passed to the client.

Furthermore:

Otherwise, what should the handler return?

Every service definition always consists of a request and a response part (top and bottom of the .srv definition respectively). Services that have "nothing" on the response side still have a Response class generated, but it will just not contain any fields.

Service handlers that should return an empty response should therefore still instantiate a Response object and return that.

See again wiki/rospy/Overview/Services - Providing services on the wiki.

I see services with empty request can be called with no problem, but it would be nice to see this documented

I think the rospy overview page on services documents this quite well.

edit flag offensive delete link more

Comments

Thanks. So the handler can return args, kwargs (a dict) or a Reponse object directly.

yong gravatar imageyong ( 2018-09-06 14:56:08 -0600 )edit

Just doing some testing. The service call doesn't work for me though.

yong gravatar imageyong ( 2018-09-06 15:14:22 -0600 )edit

If you're having issues with some specific piece of code I would suggest to post a new question. This particular question was about whether service server behaviour with empty responses was documented and specced. It is.

gvdhoorn gravatar imagegvdhoorn ( 2018-09-06 15:15:59 -0600 )edit
1

OK. got it work. will do.

yong gravatar imageyong ( 2018-09-06 15:18:51 -0600 )edit
0

answered 2018-09-06 14:48:08 -0600

ahendrix gravatar image

The request and response parts of a service request are both allowed to be empty. For example, std_srvs/Empty is an officially supported type: http://docs.ros.org/melodic/api/std_s...

As a note, the handler for rospy.Service must always return the service's result type, even if it is empty. The rospy.Service docs explicitly state that returning None from the service handler is considered a failure of the service call:

handler (fn(req)->resp) - callback function for processing service request. Function takes in a ServiceRequest and returns a ServiceResponse of the appropriate type. Function may also return a list, tuple, or dictionary with arguments to initialize a ServiceResponse instance of the correct type. If handler cannot process request, it may either return None, to indicate failure, or it may raise a rospy.ServiceException to send a specific error message to the client. Returning None is always considered a failure.

edit flag offensive delete link more

Comments

Thanks. Sorry it seems I cannot choose both answers.

yong gravatar imageyong ( 2018-09-06 15:20:04 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2018-09-06 14:38:58 -0600

Seen: 1,124 times

Last updated: Sep 06 '18