예제 #1
0
    def __init__(self, addresses, peer_type=peers.SIGNAL_SAVER):
        super(SignalSaver, self).__init__(addresses=addresses,
                                          type=peer_type)
        self._session_is_active = False

        # A method fired ever time we get new samples
        # We need to do something when got first sample
        # so for efficency reasons we do that kind of python hack...
        # self._data_received is again changed im method
        # self._first_sample_data_received
        self._data_received = self._first_sample_data_received

        # Needed slots
        self._number_of_samples = 0
        self._first_sample_timestamp = -1.0
        self._init_saving_session()
        self.debug_on = int(self.config.get_param('debug_on'))
        if self.debug_on:
            from obci.utils import streaming_debug
            self.debug = streaming_debug.Debug(int(self.config.get_param('sampling_rate')), 
                                               self.logger,
                                               self._samples_per_packet
                                               )

        self.ready()
        self._session_is_active = True
예제 #2
0
    def __init__(self, addresses):
        super(SignalReceiver, self).__init__(addresses=addresses,
                                          type=peers.SIGNAL_STREAMER)
        if DEBUG:
            self.debug = streaming_debug.Debug(
                int(self.config.get_param('sampling_rate')),
                self.logger,
                int(self.config.get_param('samples_per_packet')))

        amp_saw = self.config.get_param('amp_saw')
        driver_saw = self.config.get_param('driver_saw')
        active_channels = self.config.get_param('active_channels').split(';')
        self.driver_saw_ind = -1
        self.amp_saw_ind = -1
        self.driver_saw_max = float(self.config.get_param('driver_saw_max'))
        self.amp_saw_max = float(self.config.get_param('amp_saw_max'))
        self.driver_saw_step = float(self.config.get_param('driver_saw_step'))
        self.amp_saw_step = float(self.config.get_param('amp_saw_step'))
        self._amp_saw_last = 0.0
        self._driver_saw_last = 0.0
        try:
            self.driver_saw_ind = active_channels.index(driver_saw)
        except:
            self.logger.info("NO driver saw!")
        try:
            self.amp_saw_ind = active_channels.index(amp_saw)
        except:
            self.logger.info("NO amp saw!")            

        self.ready()
예제 #3
0
 def _manage_params(self):
     super(PyAmplifierSoft, self)._manage_params()
     self._next_msg = None
     self._prev_ts = 0.0
     self._first_sample_ts = 0.0
     self.sleep_time =(1.0/float(self.get_param('sampling_rate')))*self.samples_per_packet
     self.debug = streaming_debug.Debug(int(self.config.get_param('sampling_rate')), 
                                        self.logger,
                                        self.samples_per_packet)
예제 #4
0
    def __init__(self, addresses):
        #Create a helper object to get configuration from the system
        super(BCIP300Fda, self).__init__(addresses=addresses,
                                          type=peers.P300_ANALYSIS)
        #get stats from file
        cfg = self._get_csp_config()
        cfg['pPercent'] = float(self.config.get_param('analysis_treshold'))
        cfg['nMin'] = int(self.config.get_param("n_min"))
        cfg['nMax'] = int(self.config.get_param("n_max"))
        cfg['nLast'] = int(self.config.get_param("n_last"))
        
        cfg['debug_flag'] = int(self.config.get_param('debug_flag'))

        cfg['row'] = int(self.config.get_param('row_count'))
        cfg['col'] = int(self.config.get_param('col_count'))
        row, col = cfg['row'], cfg['col']
        #~ row = cfg['row_count'] = 6
        #~ col = cfg['col_count'] = 6
      
        print "\n"*5
        self.logger.info("COL = " + str(col) + "\n" + "ROW = " +str(row) )
        print "\n"*5

        
        montage_matrix = self._get_montage_matrix(cfg)
            
        #dec_count = int(self.config.get_param('dec_count'))

        #Create analysis object to analyse data 
        self.analysis = self._get_analysis(self.send_decision, cfg, montage_matrix)

        #Initialise round buffer that will supply analysis with data
        #See auto_ring_buffer documentation
        sampling = int(self.config.get_param('sampling_rate'))
        channels_count = len(self.config.get_param('channel_names').split(';'))
        self.buffer = auto_blink_buffer.AutoBlinkBuffer(
            from_blink=0,
            samples_count=int(float(cfg['buffer'])),
            sampling=sampling,
            num_of_channels=channels_count,
            ret_func=self.analysis.analyse,
            ret_format=self.config.get_param('buffer_ret_format'),
            copy_on_ret=int(self.config.get_param('buffer_copy_on_ret'))
            )
        
        self.hold_after_dec = float(self.config.get_param('hold_after_dec'))
        if DEBUG:
            self.debug = streaming_debug.Debug(int(self.config.get_param('sampling_rate')),
                                               self.logger,
                                               int(self.config.get_param('samples_per_packet')))
                                                   
        self._last_dec_time = time.time() + 1 #sleep 5 first seconds..
        ugm_helper.send_start_blinking(self.conn)
        self.ready()
        self.logger.info("BCIAnalysisServer init finished!")
