Common Methods — Module

This module offers common methods to find ROS_MASTER_URI, resolve URI to find a resource or create a regular expression pattern.

master_discovery_fkie.common.create_pattern(param, data, has_interface, default=[], mastername='')[source]

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:
  • param (str) – parameter name
  • data (dict) – The dictionary, which can contain the parameter name and value. The data will be ignored, if has_interface is False.
  • has_interface (bool) – True, if valid data is available.
  • default (list) – Default value will be added to the data
Returns:

the compiled regular expression

Return type:

The result of re.compile()

master_discovery_fkie.common.is_empty_pattern(re_object)[source]

Returns the value of EMPTY_PATTERN.

master_discovery_fkie.common.masteruri_from_ros()[source]

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)
master_discovery_fkie.common.read_interface(interface_file)[source]

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
master_discovery_fkie.common.resolve_url(interface_url)[source]

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

Filter Interface — Module

This module offers a Filter class to filter out nodes, topics or services from MasterInfo.

class master_discovery_fkie.filter_interface.FilterInterface[source]

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.

static from_list(l=None)[source]
Reads the tuple of
(sync_remote_nodes, 
ignore_nodes, sync_nodes, 
ignore_topics, sync_topics,
ignore_services, sync_services,
ignore_type,
ignore_publishers, ignore_subscribers)`

with types (float, str, str, str, str, str, str, str)

and creates the FilterInterface object.

Returns:FilterInterface object or None on failure
is_ignored_node(node)[source]

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
is_ignored_publisher(node, topic, topictype)[source]

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:
  • node (str) – the name of the node published or subscribed the topic.
  • topic (str) – the name of the topic to test.
  • topictype (str) – the type of the topic. (e.g. the synchronization of bond/Status terminate the nodelets)
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

is_ignored_service(node, service)[source]

Searches firstly in ignore lists ignore_nodes and ignore_services. Then in sync_nodes or sync_services.

Parameters:
  • node (str) – the name of the node provided the service.
  • topic (str) – the name of the service to test.
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

is_ignored_subscriber(node, topic, topictype)[source]

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:
  • node (str) – the name of the node published or subscribed the topic.
  • topic (str) – the name of the topic to test.
  • topictype (str) – the type of the topic. (e.g. the synchronization of bond/Status terminate the nodelets)
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

is_ignored_topic(node, topic, topictype)[source]

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:
  • node (str) – the name of the node published or subscribed the topic.
  • topic (str) – the name of the topic to test.
  • topictype (str) – the type of the topic. (e.g. the synchronization of bond/Status terminate the nodelets)
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

load(mastername='', ignore_nodes=[], sync_nodes=[], ignore_topics=[], sync_topics=[], ignore_srv=[], sync_srv=[], ignore_type=[], ignore_publishers=[], ignore_subscribers=[])[source]

Reads the parameter and creates the pattern using master_discovery_fkie.common.create_pattern()

sync_remote_nodes()[source]

Returns the value stored in sync_remote_nodes parameter.

to_list()[source]
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)
Return type:(float, str, str, str, str, str, str, str)
update_sync_topics_pattern(topics=[])[source]

Updates the sync topics pattern.

Parameters:topics (list of strings) – the list of topics to sync.

Interface Finder — Module

This module offers methods to find the interface of the running master_discovery node.

master_discovery_fkie.interface_finder.get_changes_topic(masteruri, wait=True)[source]

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:
  • masteruri (str) – the URI of the ROS master
  • wait (bool) – check every second for the topic
Returns:

the list with names of the topics of type master_discovery_fkie.msg.MasterState

Return type:

list of strings

master_discovery_fkie.interface_finder.get_listmaster_service(masteruri, wait=True)[source]

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:
  • masteruri (str) – the URI of the ROS master
  • wait (boo) – check every second for the service
Returns:

the list with names of the services ending with list_masters

Return type:

list of strings

master_discovery_fkie.interface_finder.get_refresh_service(masteruri, wait=True)[source]

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:
  • masteruri (str) – the URI of the ROS master
  • wait (boo) – check every second for the service
Returns:

the list with names of the services ending with refresh

Return type:

list of strings

master_discovery_fkie.interface_finder.get_stats_topic(masteruri, wait=True)[source]

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:
  • masteruri (str) – the URI of the ROS master
  • wait (bool) – check every second for the topic
Returns:

the list of names of the topic with type master_discovery_fkie.msg.LinkStatesStamped

Return type:

list of strings

master_discovery_fkie.interface_finder.hostFromUri(uri)[source]

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

Master Discovery — Module

class master_discovery_fkie.master_discovery.DiscoveredMaster(monitoruri, heartbeat_rate=1.0, timestamp=0.0, timestamp_local=0.0, callback_master_state=None)[source]

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:
  • monitoruri (str) – The URI of the remote RPC server, which moniter the ROS master
  • heartbeat_rate (float (Default: 1.`)) – The remote rate, which is used to send the heartbeat messages.
  • timestamp (float (Default: 0)) – The timestamp of the state of the remoter ROS master
  • timestamp_local (float (Default: 0)) – The timestamp of the state of the remoter ROS master, without the changes maked while a synchronization.
  • callback_master_state – the callback method to publish the changes of the ROS masters
