Ask Your Question

rospy service multiple argument

asked 2014-06-26 07:19:09 -0500

Maya gravatar image

updated 2014-06-26 07:19:32 -0500


It might be a total newbie question but I can't find the solution. I know that for Subscriber I can call callback_args but how am I suppose to do it for Services ?

I'm creating 2 services that are going to do the same thing BUT I want the callback to receive an id so it knows from which robot the service was required. I could pass it in the message but a better way to do it for me is to add a constant number associated to each call_back. I though of something like this but this abviously doesn't work :

service.append(rospy.Service(name, sentobject, self.check, callback_args=0) ) #Here 0 would be my id
service.append(rospy.Service(name, sentobject, self.check, callback_args=1) ) #Here 1 would be my id

With check being defined as :

def check(self, rep, robot_id):

How can I do it in python ?

Thanks a lot

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-06-26 08:14:06 -0500

bajo gravatar image

updated 2014-07-02 06:10:31 -0500


i am not sure why you want two different services that perform the same function. Other than that i would do as you mentioned and include this data in the service definition (.srv file).


When you look at the definition of the rospy services you can clearly see that there are no callback arguments expected. You can always use your Service definition in the .srv you are using to add a field like an string or int for the robot ID to be passed to the service call. For example you could take the AddTwoInts.srv

int64 a
int64 b
int64 sum

and modify it to look like this

int64 a
int64 b
int64 robotid
int64 sum

In your service callback you can than access this value and change the response message accordingly. For this you should rename the file, add it to the CMakeLists.txt in the package the .srv file is in and make a catkin_make to generate the needed include files.

edit flag offensive delete link more



That's exactly what I end up doing. Why can"t we use argument in services ? :/

Maya gravatar image Maya  ( 2014-06-30 05:43:16 -0500 )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

1 follower


Asked: 2014-06-26 07:19:09 -0500

Seen: 1,138 times

Last updated: Jul 02 '14