2nd joypad's input is interrupted by 1st joypad

I’m currently creating a joint-action experiment in Windows 10 using Builder, which involves two joypads (both Xbox controllers) controlling different stimuli simultaneously. Specifically, each joypad’s left stick sets the orientation of a specific stimulus.

To achieve this, rather than using the Joypad or JoyButtons components, I just use the code component. Here is my code:

In “Before Experiment” tab:

import math
from psychopy.hardware import joystick

nJoys = joystick.getNumJoysticks()
id = 1
xbctrl = joystick.XboxController(0)
xbctrl2 = joystick.XboxController(1)

In “Begin Routine” tab (just initialises the orientations):

pitcherOri = 0
catcherOri = 0

In “Each Frame” tab:

pitcherStick = xbctrl.get_left_thumbstick_axis()
catcherStick = xbctrl2.get_left_thumbstick_axis()

if pitcherStick[0] > 0.2 or pitcherStick[0] < -0.2 or pitcherStick[1] > 0.2 or pitcherStick[1] < -0.2:
    pitcherOri = math.atan2(pitcherStick[1],pitcherStick[0]) * (180/math.pi)

if catcherStick[0] > 0.2 or catcherStick[0] < -0.2 or catcherStick[1] > 0.2 or catcherStick[1] < -0.2:
    catcherOri = math.atan2(catcherStick[1],catcherStick[0]) * (180/math.pi)

To clarify, what happens each frame is that the left thumbstick position is read for each controller. Then, this input is checked and the orientation is set (by determining the angle of the stick). Everything works fine, with each stimulus rotating smoothly according to the stick’s inputs.

The problem arises when both sticks are moving at the same time: the second joypad (named xbctrl2)'s input is effectively blocked while the first joypad is moving its stimulus. Note that if the first joypad’s stick is held in a single position (such that the orientation of the stimulus does not change), the second joypad’s input works fine. It’s only when the first joypad is moving that the other one doesn’t work.

So, I’m not sure if this is a problem with the way the inputs from multiple joypads are read, or whether there is something else going on with my code. Any thoughts would be much appreciated!

Never mind! I immediately found the problem after posting…

So I actually did have a joystick component in my routine, which is required for the input to work at all. The problem was I only had one component. The problem was solved by adding a second joystick component by copying the first one and simply updating the “device number” value to 1 (the first stick’s device number is the default value of 0).

Hopefully this at least serves someone else struggling with joypad input!