ERR_RESOLVE_NAME = 1
ERR_SOCKET = 2
MIN_HZ_FOR_QUALILTY = 0.3
add_heartbeat(timestamp, timestamp_local, rate)[source]

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:
  • timestamp (float) – The new timestamp of the ROS master state
  • timestamp_local (float (Default: 0)) – The timestamp of the state of the remoter ROS master, without the changes maked while a synchronization.
  • rate (float) – The remote rate, which is used to send the heartbeat messages. If the rate is zero the heartbeat is ignored.
Returns:

True on changes

Return type:

bool

add_request(timestamp)[source]
errors[source]
get_quality(interval=5, offline_after=1.4)[source]

Calculates the link quality to this master.

remove_heartbeats(timestamp)[source]

Removes all hearbeat measurements, which are older as the given timestamp.

Parameters:timestamp (float) – heartbeats older this timestamp will be removed.
Returns:the count of removed heartbeats
Return type:int
set_offline()[source]

Sets this master to offline and publish the new state to the ROS network.

class master_discovery_fkie.master_discovery.Discoverer(mcast_port, mcast_group, monitor_port)[source]

Bases: object

The class to publish the current state of the ROS master.

Discovering is done by hearbeats:

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:
  • mcast_port (int) – The port used to publish and receive the multicast messages.
  • mcast_group (str) – The IPv4 or IPv6 multicast group used for discovering over nodes.
  • monitor_port (int) – The port of the RPC Server, used to get more information about the ROS master.
ACTIVE_REQUEST_AFTER = 60

send an update request, if after this time no hearbeats are received [sec] (Default: 60 sec).

CHANGE_NOTIFICATION_COUNT = 3

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.

HEARTBEAT_FMT = 'cBBiiHii'

packet format description, see: http://docs.python.org/library/struct.html

HEARTBEAT_HZ = 0.02

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.

INIT_NOTIFICATION_COUNT = 3

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.

MEASUREMENT_INTERVALS = 5

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)

NETPACKET_SIZE = 68
OFFLINE_AFTER_REQUEST_COUNT = 5

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_AFTER = 300

remove an offline host after this time in [sec] (Default: 300 sec).

ROSMASTER_HZ = 1

the test rate of ROS master state in Hz (Default: 1 Hz).

TIMEOUT_FACTOR = 1.4

the timeout is defined by calculated measurement duration multiplied by TIMEOUT_FAKTOR.

VERSION = 2

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.
checkROSMaster_loop()[source]

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()

finish(*arg)[source]

Callback called on exit of the ros node and publish the empty list of ROSMasters.

classmethod msg2masterState(msg, address)[source]
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)
publish_masterstate(master_state)[source]

Publishes the given state to the ROS network. This method is thread safe.

Parameters:master_state – the master state to publish
publish_stats(stats)[source]

Publishes the link quality states to the ROS network.This method is thread safe.

Parameters:stats – the link quality states to publish
recv_loop()[source]

This method handles the received multicast messages.

rosservice_list_masters(req)[source]

Callback for the ROS service to get the current list of the known ROS masters.

rosservice_refresh(req)[source]

Callback for the ROS service to send an active unicast and multicast request to each known master discovery.

send_heardbeat()[source]

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.

start()[source]
timed_stats_calculation()[source]

This method will be called by a timer and has two jobs: 1. set the masters offline, if no heartbeat messages are received a long time 2. calculate the quality of known links

update_master_errors()[source]

Master Monitor — Module