예제 #5
0
    def __init__(self, addresses):
        #Create a helper object to get configuration from the system
        super(BCISsvepCsp, self).__init__(addresses=addresses,
                                          type=peers.SSVEP_ANALYSIS)

        #get stats from file
        cfg = self._get_csp_config()
        montage_matrix = self._get_montage_matrix(cfg)

        freqs = [int(f) for f in cfg['freqs'].split(';')]
        str_freqs = [str(f) for f in freqs]
        self.logger.info("freqs:" + str(freqs))

        sampling = int(self.config.get_param('sampling_rate'))
        buffer = int(float(cfg['buffer']) * sampling)
        maybe_buffer = self.config.get_param('buffer_len')
        if len(maybe_buffer) > 0:
            old_buffer = buffer
            buffer = int(float(maybe_buffer) * sampling)
            self.logger.info("Overwrite buffer from csp:" + str(old_buffer) +
                             " with from config:" + str(buffer))

        #Create analysis object to analyse data
        self.analysis = self._get_analysis(self.send_decision, freqs, cfg,
                                           montage_matrix)

        #Initialise round buffer that will supply analysis with data
        #See auto_ring_buffer documentation

        channels_count = len(self.config.get_param('channel_names').split(';'))
        self.buffer = auto_ring_buffer.AutoRingBuffer(
            from_sample=buffer,
            samples_count=buffer,
            every=int(float(self.config.get_param('buffer_every')) * sampling),
            num_of_channels=channels_count,
            ret_func=self.analysis.analyse,
            ret_format=self.config.get_param('buffer_ret_format'),
            copy_on_ret=int(self.config.get_param('buffer_copy_on_ret')))

        self.hold_after_dec = float(self.config.get_param('hold_after_dec'))
        if DEBUG:
            self.debug = streaming_debug.Debug(
                int(self.config.get_param('sampling_rate')), self.logger,
                int(self.config.get_param('samples_per_packet')))
        self._last_dec_time = time.time() + 5  #sleep 5 first seconds..
        self.ready()
        appliance_helper.send_freqs(self.conn, str_freqs)
        self.logger.info("BCIAnalysisServer init finished!")
    def __init__(self, addresses):
        #Create a helper object to get configuration from the system
        super(LogicRobotFeedback2, self).__init__(addresses=addresses,
                                                  type=peers.ROBOT_FEEDBACK)

        self.ugm = ugm_config_manager.UgmConfigManager(
            self.config.get_param("ugm_config")).config_to_message()
        self.robot_image_id = int(self.config.get_param("robot_image_id"))
        self._robot = rovio.Rovio('', self.config.get_param('robot_ip'))
        self.tmp1_path = os.path.join(DEFAULT_SANDBOX_DIR,
                                      self.config.get_param('tmp_file1'))
        self.tmp2_path = os.path.join(DEFAULT_SANDBOX_DIR,
                                      self.config.get_param('tmp_file1'))
        self.paths = [self.tmp1_path, self.tmp2_path]
        self.index = 0
        self.imgpath = self.paths[self.index]
        self._last_time = time.time()
        self.is_on = int(self.config.get_param("is_on"))
        if DEBUG:
            self.debug = streaming_debug.Debug(128, self.logger, 4)
        self.ready()
