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

  • 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?

  • 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.

  • 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.

    Buy Me A Coffee

  • 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.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games