Package rospy :: Package impl :: Module tcpros_service :: Class ServiceProxy

Class ServiceProxy

source code

      object --+    
               |    
service._Service --+
                   |
                  ServiceProxy

Create a handle to a ROS service for invoking calls.

Usage:

 add_two_ints = ServiceProxy('add_two_ints', AddTwoInts)
 resp = add_two_ints(1, 2)
Instance Methods
 
__init__(self, name, service_class, persistent=False, headers=None)
ctor.
source code
 
wait_for_service(self, timeout=None) source code
 
__call__(self, *args, **kwds)
Callable-style version of the service API.
source code
 
call(self, *args, **kwds)
Call the service.
source code
 
close(self)
Close this ServiceProxy.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__init__(self, name, service_class, persistent=False, headers=None)
(Constructor)

source code 

ctor.

Parameters:
  • name (str) - name of service to call
  • service_class (Service class) - auto-generated service class
  • persistent (bool) - (optional) if True, proxy maintains a persistent connection to service. While this results in better call performance, persistent connections are discouraged as they are less resistant to network issues and service restarts.
  • headers (dict) - (optional) arbitrary headers
Overrides: object.__init__

__call__(self, *args, **kwds)
(Call operator)

source code 

Callable-style version of the service API. This accepts either a request message instance, or you can call directly with arguments to create a new request instance. e.g.:

 add_two_ints(AddTwoIntsRequest(1, 2))
 add_two_ints(1, 2)
 add_two_ints(a=1, b=2)          
Parameters:
  • args - arguments to remote service
  • kwds - message keyword arguments
Raises:

call(self, *args, **kwds)

source code 

Call the service. This accepts either a request message instance, or you can call directly with arguments to create a new request instance. e.g.:

 add_two_ints(AddTwoIntsRequest(1, 2))
 add_two_ints(1, 2)
 add_two_ints(a=1, b=2)          
Raises:
  • TypeError - if request is not of the valid type (Message)
  • ServiceException - if communication with remote service fails
  • ROSInterruptException - if node shutdown (e.g. ctrl-C) interrupts service call
  • ROSSerializationException - If unable to serialize message. This is usually a type error with one of the fields.

close(self)

source code 

Close this ServiceProxy. This only has an effect on persistent ServiceProxy instances.