Exemple #1
0
def present_message(msg):
    message = visual.TextStim(WIN,
                              text=messages[msg],
                              pos=[0, 0],
                              alignHoriz='center',
                              wrapWidth=40)
    message.draw()
    WIN.flip()
Exemple #2
0
def cross():
    # cross = visual.ShapeStim(WIN, vertices=((0, -0.5), (0, 0.5), (0, 0), (-0.5, 0), (0.5, 0)), lineWidth=5, closeShape=False, lineColor="white")
    cross = visual.GratingStim(WIN,
                               color="white",
                               colorSpace='rgb',
                               tex=None,
                               mask='cross',
                               size=1)
    cross.draw()
    WIN.flip()
Exemple #3
0
def chooseCard(
):  ##Opens a dialog for entering a cards number (== variablename without the "c" at the beginning).
    ser = variables.ser
    ser.reset_input_buffer()
    core.wait(0.5)
    ser.reset_input_buffer()

    print(ser)  # for testing
    ## Code for using the keypad (Arduino) ##
    while True:
        pad = ser.read()
        if pad == b"*":
            pad = ser.read(size=2)
            print("waiting")
            print(pad)
        if pad == b'#':
            print(pad)  # for testing
            pad = ser.readline().decode().rstrip()
            print(pad)  # for testing
            pad = int(pad)
            if pad in range(1, (config_experiment.NUMOFCARDS +
                                1)):  # If input is an existing card number
                print(pad)  # for testing
                card_input["card_selected"] = pad
                # pad_data.append(pad_int) # add to the end of data list
                ser.reset_input_buffer()
                break
            elif pad == 99:
                ###Showing a window to confirm aborting the experiment. This is intended as a measure against aborting the whole experiment by accident.
                cardDlg = gui.Dlg(title="Abort/Continue")
                cardDlg.addText(
                    'You are about to abort the experiment! Press OK to abort or Cancel to continue'
                )
                ok_data = cardDlg.show(
                )  # show dialog and wait for OK or Cancel
                if cardDlg.OK:
                    print('user cancelled')
                    ser.reset_input_buffer()
                    exit()
                    break
                else:
                    chooseCard()
            else:
                pass
        else:
            pass

    WIN.flip()
    event.clearEvents()
    core.wait(1)
Exemple #4
0
def circle(side):
    circleD = visual.GratingStim(WIN,
                                 color=(0, 1, 1),
                                 colorSpace='rgb',
                                 tex=None,
                                 mask='circle',
                                 size=3,
                                 pos=(0, 0))

    if side == 'right':
        circleD.color = str(variables.Mapping["ColorLeft"])
        circleD.pos = (15, 0)
    else:
        circleD.color = str(variables.Mapping["ColorRight"])
        circleD.pos = (-15, 0)

    circleD.draw()
    WIN.flip()
    core.wait(DURATION_EFFECT)
Exemple #5
0
def formTrue(wordlist):
    numQuestions = len(wordlist)
    surveyDicts = []
    i = 1
    j = i - 1

    for question in range(0, (numQuestions)):
        questionDict = {
            "index": i,
            "itemText": wordlist[j],
            "itemWidth": 0.05,
            "type": "choice",
            "responseWidth": 0.4,
            "options": ["Wahrheit", "Lüge", "Fehler", "weiß nicht mehr"],
            "ticks": [1, 2, 3, 4],
            'markerColor': [0.89, -0.35, -0.50],
            "layout": "horiz"
        }
        surveyDicts.append(questionDict)
        i += 1
        j += 1

    survey = visual.Form(WIN,
                         name='default',
                         items=surveyDicts,
                         size=(1.2, 1.0),
                         pos=(0.0, 0.0),
                         itemPadding=0.008,
                         textHeight=0.015,
                         autoLog=True)
    survey.autoDraw = True
    descript = visual.TextStim(WIN,
                               text="Bestätigen mit RECHTER TASTE",
                               pos=(0, -10))
    descript.autoDraw = True
    WIN.flip(clearBuffer=False)

    variables.io.clearEvents(device_label='all')  # Flushing the buffer.

    while True:
        WIN.flip(clearBuffer=False)
        keyboardActivity = variables.io.devices.keyboard.getKeys(
        )  # check for any keypress
        if not keyboardActivity == [] and keyboardActivity[
                0].key == 'l':  # if 'l' key pressed
            numAnswers = 0
            for question in range(0, (numQuestions)):
                if survey.getData()[question]['response'] != None:
                    numAnswers += 1
            if numAnswers == numQuestions:  # If there is an answer to every question
                answers = []
                for question in range(0, (numQuestions)):
                    answers.append(survey.getData()[question]['response'])
                break

    survey.autoDraw = False
    descript.autoDraw = False
    WIN.flip(clearBuffer=True)
    print(answers)  # For testing only
    return answers
