コード例 #1
0
ファイル: ssvep_15.py プロジェクト: luluqie/SSVEP-2
def ssvep_one():

    rospy.init_node('ssvep_15', anonymous=True)
    pub = rospy.Publisher('chatter_15', BCIuVolts, queue_size=1)
    while not rospy.is_shutdown():
        stimuli6 = SSVEP(frame_on=2,
                         frame_off=2,
                         fname=filename,
                         port=port_addr,
                         trialdur=flash_dur,
                         numtrials=trialnums,
                         waitdur=waitduration,
                         mywin=(1400, 200))
        stimuli6.start()
コード例 #2
0
ファイル: run_ssvep.py プロジェクト: jnaulty/SSVEP_OpenBCI
expinfos = InputBox()
filename = expinfos.file()
print expinfos.port_name()
port_addr = expinfos.port_name()
print filename
flash_dur = expinfos.stim_duration()
trialnums = expinfos.stim_trials()
waitduration = expinfos.waitduration()
print port_addr
print type(port_addr)


#set of stimuli followed by frequency of stimuli. 

"""
stimuli75 = SSVEP(frame_on=4, frame_off=4, fname=filename, port=port_addr, trialdur=flash_dur, numtrials=trialnums, waitdur=waitduration)
stimuli75.start()
print 1
"""
"""
stimuli12=SSVEP(frame_on=3, frame_off=2, fname=filename, port=port_addr,
	trialdur=flash_dur, numtrials=trialnums, waitdur=waitduration)
stimuli12.start()
print 2
"""
stimuli20=SSVEP(frame_on=2, frame_off=1, fname=filename, port=port_addr,
	trialdur=flash_dur, numtrials=trialnums, waitdur=waitduration)
stimuli20.start()

コード例 #3
0
ファイル: Receiver.py プロジェクト: YashviGulati/BrainNet
def run_main_logic(ref_list, bgm, ard, logger, fs, eeg, out_buffer_queue,
                   tms, tms_low, tms_high):
    """
    Runs main logic of the game
    """
    bgm.show_crosshair()
    # Wait until the other computers have started
    start_connection()

    # log header
    head_dict = {'Computer_type': COMPUTER_TYPE, 'sender_or_receiver': 'receiver', 'tms_low_intensity': tms_low, 'tms_high_intensity': tms_high, 'Experiment_Date': "{:%B %d, %Y}".format(datetime.datetime.now()), 'start_time': time.time()}
    logger.info(str(head_dict))

    # Count the number of trials we iterate over.
    for trial_index, control_txt in enumerate(ref_list):
        # Clear our feedback
        bgm.graphics.set_text_dictionary_list([])
        # Create a Trial dictionary for recording events in this trial
        trial_dict = {'trial_index': trial_index, 'control_trial': control_txt}
        # Set whether this is a control or experimental trial
        assert control_txt in (Constants.CONTROL_STR, Constants.EXPERIMENTAL_STR)
        # generate new board
        bgm.new_board(control=(control_txt == Constants.CONTROL_STR))
        round_info = dict()
        # for round_index in [1, 2]:  # Round_index = 1 if we are first starting, 2 if we are on the second pass.
        for round_index in range(Constants.NUM_ROUNDS):

            # show just the piece
            bgm.hide_bottom()
            bgm.show_block_game()

            # get current board string and send to Senders
            board_str = bgm.board_to_string()
            send_message_to_other_computers(message=board_str)

            # log data for this round
            round_info.clear()
            round_info['round_index'] = round_index
            round_info['initial_board_str'] = board_str
            round_info['C1_and_C2_start_message_sent_time'] = time.time()

            # let subject know we're going to wait
            pos = (None, None) if round_index == 0 else (None, 100)
            bgm.graphics.set_text_dictionary_list({'text': 'Waiting on Senders', 'pos': pos,
                                                   'color': (255, 255, 255)})

            # wait for Senders to make their selections
            c1_message, c2_message = wait_for_trial_results()

            # log data
            round_info['C1_and_C2_command_receive_time'] = time.time()
            round_info['C1_command'] = c1_message
            round_info['C2_command'] = c2_message

            # True if Sender says to rotate
            c1_rotate = (c1_message == Messages.ROTATE)
            c2_rotate = (c2_message == Messages.ROTATE)

            # Fire the TMS to transmit the Sender information to the Receiver
            fire_times = fire_twice(c1_rotate, c2_rotate, bgm, tms, tms_high, tms_low, round_index)

            # log data
            round_info['fire_tms1_time'] = fire_times[0]
            round_info['fire_tms2_time'] = fire_times[1]

            # give subject time to make decision
            time.sleep(Constants.SLEEP_AFTER_TMS_FIRE_TWICE)

            # Arduino lights on and off
            if RUN_ARDUINO:
                ard.turn_both_on()
            # -----RUN SSVEP----- #
            c0_response, c0_start_data_collection_time, c0_end_data_collection_time = \
                SSVEP.trial_logic(eeg, out_buffer_queue, bgm, fs, 17, 15, 'Do you choose to turn the piece?', 1920)
            if RUN_ARDUINO:
                ard.turn_both_off()

            # update turn flag
            turn_flag = (c0_response == Messages.ROTATE)
            bgm.show_block_game()
            time.sleep(1)
            # update board here
            if turn_flag:
                bgm.rotate_piece()
            time.sleep(1)

            # log data
            round_info['c0_response'] = c0_response
            round_info['c0_start_data_collection_time'] = c0_start_data_collection_time
            round_info['c0_end_data_collection_time'] = c0_end_data_collection_time
            round_info['turn_flag'] = turn_flag
            trial_dict['round_' + str(round_index)] = round_info

            if round_index == 0:
                # drop half way
                bgm.drop_piece_halfway()

        # send final board to Senders
        send_message_to_other_computers(message=bgm.board_to_string())
        # display the dropping of the piece
        bgm.show_bottom()
        time.sleep(1)
        bgm.drop_piece()
        time.sleep(1)
        success = bgm.clear_rows()
        time.sleep(2)
        send_message_to_other_computers(message=str(success))
        # Save all our trial information.
        logger.info(str(trial_dict))