예제 #7
0
    def __init__(self, addresses):
        #Create a helper object to get configuration from the system
        super(BCIP300Csp, self).__init__(addresses=addresses,
                                         type=peers.P300_ANALYSIS)
        #get stats from file
        cfg = self._get_csp_config()
        #~ cfg['pVal'] = float(self.config.get_param('analysis_treshold'))

        montage_matrix = self._get_montage_matrix(cfg)

        #dec_count = int(self.config.get_param('dec_count'))

        #Create analysis object to analyse data
        self.analysis = self._get_analysis(self.send_results, cfg,
                                           montage_matrix)

        #Initialise round buffer that will supply analysis with data
        #See auto_ring_buffer documentation
        sampling = int(self.config.get_param('sampling_rate'))
        channels_count = len(self.config.get_param('channel_names').split(';'))
        self.buffer = auto_blink_buffer.AutoBlinkBuffer(
            from_blink=0,
            samples_count=int(float(cfg['buffer'])),
            sampling=sampling,
            num_of_channels=channels_count,
            ret_func=self.analysis.analyse,
            ret_format=self.config.get_param('buffer_ret_format'),
            copy_on_ret=int(self.config.get_param('buffer_copy_on_ret')))

        self.hold_after_dec = float(self.config.get_param('hold_after_dec'))
        if DEBUG:
            self.debug = streaming_debug.Debug(
                int(self.config.get_param('sampling_rate')), LOGGER,
                int(self.config.get_param('samples_per_packet')))

        self._last_dec_time = time.time() + 1  #sleep 5 first seconds..
        ugm_helper.send_start_blinking(self.conn)
        self.ready()
        LOGGER.info("BCIAnalysisServer init finished!")
예제 #8
0
    def __init__(self, addresses):
        #Create a helper object to get configuration from the system
        super(BCISsvepCsp, self).__init__(addresses=addresses,
                                          type=peers.SSVEP_ANALYSIS)

        #get stats from file
        cfg = self._get_csp_config()
        montage_matrix = self._get_montage_matrix(cfg)


        freqs = [int(f) for f in cfg['freqs'].split(';')]

        dec_count = int(self.config.get_param('dec_count'))
        active_field_ids = self.config.get_param('active_field_ids')
        self.active_field_ids = [str(f) for f in active_field_ids.split(';')]
        str_freqs = [str(0)] * len(self.get_param('ugm_field_ids').split(';'))
        str_freqs[1] = str(100) #TODO fix fix fix, useful only for ssvep maze app .....
        for index1, index2 in enumerate(self.active_field_ids):
            str_freqs[int(index2)] = str(freqs[index1])

        self.str_freqs = (';').join(str_freqs)
            
        if len(freqs) != dec_count:
            raise Exception("Configuration inconsistency! logic dec_count is different from number of decisions to-be-sent from obci.analysis (len(freqs))...."+str(len(freqs))+" != "+str(dec_count))

        sampling = int(self.config.get_param('sampling_rate'))
        tmp_buf = float(cfg['buffer'])
        if tmp_buf < 2.0:
            self.logger.warning("CSP config has buf len smaller than 2.0!, precisely: "+str(tmp_buf)+" Lets make it 2.0...")
            tmp_buf = 2.0

        buffer = int(tmp_buf*sampling)
        maybe_buffer = self.config.get_param('buffer_len')
        if len(maybe_buffer) > 0:
            old_buffer = buffer
            buffer = int(float(maybe_buffer)*sampling)
            self.logger.info("Overwrite buffer from csp:"+str(old_buffer)+" with from config:"+str(buffer))

        #Create analysis object to analyse data
        self.analysis = self._get_analysis(self.send_decision, freqs, cfg, montage_matrix)

        #Initialise round buffer that will supply analysis with data
        #See auto_ring_buffer documentation

        channels_count = len(self.config.get_param('channel_names').split(';'))
        self.buffer = auto_ring_buffer.AutoRingBuffer(
            from_sample=buffer,
            samples_count=buffer,
            every=int(float(self.config.get_param('buffer_every'))*sampling),
            num_of_channels=channels_count,
            ret_func=self.analysis.analyse,
            ret_format=self.config.get_param('buffer_ret_format'),
            copy_on_ret=int(self.config.get_param('buffer_copy_on_ret'))
            )
        self.hold_after_dec = float(self.config.get_param('hold_after_dec'))
        if DEBUG:
            self.debug = streaming_debug.Debug(int(self.config.get_param('sampling_rate')),
                                               self.logger,
                                               int(self.config.get_param('samples_per_packet')))
        self._last_dec_time = time.time() + 5 #sleep 5 first seconds..
        self.ready()
        appliance_helper.send_freqs(self.conn, str_freqs)
        self.logger.info("BCIAnalysisServer init finished!")