Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

timing of responses

edited November 2016 in OpenSesame

I have got this code.
Participants give two simultaneous reactions ("f" and "-") to one stimulus.
The script goes on with only one of both reactions ("-").
Both reactions are logged.

kb = keyboard(keylist = ['f','g','h','j','<','-','d','k'])
Break = canvas()
Break.text('')
A = canvas()
A.text('A')
B = canvas()
B.text('B')
seq = [A,B]*5 
seq.reverse() #pop wählt von hinten aus
var.T_Resp=[]
var.T_Resp2=[]
var.Resp=[]
var.Resp2=[]
var.Stim=[]
var.T_Stim=[]
last=None
last2=None
t =seq[-1].show()
var.T_Stim.append(t)
if seq[-1] == A:
    var.Stim.append('A')
else:
    var.Stim.append('B')
print var.Stim, t
seq.pop() #pops out the last
while True:
    if (len(seq)!=0):
        key, time = kb.get_key(timeout=0)
        if key == 'f':
            var.T_Resp2.append(time)
            var.Resp2.append(key)
            print key, time
            kb.flush()    
        elif key == '-':
            print key, time
            var.T_Resp.append(time)
            var.Resp.append(key)
            t = seq[-1].show()
            var.T_Stim.append(t)
            if seq[-1] == A:
                var.Stim.append('A')
            else:
                var.Stim.append('B')
            print var.Stim, t
            seq.pop()
    if (len(seq)==0): #Last presses
        key, time = kb.get_key(timeout=0)
        if key == 'f':
            var.T_Resp2.append(time)
            var.Resp2.append(key)
            print key, time
            if (time-t)>200:
                last2=time
            kb.flush() 
        elif key == '-':
            print key, time
            var.T_Resp.append(time)
            var.Resp.append(key)
            last=time
        elif last>0 and last2>0:
            print "Break", var.T_Resp, var.T_Resp2
            break
        elif last2==None and len(var.Resp)>9 :
            print "Break", var.T_Resp, var.T_Resp2
            break

    #log.write_vars() #NOT POSSIBLE: slows down the whole loop

for i in range(len(var.Stim)):
    var.Stim1=var.Stim[i]
    var.T_Stim1=var.T_Stim[i]
    log.write_vars()
    print var.Stim1, var.T_Stim1

for i in range(len(var.Resp)):
    var.Resp1=var.Resp[i]
    var.T_Resp1=var.T_Resp[i]
    log.write_vars()
    print var.Resp1, var.T_Resp1

for i in range(len(var.Resp2)):
    var.Resp2_1=var.Resp2[i]
    var.T_Resp2_1=var.T_Resp2[i]
    log.write_vars()
    print var.Resp2_1, var.T_Resp2_1

print "Resp", len(var.Resp), "Resp2", len(var.Resp2)

for i in range(len(var.T_Resp)):
    print "IOI", var.T_Resp[i]-var.T_Resp2[i]

Now my questions:
1) Sometimes the "f" key is not logged. Probably when it is really simultaneous.
What can i do against that?
2) The inter onset intervals (IOIs) are strange. Certain numbers occur about random. And there is nothing in between.
On my laptop i only get -40ms, -20ms, 20ms and 40ms.
On my computer i mostly get -29ms, -2ms, 2ms, 29ms.
Any suggestions how to get the real IOIs in miliseconds?

