Clear history of cedrus response pad: button.clear_response_queue()

Hi There,

I have recently started working with a “Cedrus RB-730” response pad.

Problem:

If a participant accidentally presses a button twice the second button press is taken as a response to the following stimulus. The problem is illustrated using the code below in which participants should press a button, when a button is pressed the response queue should be cleared and there should be 4 seconds until the next trial. If you run this you can see that if you try pressing a button twice the second key press is taken as the response to the next trial :
##--------------------------------Code start------------------------

import pyxid 
from psychopy import core, event
devices = pyxid.get_xid_devices()
print devices
stimTrig = devices[0] # leg box ADJUST WHERE NEEDED
button = devices[1]# response pad
print devices
count=0

for i in range(10):
    core.wait(1)
    print 'waiting for response'
    response=0
    responseMade=0
    while responseMade==0:
        button.poll_for_response()
        if button.response_queue_size()>0:
            response=button.get_next_response()
            if response['pressed']:
                responseMade=1
                print response
    button.clear_response_queue()
    core.wait(4)

##--------------------------------Code end------------------------

I think my issue is that I am clearly not implementing button.clear_response_queue() correctly. As this should clear the response queue and mean the experiment waits for the next response key press in the next trial.

Any advice at all would be greatly appreciated !!

Thank-you in advance!

Becca

1 Like

I don’t have a cedrus box so I don’t have any experience with this, but on first glance I wonder if your call to clear_response_queue() comes too quickly after you collect the first response.

At the moment, you collect response #1, and then immediately clear the response queue. Try moving clear_response_queue() after your core.wait(4) line.

PS: If you enclose your code in three back-ticks, it gets formatted as code:

```
import pyxid
from psychopy import core, event
devices = pyxid.get_xid_devices()
print devices
stimTrig = devices[0] # leg box ADJUST WHERE NEEDED
button = devices[1]# response pad
print devices
count=0
```

becomes

import pyxid 
from psychopy import core, event
devices = pyxid.get_xid_devices()
print devices
stimTrig = devices[0] # leg box ADJUST WHERE NEEDED
button = devices[1]# response pad
print devices
count=0

Hi Jan.freyberg,

I thought this initially as well. However I have tried placing the clear_response_queue() after the core.wait(4) and also at the start of the for loop (so it should refresh at the start of each trial!) however I still seem to get the same problem which is strange!

Thanks for the tip on how to format me comment ! I have edited the post as you suggest (this is much better thanks!)

Becca

In that case I don’t know what’s going on, sorry - maybe someone on here with a cedrus box will be able to help you out.

Hi,

Did you ever solve this - I have exactly the same issue.

Kind regards,

Gabriela

sorry I can’t be more help here ! never managed to fix it so used a keyboard !! let me know if you get any further with it ! would be great to see what the issue is!

Hi,

We didn’t find a fix for this problem here, but we inserted these lines to run between each trial which has cured the symptoms

#Nasty Hacky fix to avoid multiple button presses cascading through subsequent trials
     for i in range(1,100):
         dev.poll_for_response()
         dev.clear_response_queue()

It doesn’t add any significant delay (although currently we don’t care about inter trial intervals, so YMMV) and being as the first button press is all we’re after in each trial and can safely ignore anything that happens before the next trial starts this works for us right now. That said, if anyone knows an actual fix for this, I’d love to get this cludge removed from our code :slight_smile:

1 Like

If you could timestamp the button presses and you timestamped the stimulus onsets then you could reject repeated button presses which occurred before stimulus onsets by comparing the the timestamps.

I don’t have a Cedrus keypad but I had quick look at their API on GitHub. Looks like it might timestamp button presses, though their readme says that their clock drifts. Perhaps that is correctable by measuring the drift rate?

Allen

Hi Allen,

Nice idea, but what does currently work is resetting the on-board timer to stimulus onset/trial start (avoiding the drift issue), so the timestamps aren’t as informative for this as you might hope! :slight_smile:

Additionally the dev.response_queue_size() command doesn’t seem to give accurate readings - i.e. doesn’t reflect this problem - and the dev.poll_for_response() command pops only the next button press in the queue - so even with a plan to discount erroneous responses by timestamp you’d still end up needing to iterate the dev.poll_for_response() command a high (and arbitrary) number of times to find out how many there had been - my cludge will fail if somehow there’s 101 erroneous button presses in a trial :smile:

Cheers,

Martin

Hi everyone,

The solution to this problem is to check if the “pressed” entry of the dict returned by dev.get_next_response() is True. Here’s an example that works for me:

pressed = False
while pressed == False:
ResBox.poll_for_response()
if ResBox.response_queue_size() > 0:
result = ResBox.get_next_response()
if result[“pressed”] == True:
pressed = True
result = result[“key”]
ResBox.clear_response_queue()

1 Like

Hi @Thomas_H and Everyone,

I tried @Thomas_H’s solution (I am using the pyxid2 library), but the button box doesn’t seem to poll for responses unless the command below is entered:

while not dev.has_responses():
       dev.poll_for_response()

If I modify this command such as:

pressed = False
while pressed == False:
     dev.poll_for_response()

or modified as:

pressed = False
while (not dev.has_responses()) and (pressed == False):
      dev.poll_for_response()

The program is not polling and the screen does not advance (my task is self-paced) unless the while loop only has “not dev.has_responses()” as a condition (again, this is with pyxid2)

I was wondering if anyone has a solution for this using the pyxid2 library?

much appreciated,
-Arkadiy

Just tried the hacky fix, and it works (4 years later!). thank you!