Saving joystick data

Hi all,

I’m trying to save continuous positional data from a joystick. Well, it’s actually a fibre-optic linear response device, but the interface presents it as a joystick to the OS, so essentially, it’s a joystick. I have an on-screen marker which is positioned by the x-position of the joystick (so, updates every frame) and that works great, but I can’t seem to get that data saved anywhere. So, changing the ‘Save joystick state’ option in the joystick properties GUI to ‘every frame’ should do it, right? Still though, just a single x and y value are saved, which are (presumably) the final state/position of the joystick.

I’ve also tried just creating a list in a code component, appending the x value on each frame to the list, and then dumping that list to a text file at the end of the routine. As well as being crashingly inelegant, that doesn’t seem to work either - no error message, but PsychoPy hangs/crashes, and nothing gets saved.

Any ideas gratefully received! Thanks in advance.

Matt.

OS Win10 and OS X
PsychoPy version (e.g. 1.84.x): 3.1.5
Standard Standalone? (y/n) If not then what?: Y
What are you trying to achieve?: Saving joystick x/y positions every frame.

What did you try to make it work?: Enabled option in joystick properties for 'Save joystick state: every frame"

What specifically went wrong when you tried that?: No error message, but only a single joystick x/y position is saved in the data file.

Hi Matt,

I haven’t got a joystick to test with, but also would have assumed it would behave in the same way as a mouse in terms of recording frame-by-frame data.

We’d have to see your code to see what might might be the issue with saving the data to disk, but a quick fix would just be to take your collected list at the end of each routine and save it in the data file:

thisExp.addData('joystick_positions', your_position_list)

This is a a bit painful because you’re nesting frame-by-frame data within a cell, but if you analyse data in R, this should be easy to get out, using unnest functions available in dplyr/tidyr. There’d be a way to do it in Python too of course, but might take more wrangling.