Ask Your Question
0

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
0

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

andreas.gerken gravatar image

Hi,

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

http:// wiki.ros.org/ROS/Tutorials/CreatingMsgAndSrv.

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

Comments

Thanks - that's exactly what I missed!

RigorMortis gravatar imageRigorMortis ( 2014-06-25 12:15:21 -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

Stats

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

Seen: 110 times

Last updated: Jun 25 '14