Ask Your Question
0

Calling a third party service on a client

asked 2018-01-21 13:16:17 -0500

bxl gravatar image

updated 2018-01-22 12:52:31 -0500

I'm trying to write a service client in python to enable_motors of hector_quadrotor. I would like to turn on engine on my code instead of doing that by invoking the provided service

In Writing the Client Node tutorial it is used rospy.ServiceProxy. However, this method needs the service type which is implemented on the server side, which I don't have access.

My doubt is: How can I call a service that was defined by a third part? It is similar to that question, I'm coding in python not in C++ though: https://answers.ros.org/question/201617/how-to-call-a-service-inside-a-node/

EDIT: In my case it gets:

       motors_on = rospy.ServiceProxy('enable_motors', hector_uav_msgs/EnableMotors)
       TypeError: unsupported operand type(s) for /: 'module' and 'type'

and results on the error above

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-01-21 13:46:35 -0500

gvdhoorn gravatar image

updated 2018-01-22 12:58:22 -0500

This is a bit of a guess, but:

However, this method needs a callback function which is implemented on the server side, which I don't have access.

Are you referring to this line in the Writing the Client Node section:

add_two_ints = rospy.ServiceProxy('add_two_ints', AddTwoInts)

and then specifically AddTwoInts?

That is not a callback method, but the type of the service.


Edit:

However the issue stands: How call I call the the service, once I don't have access to server side of code?

I don't really understand your question. Is the tutorial not clear?

You create a ServiceProxy instance. This instance is a callable by itself, so once bound, you can invoke the service by doing something like:

result = add_two_ints(1, 2)

See also wiki/rospy/Overview/Services - Service proxies on the wiki, which might be clearer than the tutorial.

If this still doesn't help you, then you'll have to explain more precisely what it is you don't understand.


Edit2: are you actually wondering how to get access to the type definitions for the remote service? If that is the case, you'll have to make sure to import the correct class from the ROS package that defines the service files.

For the hector_quadrotor collection of packages, that is probably hector_uav_msgs, so something like the following should work (after having declared a proper run_depend on the package):

from hector_uav_msgs.srv import EnableMotors

and then the ServiceProxy instance should be created like so:

motors_on = rospy.ServiceProxy('enable_motors', EnableMotors)
edit flag offensive delete link more

Comments

Yes, I saw it now. I edited my question. However the issue stands: How call I call the the service, once I don't have access to server side of code?

bxl gravatar image bxl  ( 2018-01-22 12:08:42 -0500 )edit

OK. My issue is access service type

bxl gravatar image bxl  ( 2018-01-22 12:52:56 -0500 )edit

In that case see Edit2.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-22 12:53:53 -0500 )edit
1

Btw: I get the feeling you don't have much experience with Python. That is fine, but I would suggest you first find some good tutorials or a book about Python itself, and then start looking at rospy. Trying to learn all of this at the same time is going to be quite involved.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-22 12:54:59 -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

Stats

Asked: 2018-01-21 13:16:17 -0500

Seen: 357 times

Last updated: Jan 22 '18