Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 import re
00011 import time
00012 import rospy
00013 import gateway_msgs.msg as gateway_msgs
00014 import rocon_python_comms
00015 import rosservice
00016
00017
00018
00019
00020
00021
00022 def resolve_local_gateway(timeout=None):
00023 '''
00024 @param timeout : timeout on checking for the gateway, if None, it just makes a single attempt.
00025 @type rospy.rostime.Duration
00026
00027 @raise rocon_python_comms.NotFoundException: if no remote gateways or no matching gateways available.
00028 '''
00029
00030 gateway_namespace = None
00031 service_names = []
00032 timeout_time = time.time() + timeout.to_sec() if timeout is not None else None
00033 while not rospy.is_shutdown():
00034 if timeout_time is not None and time.time() > timeout_time:
00035 break
00036 service_names = rosservice.rosservice_find("gateway_msgs/RemoteGatewayInfo")
00037 if not service_names or len(service_names) > 1:
00038 gateway_namespace = None
00039 elif service_names[0] == '/remote_gateway_info':
00040 gateway_namespace = "/"
00041 else:
00042 gateway_namespace = re.sub(r'/remote_gateway_info', '', service_names[0])
00043 if gateway_namespace is not None or timeout is None:
00044 break
00045 else:
00046 rospy.rostime.wallsleep(0.1)
00047 if not gateway_namespace:
00048 if not service_names:
00049 raise rocon_python_comms.NotFoundException("no gateway found attached to this local master - did you start it?")
00050 else:
00051 raise rocon_python_comms.NotFoundException("found more than one gateway connected to this master, this is an invalid configuration.")
00052
00053 return gateway_namespace
00054
00055
00056 def resolve_gateway_info(gateway_namespace=None):
00057 '''
00058 @param the local topic namespace to prepend to the 'gateway_info' identifier. Uses
00059 resolve_local_gateway if none is specified.
00060 @type str
00061
00062 @return the local gateway info in all its gory detail.
00063 @rtype gateway_msgs.GatewayInfo
00064
00065 @raise rocon_gateway.GatewayError: if no remote gateways or no matching gateways available.
00066 '''
00067 if gateway_namespace == None:
00068 gateway_namespace = resolve_local_gateway()
00069 gateway_info = rocon_python_comms.SubscriberProxy(gateway_namespace + '/gateway_info', gateway_msgs.GatewayInfo)()
00070 return gateway_info