Return joystick to neutral position

Hello,

I am working on an approach avoidance task with a joystick as response. Right now I am trying to achieve that the position of the joystick resets on a trial by trial basis, because it seems like the program saves the last location of the joystick, which contradicts the approach avoidance task.
In the first trial, everything is in a neutral position, and depending on the joystick movements the presented picture should increase or decrease in size, which works already. But as soon as the second trial starts, the picture already increases/decreases, even though the joystick was not touched. I think the reason for this is that the program does not reset the joystick position, because it increases/decreases in size just like in the trial before, which led to my assumption that the position does not reset. Could you help me find a way to reset the position?

Right now, my code looks like this:
Begin Experiment:

sizeChange1 = 0.3  # Start with default size
sizeChange2 = 0.45

Begin Routine:

sizeChange1 = 0.3 # Start with default size
sizeChange2 = 0.45

joystickrec = joystick.device.getY()
moved = False

Each Frame:

yMove = joystick.getY()  # Check whether joystick moved on Y dimension

# Increase or decrease sizeChange variable
# depending on direction of movement
# e.g., make smaller if pushing away

if yMove >  0:
    sizeChange1 -= .0066
    sizeChange2 -= .01
elif yMove <  0:
    sizeChange1 += .0066
    sizeChange2 += .01

if moved == False:
     joystickloc = joystick.getY()
     if joystickloc != joystickrec:
          moved = True
          thisExp.addData('Moved',round(t*1000)) # reaction time for movement

End Routine:

thisExp.addData('joystickloc', joystickloc)

This code looks very much like my mouse code for mobile devices.

Try

joystickloc = joystick.getY()

if moved == False:
     if joystickloc != joystickrec:
          moved = True
          thisExp.addData('Moved',round(t*1000)) # reaction time for movement

yMove = joystickloc-joystickrec  # Check whether joystick moved on Y dimension

# Increase or decrease sizeChange variable
# depending on direction of movement
# e.g., make smaller if pushing away

if yMove >  0:
    sizeChange1 -= .0066
    sizeChange2 -= .01
elif yMove <  0:
    sizeChange1 += .0066
    sizeChange2 += .01

P.S. What’s the difference between joystick.device.getY() and joystick.getY() ?

1 Like

Do not really know the difference to be honest, I was just trying different things to make it work.
Your code works! Just had to change joystickrec in the begin routine tab to joystick.geY() instead of joystick.device.getY().

Thank you very much!

1 Like