exception master_discovery_fkie.master_monitor.MasterConnectionException[source]

Bases: exceptions.Exception

The exception class to handle the connection problems with ROS Master.

class master_discovery_fkie.master_monitor.MasterMonitor(rpcport=11611, do_retry=True, ipv6=False)[source]

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:
  • rpcport (int) – the port number for the XML-RPC server
  • do_retry (bool) – retry to create XML-RPC server
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()

INTERVAL_UPDATE_LAUNCH_URIS = 15.0
MAX_PING_SEC = 10.0

The time to update the node URI, ID or service URI (Default: 10.0)

checkState(clear_cache=False)[source]

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
getCurrentState()[source]
Returns:The current ROS Master State
Return type:master_discovery_fkie.master_info.MasterInfo or None
getListedMasterInfo()[source]
Returns:a extended ROS Master State.
Return type:master_discovery_fkie.master_info.MasterInfo.listedState() for result type
getListedMasterInfoFiltered(filter_list)[source]
Returns:a extended filtered ROS Master State.
Return type:master_discovery_fkie.master_info.MasterInfo.listedState() for result type
getMasterContacts()[source]

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)
getMasterErrors()[source]

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, [str])
getMastername()[source]

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
getMasteruri()[source]

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
reset()[source]

Sets the master state to None.

rpcport = None

the port number of the RPC server

shutdown()[source]

Shutdown the RPC Server.

updateState(clear_cache=False)[source]

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.
updateSyncInfo()[source]

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().

update_master_errors(error_list)[source]
class master_discovery_fkie.master_monitor.RPCThreading(addr, requestHandler=<class SimpleXMLRPCServer.SimpleXMLRPCRequestHandler at 0x47d44c8>, logRequests=True, allow_none=False, encoding=None, bind_and_activate=True)[source]

Bases: SocketServer.ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer

class master_discovery_fkie.master_monitor.RPCThreadingV6(addr, requestHandler=<class SimpleXMLRPCServer.SimpleXMLRPCRequestHandler at 0x47d44c8>, logRequests=True, allow_none=False, encoding=None, bind_and_activate=True)[source]

Bases: SocketServer.ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer

address_family = 10

Master Info — Module

class master_discovery_fkie.master_info.MasterInfo(masteruri, mastername=None)[source]

Bases: object

The MasterInfo class stores informations about a ROS master. Not thread safe!

Parameters:
  • masteruri (str) – The URI of the corresponding master
  • mastername (str or None (Default: None)) – The name of the ROS master. If no one is given, it will be extracted from the masteruri.
check_ts = None

the last time, when the state of the ROS master retrieved

static from_list(l)[source]

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
getNode(name)[source]
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
getNodeEndsWith(suffix)[source]

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
getService(name)[source]

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
getTopic(name)[source]

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
has_local_changes(other)[source]

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)
listedState(filter_interface=None)[source]

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)

  • publishers is of the form

    [ [topic1, [topic1Publisher1...topic1PublisherN]] ... ]

  • subscribers is of the form

    [ [topic1, [topic1Subscriber1...topic1SubscriberN]] ... ]

  • services is of the form

    [ [service1, [service1Provider1...service1ProviderN]] ... ]

  • topicTypes is a list of

    [ [topicName1, topicType1], ... ]

  • nodes is a list of (the pid of remote Nodes will not be resolved)

    [nodename, XML-RPC URI, origin ROS_MASTER_URI, pid, {local, remote}]

  • serviceProvider is a list of (the type, serviceClass and args of remote Services will not be resolved)

    [service, XML-RPC URI, origin ROS_MASTER_URI, type, {local, remote}]

Return type:(float, float, str, str, [ [str,[str] ] ], [ [str,[str] ] ], [ [str,[str] ] ], [ [str,str] ], [ [str,str,str,int,str] ], [ [str,str,str,str,str] ])
mastername[source]
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
masteruri[source]
Returns:the URI of the ROS master.
Return type:str
node_names[source]
Returns:the list with node names
Return type:list of strings
node_uris[source]
Returns:the list with node URI’s.
Return type:list of strings
nodes[source]
Returns:the dictionary with node names and corresponding instances of NodeInfo.
Return type:dict of (str : master_discovery_fkie.master_info.NodeInfo)
service_names[source]
Returns:the list with service names.
Return type:list of strings
service_uris[source]
Returns:the list with service URI’s.
Return type:list of strings
services[source]
Returns:the dictionary with service names and corresponding ServiceInfo instances.
Return type:dict of (str : master_discovery_fkie.master_info.ServiceInfo)
timestamp[source]
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
timestamp_local[source]
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
topic_names[source]
Returns:the list with topic names.
Return type:list of strings
topics[source]
Returns:the dictionary with topic names and corresponding TopicInfo instances.
Return type:dict of (str : master_discovery_fkie.master_info.TopicInfo)
updateInfo(other)[source]

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)

