Howdy, Stranger!

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

Supported by

[open] Log response time of button press via serial port

edited July 2014 in OpenSesame

Hello,
we are dealing with a staircase paradigm in the fMRI scanner and we record subject's responses through a serial port. We use PySerial to set the serial port and log the responses. Responses are mostly given while the current stimuli are still being presented. After they are presented we can read the serial port. OS correctly records the response button identity, and uses it to set subsequent stimuli presentations (following the logic of our staircase). However, we are not able to log the actual time of button press. We checked PySerial documentation to see whether there is a function that logs the instant in which the serial port receives a bit ( = a subject's button press), but there is none.
Do you have any suggestion on how to approach this issues?
Thanks, Stefania and Ambra

Comments

  • edited 2:18PM

    Hi Stefania and Ambra,

    Assuming that your button box simply sends a response as soon as a press has been detected, you can just use OpenSesame's self.time() function to get the time immediately after you have collected the response, like so:

    # Your response collection code here
    response_timestamp = self.time()
    exp.set('response_timestamp', response_timestamp)
    

    This will log the timestamp of the response, not the response time relative to some other event, such as the presentation of a sketchpad. But you can deduce the response time easily, simply subtracting the timestamp of the starting event from the timestamp of the response.

    Cheers!
    Sebastiaan

  • edited 2:18PM

    Hi Sebastiaan,
    thank you for your immediate response, that we really appreciated.

    However, if the subject presses the button while the stimulus is still being presented (60 frames), the serial port receives a response during the loop. We only read the response after that loop, so this means that self.time() does not necessarily report the precise time of button press (i.e. when it occurred during the loop).

    We probably need a parallel pooling loop that reads the serial port (and uses self.time() to get the actual time of presses) inside the presentation loop. Is that correct? again, any suggestions will be very welcome.

    Thanks, Stefania and Ambra

  • edited 2:18PM

    Hi guys,

    Actually, you could do this in a serial fashion, rather than using the more complicated parallel threading approach. Place the following code in an inline_script placed directly behind the sketchpad that you use to present your stimulus, and set the duration of that sketchpad to 0.

    # get the starting time
    t0 = self.time()
    
    # determine the presentation time in milliseconds
    # (= Nframes * (1/refresh rate in Hz) * 1000 - half a frame time)
    Nframes = 60 # frames
    refrate = 60 # Hz
    frametime = (1.0 / refrate) * 1000
    prestime = int(Nframes * frametime - (frametime/2))
    
    # run until the presentation time passes or a response is made
    response = None
    while self.time() - t0 < prestime and response == None:
        # get the button response
        response = # PLACE YOUR CODE HERE
        # check if there is a response
        if response != None:
            # set the OpenSesame response variables
            exp.set('response_timestamp', t0)
            exp.set('response', response)
            # save a timestamp
            t1 = self.time()
    
    # pause for the remainder of the stimulus duration
    if response != None:
        self.sleep(prestime - (t1-t0))
    

    Does that work for you?

  • edited 2:18PM

    First of all thanks for putting out this great program! Quick question: in PsychoPy it is possible to start recording keypresses at certain frames. My experiment uses a paradigm where I need a 'beep' played at a certain frame (the first after an edit) and the participant will then press a button, the RT time of which also needs to be recorded. How do I anchor the keypress, the recording, and the sound to a certain frame?

  • edited 2:18PM

    Hi Xandra,

    My experiment uses a paradigm where I need a 'beep' played at a certain frame (the first after an edit) and the participant will then press a button, the RT time of which also needs to be recorded. How do I anchor the keypress, the recording, and the sound to a certain frame?

    That really depends on how your experiment is structured. What does your trial look like exactly and how have you implemented it at the moment?

    Cheers,
    Sebastiaan

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