Recording mouse trajectory

Dear all,

I am facing a problem and I hope you'll be able to give me some useful advices. I am currently trying to design an experiment with psychtoolbox where I would like to continuously record the coordinates of my mouse. Basically, on each trial, subjects are presented with a photograph of a waiting room and have to choose where to sit by guiding their mouse toward the chosen seat.

I would like to compare the trajectories of the mouse in my different conditions by recording the coordinates of the mouse with a high sampling rate (for instance 1 point every 10ms) that would allow me to get the trajectory of the mouse on each trial.

I have been trying to use a software which records this type of data but my design is a bit complicated and I don't manage to make Matlab communicate  with the software. Then I decided to record the mouse coordinates with the GetMouse function in a timer object as following :


t = timer('TimerFcn', @GetMouse, 'StartDelay', 0,'TasksToExecute',40, 'Period', 0.01,'UserData', coords , 'ExecutionMode', 'fixedRate') ;

But I don't know how to save all the xy coordinates with UserData,
I only get one point (one x and one y coordinates) as if the task wasn't repeating itself. Then, I have two questions :

- do you think that the use of a timer callback function is the best option ?

- do you think that the temporal resolution won't be disrupted by the "continuous" sampling of the coordinates ?


Looking forward to reading any comments/feedbacks !


Thank you in advance,


Emma


Look at the MouseTraceDemo.. demos on how to do this. You could use a sampling loop in Matlab (while loop) which uses WaitSecs(0.010); to sample only once every 10 msecs.

Most mice update at 8 msec intervals, so 0.008 secs sampling might be most appropriate. On OSX you may only get sampling at the video refresh rate on the display because the iToys company decided that's the thing everybody should want.

-mario
What I've done for complex experiments that need one or two functions to be called frequently is to put it all into a large loop with a switch statement or something like that which can advance the trial as needed without having to copy and paste the function calls over and over again in between stimuli presentations. For instance if you need a series of 4 photos to be shown and also save the mouse position, then write a loop that saves the mouse position, and insert into that loop a set of if statements or a switch statement that draw the different photos as a function of how much time has elapsed since the start of the experiment. In this model, each if statement is an "event" that only happens once.


On Thu, Sep 11, 2014 at 9:25 AM, Emma Vilarem emma.vilarem@... [PSYCHTOOLBOX] <PSYCHTOOLBOX@yahoogroups.com> wrote:

Thank you very much for your quick answers.

I am now trying to use the MouseTraceDemo script to get the mouse coordinates and trace. It doesn't really work for now but I'm working on it. Thank you again !


On Tuesday, September 9, 2014 8:53 PM, "e_flister@... [PSYCHTOOLBOX]" <PSYCHTOOLBOX@yahoogroups.com> wrote:


hi emma-
i record mouse trajectories because we use a usb optical mouse to record the running of a mouse (the animal) on a spherical treadmill. i don't see why a timer object wouldn't work, but since you're already in psychtoolbox and have a flip loop, why not just record the position during each loop iteration? that's what we do and it works fine. two points to remember: preallocate your storage for the trajectories (for the usual reason), and also store GetSecs timepoints for each iteration.

if timer objects were well designed, they'd be a potential option for faking threads -- a useful (if fraught) abstraction for keeping your code modular. but last i looked into them (7ish years ago?) they were awful -- couldn't execute faster than a few times a second, no priority/scheduling semantics, no inter-thread communication, etc. maybe they're better these days, dunno -- what kind of speed do you get if you call GetSecs as fast as possible with no other load? note the warning in the doc saying you shouldn't use them for real-time code, which you're verging on.

> But I don't know how to save all the xy coordinates with UserData, I only get one point (one x and one y coordinates) as if the task wasn't repeating itself.

if you insist on doing it this way, you need to write a callback that includes your call to GetMouse + GetSecs, keeps track of what iteration it's on, and stores the results in the appropriate slot of UserData (remember to preallocate), or maybe instead in some shared memory (a variable from the scope surrounding the callback, written as an inner (nested?) function).

> a high sampling rate (for instance 1 point every 10ms) that would allow me to get the trajectory of the mouse on each trial.

details of your OS and mouse design (ie, USB, etc) will limit the true temporal resolution, but if you ask for a new sample before the OS has gotten an update from the mouse, you'll just get the old position -- no problem.

> do you think that the temporal resolution won't be disrupted by the "continuous" sampling of the coordinates ?

what?

-e