コード例 #4
0
ファイル: run_ssvep.py プロジェクト: zapp926/SSVEP_OpenBCI
expinfos = InputBox()
filename = expinfos.file()
print (expinfos.port_name())
port_addr = expinfos.port_name()
print (filename)
flash_dur = expinfos.stim_duration()
trialnums = expinfos.stim_trials()
waitduration = expinfos.waitduration()
print (port_addr)
print (type(port_addr))


#set of stimuli followed by frequency of stimuli. 

"""
stimuli75 = SSVEP(frame_on=4, frame_off=4, fname=filename, port=port_addr, trialdur=flash_dur, numtrials=trialnums, waitdur=waitduration)
stimuli75.start()
print 1
"""
"""
stimuli12=SSVEP(frame_on=3, frame_off=2, fname=filename, port=port_addr,
	trialdur=flash_dur, numtrials=trialnums, waitdur=waitduration)
stimuli12.start()
print 2
"""
stimuli20=SSVEP(frame_on=2, frame_off=1, fname=filename, port=port_addr,
	trialdur=flash_dur, numtrials=trialnums, waitdur=waitduration)
stimuli20.start()

コード例 #5
0
ファイル: Sender.py プロジェクト: YashviGulati/BrainNet
def run_main_logic(bgm, fs, eeg, high_freq, low_freq, out_buffer_queue, ard,
                   logger):
    """
    Runs main logic of the game
    """
    # -----Set up----- #
    bgm.show_crosshair()
    # Send "Ready" message
    send_msg(message=Messages.READY_TO_START)
    # Record our header for our log file
    head_dict = {
        'Computer_type': COMPUTER_TYPE,
        'sender_or_receiver': 'sender',
        'Experiment_Date': "{:%B %d, %Y}".format(datetime.datetime.now()),
        'start_time': time.time()
    }
    logger.info(str(head_dict))
    # Count the number of trials we iterate over.
    trial_index = 0

    while trial_index < Constants.NUM_EXP_TRIALS:
        # We don't need to record if this is a control trial or not.  This should be saved in the C0 log.
        trial_dict = {'trial_index': trial_index}
        turn_flag = None
        turn_times = 0
        for round_index in range(Constants.NUM_ROUNDS):
            # get board from c0
            bgm.set_board(str(get_msg()))
            bgm.show_block_game()
            bgm.graphics.update_graphics()
            # create dict to save info
            round_dict = dict()
            # Record meta information on the current round
            round_dict['round_index'] = round_index
            round_dict['initial_board_str'] = bgm.board_to_string()
            round_dict['C0_start_message_received'] = time.time()
            # wait to let subject determine their answer
            time.sleep(Constants.SLEEP_AFTER_SHOWING_BLOCK_GAME_TO_CX)
            # Get our response from the sender and send it to C0
            if RUN_ARDUINO:
                ard.turn_both_on()
            # ----------RUN SSVEP----------
            response, start_data_collection_time, end_data_collection_time = \
                SSVEP.trial_logic(eeg, out_buffer_queue, bgm, fs, high_freq, low_freq, "Turn the piece or not?", 1680,
                                  drift_correction=True)
            if RUN_ARDUINO:
                ard.turn_both_off()
            # Give our answer to receiver
            send_msg(message=response)
            # Give Feedback to the Sender
            turn_flag = response == Messages.ROTATE
            if turn_flag:
                turn_times += 1
            # update prompt
            bgm.graphics.set_text_dictionary_list({
                'text': 'Waiting for Receiver to make a decision',
                'pos': (None, 150),
                'color': (255, 255, 255)
            })
            # Store our round dictionary into our trial dictionary
            round_dict['response'] = response
            round_dict[
                'start_data_collection_time'] = start_data_collection_time
            round_dict['end_data_collection_time'] = end_data_collection_time
            round_dict['turn_flag'] = turn_flag
            trial_dict['round_' + str(round_index)] = round_dict
            # sleep for a sec
            time.sleep(Constants.SLEEP_AFTER_SHOWING_CX_FEEDBACK)

        # blocking call -- only show board after receive the new board
        board = str(get_msg())
        bgm.show_block_game()
        bgm.set_board(board)
        time.sleep(1)
        # show it
        bgm.drop_piece()
        time.sleep(1)
        bgm.clear_rows()
        time.sleep(1)
        # show feedback
        if get_msg() == 'True':
            feedback = 'You successfully cleared a line'
        else:
            feedback = 'You failed to clear a line'
        bgm.graphics.set_text_dictionary_list({
            'text': feedback,
            'pos': (None, None),
            'color': (255, 255, 255)
        })
        time.sleep(3)
        logger.info(str(trial_dict))
