def resolve_local_gateway(timeout=None): ''' @param timeout : timeout on checking for the gateway, if None, it just makes a single attempt. @type rospy.rostime.Duration @raise rocon_python_comms.NotFoundException: if no remote gateways or no matching gateways available. ''' #master = rosgraph.Master(rospy.get_name()) gateway_namespace = None service_names = [] timeout_time = time.time() + timeout.to_sec() if timeout is not None else None while not rospy.is_shutdown(): if timeout_time is not None and time.time() > timeout_time: break service_names = rosservice.rosservice_find("gateway_msgs/RemoteGatewayInfo") if not service_names or len(service_names) > 1: gateway_namespace = None elif service_names[0] == '/remote_gateway_info': gateway_namespace = "/" else: gateway_namespace = re.sub(r'/remote_gateway_info', '', service_names[0]) if gateway_namespace is not None or timeout is None: break else: rospy.rostime.wallsleep(0.1) if not gateway_namespace: if not service_names: raise rocon_python_comms.NotFoundException("no gateway found attached to this local master - did you start it?") else: raise rocon_python_comms.NotFoundException("found more than one gateway connected to this master, this is an invalid configuration.") #console.debug("Found a local gateway at %s"%gateway_namespace) return gateway_namespace
def find_service(namespace, service_type): try: service_name = rosservice.rosservice_find(service_type) except rosservice.ROSServiceIOException as e: print(console.red + "ERROR: {0}".format(str(e)) + console.reset) sys.exit(1) if len(service_name) > 0: if len(service_name) == 1: service_name = service_name[0] elif namespace is not None: for service in service_name: if namespace in service: service_name = service break if type(service_name) is list: print(console.red + "\nERROR: multiple blackboard services found %s" % service_name + console.reset) print(console.red + "\nERROR: but none matching the requested '%s'" % namespace + console.reset) sys.exit(1) else: print(console.red + "\nERROR: multiple blackboard services found %s" % service_name + console.reset) print(console.red + "\nERROR: select one with the --namespace argument" + console.reset) sys.exit(1) else: print(console.red + "ERROR: blackboard services not found" + console.reset) sys.exit(1) return service_name
def _rosapp_stop(args, robot=None): matches = [] if robot is None: matches.extend(rosservice.rosservice_find('app_manager/StopApp')) else: matches.append('/' + str(robot) + '/stop_app') for match in matches: (req, resp) = rosservice.call_service(match, args, StopApp) print resp
def setUp(self): # warn on /use_sim_time is true use_sim_time = rospy.get_param('/use_sim_time', False) t_start = time.time() while not rospy.is_shutdown() and \ use_sim_time and (rospy.Time.now() == rospy.Time(0)): rospy.logwarn_throttle( 1, '/use_sim_time is specified and rostime is 0, /clock is published?' ) if time.time() - t_start > 10: self.fail('Timed out (10s) of /clock publication.') # must use time.sleep because /clock isn't yet published, so rospy.sleep hangs. time.sleep(0.1) # Use `rosservice find rviz/SendFilePath` to get rviz node name rviz_service_names = [] while not rospy.is_shutdown() and len(rviz_service_names) == 0: rviz_service_names = rosservice.rosservice_find( 'rviz/SendFilePath') if len(rviz_service_names) == 0: rospy.logwarn( "[{}] Waiting rviz service (rviz/SendFilePath) for {:.3f} sec" .format(rospy.get_name(), time.time() - t_start)) # rviz/SendFilePath only available >melodic if os.environ['ROS_DISTRO'] < 'melodic': rviz_service_names = rosservice.rosservice_find( 'std_srvs/Empty') time.sleep(0.1) # check if rospy.logwarn("[{}] Found rviz service names {}".format( rospy.get_name(), rviz_service_names)) rviz_node_names = set( map(rosservice.get_service_node, rviz_service_names)) rospy.logwarn("[{}] Found rviz node names {}".format( rospy.get_name(), rviz_node_names)) if len(rviz_node_names) == 0: rospy.logerr("[{}] Could not find rviz nodes".format( rospy.get_name())) raise AssertionError self.rviz_node_name = list(rviz_node_names)[0]
def get_services_for_type(self, svc_type, clb=None): """Returns a list of services of given type Args: svc_type (str): The ROS Service type. clb (function, optional): Callback function that is called upon response is received. """ services_ft_list = rosservice.rosservice_find(svc_type) return services_ft_list
def _rosapp_list(running=True, available=True, verbose=False, robot=None): try: matches = rosservice.rosservice_find('app_manager/ListApps') except: pass for match in matches: (req, resp) = rosservice.call_service(match, None, ListApps) if running: for app in resp.running_apps: print str(app.name) if available: for app in resp.available_apps: print str(app.name)
def find_service(service_type, timeout=rospy.rostime.Duration(5.0), unique=False): ''' Do a lookup to find services of the type specified. This will raise exceptions if it times out or returns multiple values. It can apply the additional logic of whether this should return a single unique result, or a list. @param service_type : service type specification, e.g. concert_msgs/GetInteractions @type str @param timeout : raise an exception if nothing is found before this timeout occurs. @type rospy.rostime.Duration @param unique : flag to select the lookup behaviour (single/multiple results) @type bool @return the fully resolved name of the service (unique) or list of names (non-unique) @type str @raise rocon_python_comms.NotFoundException ''' service_name = None service_names = [] timeout_time = time.time() + timeout.to_sec() while not rospy.is_shutdown() and time.time() < timeout_time and not service_names: try: service_names = rosservice_find(service_type) except ROSServiceIOException: raise NotFoundException("ros shutdown") if unique: if len(service_names) > 1: raise NotFoundException("multiple services found %s." % service_names) elif len(service_names) == 1: service_name = service_names[0] if not service_names: rospy.rostime.wallsleep(0.1) if service_name is None: raise NotFoundException("timed out") return service_name
def resolve_local_gateway(timeout=None): ''' @param timeout : timeout on checking for the gateway, if None, it just makes a single attempt. @type rospy.rostime.Duration @raise rocon_python_comms.NotFoundException: if no remote gateways or no matching gateways available. ''' #master = rosgraph.Master(rospy.get_name()) gateway_namespace = None service_names = [] timeout_time = time.time() + timeout.to_sec( ) if timeout is not None else None while not rospy.is_shutdown(): if timeout_time is not None and time.time() > timeout_time: break service_names = rosservice.rosservice_find( "gateway_msgs/RemoteGatewayInfo") if not service_names or len(service_names) > 1: gateway_namespace = None elif service_names[0] == '/remote_gateway_info': gateway_namespace = "/" else: gateway_namespace = re.sub(r'/remote_gateway_info', '', service_names[0]) if gateway_namespace is not None or timeout is None: break else: rospy.rostime.wallsleep(0.1) if not gateway_namespace: if not service_names: raise rocon_python_comms.NotFoundException( "no gateway found attached to this local master - did you start it?" ) else: raise rocon_python_comms.NotFoundException( "found more than one gateway connected to this master, this is an invalid configuration." ) #console.debug("Found a local gateway at %s"%gateway_namespace) return gateway_namespace
def get_service_type(service): """ Returns the type of the specified ROS service, """ try: return rosservice_find(service) except: return ""
def get_services_for_type(service_type): """ Returns a list of services as specific service type """ return rosservice_find(service_type)
try: response = self.client(request) output = [ response.distance, response.number_of_objects, response.objects_type ] except Exception as e: print(e) #print ("sending the request failed") response = "failed" #print(command,"---",robot1,"---",robot2) return output server_list = rosservice.rosservice_find( "gazebo_information_plugins/distance_serivce" ) # we call rosservice_find to find any service with the distance_srvice type environment_info = [] for i in server_list: environment_info.append(GetInfo(i)) counter = 0 def get_current_position(name_space): """Get current location of robot using tf translation :parameter namespace : string, robot namespace :returns location : float, location of robot
def get_services_for_type(service_type, services_glob): """ Returns a list of services as specific service type """ # Filter the list of services by whether they are public before returning. return filter_globs(services_glob, rosservice_find(service_type))
def get_services_for_type(service_type, services_glob): """ Returns a list of services as specific service type """ # Filter the list of services by whether they are public before returning. return filter( lambda x: any(fnmatch.fnmatch(str(x), glob) for glob in services_glob), rosservice_find(service_type))