psychopy.org | Reference | Downloads | Github

Using t for mouse-tracking online

I am trying to use mouse-tracking online. My code works well enough that I collect [x,y] coordinates and a tracking timestamp for each trial. However, it seems that I am collecting mouse position and timing data every 50ms, when I think it should be closer to 16-17ms based on my ~58 framerate.
This is the code I am using to log both time and position in each frame:

trackingtime.push(t);
mousetracking.push(mouse_encoding.getPos());

So, a couple of questions:

  • Does anyone know why I may be having this issue?
  • What exactly does the “Sync timing with screen refresh” option for my mouse element do? Does this apply to online experiment as well?

Thanks in advance!

Hi @matiasfduque, could you send me a link to your project? Here to help, s.

Hi @sotiri ! Here’s the link to my project:
https://gitlab.pavlovia.org/matiasfduque/qrp_english

Do you in general have any advice on whether I should check “Sync timing on screen refresh”? I’ve had a hard time finding clear documentation on what that checkbox does exactly.

Thanks!

Hi @matiasfduque, thanks for the link, I think it means it’s giving the time of the nearest flip rather than just the absolute time, but that has no effect online anyway. Why do you say that the timestamps are off though? Have you tried saving mouse coordinates using psychoJS.experiment.addData() on each frame directly? The way you are infinitely appending to those arrays is a little unsafe and can slow down the code. You can find an example of continuously tracking x, y data in this demo →

Thanks @sotiri ! I didn’t know adding to arrays per frame could cause issues, so I’ll try using your suggested code instead and see what happens. The reason I think something is off with the timestamps is that given my framerate is ~58 Hz, I would expect the position of the cursor to be recorded approx. every 16-17ms (1/58 = .017). Instead, when I calculate the difference in time between frames, it is around .05 = 50 ms. So the cursor is being recorded every 50ms.

Adding to this:
So, using psychoJS.experiment.addData() in the Each Frame tab only saves one final timestamp, rather than array of timestamps, which is what I need. That’s the reason why I initialize and add to those arrays. Any idea why this would be? Or a better way to do this?

Hi @matiasfduque, sorry one would need to call psychoJS.experiment.nextEntry() without the snapshot argument for it to be saving row by row. I have made the relevant changes in the support fork. You can consult the timestamp column for frame by frame delta timings, hope that helps for now, x

Thanks for your help @sotiri . I seem to not have access to the support fork? Is it a permissions issue?

Sorry @matiasfduque, my bad, you should have access now, x

Thanks again @sotiri, I got this working on my experiment. I noticed you added the line

psychoJS.experiment.addData('performance.now()', performance.now());

What exactly is performance.now()? I can’t find much info on it.

Hi @matiasfduque, no problem, performance.now() tells you how many milliseconds have passed since the browser started timing on the document. You can use it to calculate frame deltas for example and it is used internally for clocking in PsychoJS too. You can read more about it below,