This module offers common methods to find ROS_MASTER_URI, resolve URI to find a resource or create a regular expression pattern.
Create and compile the regular expression for given parameter. The data is taken from data. If the data was read from the interface file, then you have to set the has_interface to True. If has_interface is False, the data will be ignored and the parameter will be read from ROS parameter server. If resulting value is an empty list, \b (http://docs.python.org/2/library/re.html) will be added to the pattern as EMPTY_PATTERN.
Parameters: | |
---|---|
Returns: | the compiled regular expression |
Return type: | The result of re.compile() |
Returns the value of EMPTY_PATTERN.
Returns the master URI depending on ROS distribution API.
Returns: | ROS master URI |
---|---|
Return type: | str |
See : | rosgraph.rosenv.get_master_uri() (fuerte) |
See : | roslib.rosenv.get_master_uri() (prior) |
Reads the given file. You can use master_discovery_fkie.common.resolve_url() to resolve an URL to a file.
Parameters: | interface_file (str) – the file containing the interface. |
---|---|
Raises ValueError: | |
on error while read interface | |
Returns: | directory with content of the given file |
The supported URL begins with file:///, package:// or pkg://. The package URL will be resolved to a valid file path. If the file is in a subdirectory, you can replace the subdirectory by ///.
E.g.: package://master_discovery_fkie///master_discovery.launch
Raises ValueError: | |
---|---|
on invalid URL or not existent file | |
Returns: | the file path |
This module offers a Filter class to filter out nodes, topics or services from MasterInfo.
Bases: object
The class represents a filter used by sync node to filter nodes, topics or services. The filter is based on regular expressions. The filter object can be converted to a tuple of strings and then passed to the XML-RPC method to get a filtered ROS master state. After creation of the filter object you must call master_discovery_fkie.filter_interface.FilterInterface.load() or master_discovery_fkie.filter_interface.FilterInterface.from_list(). Otherwise the object is invalid and the test methods return always False.
(sync_remote_nodes,
ignore_nodes, sync_nodes,
ignore_topics, sync_topics,
ignore_services, sync_services,
ignore_type)`
with types (float, str, str, str, str, str, str, str)
and creates the FilterInterface object.
Returns: | FilterInterface object or None on failure |
---|
Searches the given node in ignore_nodes and sync_nodes lists.
Parameters: | node (str) – the name of the node to test. |
---|---|
Returns: | True, if the node was found in the ignore_nodes list or the sync_nodes is not empty. |
Note : | If the filter object is not initialized by load() or from_list() the returned value is False |
Searches firstly in ignore lists ignore_nodes and ignore_services. Then in sync_nodes or sync_services.
Parameters: | |
---|---|
Returns: | True, if the values are found in ignore_nodes or ignore_services. If sync_nodes or sync_services is empty True will be returned, too. |
Note : | If the filter object is not initialized by load() or from_list() the returned value is False |
Searches firstly in ignore lists ignore_type, ignore_nodes and ignore_topics. Then in sync_nodes or sync_topics.
Parameters: | |
---|---|
Returns: | True, if the values are found in ignore_type, ignore_nodes or ignore_topics. If sync_nodes or sync_topics is empty True will be returned, too. |
Note : | If the filter object is not initialized by load() or from_list() the returned value is False |
Reads the parameter and creates the pattern using master_discovery_fkie.common.create_pattern()
This module offers methods to find the interface of the running master_discovery node.
Search in publishers of ROS master for a topic with type master_discovery_fkie.msg.MasterState and returns his name, if it runs on the local host. Returns empty list if no topic was found and wait is False.
Parameters: | |
---|---|
Returns: | the list with names of the topics of type master_discovery_fkie.msg.MasterState |
Return type: | list of strings |
Search in services of ROS master for a service with name ending by list_masters and returns his name, if it runs on the local host. Returns empty list if no service was found and wait is False.
Parameters: |
|
---|---|
Returns: | the list with names of the services ending with list_masters |
Return type: | list of strings |
Search in publishers of ROS master for a topic with type LinkStatesStamped and returns his name, if it runs on the local host. Returns empty list if no topic was found and wait is False.
Parameters: | |
---|---|
Returns: | the list of names of the topic with type master_discovery_fkie.msg.LinkStatesStamped |
Return type: | list of strings |
Extracts the hostname from given uri.
Parameters: | uri (str) – the uri to parse |
---|---|
Returns: | the hostname or None, if the uri is None or invalid |
Return type: | str |
See : | http://docs.python.org/library/urlparse.html |
Bases: object
The class stores all information about the remote ROS master and the all received heartbeat messages of the remote node. On first contact a theaded connection to remote discoverer will be established to get additional information about the ROS master.
Parameters: |
|
---|
Adds a new heartbeat measurement. If it is a new timestamp a ROS message about the change of this ROS master will be published into ROS network.
Parameters: | |
---|---|
Returns: | True on changes |
Return type: | bool |
Bases: threading.Thread
The class to publish the current state of the ROS master.
Parameters: |
---|
packet format description, see: http://docs.python.org/library/struct.html
the send rate of the heartbeat packets in hz (Default: 2 Hz)
the count of intervals (1 sec) used for a quality calculation. If HEARTBEAT_HZ is smaller then 1, MEASUREMENT_INTERVALS will be divided by HEARTBEAT_HZ value. (Default: 5 sec are used to determine the link qaulity)
remove an offline host after this time in [sec] (Default: 300 sec).
the test rate of ROS master state in Hz (Default: 1 Hz).
the timeout is defined by calculated measurement duration multiplied by TIMEOUT_FAKTOR.
the version of the packet format described by HEARTBEAT_FMT
Version 1: | ‘cBBiiH’ |
---|
one character 'R'
unsigned char: version of the hearbeat message
unsigned char: rate of the heartbeat message in HZ*10. Maximal rate: 25.5 Hz -> value 255
int: secs of the ROS Master state
int: nsecs of the ROS Master state
unsigned short: the port number of the RPC Server of the remote ROS-Core monitor
Version 2: | ‘cBBiiHii’ |
---|
``Version 1``
int: secs of the ROS Master state (only local changes). Changes while sync will be ignored.
int: nsecs of the ROS Master state (only local changes). Changes while sync will be ignored.
The method test periodically the state of the ROS master. The new state will be published as heartbeat messages. master_discovery_fkie.master_monitor.MasterMonitor.checkState()
Callback called on exit of the ros node and publish the empty list of ROSMasters.
Returns: | parses the hearbeat message and return a tuple of version and values corresponding with current version of message. master_discovery_fkie.master_discovery.Discoverer.HEARTBEAT_FMT |
---|---|
Raise : | Exception on invalid message |
Return type: | (unsigned char, tuple corresponding to master_discovery_fkie.master_discovery.Discoverer.HEARTBEAT_FMT) |
Publishes the given state to the ROS network. This method is thread safe.
Parameters: | master_state – the master state to publish |
---|
Publishes the link quality states to the ROS network.This method is thread safe.
Parameters: | stats – the link quality states to publish |
---|
Callback for the ROS service to get the current list of the known ROS masters.
Bases: exceptions.Exception
The exception class to handle the connection problems with ROS Master.
Bases: object
This class provides methods to get the state from the ROS master using his RPC API and test for changes. Furthermore an XML-RPC server will be created to offer the complete current state of the ROS master by one method call.
Parameters: | |
---|---|
See : | master_discovery_fkie.master_monitor.MasterMonitor.getCurrentState(), respectively master_discovery_fkie.master_monitor.MasterMonitor.updateState() |
Rpc Methods: | master_discovery_fkie.master_monitor.MasterMonitor.getListedMasterInfo() or master_discovery_fkie.master_monitor.MasterMonitor.getMasterContacts() as RPC: masterInfo() and masterContacts() |
The time to update the node URI, ID or service URI (Default: 10.0)
Gets the state from the ROS master and compares it to the stored state.
Parameters: | clear_cache (bool (Default: False)) – The URI of nodes and services will be cached to reduce the load. If remote hosted nodes or services was restarted, the cache must be cleared! The local nodes will be updated periodically after master_discovery_fkie.master_monitor.MasterMonitor.MAX_PING_SEC. |
---|---|
Returns: | True if the ROS master state is changed |
Return type: | bool |
Returns: | The current ROS Master State |
---|---|
Return type: | master_discovery_fkie.master_info.MasterInfo or None |
Returns: | a extended ROS Master State. |
---|---|
Return type: | master_discovery_fkie.master_info.MasterInfo.listedState() for result type |
Returns: | a extended filtered ROS Master State. |
---|---|
Return type: | master_discovery_fkie.master_info.MasterInfo.listedState() for result type |
The RPC method called by XML-RPC server to request the master contact information.
Returns: | (timestamp of the ROS master state, ROS master URI, master name, name of this service, URI of this RPC server) |
---|---|
Return type: | (str, str, str, str, str) |
Returns the name of the master. If no name is set, the hostname of the ROS master URI will be extracted.
Returns: | the name of the ROS master |
---|---|
Return type: | str or None |
Requests the ROS master URI from the ROS master through the RPC interface and returns it.
Returns: | ROS master URI |
---|---|
Return type: | str or None |
the port number of the RPC server
Gets state from the ROS Master through his RPC interface.
Parameters: | clear_cache (bool (Default: False)) – The URI of nodes and services will be cached to reduce the load. If remote hosted nodes or services was restarted, the cache must be cleared! The local nodes will be updated periodically after master_discovery_fkie.master_monitor.MasterMonitor.MAX_PING_SEC. |
---|---|
Return type: | master_discovery_fkie.master_info.MasterInfo |
Raise : | MasterConnectionException, if not complete information was get from the ROS master. |
This method can be called to update the origin ROS master URI of the nodes and services in new master_state. This is only need, if a synchronization is running. The synchronization service will be detect automatically by searching for the service ending with get_sync_info. The method will be called by master_discovery_fkie.master_monitor.MasterMonitor.checkState().
Bases: SocketServer.ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer
Bases: object
The MasterInfo class stores informations about a ROS master. Not thread safe!
Parameters: |
|
---|
the last time, when the state of the ROS master retrieved
Creates a new instance of the MasterInfo from given list.
Parameters: | l (list) – the list returned by master_discovery_fkie.master_info.MasterInfo.listedState() |
---|---|
Returns: | the new instance of the MasterInfo filled from list. |
Return type: | master_discovery_fkie.master_info.MasterInfo |
Parameters: | name (str) – the name of the node |
---|---|
Returns: | the instance of the master_discovery_fkie.master_info.NodeInfo with given name |
Return type: | master_discovery_fkie.master_info.NodeInfo or None |
Returns the node, which name ends with given suffix. On more then one node, only the fist found will be returned.
Parameters: | suffix (str) – the end of the name |
---|---|
Returns: | the instance of the master_discovery_fkie.master_info.NodeInfo with with given suffix |
Return type: | master_discovery_fkie.master_info.NodeInfo or None |
Returns the service with given name.
Parameters: | name (str) – the name of the service |
---|---|
Returns: | the instance of the master_discovery_fkie.master_info.ServiceInfo with given name |
Return type: | master_discovery_fkie.master_info.ServiceInfo or None |
Returns the topics with given name.
Parameters: | name (str) – the name of the topic |
---|---|
Returns: | the instance of the master_discovery_fkie.master_info.TopicInfo with given name. |
Return type: | master_discovery_fkie.master_info.TopicInfo or None |
Compares the master state with other master state. The timestamp will not be compared.
Parameters: | other (master_discovery_fkie.master_info.MasterInfo) – the another MasterInfo instance. |
---|---|
Returns: | a tupel with two boolean values (all equal, only local equal) |
Return type: | (bool, bool) |
Returns a extended ROS Master State.
Parameters: | filter_interface (FilterInterface) – The filter used to filter the nodes, topics or serivces out. |
---|---|
Returns: | complete ROS Master State as (stamp, stamp_local, masteruri, name, publishers, subscribers, services, topicTypes, nodes, serviceProvider)
|
Return type: | (float, float, str, str, [ [str,[str] ] ], [ [str,[str] ] ], [ [str,[str] ] ], [ [str,str] ], [ [str,str,str,int,str] ], [ [str,str,str,str,str] ]) |
Returns: | the name of the ROS master. In most cases the ROS master name is the name of the host, where the ROS master running. Although it can differ. |
---|---|
Return type: | str |
Returns: | the dictionary with node names and corresponding instances of NodeInfo. |
---|---|
Return type: | dict of (str : master_discovery_fkie.master_info.NodeInfo) |
Returns: | the dictionary with service names and corresponding ServiceInfo instances. |
---|---|
Return type: | dict of (str : master_discovery_fkie.master_info.ServiceInfo) |
Returns: | The timestamp when this MasterInfo was first time filled with the information. See master_discovery_fkie.master_info.MasterInfo.check_ts() to get the time, when the information was compared with the data of ROS Master. |
---|---|
Return type: | float |
Returns: | The timestamp when this MasterInfo was first time filled with the information. See master_discovery_fkie.master_info.MasterInfo.check_ts() to get the time, when the information was compared with the data of ROS Master. This timestamp is only updated, not synchronized nodes, topics or services are changed. |
---|---|
Return type: | float |
Returns: | the dictionary with topic names and corresponding TopicInfo instances. |
---|---|
Return type: | dict of (str : master_discovery_fkie.master_info.TopicInfo) |
Updates the information about nodes, topics and services. If the other masterinfo is from the same ROS Master all informations are copied. If other contains the info from remote ROS Master, only the informations for synchronized nodes, topics or services are copied. :param other: the new master information object :type other: MasterInfo :return: The tuple of sets with added, changed and removed nodes, topics and services :rtype: (nodes_added, nodes_changed, nodes_removed, topics_added, topics_changed, topics_removed, services_added, services_changed, services_removed)
Bases: object
The NodeInfo class stores informations about a ROS node.
Parameters: |
---|
Creates a copy of this object and returns it.
Parameters: | new_masteruri – the masteruri of the new masterinfo |
---|---|
Return type: | master_discovery_fkie.master_info.NodeInfo |
Returns: | True if the node and the ROS master are running on the same machine. |
---|---|
Return type: | bool |
Test the node whether it’s run on the same machineas the ROS master and masteruri and org_masteruri are equal.
Parameters: | |
---|---|
Return type: | bool |
the process id of the node. Invalid id has a None value
Returns: | the list of all published topics by this node. |
---|---|
Return type: | list of strings |
Returns: | the list of all services provided by this node. |
---|---|
Return type: | list of strings |
Bases: object
The ServiceInfo class stores informations about a ROS service.
Parameters: |
---|
Creates a copy of this object and returns it.
Parameters: | new_masteruri – the masteruri of the new masterinfo |
---|---|
Return type: | master_discovery_fkie.master_info.NodeInfo |
Get the service class using the type of the service. NOTE: this method is from rosservice and changed to avoid a probe call to the service.
Parameters: | allow_get_type (bool) – allow to connect to service and get the type if the type is not valid (in case of other host) |
---|---|
Returns: | service class |
Return type: | ServiceDefinition: service class |
Raise : | ROSServiceException, if service class cannot be retrieved |
Returns: | True, if this service and the master are on the same machine. This will be determine on setting the uri-parameter. |
---|---|
Return type: | bool |
Returns: | the list of the node names, which provide this service. |
---|---|
Return type: | list of strings |
the type of the service. (Default: None)
Bases: object
The TopicInfo class stores informations about a ROS topic.
Parameters: | name (str) – the name of the topic |
---|
Creates a copy this object and returns it.
Return type: | master_discovery_fkie.master_info.TopicInfo |
---|
Returns: | the list with node names witch are publishing to this topic. |
---|---|
Return type: | list of strings |
Returns: | the list with node names witch are subscribed to this topic. |
---|---|
Return type: | list of strings |
the type of the topic. (Default: None)
Bases: socket._socketobject
The McastSocket class enables the send and receive UDP messages to a multicast group.
Parameters: |
---|
Test all enabled interfaces for a MULTICAST flag. If no enabled interfaces has a multicast support, False will be returned.
Returns: | True, if any interfaces with multicast support are enabled. |
---|---|
Return type: | bool |
Used to get a list of the up interfaces and associated IP addresses on this machine (linux only).
Returns: | List of interface tuples. Each tuple consists of (interface name, interface IP) |
---|---|
Return type: | list of (str, str) |