コード例 #6
0
        if pair[0] == 3 and pair[1] == 2:
            msg.data[0] = 3
        elif pair[0] == 2 and pair[1] == 2:
            msg.data[0] = 4
        # elif pair[0] == 3 and pair[1] == 2:
        # 	msg.data[0] = 3
        elif pair[0] == 2 and pair[1] == 1:
            msg.data[0] = 5
        #elif pair[0] == 2 and pair[1] == 1:
        #msg.data[0] = 5

        sleep(5)
        stimuli6 = SSVEP(frame_on=pair[0],
                         frame_off=pair[1],
                         fname=filename,
                         port=port_addr,
                         trialdur=flash_dur,
                         numtrials=trialnums,
                         waitdur=waitduration)
        stamp = rospy.get_rostime()
        msg.stamp = stamp
        pub.publish(msg)
        stimuli6.start()
        stamp = rospy.get_rostime()
        msg.stamp = stamp
        pub.publish(msg)

    # stimuli10=SSVEP(frame_on=3, frame_off=3, fname=filename, port=port_addr,
    # 	trialdur=flash_dur, numtrials=trialnums, waitdur=waitduration)
    # stimuli10.start()
コード例 #7
0
def run():
    if frequency_selection == 6:
        stimuli6 = SSVEP(frame_on=5,
                         frame_off=5,
                         fname=filename,
                         port=port_addr,
                         trialdur=flash_dur,
                         numtrials=trialnums,
                         waitdur=waitduration)
        stimuli6.start()
    elif frequency_selection == 7.5:
        stimuli75 = SSVEP(frame_on=4,
                          frame_off=4,
                          fname=filename,
                          port=port_addr,
                          trialdur=flash_dur,
                          numtrials=trialnums,
                          waitdur=waitduration)
        stimuli75.start()
    elif frequency_selection == 10:
        stimuli10 = SSVEP(frame_on=3,
                          frame_off=3,
                          fname=filename,
                          port=port_addr,
                          trialdur=flash_dur,
                          numtrials=trialnums,
                          waitdur=waitduration)
        stimuli10.start()
    elif frequency_selection == 12:
        stimuli12 = SSVEP(frame_on=3,
                          frame_off=2,
                          fname=filename,
                          port=port_addr,
                          trialdur=flash_dur,
                          numtrials=trialnums,
                          waitdur=waitduration)
        stimuli12.start()
    elif frequency_selection == 15:
        stimuli15 = SSVEP(frame_on=2,
                          frame_off=2,
                          fname=filename,
                          port=port_addr,
                          trialdur=flash_dur,
                          numtrials=trialnums,
                          waitdur=waitduration)
        stimuli15.start()
    elif frequency_selection == 20:
        stimuli20 = SSVEP(frame_on=2,
                          frame_off=1,
                          fname=filename,
                          port=port_addr,
                          trialdur=flash_dur,
                          numtrials=trialnums,
                          waitdur=waitduration)
        stimuli20.start()
    else:
        print 'sorry, you chose none'
コード例 #8
0
def run():
	if frequency_selection == 6:
		stimuli6 = SSVEP(frame_on=5, frame_off=5, fname=filename, port=port_addr, trialdur=flash_dur, numtrials=trialnums, waitdur=waitduration)
		stimuli6.start()
	elif frequency_selection == 7.5:
		stimuli75=SSVEP(frame_on=4, frame_off=4, fname=filename, port=port_addr,
		trialdur=flash_dur, numtrials=trialnums, waitdur=waitduration)
		stimuli75.start()
	elif frequency_selection == 10:
		stimuli10=SSVEP(frame_on=3, frame_off=3, fname=filename, port=port_addr,
		trialdur=flash_dur, numtrials=trialnums, waitdur=waitduration)
		stimuli10.start()
	elif frequency_selection == 12:
		stimuli12=SSVEP(frame_on=3, frame_off=2, fname=filename, port=port_addr,
		trialdur=flash_dur, numtrials=trialnums, waitdur=waitduration)
		stimuli12.start()
	elif frequency_selection == 15:
		stimuli15=SSVEP(frame_on=2, frame_off=2, fname=filename, port=port_addr,
		trialdur=flash_dur, numtrials=trialnums, waitdur=waitduration)
		stimuli15.start()
	elif frequency_selection == 20:
		stimuli20=SSVEP(frame_on=2, frame_off=1, fname=filename, port=port_addr,
		trialdur=flash_dur, numtrials=trialnums, waitdur=waitduration)
		stimuli20.start()
	else:
		print 'sorry, you chose none'