Howdy, Stranger!

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

Supported by

[solved] Two independent sequences in parallel

edited April 2013 in OpenSesame

Hello board!
To begin with, OpenSesame's obviously a great piece of software. I find it easy to create basic experiments, and the best thing about it might be that it teaches me some Python. Sebastiaan, I told you I'd use OpenSesame for the next thing I'm going to pre-register :) (This is intended for Cortex.)

Still, I'm stuck with my current experiment. I'm trying to program an RSVP sentence presentation experiment that allows the participant to immediately respond to individual words, and get immediate auditory feedback while the sentence keeps being presented.
So I've programmed two sequences. One presents a sentence word by word, with individual words on sketchpads with fixed timing (around 500 ms per word). The other sequence contains 1. a delay (depending on which word is the critical word, set by the loop), 2. a keyboard response, 3. two samplers with "yay!" and "boooh!" sounds, depending on the value of [correct]. And then I've simply put both sequences into a "parallel" item.
The idea is that the two sequences should work completely independently, with the sentence being presented in full, with strict timing, unperturbed by participant behaviour, and a keyboard response (when the participant detects a certain word in the stream) that is immediately followed by auditory feedback, without waiting for the sentence presentation sequence to finish..
Note that the average sentence is around 5 seconds, the average reaction time around 1 second, and the critical word appears halfway through the sentence.

It doesn't work, so far. Keyboard response (I'm on a Mac btw., so it's probably not the Windows/multithread bug I've seen mentioned here) are not recognized, 'correct' is stuck on "0" and the timing of the sentence sketchpads seems to be influenced by the events in the other sequence.
Is the basic approach sound? If so, I would put up my script on pastebin and kindly ask for more specific feedback. Or is it simply not possible the way I'm trying to do it right now?
I appreciate any feedback! Thanks,
Jona

Comments

  • edited April 2013

    To begin with, OpenSesame's obviously a great piece of software. I find it easy to create basic experiments, and the best thing about it might be that it teaches me some Python. Sebastiaan, I told you I'd use OpenSesame for the next thing I'm going to pre-register (This is intended for Cortex.)

    Thank you, and good luck with the new format!

    Is the basic approach sound? If so, I would put up my script on pastebin and kindly ask for more specific feedback. Or is it simply not possible the way I'm trying to do it right now?

    The basic approach should be sound, if the parallel plug-in would function as you would hope. Unfortunately, on many systems it doesn't. I don't use a Mac myself, but it sounds like a threading problem again.

    My recommendation would be to implement the RSVP task through an inline_script. It's not that difficult, and it will save you considerable headaches. The basic idea is demonstrated in this script:

    from openexp.canvas import canvas
    from openexp.keyboard import keyboard
    
    N = 10 # Nr. of canvases
    SOA = 495 # Just short of 500ms
    
    # Create a list of canvases. These could in principle
    # also be copied from sketchpad items, using
    # `self.copy_sketchpad()`.
    canvas_list = []
    for i in range(N):
        my_canvas = canvas(exp)
        my_canvas.text('%s' % i)
        canvas_list.append(my_canvas)
    
    # Create a keyboard object that also servers as a
    # delay period.
    my_keyboard = keyboard(exp, timeout=SOA)
    
    # Alternately show canvases and record keypresses,
    # until a key has been pressed.
    t1 = self.time()
    for i in range(N):
        canvas_list[i].show()
        key, t2 = my_keyboard.get_key()
        if key != None:
            break
    
    # Set the response variables
    exp.set('response_time', t2-t1)
    exp.set('response', key)
    

    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

  • edited April 2013

    Thanks Sebastiaan! I think I mostly understand what's going on in that script. It will take me some time to implement it though. Alas, at least I'm learning Python.

    However, one thing I'm worrying about is that the feedback sound cannot be time-locked to the text presentation, but must be time-locked to the button press (after some delay), while the canvas presentation should go on unperturbed (the sentence must be fully presented, and at the same speed). If I understand correctly the "if key != None:" line, whatever happens afterwards would start at the next iteration of the loop (when a new canvas would have been presented), and anything with a real duration here will delay the next canvas.

    I think I have a vague idea of how to manage that - delay the sound file by a value dependent on RT (t2), as in the mock code here:

    <br />t1 = self.time()
    flag = 0
    for i in range(N):
        canvas_list[i].show()
        if key != None:
        key, t2 = my_keyboard.get_key()
    # after a delay based on RT, play either hit or miss sound
    # ... but only if no sound has been played before in this cycle
        if key = [correct_response] and flag = 0:
            self.sleep(500-t2)
                (play "hit" soundfile)
            flag = 1    
        elseif key = [incorrect_response] and flag = 0:
            self.sleep(500-t2)
                (play "miss" soundfile)
            flag = 1    
    
    

    However, this would also delay the presentation of the next phrase. And as far as I understand it, updating SOA to a new value wouldn't change anything in the loop? Seems like I need a real parallel process again.

    Best,
    Jona

  • edited 4:16AM

    Okay, I've had a co-worker explain things to me a bit and I see where I understood your script, Sebastiaan. I will fiddle around with myself some more for now, please don't concern yourself with fixing what I should be able to do myself :) I'll post again when I run into actual problems.
    Thanks for the help.

  • edited April 2013

    I've adapted Sebastiaan's proposed solution and it works up to this point. The main problem was getting the next canvas to be delayed after a button press, and only allowing key presses once the critical event of the sequence had been presented, which I solved using something not especially elegant, but functional.
    Here is a link to what I did: http://pastebin.com/sP8J9Z0B

    I've changed the thread tag to [solved] accordingly.

  • edited 4:16AM

    Great, and good luck with the experiment!

    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

Sign In or Register to comment.