Go to the documentation of this file.00001
00002
00003
00004
00005 import rosnode
00006 from .exceptions import NotFoundException
00007
00008
00009 def find_node(wanted_node_name, unique=False):
00010 '''
00011 Do a lookup to find a node with the given name. The given name is treated as the unresolved node name.
00012 Hence this lookup will find nodes with the same name, but different namespaces.
00013
00014 This will raise exceptions, if the node couldn't be found
00015 or in case unique is set multiple nodes with the same name are found.
00016
00017 :param wanted_node_name str: unresolved name of the node looked for (e.g. 'gateway', not '/concert/gateway')
00018
00019 :returns: the fully resolved name of the node (unique) or list of fully resolved names (non-unique)
00020 :rtype: str
00021
00022 :raises: rocon_python_comms.NotFoundException
00023
00024 :todo: accept resolved names -> https://github.com/robotics-in-concert/rocon_tools/issues/30
00025 '''
00026 available_nodes = rosnode.get_node_names()
00027 found_nodes = []
00028 for resolved_node_name in available_nodes:
00029 node_name = resolved_node_name[(resolved_node_name.rfind('/') + 1):len(resolved_node_name)]
00030 if node_name == wanted_node_name:
00031 found_nodes.append(resolved_node_name)
00032
00033 if len(found_nodes) == 0:
00034 raise NotFoundException("Node '" + str(wanted_node_name) + "' not found.")
00035 if unique:
00036 if len(found_nodes) > 1:
00037 raise NotFoundException('More then one node with the same name found:' + str(found_nodes))
00038
00039 return found_nodes