def __init__(self, name, uri, discoverer_name, monitoruri, timestamp, sync_on_demand=False):
    '''
    Initialization method for the SyncThread. 
    @param name: the name of the ROS master synchronized with.
    @type name:  C{str}
    @param uri: the URI of the ROS master synchronized with
    @type uri:  C{str}
    @param discoverer_name: the name of the discovery node running on ROS master synchronized with.
    @type discoverer_name:  C{str}
    @param monitoruri: The URI of RPC server of the discovery node to get the ROS master state by calling a method only once.
    @type monitoruri:  C{str}
    @param timestamp: The timestamp of the current state of the ROS master info.
    @type timestamp:  C{float64}
    @param sync_on_demand: Synchronize topics on demand
    @type sync_on_demand: bool
    '''
    self.name = name
    self.uri = uri
    self.discoverer_name = discoverer_name
    self.monitoruri = monitoruri
    self.timestamp = timestamp
    self.timestamp_local = 0.
    self.timestamp_remote = 0.

    self.localMasteruri = masteruri_from_ros()
    rospy.logdebug("SyncThread[%s]: create this sync thread", self.name)
    # synchronization variables 
    self.__lock_info = threading.RLock()
    self.__lock_intern = threading.RLock()
    self._use_filtered_method = None
    # SyncMasterInfo with currently synchronized nodes, publisher (topic, node, nodeuri), subscriber(topic, node, nodeuri) and services
    self.__sync_info = None
    self.__unregistered = False
    # a list with published topics as a tuple of (topic name, node name, node URL)
    self.__publisher = []
    # a list with subscribed topics as a tuple of (topic name, node name, node URL)
    self.__subscriber = []
    # a list with services as a tuple of (service name, service URL, node name, node URL)
    self.__services = []
    # the state of the own ROS master is used if `sync_on_demand` is enabled or
    # to determine the type of topic subscribed remote with `Empty` type
    self.__own_state = None

    #setup the filter
    self._filter = FilterInterface()
    self._filter.load(self.name,
                      ['/rosout', rospy.get_name().replace('/', '/*')+'*', self.discoverer_name.replace('/', '/*')+'*', '/*node_manager', '/*zeroconf'], [],
                      ['/rosout', '/rosout_agg'], ['/'] if sync_on_demand else [],
                      ['/*get_loggers', '/*set_logger_level'], [],
                      # do not sync the bond message of the nodelets!!
                      ['bond/Status'],
                      [], [])

    # congestion avoidance: wait for random.random*2 sec. If an update request 
    # is received try to cancel and restart the current timer. The timer can be
    # canceled for maximal MAX_UPDATE_DELAY times.
    self._update_timer = None
    self._delayed_update = 0
    self.__on_update = False
Example #2
0
def get_default_rtcp_port(zeroconf=False):
    try:
        from master_discovery_fkie.common import masteruri_from_ros
        masteruri = masteruri_from_ros()
        rospy.loginfo("ROS Master URI: %s", masteruri)
        from urlparse import urlparse
        return urlparse(masteruri).port + (600 if zeroconf else 300)
    except:
        import traceback
        print traceback.format_exc()
        return 11911 if zeroconf else 11611
