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
Esempio n. 2
0
def get_board_info(board_type,
                   usb_port=None,
                   ip_addr=None,
                   ip_port=None,
                   serial_num=None):

    params = BrainFlowInputParams()

    if board_type == 'synthetic':
        board_id = BoardIds.SYNTHETIC_BOARD.value

    elif board_type == 'ganglion':
        board_id = BoardIds.GANGLION_BOARD.value
        params.serial_port = get_openbci_usb(usb_port)

    elif board_type == 'cyton':
        board_id = BoardIds.CYTON_BOARD.value
        params.serial_port = get_openbci_usb(usb_port)

    elif board_type == 'cyton_daisy':
        board_id = BoardIds.CYTON_DAISY_BOARD.value
        params.serial_port = get_openbci_usb(usb_port)

    elif board_type == 'ganglion_wifi':
        board_id = BoardIds.GANGLION_WIFI_BOARD.value
        params.ip_address, params.ip_port = get_openbci_ip(ip_addr, ip_port)

    elif board_type == 'cyton_wifi':
        board_id = BoardIds.CYTON_WIFI_BOARD.value
        params.ip_address, params.ip_port = get_openbci_ip(ip_addr, ip_port)

    elif board_type == 'cyton_daisy_wifi':
        board_id = BoardIds.CYTON_DAISY_WIFI_BOARD.value
        params.ip_address, params.ip_port = get_openbci_ip(ip_addr, ip_port)

    elif board_type == 'brainbit':
        board_id = BoardIds.BRAINBIT_BOARD.value
        if serial_num:
            params.other_info = serial_num

    elif board_type == 'unicorn':
        board_id = BoardIds.UNICORN_BOARD.value
        if serial_num:
            params.other_info = serial_num

    return board_id, params
Esempio n. 3
0
#############################################################

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--serial-port', type=str, help='serial port',
                        required=False, default='/dev/ttyUSB0')

    # if you are on Linux remember to give permission to access the port:
    # sudo chmod 666 /dev/ttyUSB0
    # or change the user group
    # check BrainFlow documentation for Windows configs

    args = parser.parse_args()
    params = BrainFlowInputParams()
    params.serial_port = args.serial_port

    board = BoardShim(BoardIds.CYTON_BOARD.value, params)
    board.prepare_session()

    shared_vars = Shared()
    mutex = threading.Lock()

    board.start_stream()  # use this for default options

    acquisition = threading.Thread(target=acquire_signals)
    acquisition.start()
    computing = threading.Thread(target=compute_signals)
    computing.start()

    acquisition.join()
Esempio n. 4
0
    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)