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

defining a service message with no return value

asked 2020-03-22 18:05:22 -0500

waspinator gravatar image

updated 2020-03-22 18:06:13 -0500

I want to create a service that doesn't return anything, but returning None or an Empty message considered an error.

Test.srv

string message
---

test.py

service = rospy.Service('test', my_msgs.srv.Test, callback)

def callback(request):
    print(request.message)
    return std_srvs.srv.Empty()

results in a ServiceException, service cannot process request: handler returned invalid value: Invalid number of arguments, args should be [] args are (std_srvs.srv._Empty.Empty object at 0xffasdassa)

What's the right way of defining a service with no return value?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-03-23 02:31:12 -0500

mgruhler gravatar image

updated 2020-03-30 01:08:47 -0500

The problem is that you try to return

  1. the full Empty Service object. You need to only return the response.
  2. you try to return the wrong type of Service. The Service Server is declared using your my_msgs.srv.Test, thus the Response and the Request have to be of the types TestRequest and TestResponse, respectively. You don't have to explicitly set the request type. But you have to make sure you return the correct Response type. i.e.

return my_msgs.srv.TestResponse()

See also the tutorial.

edit flag offensive delete link more

Comments

still get an error when trying to return. Do I have to modify the Test.srv definition? service cannot process request: handler returned invalid value: Invalid number of arguments, args should be [] args are(,)

waspinator gravatar image waspinator  ( 2020-03-27 15:28:17 -0500 )edit
1

Whoops, soory, got confused because you are trying to return an std_srvs/Empty as a response. Obviously, you have to return the TestResponse(). The callback has to receive the Request and return the Response of the appropriate type declared in the service server...

And no, you don't have to edit your service definition.

Edited the answer above...

mgruhler gravatar image mgruhler  ( 2020-03-30 01:06:41 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2020-03-22 18:05:22 -0500

Seen: 1,208 times

Last updated: Mar 30 '20