def get_board_info(board_type='synthetic', connection='usb', usb_port=None): """ Gets the BarinFlow ID for the respective OpenBCI board in use Parameters: board_type (str): Type of base OpenBCI board (options: synthetic, cyton, daisy) connection (str): Connection method, either via USB dongle or the Wifi board Returns: board_id (int): Id value for the board in the BrainFlow API """ params = BrainFlowInputParams() if usb_port is None: usb_port = STD_PORT if board_type == 'synthetic': board_id = BoardIds.SYNTHETIC_BOARD.value elif board_type == 'cyton': if connection == 'usb': board_id = BoardIds.CYTON_BOARD.value params.serial_port = usb_port elif connection == 'wifi': board_id = BoardIds.CYTON_WIFI_BOARD.value elif board_type == 'daisy': if connection == 'usb': board_id = BoardIds.CYTON_DAISY_BOARD.value params.serial_port = usb_port elif connection == 'wifi': board_id = BoardIds.CYTON_DAISY_WIFI_BOARD.value return board_id, params
def __init__(self, board_id=BoardIds.CYTON_DAISY_BOARD.value, ip_port=6677, serial_port="COM3"): # Board params self.board_id = board_id self.params = BrainFlowInputParams() self.params.ip_port = ip_port self.params.serial_port = serial_port self.board = BoardShim(board_id, self.params) self.sfreq = self.board.get_sampling_rate(board_id) self.marker_row = self.board.get_marker_channel(self.board_id) self.eeg_names = self.board.get_eeg_names(board_id) # Features params # todo: get as arg self.features_params = {'channels': ['C03', 'C04']}
def run(self): # 线程执行函数 params = BrainFlowInputParams() board_id = self.board_set[0] self.c_value = [] params.serial_port = self.board_set[1] self.board = BoardShim(board_id, params) # 在线数据 #一导联数据和量导联数据 self.board.prepare_session() self.board.start_stream() time.sleep(3) n = 0 m = np.zeros(2) while self.is_on: time.sleep(1) data = self.board.get_current_board_data(self.board_set[3]) data = data[1:9] mean_data = np.tile( data.mean(axis=1).reshape(8, 1), (1, self.board_set[3])) # print(data.shape) data = data - mean_data if self.puanduan1: self.org_signal.emit(data) filter1_data = self.processing_step1.step_1_list[ self.pre_set[0][0]](data, self.pre_set[0]) filter2_data = self.processing_step2.step_2_list[ self.pre_set[1][0]](filter1_data, self.pre_set[1]) if self.puanduan2: # print(self.pre_set) self.pre_signal.emit(filter2_data) feature_data = self.feature.feature_list[self.class_set[0]]( filter2_data, self.class_set) # print(np.argmax(feature_data)) if self.puanduan3: self.feature_signal.emit(feature_data) # print(feature_data) result = np.argmax(feature_data) r = feature_data[result] # 更改部分(将程序中2s读取一次改为1s读取一次,每次512采样点改为256采样点) if result == 5: r = r + 0.1 elif result == 6: r = r + 0.05 if r > 0.5: n = n + 1 p = result + 1 print("分类结果:", p, " n = ", n) m = np.append(m, p) m = m[1:] if m[0] == m[1]: m[1] = 0 else: b = str(p) self.command_signal.emit(b) print("发送指令:", p)