Package rospy :: Package impl :: Module tcpros_service :: Class Service

Class Service

source code

      object --+        
               |        
service._Service --+    
                   |    
         ServiceImpl --+
                       |
                      Service

Declare a ROS service. Service requests are passed to the specified handler.

Service Usage:

 s = Service('getmapservice', GetMap, get_map_handler)
Instance Methods
 
__init__(self, name, service_class, handler, buff_size=65536, error_handler=None)
ctor.
source code
 
error_handler(self, e, exc_type, exc_value, tb) (Inherited from rospy.impl.tcpros_service.ServiceImpl) source code
 
handle(self, transport, header)
Process incoming request. (Inherited from rospy.impl.tcpros_service.ServiceImpl)
source code
 
shutdown(self, reason='')
Stop this service (Inherited from rospy.impl.tcpros_service.ServiceImpl)
source code
 
spin(self)
Let service run and take over thread until service or node shutdown. (Inherited from rospy.impl.tcpros_service.ServiceImpl)
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, handler, buff_size=65536, error_handler=None)
(Constructor)

source code 

ctor.

Parameters:
  • name - service name, ``str``
  • service_class - Service definition class
  • handler (fn(req)->resp) - callback function for processing service request. Function takes in a ServiceRequest and returns a ServiceResponse of the appropriate type. Function may also return a list, tuple, or dictionary with arguments to initialize a ServiceResponse instance of the correct type.

    If handler cannot process request, it may either return None, to indicate failure, or it may raise a rospy.ServiceException to send a specific error message to the client. Returning None is always considered a failure.

  • buff_size (int) - size of buffer for reading incoming requests. Should be at least size of request message
  • error_handler (fn(exception, exception_type, exception_value, traceback)->None) - callback function for handling errors raised in the service code.
Overrides: object.__init__