def blinks_detector(quit_program, blink, blink_det, blinks_num): def detect_blinks(sample): smp = sample.channels_data[0] smp_flted = frt.filterIIR(smp, 0) #print(smp_flted) brt.blink_detect(smp_flted, -38000) # report it the new blink is spotted if brt.new_blink: if brt.blinks_num == 1: # First detected blink is in fact artifact from filter # settling. Correct blink number by subtracting 1. # First "blink" successfully detected - device is connected. connected.set() print('CONNECTED. Speller starts detecting blinks.') else: blink_det.put(brt.blinks_num) blinks_num.value = brt.blinks_num blink.value = 1 print('BLINK!') if quit_program.is_set(): print('Disconnect signal sent...') board.stop_stream() if __name__ == '__main__': # filtering in real time object creation frt = flt.FltRealTime() # blink detection in real time object creation brt = blk.BlinkRealTime() board = OpenBCIGanglion(mac=mac_adress) board.start_stream(detect_blinks)
def blinks_detector( quit_program, blink_det, blinks_num, blink, ): def detect_blinks(sample): if SYMULACJA_SYGNALU: smp_flted = sample else: smp = sample.channels_data[0] smp_flted = frt.filterIIR(smp, 0) #print(smp_flted) brt.blink_detect(smp_flted, -38000) if brt.new_blink: if brt.blinks_num == 1: #connected.set() print('CONNECTED. Speller starts detecting blinks.') else: blink_det.put(brt.blinks_num) blinks_num.value = brt.blinks_num blink.value = 1 print("sss") if quit_program.is_set(): if not SYMULACJA_SYGNALU: print('Disconnect signal sent...') board.stop_stream() #################################################### SYMULACJA_SYGNALU = False #################################################### mac_adress = 'e5:32:b4:53:55:ba' #################################################### clock = pg.time.Clock() frt = flt.FltRealTime() brt = blk.BlinkRealTime() if SYMULACJA_SYGNALU: df = pd.read_csv('dane_do_symulacji/data.csv') for sample in df['signal']: if quit_program.is_set(): break detect_blinks(sample) clock.tick(200) print('KONIEC SYGNAŁU') quit_program.set() else: board = OpenBCIGanglion(mac=mac_adress) board.start_stream(detect_blinks)
def benchmark_ganglion(mac: str, runs: int, run_duration: float) -> np.ndarray: sampling_rates = [] board = OpenBCIGanglion(mac=mac) total_recv_samples = 0 total_lost_samples = 0 counter = GanglionSampleCounter(board) counter.start() print(f'Sleeping for 10 seconds to let receiver warm up.') time.sleep(10.0) for r in range(runs): print(f'\rExecuting run {r + 1}/{runs}...', end='', flush=True) samples_i, lost_samples_i = counter.sample_count t_i = time.time() time.sleep(run_duration) delta_t = time.time() - t_i samples, lost_samples = counter.sample_count delta_cnt = samples - samples_i total_recv_samples += delta_cnt total_lost_samples += lost_samples - lost_samples_i sampling_rates.append(delta_cnt / delta_t) sampling_rates = np.array(sampling_rates) _, minmax, mean, var, _, _, = scipy.stats.describe(sampling_rates) counter.stop() board.disconnect() print(f''' ... Sampling rate benchmark results for OpenBCI Ganglion ... Measured sampling rates over ~{run_duration:.2f}s intervals: Mean: {mean} Hz Min: {minmax[0]} Hz Max: {minmax[1]} Hz Variance: {var} Hz Total received samples: {total_recv_samples} Total lost samples: {total_lost_samples} Loss rate: {(total_lost_samples / (total_recv_samples + total_lost_samples)) * 100.0}% ''') return sampling_rates
def main(): print("Connecting...") board = OpenBCIGanglion(mac='ff:ce:cf:9f:7d:74') print("Connected!") t = Thread(target=board.start_stream, args=(reader, ), daemon=True) t.start() while True: plot() sleep(0.01)
print("Creating LSL stream for EEG. \nName: OpenBCIEEG\nID: OpenBCItestEEG\n") info_eeg = StreamInfo('OpenBCIEEG', 'EEG', 4, 250, 'float32', 'OpenBCItestEEG') print("Creating LSL stream for AUX. \nName: OpenBCIAUX\nID: OpenBCItestEEG\n") info_aux = StreamInfo('OpenBCIAUX', 'AUX', 3, 250, 'float32', 'OpenBCItestAUX') outlet_eeg = StreamOutlet(info_eeg) outlet_aux = StreamOutlet(info_aux) info = StreamInfo('MyMarkerStream', 'Markers', 1, 0, 'string', 'myuidw43536') # next make an outlet outlet = StreamOutlet(info) markernames = ['Marker', 'Marker', 'Marker', 'Marker', 'Marker', 'Marker'] def lsl_streamers(sample): outlet_eeg.push_sample(np.array(sample.channels_data) * SCALE_FACTOR_EEG) outlet.push_sample([random.choice(markernames)]) print(np.array(sample.channels_data) * SCALE_FACTOR_EEG) # outlet_aux.push_sample(np.array(sample.aux_data)*SCALE_FACTOR_AUX) board = OpenBCIGanglion(mac='E0:40:DA:FF:A2:F7') board.start_stream(lsl_streamers) # myResol = ContinuousResolver() # print(myResol.results)
def print_raw(sample): print(sample.channels_data) callback = eval(args.fun) if args.board not in ['Cyton', 'CytonDaisy', 'Ganglion', 'Wifi']: sys.exit( 'No Board Selected. You should use Cyton, CytonDaisy, Ganglion, or Wifi. Try: python openbci_interface.py --board Cyton' ) elif args.board == 'Cyton': board = OpenBCICyton(port=args.port) elif args.boad == 'CytonDaisy': board = OpenBCICyton(port=args.port, daisy=True) elif args.board == 'Ganglion': if sys.platform.startswith("linux"): board = OpenBCIGanglion(mac=args.port) else: sys.exit( 'Currently the Ganglion Python repo only works with Linux OS.') else: board = OpenBCIWiFi() valid_commands = '012345678!@#$%^&*qwertyuiQWERTYUI[]pdbsvnN;-=xXDzZASFGHJKLajbs?c<>' while True: command = input('--> ') if str(command).lower() in ['start', 'stream']: print('Starting Board Stream') stream_thread = threading.Thread(target=board.start_stream, args=(callback, ), daemon=True)
from pyOpenBCI import OpenBCIGanglion def print_raw(sample): print(sample.channels_data) #Set (daisy = True) to stream 16 ch board = OpenBCIGanglion(mac='E0:40:DA:FF:A2:F7') board.start_stream(print_raw)