Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 import rospy
00010 import time
00011 from rosservice import rosservice_find, ROSServiceIOException
00012
00013
00014 from .exceptions import NotFoundException
00015
00016
00017
00018
00019
00020
00021 def find_service(service_type, timeout=rospy.rostime.Duration(5.0), unique=False):
00022 '''
00023 Do a lookup to find services of the type
00024 specified. This will raise exceptions if it times out or returns
00025 multiple values. It can apply the additional logic of whether this should
00026 return a single unique result, or a list.
00027
00028 @param service_type : service type specification, e.g. concert_msgs/GetInteractions
00029 @type str
00030
00031 @param timeout : raise an exception if nothing is found before this timeout occurs.
00032 @type rospy.rostime.Duration
00033
00034 @param unique : flag to select the lookup behaviour (single/multiple results)
00035 @type bool
00036
00037 @return the fully resolved name of the service (unique) or list of names (non-unique)
00038 @type str
00039
00040 @raise rocon_python_comms.NotFoundException
00041 '''
00042 service_name = None
00043 service_names = []
00044 timeout_time = time.time() + timeout.to_sec()
00045 while not rospy.is_shutdown() and time.time() < timeout_time and not service_names:
00046 try:
00047 service_names = rosservice_find(service_type)
00048 except ROSServiceIOException:
00049 raise NotFoundException("ros shutdown")
00050 if unique:
00051 if len(service_names) > 1:
00052 raise NotFoundException("multiple services found %s." % service_names)
00053 elif len(service_names) == 1:
00054 service_name = service_names[0]
00055 if not service_names:
00056 rospy.rostime.wallsleep(0.1)
00057 if not service_names:
00058 raise NotFoundException("timed out")
00059 return service_name if service_name else service_names