Exemple #6
0
def show_cardimage(
    card_number, blockNumber
):  # Presenting the scan of the chosen card or a random other card
    randnum = randrange(1, 101)
    if randnum in range(
            1, ((100 - config_experiment.PERCENTAGECORRECTCARD[
                (config_experiment.block_max - blockNumber)]) + 1)
    ):  # If random number (from 1 to 100) is in range defined for erroneosly showing a random cards image.
        randcard = randrange(
            1, (config_experiment.NUMOFIMAGES +
                1))  # choosing a random card within the range of images
        image_number = randcard
    else:
        image_number = card_number  # show the card actually chosen

    ## presenting the card ##
    card_image = Cards[image_number]['path']
    img = visual.ImageStim(
        WIN, image=card_image,
        size=(12, 23))  # All images of cards are roughly 1200 x 1800 pixel
    img.draw(WIN)
    WIN.flip()
    return image_number
Exemple #7
0
def noButtonTrial(word, delayEffectLeft, delayEffectRight):
    ## setting variables to their initial values
    tooEarly = False
    inTime = False
    tooLate = False
    key = ""
    timestamp_reaction = 0  # to make sure the value from the last trial is not carried over if no reaction in this one
    timestamp_effect = 0  # to make sure the value from the last trial is not carried over if no reaction in this one
    button_pressed = False
    durationFixation = random.uniform(
        *config_experiment.DURATION_SPAN_FIXATION
    )  # Determining the random fixation period, within the predifined span

    ##Presenting the fixation cross
    present_message("blackscreen")  # Blackscreen
    core.wait(config_experiment.DELAY_INITIAL)
    variables.io.clearEvents(device_label='all')  #Flushing the buffer.
    tk.sendMessage('Fixation_Onset')
    effects.cross()  # Displaying a fixation cross
    variables.timer.reset(newT=0.0)
    timestampFixation = variables.timer.getTime()

    keyInput = []
    while True:
        #i = i + 1  # for testing only
        keyboardActivity = variables.io.devices.keyboard.getKeys()
        if keyboardActivity != []:
            keyInput = keyboardActivity[0].key

        if keyInput in ['s', 'l'] and variables.timer.getTime() < (
                timestampFixation + durationFixation):
            tk.sendMessage('tooEarly_Onset')
            WIN.flip()
            event.clearEvents()
            present_message("early")  # "Too early"
            tooEarly = True
            core.wait(config_experiment.DURATION_MESSAGE_TOOEARLY)
            tk.sendMessage('tooEarly_Offset')
            #print(i)  # For testing only
            break

        if variables.timer.getTime() > (timestampFixation +
                                        durationFixation):  # q.empty():
            event.clearEvents()
            #print(i)  # For testing only
            tk.sendMessage('Fixation_Offset')
            break

    if not tooEarly:
        target = visual.TextStim(
            WIN, text=word, pos=[0, 0],
            alignHoriz='center')  # stimulus (i.e. the word)
        target.draw()
        variables.io.clearEvents(device_label='all')  # Flushing the buffer.
        core.wait(config_experiment.DELAY_TARGET)
        #q.queue.clear()  # flushing the queue
        variables.timer.reset(newT=0.0)
        print(word)  # for testing only
        timestamp_target = variables.timer.getTime()
        tk.sendMessage('%d TargetOnset' % timestamp_target)
        WIN.flip()  # display the stimulus
        screenRefreshed = False
        #i = 0  # for testing only

        keyInput = []
        while True:
            #i = i + 1  # for testing only
            keyboardActivity = variables.io.devices.keyboard.getKeys()
            if keyboardActivity != []:
                keyInput = keyboardActivity[0].key

            if screenRefreshed == False and variables.timer.getTime() > (
                    timestamp_target + config_experiment.DURATION_TARGET
            ):  # q.empty():  # Value to be adjusted for final experiment
                screenRefreshed = True
                WIN.flip()
                tk.sendMessage('Target_Offset')
                event.clearEvents()
                #print(i)  # For testing only
                pass

            if keyInput in ['s', 'l']:  # If any button is pressed
                print("button pressed")  # For testing
                button_pressed = True
                timestamp_reaction = variables.timer.getTime()
                tk.sendMessage('Reaction')
                ##If the reaction is so early that no target-specific reaction can be assumed -> "Too early"
                if keyInput == 's':
                    key = 'l'
                    core.wait(delayEffectLeft)
                if keyInput == 'l':
                    key = 'r'
                    core.wait(delayEffectRight)
                #WIN.flip()
                timestamp_effect = variables.timer.getTime()
                tk.sendMessage('Effect_Onset')
                effects.reaction(key)
                tk.sendMessage('Effect_Offset')
                inTime = True

                print(key)  # For testing
                #print(i)  # For testing only
                inTime = True
                break

            ##If there is no response within the given timeframe -> "Too late"
            if variables.timer.getTime() > (
                    timestamp_target + config_experiment.TIME_TOOLATE
            ):  #and not button_pressed:  # q.empty():
                event.clearEvents()
                present_message("late")  # "Too late"
                tk.sendMessage('tooLate_Onset')
                tooLate = True
                core.wait(config_experiment.DURATION_MESSAGE_TOOLATE)
                tk.sendMessage('tooLate_Offset')
                #print(i)  # For testing only
                break

        ### writing the data of the trial into the data dictionary ###
        trial_data = {
            "Stimulus": word,
            "Response": key,
            "RTTime": round((timestamp_reaction - timestamp_target), 4),
            "ActionEffectOnsetTime": round(timestamp_effect, 4),
            "TooEarly": tooEarly,
            "TooLate": tooLate,
            "InTime": inTime,
            "DurationFixation": durationFixation
        }

    else:  # If tooEarly == True
        ### writing the data of the trial into the data dictionary ###
        trial_data = {
            "Stimulus": word,
            "Response": key,
            "RTTime": "none",
            "ActionEffectOnsetTime": "none",
            "TooEarly": tooEarly,
            "TooLate": tooLate,
            "InTime": inTime,
            "DurationFixation": durationFixation
        }

    return trial_data
