Guidance on using eyetracking with ioHub and YAML files post 2021.2.0

Thanks a lot for the reply,

I’m in the process of trying to make the experiment work with the latest version of PsychoPy now and will update this reply as I go.

When writting your experiment in Python / using Coder, using launchHubServer has been the suggested way of starting iohub for several years now. Which demo / example uses the client.ioHubConnection directly? I should update that if possible.

It doesn’t include eyetracking but this .py file and its corresponding .psyexp file use the ioHubConnection method. This seems to be the only demo that does this(BTW, Github’s ‘within-repo search’ functionality is great for finding things like this, if you’re not already using it). Also, the examples in the official PsychoPy book by jon and Michael do the same thing, IIRC. (I don’t think the book has been updated in a few years though)

Updated experiment
I tried changing the code as you suggested, and using the new ‘mouse/mock eyetracker’ (since I’m not at a computer with an eyetracker now). I wanted to first try changing just the code, since I think switching over to the Builder components for eyetracking would lead to chain effects where more has to be restructured.

from psychopy.iohub import launchHubServer

# (this is automatically generated by Builder. there is a valid 'spectrum_monitor'
# specification file on the computer I'm using
win = visual.Window(
    size=[1920, 1080], fullscr=True, screen=0, 
    winType='pyglet', allowGUI=False, allowStencil=False,
    monitor='spectrum_monitor', color=[1,1,1], colorSpace='rgb',
    blendMode='avg', useFBO=True, 
    units='deg'
)

config_file = 'MOUSE_eyetracker.yaml'

eye_tracker_name = 'tracker'

io_connection = launchHubServer(
    iohub_config_name=config_file,
    window=win
)

if io_connection.getDevice(eye_tracker_name):
    # assign the tracker to a variable to make
    # it easier to reference
    eye_tracker = io_connection.getDevice('tracker')
else:
    print(
        f"Could not connect to eye tracker '{eye_tracker_name}', is it on?"
        " Quitting..."
    )
    core.quit()

(Note that I’m passing in the window instance now, based on launchHubServer’s documentation and what you wrote)

Here’s the ‘MOUSE_eyetracker.yaml’ file, after being stripped of redundant sections, in case it helps others who might want to still use the separate YAML file approach.

# SIMULATES eyetracker by using the mouse
monitor_devices:
    - eyetracker.hw.mouse.EyeTracker:
        enable: True
        name: tracker
        controls:
            move: [LEFT_BUTTON,]
            blink: [LEFT_BUTTON, RIGHT_BUTTON]
            saccade_threshold: 0.5
        monitor_event_types: [ MonocularEyeSampleEvent, FixationStartEvent, FixationEndEvent, SaccadeStartEvent, SaccadeEndEvent, BlinkStartEvent, BlinkEndEvent]
data_store:
    enable: True
    experiment_info:
        title: Infant visual search with audio stimuli and eye tracking
    session_info:
        code: EXPERIMENT_RUN

This at first caused an error, but it turned out that it had to do with me forgetting to change the ‘display number’ to 1 in Builder (0 in the code above), since I’m now testing directly on my laptop’s screen (very similar to what’s discussed here), and a separate issue with the PTB sound engine.

Everything now works as expected. Having the mouse/mock eyetracker built into PsychoPy/ioHub directly is brilliant and really helps for development.