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

Revision history [back]

click to hide/show revision 1
initial version

rospy.ServiceProxy() requires as argument the name of the service and its type. This is used to create a handler that you can use as a function that needs the srv request as arguments. Have a look at the ros tutorial, it is well documented.

I haven't tested but this should do what you want :

def gripper_control():
    try:
        rospy.wait_for_service('bcap_service')

        #define the request
        func_id = 3
        vt = 8
        value_1 = 'value: b-CAP'
        value_2 = 'CaoProv.DENSO.VRC'
        value_3 = 'localhost'
        value_4 = ''
        vntArgs = [vt, value_1, vt, value_2, vt, value_3, vt, value_4]

        #create handler to call the service
        call_bcap = rospy.ServiceProxy('bcap_service', bcap)

        #call the service by passing the request to the handler
        #it doesn't require to have the same names as in the .srv
        #But I did it for clarity
        response = call_bcap(func_id, vntArgs)

        #store the response in some variables
        result1 = response.HRESULT
        result2 = response.vntRet

        #return the whole response
        return response

    except rospy.ServiceException, e:
        print "Service call failed: %s"%e