Comments

  • Hi,

    This script took me a while to wrap my head around.

    But I think I got it now, at least well enough to answer your questions:

    1) Sometimes the "f" key is not logged. Probably when it is really simultaneous. What can i do against that?

    You're flushing the key buffer (kb.flush()) after collecting a response. There's no need to do that, and in the unlikely event that another key was pressed just before flushing (so indeed if two keystrokes were almost simultaneous), you lose the key. So just removing kb.flush() should do the trick.

    2) The inter onset intervals (IOIs) are strange. Certain numbers occur about random. And there is nothing in between.

    You're seeing the refresh rate of the monitor. You're showing things on the screen, and the computer needs to wait until the start of the next refresh cycle before it can do this. For more information:

    That's what causes the periodicity in your RTs, with the exact values depending (mainly) on the refresh rate. There's nothing you can do about this, at least nothing that it's practically feasible.

    Cheers,
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • Hi Sebastiaan,

    many thanks for your answer on a 2nd Sunday of Advent!
    This script is just a simplified version of my actual script ;)

    The second part is not really satisfactory.
    a) I wonder whether it is only the refresh rate? When the 'f' key is pressed first, there is no stimulus presented. Does the while loop really need 2ms to go into the next round?

    b) Just an idea for future releases:
    I am not an expert in programming, but as a user it would be nice to have an optional button in the main parts of open sesame to select independent loggers of the keyboard/mouse/parallel port (maybe like this http://www.tandfonline.com/doi/abs/10.1080/00140130412331290871) that logs any keypress/mouse click during the experiment. So that it is independent from the script and the refresh rate of the monitor. May that is how it works in presentation? (When i used presentation i did not have this problem for IOIs at least.)

    Greetz
    Stephan

  • many thanks for your answer on a 2nd Sunday of Advent!

    This may be my atheist background showing through, but I actually had to look that up. It was also pakjesavond though.

    a) I wonder whether it is only the refresh rate? When the 'f' key is pressed first, there is no stimulus presented. Does the while loop really need 2ms to go into the next round?

    Possibly, yes. But it may also be related to the keyboard. Keyboards also poll periodically, although typically faster than the refresh cycle of the monitor. In particular, I'm not sure how a keyboard deals with two keys that are pressed simultaneously (@Jarik?).

    My recommendation would be:

    • Simplify the structure of the loop so that it's easier to understand (also for you and your future self) and doesn't do unnecessary things
    • Make sure that the logic works in all cases, also when participants press the same key multiple times in a row (even if they're not supposed to)
    • Use the legacy backend so that you don't have a blocking flip (i.e. the experiment doesn't pause when showing a canvas, at the expense of slightly less accurate display timestamps)

    For example, if I understand correctly what you want to do, then something based on the following logic may be more straightforward:

    N_RESPONSE = 10
    
    # Create a tuple of canvas objects that will be shown in alternation
    c1 = canvas()
    c1.text('A')
    c2 = canvas()
    c2.text('B')
    c_tuple = c1, c2
    
    kb = keyboard()
    
    c1.show()
    for i in range(N_RESPONSE): 
        key, time = kb.get_key()
        if key == 'f':
            # Do stuff
            # ...
            continue
        if key == '-':
            # Do stuff
            # ...
            # Flip the canvas order around and show the canvas that now comes first
            c_tuple = c_tuple[1], c_tuple[0]
            c_tuple[0].show()
    

    I am not an expert in programming, but as a user it would be nice to have an optional button in the main parts of open sesame to select independent loggers of the keyboard/mouse/parallel port (maybe like this http://www.tandfonline.com/doi/abs/10.1080/00140130412331290871) that logs any keypress/mouse click during the experiment.

    That kind of event-loop system indeed has its advantages. It's something that occasionally comes up, but for now it doesn't fit the way that OpenSesame is structured. We do have coroutines that allow you to do things in parallel, though. But I don't think it's a solution for your particular case.

    What are you trying to investigate, if I may ask? Whether participants implicitly associate the appearance of the display with one of the two keys?

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • Possibly, yes. But it may also be related to the keyboard. Keyboards also poll periodically, although typically faster than the refresh cycle of the monitor. In particular, I'm not sure how a keyboard deals with two keys that are pressed simultaneously (@Jarik?).

    I also don't know, but would consider using some buttonbox (like srbox) when you are into high precision timing, multi key presses and measuring key releases.

    Best,
    Jarik

  • @sebastiaan: >What are you trying to investigate, if I may ask?

    On your question:
    I want to implement a serial reaction time (SRT) task in mental practice (MP).
    Hence in the MP group participants press shift when they imagine to press the target buttons. This is needed in order to have RTs and to keep the programm going with individual pace.
    In physical practice (PP) it should be as similar as possible. Hence participants press the target and shift simultaneously. Presentation of the stimuli only depends on Shifts as in MP.

    I now refused from assessing the targets in PP as it seems to complicated. My students need to start data collection and I have lost already one month on that issue.

  • There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • Do I understand correctly, that in the PP group, the pressing of the shift key has no effect, but is only required to have the make the groups more comparable? In this case, you could exclude the key from the keyboard, so that pressing it would not have an effect on your actual responses. Of course this has the downside, that you can't really control whether participants actually did press it.

  • Thanks for your motivation boys! :p
    @eduard : That's exactly what i do now. However, as you said there is data missing.

    sunny greetings from the snow-covered Alps

Sign In or Register to comment.