0
$\begingroup$

Rosanswers logo

Hello,

I would want to call a service using python. Currently this command line is working :

rosservice call /camera/start_capture

but I can't figure out how to do the same thing with python. I already tried this without succes :

rospy.ServiceProxy('/camera/start_capture',True)

Any idea ?

Matt


Originally posted by mattMGN on ROS Answers with karma: 78 on 2017-06-02

Post score: 2


Original comments

Comment by yzheng0310 on 2017-06-02:
Hi, the second argument in SeriveProxy should be your service class associated with the name '/camera/start_capture'

Comment by googooroom on 2021-08-11:
from command line, use rosservice info /camera/start_capture to find the service type from the service type, find out the input/output of this service when call this using python: thisService = rospy.ServiceProxy('/camera/start_capture', type) result = thisService(input) #input is to trigger the server, result is the output/acknowledgement from server.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

As @yzheng0310 said, you must use the class that defines your service.

Let's suppose that the service used by /camera/start_capture is a StartCatpure that is defined in your package, and let's suppose that your package is named my_package.

In this case you would do the following:

import rospy 
from my_package.srv import StartCatpure
start_capture = rospy.ServiceProxy('start_capture_node', StartCapture)

Now, let's call the service. In this case, supposing that the service doesn't accept parameters:

start_capture()

You can check the ROS Tutorial Writing a SImple Publisher and Subscriber in Python that explains step by step.


Originally posted by Ruben Alves with karma: 1038 on 2017-08-04

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by NEngelhard on 2017-08-04:
(Small hint: use the 101010-Button to format code)

$\endgroup$

Your Answer

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