3 import roslib; roslib.load_manifest(
'flexbe_core')
5 from threading
import Timer
13 A proxy for calling services. 19 Initializes the proxy with optionally a given set of clients. 21 @type topics: dictionary string - message class 22 @param topics: A dictionay containing a collection of topic - message type pairs. 25 for topic, msg_type
in topics.iteritems():
29 def setupService(self, topic, msg_type, persistent=False, wait_duration=10):
31 Tries to set up a service caller for calling it later. 34 @param topic: The topic of the service to call. 36 @type msg_type: service class 37 @param msg_type: The type of messages of this service. 39 @type persistent: bool 40 @param persistent: Defines if this service caller is persistent. 42 @type wait_duration: int 43 @param wait_duration: Defines how long to wait for the given service if it is not available right now. 45 if topic
not in ProxyServiceCaller._services:
51 rospy.wait_for_service(topic, wait_duration)
53 except rospy.exceptions.ROSException, e:
58 except Exception
as ve:
63 Logger.logerr(
"Service client %s timed out!" % topic)
65 ProxyServiceCaller._services[topic] = rospy.ServiceProxy(topic, msg_type, persistent)
67 Logger.loginfo(
"Finally found action client %s..." % (topic))
72 Checks if the service on the given topic is available. 75 @param topic: The topic of interest. 77 return topic
in ProxyServiceCaller._services
80 def call(self, topic, request):
82 Performs a service call on the given topic. 85 @param topic: The topic to call. 87 @type request: service 88 @param request: The request to send to this service. 90 if topic
not in ProxyServiceCaller._services:
91 rospy.logwarn(
'ProxyServiceCaller: topic not yet registered!')
95 return ProxyServiceCaller._services[topic].
call(request)
97 print 'error: ' + str(e)
102 Logger.logwarn(
"Waiting for service client %s..." % (topic))
def _print_wait_warning(self, topic)
def call(self, topic, request)
def setupService(self, topic, msg_type, persistent=False, wait_duration=10)
def __init__(self, topics={})
def is_available(self, topic)