class master_discovery_fkie.master_info.NodeInfo(name, masteruri)[source]

Bases: object

The NodeInfo class stores informations about a ROS node.

Parameters:
  • name (str) – the name of the node
  • masteruri (str) – the URI of the ROS master, where the node is registered. This masteruri will be used to determine, whether the ROS master and the node are running on the same machine.
copy(new_masteruri=None)[source]

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
isLocal[source]
Returns:True if the node and the ROS master are running on the same machine.
Return type:bool
static local_(masteruri, org_masteruri, uri)[source]

Test the node whether it’s run on the same machineas the ROS master and masteruri and org_masteruri are equal.

Parameters:
  • masteruri (str) – The URI of the ROS master currently tested.
  • org_masteruri (str) – The URI of the ROS master, where the node was originally registered.
  • uri (str) – The URI of the node.
Return type:

bool

masteruri[source]
Returns:the URI of the ROS master where the node is registered.
Return type:str
name[source]
Returns:the name of the node.
Return type:str
pid = None

the process id of the node. Invalid id has a None value

publishedTopics[source]
Returns:the list of all published topics by this node.
Return type:list of strings
services[source]
Returns:the list of all services provided by this node.
Return type:list of strings
subscribedTopics[source]
Returns:the list of all subscribed topics by this node.
Return type:list of strings
uri[source]
Returns:the URI of the RPC API of the node.
Return type:str
class master_discovery_fkie.master_info.ServiceInfo(name, masteruri)[source]

Bases: object

The ServiceInfo class stores informations about a ROS service.

Parameters:
  • name (str) – the name of the service
  • masteruri (str) – the URI of the ROS master, where the service is registered. This masteruri will be used to determine, whether the ROS master and the service are running on the same machine.
copy(new_masteruri=None)[source]

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_service_class(allow_get_type=False)[source]

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
isLocal[source]
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
masteruri[source]
Returns:the URI of the ROS master of the service
Return type:str
name[source]
Returns:the name of the service.
Return type:str
serviceProvider[source]
Returns:the list of the node names, which provide this service.
Return type:list of strings
type = None

the type of the service. (Default: None)

uri[source]
Returns:the URI of the RPC API of the service
Return type:str
class master_discovery_fkie.master_info.TopicInfo(name)[source]

Bases: object

The TopicInfo class stores informations about a ROS topic.

Parameters:name (str) – the name of the topic
copy()[source]

Creates a copy this object and returns it.

Return type:master_discovery_fkie.master_info.TopicInfo
name[source]
Returns:the name of the topic.
Return type:str
publisherNodes[source]
Returns:the list with node names witch are publishing to this topic.
Return type:list of strings
subscriberNodes[source]
Returns:the list with node names witch are subscribed to this topic.
Return type:list of strings
type = None

the type of the topic. (Default: None)

udp — Module

class master_discovery_fkie.udp.McastSocket(port, mgroup, reuse=True, ttl=20)[source]

Bases: socket._socketobject

The McastSocket class enables the send and receive UDP messages to a multicast group.

Parameters:
  • port (int) – the port to bind the socket
  • mgroup (str) – the multicast group to join
  • reuse (boolean (Default: True)) – allows the reusing of the port
  • ttl (int (Default: 20)) – time to leave
close()[source]

Unregister from the multicast group and close the socket.

hasEnabledMulticastIface()[source]

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
static localifs()[source]

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)
send2addr(msg, addr)[source]

Sends the given message to the joined multicast group. Some errors on send will be ignored (ENETRESET, ENETDOWN, ENETUNREACH)

Parameters:
  • msg (str) – message to send
  • addr (str) – IPv4 or IPv6 address
send2group(msg)[source]

Sends the given message to the joined multicast group. Some errors on send will be ignored (ENETRESET, ENETDOWN, ENETUNREACH)

Parameters:msg (str) – message to send

zeroconf — Module