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

How do I know the variable names in a ros service handler

asked 2014-06-25 10:07:53 -0500

RigorMortis gravatar image

In the beginner tutorial here:

def handle_add_two_ints(req):
print "Returning [%s + %s = %s]"%(req.a, req.b, (req.a + req.b))
return AddTwoIntsResponse(req.a + req.b)

I understand that the message received will get passed to the 'handle_add_two_ints' function as the object 'req' -- what I do not understand is where the naming convention comes from. They seem to have pulled '.a' and '.b' out of thin air. Can someone please clarify or point me to a site that does? What if I am passing many variables of different types... will they always be alphabetically named?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-06-25 11:41:53 -0500

andreas.gerken gravatar image


you created a definition of your service interface in a earlier tutorial:


Perhaps you didn't realize because you copied it from another project.

roscp rospy_tutorials AddTwoInts.srv srv/AddTwoInts.srv

The file contains the interface which the function implements.

int64 a
int64 b
int64 sum

hope i helped you

cheers Andreas

edit flag offensive delete link more


Thanks - that's exactly what I missed!

RigorMortis gravatar image RigorMortis  ( 2014-06-25 12:15:21 -0500 )edit

Question Tools


Asked: 2014-06-25 10:07:53 -0500

Seen: 307 times

Last updated: Jun 25 '14