Experiment runs perfectly if keyboard is used as user response device, but crashes if it is replaced by X-Box controller

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2022.1.3

What are you trying to achieve?:
I created an experiment in which the contrast of an image changes according to the users response. The experiment runs perfectly, when the user response device is a keyboard, but crashes, when it is replaced by an X-Box controller.

What did you try to make it work?:
I used almost the same experimental design for both devices. The only things I changed, were to replace the keyboard element by a joy button (X-Box controller) element and to redefine the level variable, so that it ts attached to the controller. Allowed buttons and a correct answer button were also defined.

What specifically went wrong when you tried that?:
The experiment started normally and showed the welcome screen correctly. But after that, the experiment didnā€™t continue as expected to the next routine with the loop, but was canceled. Then the following error message was shown in the Runner:

print(fā€™Level: {level}. Correct:{resp1.corr}.ā€™)
AttributeError: ā€˜ā€™ object has no attribute 'corrā€™
################# Experiment ended with exit code 1 [pid:5680] #################

Since I defined a correct answer key/button, I donā€™t understand why Psychopy claimes that my response element doesnā€™t have a correct object. What can I do to make it work?


3 Elements of the Routine


Contrast defined as level variable, so it changes according to the users respone.
All Properties are set to ā€œset every repeatā€


Defintion of allowed and correct buttons of X-Box controller.
(Psychopy detects the Controller - it is used in a previous (working) step, too)


Code Fragment that defines the level variable. Works if the response device is a keyboard.

Hi @Brezelbayer,

If you open one of the data files, what column headers are created for the joystick component?

Thanks,

Kim

Hi @Kimberley_Dundas,

for the above described case no column header shows up for the controller component in the data.

Also, a lot other columns are missing, that I get in the other experiment (with the keyboard) e.g. ā€œstaircase.responseā€, ā€œkey_resp.rtā€, ā€œkey_resp.startedā€ and ā€œkey_resp.endedā€.

zero.psyexp (12.4 KB)
Here is the file, maybe you can find something that I execued wrong.

Hi @Brezelbayer,

Hmm. I canā€™t see anything wrong with the way this is set up - Iā€™m going to assign one of our developers to this post so that he can take a look!

Thanks so much,

Kim

From looking at the generated code, resp1.corr is first defined during the frame loop, which means it hasnā€™t been defined yet at the start of the routine when the ā€œBegin Routineā€ code happens as this code is run before the start of the frame loop.

This isnā€™t an issue with :keyboard: Keyboard as the underlying hardware.Keyboard object has a placeholder value for .corr as soon as itā€™s created, which we can absolutely add to the :joy_buttons: Joy Buttons component so thank you for spotting this! As a temporary solution, you can use this before your print statement to make sure .corr is defined:

if not hasattr(resp1, "corr"):
    resp1.corr = 0

Hi @TParsons
Thanks for your reply!

The code fragment you sent me allows me to show the startimage, but if I press any of the (allowed) buttons, nothing happens - the image stimulus remains the same.
Do you know how to solve this?

Hmm, I wonder if itā€™s because resp1.corr is being set here and then supplied to the staircase handler in place of an actual responseā€¦ What happens when you put that code in the Begin Experiment tab of the :code: Code component, and move the component to the bottom of the routine? That would mean the code is called only once, after resp1 has been initialised.

The result is the same as before:
the image is shown, but doesnā€™t change if one of the buttons is pressed.

Do you think itā€™s possible to manipulate the controller in a way that psychopy interprets itā€™s signals as keyboard signals, e.g. left shoulder button is read as left arrow key, and right shoulder button is read as right arrow, and A as Enter.

Maybe then the experiment would work.

I believe thatā€™s pretty similar to how JoyButtons works behind the scenes - just as keyboard keys are mapped to certain values, the buttons on a game controller are mapped to their own values, these values just arenā€™t associated with inserting a character. I have an XBox controller at home so tomorrow Iā€™ll plug it in and whip up a quick demo to print the values associated with each button, in theory you should then be able to use a :keyboard: Keyboard component with those values as the allowed keys. Iā€™ll let you know whether that works in practice!

1 Like

That would be great!
Thank you so much!

I cracked out the old XBox controller to give this a go then realised Iā€™ve got a new PC since I last used itā€¦ So all the drivers are outdated and no longer supported. However, when I use my Steam controller its inputs are detected by the Keyboard component - what happens if you run the keyNameFinder demo from the Builder demos folder? Do button presses on your XBox controller register as keys?

Iā€™ve tried it with 2 different X-Box controllers but in both cases the buttons were not recognized as keys. The usual keyboard worked, so the demo file itself works.