Eye-tracking with EyeLink 1000 plus

PsychoPy version: 2020.2.10

Hi, I´m trying to use the implement eye-tracking in my script. However, something does not seem to work. Every time Psychopy reaches the code where the eye-tracker is started, it crashes and I have to reboot the system.

In Begin Routine I have the following code:

from psychopy.iohub import launchHubServer
from psychopy.core import getTime, wait

iohub_config = {'eyetracker.hw.sr_research.eyelink.EyeTracker':
                {'name': 'tracker',
                 'model_name': 'EYELINK 1000 DESKTOP',
                 'runtime_settings': {'sampling_rate': 500,
                                      'track_eyes': 'BINOCULAR'}
                 }
                }

io = launchHubServer(**iohub_config)

# Get the eye tracker device.
tracker = io.devices.tracker 

# run eyetracker calibration
r = tracker.runSetupProcedure()  

Is there something additional I need to do, to make this script work?

When it crashes, do you mean that you get an error or just a grey screen which you can’t exit? If the latter that’s probably that ioHub has taken control of the PsychoPy window, but hasn’t initialised its keyboard successfully, so can’t recognise the Escape key to close it…

Using the same setup as you have here in Builder, the following code is generated:

# Setup eyetracking
ioDevice = 'eyetracker.hw.sr_research.eyelink.EyeTracker'
ioConfig = {
    ioDevice: {
        'name': 'tracker',
        'model_name': 'EYELINK 1000 DESKTOP',
        'simulation_mode': False,
        'network_settings': '100.1.1.1',
        'default_native_data_file_name': 'EXPFILE',
        'runtime_settings': {
            'sampling_rate': 500.0,
            'track_eyes': 'BOTH',
            'sample_filtering': {
                'sample_filtering': 'FILTER_LEVEL_OFF',
                'elLiveFiltering': 'FILTER_LEVEL_2',
            },
            'vog_settings': {
                'pupil_measure_types': 'PUPIL_AREA',
                'tracking_mode': 'PUPIL_CR_TRACKING',
                'pupil_center_algorithm': 'ELLIPSE_FIT',
            }
        }
    }
}
ioSession = '1'
if 'session' in expInfo:
    ioSession = str(expInfo['session'])
ioServer = io.launchHubServer(window=win, **ioConfig)
eyetracker = ioServer.getDevice('tracker')

# -------Run Routine 'calibration'-------

# define target for calibration
calibrationTarget = visual.TargetStim(win, 
    name='calibrationTarget',
    radius=0.01, fillColor='', borderColor='black', lineWidth=2.0,
    innerRadius=0.0035, innerFillColor='green', innerBorderColor='black', innerLineWidth=2.0,
    colorSpace='rgb', units=None
)
# define parameters for calibration
calibration = hardware.eyetracker.EyetrackerCalibration(win, 
    eyetracker, calibrationTarget,
    units=None, colorSpace='rgb',
    progressMode='time', targetDur=1.5, expandScale=1.5,
    targetLayout='NINE_POINTS', randomisePos=True,
    movementAnimation=True, targetDelay=1.0
)
# run calibration
calibration.run()
# clear any keypresses from during calibration so they don't interfere with the experiment
defaultKeyboard.clearEvents()

I’m guessing the problem is missing parameters in iohub_confg - what happens if you copy the dict used here in its place?

Thank you very much for the tip. I used to get a grey screen which I couldn’t exit. Now I copy-pasted this code and replaced the other but still I get some errors.

Initially I got this error

   ioServer = io.launchHubServer(window=win, **ioConfig)
NameError: name 'io' is not defined

So I just added an import io statement at Begin Experiment. However, this raised the following error

    ioServer = io.launchHubServer(window=win, **ioConfig)
AttributeError: module 'io' has no attribute 'launchHubServer'

What could be a solution to this problem?


I also tried another way. I removed the import io statement and added

io = launchHubServer(window=win; **ioConfig)

before

ioServer = io.launchHubServer(window=win, **ioConfig).

I’m not sure how much sense it makes, but I get the following error anyway:

TypeError: Object of type "Window" is not JSON serializable

I’ve just noticed your version number, we made pretty substantial changes to eyetracking in 2021.2 so I think that first error will be fixed if you update to the latest version. The one about widow being a JSON I’m not so sure about, but it’s worth updating and seeing what happens

Thanks for the help :slight_smile:

I just tried using the original script using PsychoPy v. 2021.1.3.

The script doesn’t get stuck anymore, but I still get many attribute errors, such as

AttributeError: module 'pylink' has no attribute 'EyeLink'
** EyeLink Error: could not connect to EyeLink Eye Tracker.
EyeLink Eye tracker device will run in 'dummy' mode.

I’ll ask the IT to install the 2021.2 version and I’ll let you know if it works or not!

1 Like

Dear all,
I am using the code of @TParsons TParson above to perform the calibration procedure within the psychopy.
Is there a way that I can tell maintain the settings I have manually inserted in the eye-link host computer and use the psychopy only to perform the calibration without having to define all the settings in the coder too?
Thank you
Martina

The settings must be specified in your script; any setting not specified will use the iohub default setting for the device.

If you are using Builder to create the experiment, as of PsychoPy 2021.2.x you can setup the eye tracker using the Builder Experiment Settings / Properties dialog → Eye Tracking tab.

2 Likes

Super thanks. I am now using that one.
However, I would like to be able to select l input port data under file sample contents. Do you know how to do it?
Thank you in advance
Martina

I’m not sure I understand the question. By ‘input port data’ do you mean the eyelink INPUT field that can be saved as events or as part of each eyelink sample? If so, this field is not saved to the hdf5 file, but it should be saved to the eyelink .edf file; these are the eyelink commands being sent to control what data is saved to the edf file:

eyelink.sendCommand( 'file_event_filter = LEFT, RIGHT, FIXATION, SACCADE, BLINK, MESSAGE, BUTTON, INPUT')
eyelink.sendCommand('file_event_data = GAZE , GAZERES , HREF , AREA  , VELOCITY , STATUS')
eyelink.sendCommand('file_sample_data = GAZE, GAZERES, HREF , PUPIL , AREA ,STATUS, BUTTON, INPUT, HTARGET')

thank you

1 Like

yes it was what I meant!
thank you.
I have a last question:I enabled to randomized calibration procedure in the experimenter builder. but for some reasons, in the host pc it is not selected the button randomized order (so no randomization actually happens). am I doing something wrong or?
Martina

Thank you for reporting this issue; it looks like this setting is not being applied when eyelink is used. I’m fixing it in the source for the next official release. Until then you can work around the bug by manually sending tthe necessary commands before starting the calibration. Send YES to enable or NO to disable target randomization.

eyetracker.sendCommand('randomize_calibration_order = YES')
eyetracker.sendCommand('randomize_validation_order = YES')

Thanks again for reporting the bug.