Howdy, Stranger!

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

Supported by

[open] Mouse function- Register online pain score in the form of Visual Analogue Scale

edited November 2014 in OpenSesame

Dear expert and O.S. users,

I am new to use this software and I would like to use it to build a fMRI experiment but I am having some difficulties.

In my experiment, I want to collect continuously pain score of the participant in the form of a visual analogue scale from 0 to 100 (or at least during and after a painful stimuli). It is necessary that the participants see their rating and ideally when they press the right button of the mouse a trick meter (= a gauge) fills and when they press the left button it decreases.

It is possible to do this with opensesame ? What is the right procedure to program this in opensesame ?
Are there any particular precautions to register data in this way?

I remain at your disposal for any information needed to facilitate the resolution of this problem. Thank you so much for your help.

(Ps : I am just learning Python...)

Camille PhD Student

Comments

  • edited 12:22PM

    Hi Camille,

    You'll need a bit Python script for this, but nothing overwhelmingly difficult. Basically, the trick is to draw a slider, which is just an empty rectangle with a filled rectangle in it. The size of the inner rectangle is increased when you click right, and decreased when you click left, based on a score variable. A middle click accepts the score. You can see an example script below. That should help you get started, although you'll probably want to tweak it a bit.

    If you're not familiar with Python, I would recommend walking through one of the basic Python tutorials. You don't need to be a coding wizard, but some knowledge will give you a lot of freedom!

    Cheers,
    Sebastiaan

    # Create canvas and mouse objects
    from openexp.mouse import mouse
    from openexp.canvas import canvas
    my_canvas = canvas(exp)
    my_mouse = mouse(exp)
    
    # The starting score, and the step size, i.e. the score
    # change per click
    score = .5
    step_size = .1
    
    # Width and height of slider
    w = 400
    h = 50
    
    # Display center coordinates
    xc = self.get('width')/2
    yc = self.get('height')/2
    
    while True:
    
        # Show slider   
        my_canvas.clear()
        my_canvas.rect(xc-w/2, yc-h/2, w, h) # Border
        my_canvas.rect(xc-w/2, yc-h/2, w*score, h, fill=1) # Fill
        my_canvas.show()
    
        # Get a click
        button, pos, timestamp = my_mouse.get_click()
        if button == 1: # Increment on left click
            score -= step_size
        elif button == 3: # Decrement on right click
            score += step_size
        elif button == 2: # Quit on middle click
            break
    
        # Make sure the score stays between 0 and 1
        score = max(0, min(1, score))
    
    exp.set('score', score)
    
  • edited 12:22PM

    Hi Sebastiaan !

    Thank you for responding so quickly and for the trick. I’ll start with this script.

    Best regards

    Camille

  • edited 12:22PM

    Hi both,

    I think the issue was to get a continuous reading, not just have one slider. So @sebastiaan 's script is almost perfect, but needs to log the score on every iteration to make it completely match the question.

    You could implement this using the log function.

    Good luck!

  • edited 12:22PM

    Hi Sebastiann and Edwin,

    Thank you for your previous answers. I'm working my way through a codecademy python introduction course (which so far has proven to be worthwile).
    However, I still have some problems which exceeds my level... I hope you can help me.

    My experience was changed slightly but it is always simple :

    I want to send a triggers with a parallel port to an external device and after to broadcast a soundtrack.

    During audio " I want to collect continuously pain score of the participant in the form of a visual analogue scale from 0 to 100 (or at least during and after a painful stimuli). It is necessary that the participants see their rating and ideally when they press the right button of the Srbox a trick meter (= a gauge) fills and when they press the left button it decreases."

    In fMRI, we don't use the mouse but the Srbox (serial port, Lumina) LP-400 (cedrus.com).
    (I believed that the configuration was the same but not...)

    I have found some informations on the forum and I downloaded the Python library pyxid but I don't manage to use it.

    http://www.cogsci.nl/forum/index.php?p=/discussion/582

    https://github.com/cedrus-opensource/pyxid

    I placed the following code at the beginning of the experiment, in the prepare phase:

    import pyxid

    devices = pyxid.get_xid_devices() # get a list of all attached XID devices

    dev = devices[0] # get the first device to use

    Then I put this in the beginning of the trial sequence :

    if dev.is_response_device():

    dev.reset_base_timer()
    
    dev.reset_rt_timer()
    
    while True:
    
        dev.poll_for_response()
    
        if dev.response_queue_size() > 0:
    
            response = dev.get_next_response()   # Do something with the response
    

    It gives me the following error : (corresponding to dev = devices[0] )

    Error while executing inline script

    phase: prepare

    item: Close_parallel_port_and_configure_Srbox

    line: 6

    exception message: list index out of range

    exception type: IndexError

    Is it the good way to do ? How do you solve this error ?

    I have several questions :

    _How do you set the value of the buttons?

    _How do you insert them into the canvas to get the score of the subject in continues?

    I'm a little desperate I spent a lot of time without result... your help will be more than welcome.
    I remain at your disposal for any information needed to facilitate the resolution of this problem.

    Camille PhD Student

  • edited 12:22PM

    Hi Camille,

    I hope it's okay for you if someone else than Sebastiaan or Edwin responds...

    Is it the good way to do ? How do you solve this error ?

    Is it possible that no device is recognized? You can print out devices to see whether the list is empty (This would explain why devices[0] gives an Indexerror).

    _How do you set the value of the buttons?

    Do you mean, which values to pick to set the buttons, or how to do so? As far as I understand, you only need the values to distinguish between the buttons, where the exact value of the buttons is not important, right? In this sense, your logic is supposed to look like this:

    if button1 == pressed:
         step = positive_value
    elif button2 == pressed:
         step = negative_value
    

    Please correct me if I am mistaken.

    _How do you insert them into the canvas to get the score of the subject in continues?

    Well, it works pretty much the way Sebastiaan explained to you in his long answer. So you're waiting for key presses. As soon as you record on, you check which button was pressed and set the step size to the corresponding value. Then you adjust the score by this step size and draw the analogue scale on the screen. This loop you repeat as often as you want to.

    I'm not sure whether I understood all your questions correctly. Feel free to ask again, if I was of no help for you.

    Good luck,

    Eduard

    Buy Me A Coffee

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