Example #3
0
 def getMasteruri(self):
     '''
 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.
 @return: ROS master URI
 @rtype: C{str} or C{None}
 '''
     if not hasattr(self, 'materuri') or self.materuri is None:
         masteruri = masteruri_from_ros()
         master = xmlrpclib.ServerProxy(masteruri)
         code, message, self.materuri = master.getUri(rospy.get_name())
     return self.materuri
 def getMasteruri(self):
   '''
   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.
   @return: ROS master URI
   @rtype: C{str} or C{None}
   '''
   if not hasattr(self, 'materuri') or self.materuri is None:
     masteruri = masteruri_from_ros()
     master = xmlrpclib.ServerProxy(masteruri)
     code, message, self.materuri = master.getUri(rospy.get_name())
   return self.materuri
  def __init__(self, name, uri, discoverer_name, monitoruri, timestamp, sync_on_demand=False):
    '''
    Initialization method for the SyncThread. 
    @param name: the name of the ROS master synchronized with.
    @type name:  C{str}
    @param uri: the URI of the ROS master synchronized with
    @type uri:  C{str}
    @param discoverer_name: the name of the discovery node running on ROS master synchronized with.
    @type discoverer_name:  C{str}
    @param monitoruri: The URI of RPC server of the discovery node to get the ROS master state by calling a method only once.
    @type monitoruri:  C{str}
    @param timestamp: The timestamp of the current state of the ROS master info.
    @type timestamp:  C{float64}
    @param sync_on_demand: Synchronize topics on demand
    @type sync_on_demand: bool
    '''
    # init thread
    threading.Thread.__init__(self)
    self.masterInfo = MasterInfo(name, uri, discoverer_name, monitoruri, timestamp)
    self.localMasteruri = masteruri_from_ros()
    rospy.logdebug("SyncThread[%s]: create this sync thread", self.masterInfo.name)
    # synchronization variables 
    self.__cv = threading.Condition()
    self.__lock_info = threading.RLock()
    self.__sync_info = None #SyncMasterInfo with currently synchronized nodes, publisher (topic, node, nodeuri), subscriber(topic, node, nodeuri) and services
    self.__stop = False
    # a list with published topics as a tuple of (topic name, node name, node URL)
    self.__publisher = []
    # a list with subscribed topics as a tuple of (topic name, node name, node URL)
    self.__subscriber = []
    # a list with services as a tuple of (service name, service URL, node name, node URL)
    self.__services = []
    self.__own_state = None
    
    #setup the filter
    self._filter = FilterInterface()
    self._filter.load(self.masterInfo.name,
                      ['/rosout', rospy.get_name().replace('/', '/*')+'*', self.masterInfo.discoverer_name.replace('/', '/*')+'*', '/*node_manager', '/*zeroconf'], [],
                      ['/rosout', '/rosout_agg'], ['/'] if sync_on_demand else [],
                      ['/*get_loggers', '/*set_logger_level'], [],
                      # do not sync the bond message of the nodelets!!
                      ['bond/Status'])

    # congestion avoidance: wait for minimum 1 sec. If an update request is received wait 
    # for next 1 second. Force update after maximum 5 sec since first update request.
    self._ts_first_update_request = None
    self._ts_last_update_request = None
    self._use_filtered_method = None

    self.start()
    def __init__(self, name, uri, discoverer_name, monitoruri, timestamp, sync_on_demand=False):
        '''
        Initialization method for the SyncThread.
        @param name: the name of the ROS master synchronized with.
        @type name:  C{str}
        @param uri: the URI of the ROS master synchronized with
        @type uri:  C{str}
        @param discoverer_name: the name of the discovery node running on ROS master synchronized with.
        @type discoverer_name:  C{str}
        @param monitoruri: The URI of RPC server of the discovery node to get the ROS master state by calling a method only once.
        @type monitoruri:  C{str}
        @param timestamp: The timestamp of the current state of the ROS master info.
        @type timestamp:  C{float64}
        @param sync_on_demand: Synchronize topics on demand
        @type sync_on_demand: bool
        '''
        self.name = name
        self.uri = uri
        self.discoverer_name = discoverer_name
        self.monitoruri = monitoruri
        self.timestamp = timestamp
        self.timestamp_local = 0.
        self.timestamp_remote = 0.
        self._online = True
        self._offline_ts = 0

        self.masteruri_local = masteruri_from_ros()
        rospy.logdebug("SyncThread[%s]: create this sync thread", self.name)
        # synchronization variables
        self.__lock_info = threading.RLock()
        self.__lock_intern = threading.RLock()
        self._use_filtered_method = None
        # SyncMasterInfo with currently synchronized nodes, publisher (topic, node, nodeuri), subscriber(topic, node, nodeuri) and services
        self.__sync_info = None
        self.__unregistered = False
        # a list with published topics as a tuple of (topic name, node name, node URL)
        self.__publisher = []
        # a list with subscribed topics as a tuple of (topic name, node name, node URL)
        self.__subscriber = []
        # a list with services as a tuple of (service name, service URL, node name, node URL)
        self.__services = []
        # the state of the own ROS master is used if `sync_on_demand` is enabled or
        # to determine the type of topic subscribed remote with `Empty` type
        self.__own_state = None

        # setup the filter
        self._filter = FilterInterface()
        self._filter.load(self.name,
                          ['/rosout', rospy.get_name(), self.discoverer_name, '/node_manager', '/zeroconf'], [],
                          ['/rosout', '/rosout_agg'], ['/'] if sync_on_demand else [],
                          ['/*get_loggers', '/*set_logger_level'], [],
                          # do not sync the bond message of the nodelets!!
                          ['bond/Status'],
                          [], [],
                          [])

        # congestion avoidance: wait for random.random*2 sec. If an update request
        # is received try to cancel and restart the current timer. The timer can be
        # canceled for maximal MAX_UPDATE_DELAY times.
        self._update_timer = None
        self._delayed_update = 0
        self.__on_update = False