0
$\begingroup$

Rosanswers logo

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


Originally posted by bxl on ROS Answers with karma: 56 on 2018-01-21

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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)

Originally posted by gvdhoorn with karma: 86574 on 2018-01-21

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by bxl on 2018-01-22:
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?

Comment by bxl on 2018-01-22:
OK. My issue is access service type

Comment by gvdhoorn on 2018-01-22:
In that case see Edit2.

Comment by gvdhoorn on 2018-01-22:
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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.