Exemple #8
0
def main():
    ###################Experiment starting sequence###########################
    tk.sendMessage('%d ITIoffset' % 0)

    ## Initializing serial connection to Arduino ##
    initSer()  ## stored in variables.ser
    print(variables.ser)  # For testing

    ## Basic info dialog, defining participants number, dominant eye & hand, basic demografics ##
    expInfo = variables.infoBuffer
    print(expInfo, file=behaviour)

    ## Initializing Eyetracker ##
    dataFileName = initTk(
        expInfo
    )  # inits the eyetracker and returns the name of the eyetracker-data file

    ## Initializing randomization of response keys and effect colors ##
    initMapping(
    )  # Randomized assignment of effect colors and key for yes/no (stored in variables.RandomMapping)
    print(variables.Mapping)  # For testing
    print("variable mapping defined")  # For testing

    ################################# Experiment ###########################################

    if not dummyMode:
        print("tracker setup started")
        tk.doTrackerSetup()
    print("tracker setup done")  # for testing

    #######Wellcoming message#######
    present_message("welcome")
    core.wait(0.5)
    waitForKey(variables.ser)
    #variables.ser.reset_input_buffer()

    present_message("welcome_2")
    core.wait(0.5)
    waitForKey(variables.ser)
    #variables.ser.reset_input_buffer()

    present_message("welcome_3")
    core.wait(0.5)
    waitForKey(variables.ser)
    #variables.ser.reset_input_buffer()

    present_message("welcome_4")
    core.wait(0.5)
    waitForKey(variables.ser)
    #variables.ser.reset_input_buffer()

    ######

    ##Explanations of what to do
    present_message("explanation_initial_general")
    core.wait(0.5)
    waitForKey(variables.ser)
    #variables.ser.reset_input_buffer()

    if variables.Mapping["KeyYes"] == 'r':
        present_message("explanation_initial_yes_right")
    else:
        present_message("explanation_initial_yes_left")
    core.wait(0.5)
    waitForKey(variables.ser)
    #variables.ser.reset_input_buffer()

    ##important
    present_message("explanation_initial_important")
    core.wait(0.5)
    waitForKey(variables.ser)
    #variables.ser.reset_input_buffer()

    ##Explanations of what to do
    present_message("explanation_initial_procedure")
    core.wait(0.5)
    waitForKey(variables.ser)
    #variables.ser.reset_input_buffer()

    ##Explanations of what to do
    present_message("explanation_initial_procedure_2")
    core.wait(0.5)
    waitForKey(variables.ser)
    #variables.ser.reset_input_buffer()

    ######

    ###### Practice #####
    ##First some questions for practice
    present_message("practice")
    waitForKey(variables.ser)
    variables.ser.reset_input_buffer()

    ################ Block Structure ################
    ## Setting up a block-counter and a loop of 10 blocks ##
    block_number = 1
    while block_number <= block_max:  # Set block_max in the config_experiment file in order to run more or less blocks
        if block_number == 0:
            practice = True
        else:
            practice = False

        ## Choosing a (new) card and running a block ##
        if practice:
            present_message(
                "practice_ready"
            )  # "Please advice the researcher when you are ready"
        else:
            present_message(
                "choose_ready"
            )  # "Choose a new card and advice the researcher when you are ready"
        core.wait(0.5)
        waitForKey(variables.ser)
        variables.ser.reset_input_buffer()

        ## Presenting a message about some initialization
        present_message("initialization")
        chooseCard(
        )  # At this point the researcher gives input on the chosen card via the Arduino's numpad

        block(expInfo, practice, block_number)  # Runs a block of 10 trials

        if practice:
            present_message("practice_finished")
            core.wait(0.5)
            waitForKey(variables.ser)
            #variables.ser.reset_input_buffer()

        block_number += 1  # raises the block_number after each block by one

    ## Receiving data from the eyetracker (if not in dummy mode) ##
    if not dummyMode:
        receiveData(dataFileName)
    else:
        print(
            "No eyetracker data received because you are running the experiment in dummy mode"
        )

    ################  Thank you message and end sequence  ################
    present_message("thanks")
    core.wait(0.5)
    waitForKey(variables.ser)
    event.clearEvents()
    print("experiment completed", file=behaviour)
    #############################################################################

    # make sure everything is closed down
    behaviour.close()
    tk.close()
    variables.ser.close()
    WIN.close()
    core.quit()
Exemple #9
0
def reaction(key):
    if key == 'r':
        circle(side='right')
    elif key == 'l':
        circle(side='left')
    WIN.flip()