Eye tracking with Matlab (Psychtoolbox / Cogent)
The easiest way to interface with the SMI eye trackers is over the serial port. This works for any Matlab-based experiment toolbox. The serial port interface is up and running for the MRI and hi-speed eye trackers, and should be easy to set up on the other eye trackers. The main limitation is that communication is only from the stimulus PC to the eye tracker - there is no trivial way to get gaze information back to the experiment PC.
Currently, there is no in-Matlab solution for calibrating, so before starting your experiment you need to run through the standard calibration routine with WinCAL. Make sure you disable WinCAL before attempting to start your script as Matlab will otherwise find the Serial port busy and raise an exception.
Initialising the serial connection
The serial port needs to be set up. After this, we send text strings that the eye tracker PC interprets. These commands take the format "ET_X."
eyetracking = input('Eyetracking (1 to enable, 0 to disable): ');
if eyetracking
ET_serial = serial('COM1', 'BaudRate', 9600, 'Databits', 8);
fopen(ET_serial); % Open serial port
fprintf(ET_serial,'ET_CLR'); % Clear recording buffer
fprintf(ET_serial,'ET_REC'); % Start recording
display(sprintf('%s\t%s','Eyetracking:','enabled'))
else
display(sprintf('%s\t%s','Eyetracking:','disabled'))
end
Calibrating in Psychtoolbox
TODO. For now, just calibrate in WinCAL before starting your experiment script.
Sending events
If you send ET_REM [x] to the eyetracker, [x] gets written as an event in the eyetracking log. This can then be used to identify your events in an analysis. Note that BeGaze can automatically match up your events with images, and for this to work the string you send must be the exact filename of the image you wish to associate the event with. So for instance, if your fixation cross image is fixation.png, sending 'ET_REM fixation.png' will then make it reasonably easy to overlay heatmaps etc over the fixation image in BeGaze.
% One way to send a trial string. You need to do this for each onset you are interested in, e.g., start of each trial.
if eyetracking
trialname = 'mystimimage'; % Whatever your stimulus is.
fprintf(ET_serial,sprintf('ET_REM %s.png',trialname));
Finishing the recording
Once your experiment has finished, you need to stop the eyetracking recording, and close the serial port connection.
if eyetracking
% Stop recording
fprintf(ET_serial,'ET_STP');
% Still need to save data manually
% In principle, ET_SAV C:\YourDir\YourLog should do it. Debugging this...
% Close to flush buffer
fclose(ET_serial);
end
General notes
The most common errors you will see are related to the serial port being busy. This happens when a) you forgot to disable WinCAL before starting your experiment script, b) your script crashed and you are trying to restart without properly closing the serial port (fclose(ET_serial) above).
