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() |
Extracts the hostname from given url.
Parameters: | url (str) – the url to parse |
---|---|
Returns: | the hostname or None, if the url is None or invalid |
Return type: | str |
See: | http://docs.python.org/library/urlparse.html |
Extracts the port from given url.
Parameters: | url (str) – the url to parse |
---|---|
Returns: | the port or None, if the url is None or invalid |
Return type: | int |
See: | http://docs.python.org/library/urlparse.html |
Returns the value of EMPTY_PATTERN.
Requests the ROS master URI from the ROS master through the RPC interface and returns it. The ‘materuri’ attribute will be set to the requested value.
Returns: | ROS master URI |
---|---|
Return type: | C{str} or C{None} |
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,
ignore_publishers, ignore_subscribers,
do_not_sync)`
with types (bool, str, 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 first in the ignore_publishers ignore list Then in ignore lists ignore_type, ignore_nodes and ignore_topics. Finally 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 |
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 first in the ignore_subscribers ignore list Then in ignore lists ignore_type, ignore_nodes and ignore_topics. Finally 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 |
NOTE: This function is deprecated. Please use is_ignored_subscriber and is_ignored_publisher instead
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()
Returns: | the tuple of the all filter patterns.(sync_remote_nodes,
ignore_nodes, sync_nodes,
ignore_topics, sync_topics,
ignore_services, sync_services,
ignore_type,
ignore_publishers, ignore_subscribers,
do_not_sync)
|
---|---|
Return type: | (bool, str, str, str, str, str, str, str, str, str, str) |
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 services of ROS master for a service with name ending by refresh 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 refresh |
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 |
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 |
Stores the count of requests. This count is used to determine offline state of remote master.
Parameters: | timestamp (float) – time the request is sent. |
---|
Copies the errors and returns as dictionary. :return: a dictionry of error type (ERR_*) and a message
Bases: object
The class to publish the current state of the ROS master.
Each master discovery node sends to a multicast group periodically messages with current state. If the frequency is less than 0.3 the detected changes on ROS master are published immediately. The current state is described by timestamp of last change. The frequency of heartbeats can be changed by ~heartbeat_hz parameter.
If hearbeats are disabled (~heartbeat_hz is zero) each master discovery node sends on start three notification messages and requests.
If for a host no more heartbeat are received while ACTIVE_REQUEST_AFTER (60 sec) a request to this host will be sent as an unicast message. After five unanswered requests the host state will be changed to offline. After REMOVE_AFTER (300 sec) the host will be removed.
Parameters: |
---|
send an update request, if after this time no hearbeats are received [sec] (Default: 60 sec).
After the ROS master was changed the new state will be sent for CHANGE_NOTIFICATION_COUNT times (Default: 3 sec). The new state will be sent with ROSMASTER_HZ and only if HEARTBEAT_HZ is zero.
packet format description, see: http://docs.python.org/library/struct.html
the send rate of the heartbeat packets in hz. Zero disables the heartbeats. (Default: 0.02 Hz) Only values between 0.1 and 25.5 are used to detemine the link quality.
the count of heartbeats and update request to send at the start (Default: 3 sec). It will be send with 1Hz. Only used if HEARTBEAT_HZ is zero.
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)
After this unanswered count of requests for update the remote master is set to offline state (Default: 5 sec). The requests are send after ACTIVE_REQUEST_AFTER with ROSMASTER_HZ.
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.
Version 3: | ‘cBBiiHii’ |
---|
``Version 2``
if the timestamp of ROS Master state is zero, the reply as unicast
message will be send to the sender.
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.
Callback for the ROS service to send an active unicast and multicast request to each known master discovery.
Sends current state as heartbeat messages to defined multicast group. If the Discoverer.HEARTBEAT_HZ is greather then zero a timer will be started to send heartbeat messages periodically. This message will also send on start of the discoverer.
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 |
The RPC method called by XML-RPC server to request the current host time.
Returns: | (ROS master URI, current time) |
---|---|
Return type: | (str, float) |
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) |
The RPC method called by XML-RPC server to request the occured network errors.
Returns: | (ROS master URI, list with errors) |
---|---|
Return type: | (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
The RPC method called by XML-RPC server to set new host time. :param timestamp: UNIX timestamp :type timestamp: float :return: (ROS master URI, current time) :rtype: (str, float)
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: 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 |
Returns: | True if the node is registered on the local 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: | True if the service is registered on the local machine. |
---|---|
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 DiscoverSocket class enables the send and receive UDP messages to a multicast group and unicast address. The unicast socket is only created if ‘send_mcast’ and ‘listen_mcast’ parameter are set to False or a specific interface is defined.
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 |