Tobii and OpenSesame

Last modified by Iris Spruit on 2024/06/25 16:39

Introduction

OpenSesame uses the PyGaze library to enable eye tracking. With this library eye tracking is possible with many eye trackers, including Tobii. PyGaze uses the Tobii Pro software development kit (SDK) to communicate with the Tobii eye tracker. The PyGaze library is automatically installed with the OpenSesame Windows version. However, see the instructions below for setting up/installing OpenSesame for working specifically with a Tobii eye tracker.

Setting up OpenSesame for Tobii

The Tobii research library (part of the Tobii Pro SDK) is unfortunately not available for Python 3.11, which is what the OpenSesame 4.0 distribution comes with, nor available for Python 3.7, which is what the OpenSesame 3.3 distribution comes with. As a result, you cannot use Tobii eye-trackers with the downloadable version of OpenSesame 4.0 or 3.3. To get around this, OpenSesame can be run in its own Python 3.10 or 3.8 environment, which is supported by Tobii. Running OpenSesame inside an environment can be done using Conda.

Instructions on creating a Conda environment for OpenSesame 4 or OpenSesame 3 that can be used with Tobii, can be found on Github

OpenSesame and Tobii at FSW Leiden

A Conda environment with OpenSesame 4 and OpenSesame 3 that comes with the Python version necessary for Tobii are installed on all lab pc's at FSW Leiden (PdlC and Sylvius). Use the OpenSesame 4 - Tobii and OpenSesame 3 - Tobii shortcuts on the Desktop to open OpenSesame in these environments. See the main OpenSesame page for more information. Contact labsupport@fsw.leidenuniv.nl if you have trouble using these environments.

Note that launching the installed OpenSesame by running it from the start menu, or by double-clicking an osexp file, will not launch the OpenSesame version inside of the new environment. Instead, the OpenSesame version installed on the PC will launch in its own bundled Python runtime.

Installing and Running OpenSesame Through Conda

Conda is a package manager included in Anaconda and Miniconda. Please make sure one of the two is installed before attempting to use Conda. It is preferable to install Anaconda as it provides a handy graphical user interface and more features, although those are not required. Note that both Miniconda and Anaconda can be installed for the current user without admin privileges by choosing “just me” at the “install for” prompt.

To run OpenSesame through Conda for the purpose of using Tobii, a new Python environment must be created and configured. Subsequently, the OpenSesame code and all its dependencies must be downloaded and installed inside that environment.

Once the environment has been set up, the OpenSesame installed inside of it can be launched by first activating that environment, then running the opensesame command.

The above has been automated in a few scripts, see Github for more information.

If you want to create your own environment, see Managing environments — conda 24.5.1.dev56 documentation for more information on Conda and see Download // OpenSesame documentation (cogsci.nl) for more information on how to download OpenSesame in a Conda environment.

Configuring PyGaze for Tobii

A sample OpenSesame task with PyGaze and Tobii can be downloaded here.

For more general information about using the PyGaze library in OpenSesame, check the PyGaze and OpenSesame page and the official OpenSesame documentation. Below, some information when working specifically with Tobii are given.

Serial number

Before you can use a Tobii eye-tracker with PyGaze, which is what OpenSesame uses to interface with eye-trackers, you need to register the eye-tracker's serial number. This can be done by adding a Python Inline script item at the start of the experiment sequence, and then adding the following code to it:

"""
When using Tobii eye-trackers, add a Python inline script to the
top of the experiment with the code below. Change the serial number
to the one matching your device. Use the Tobii Eye Tracker Manager
to find the serial number:
  https://www.tobiipro.com/product-listing/eye-tracker-manager/
"""


from pygaze import settings
settings.TRACKERSERIALNUMBER = "X3120-XXXXXXXXXXXXX"

Make sure to change the serial number to one matching the eye-tracker you have and want to use. You can find the serial number in the Eye Tracker Manager when the eye-tracker is connected to the PC and turned on. 

Tobii-SerialNumber.PNG

Initialize PyGaze

Make sure to configure the pygaze_init object so that it communicates with a Tobii eye-tracker (Select tracker type: Tobii). Also, it is highly advised to check the Calibrate tracker option, so that the eye-tracker is calibrated at the start of the task.

FAQ

TopicQuestionAnswer
OpenSesame crashes with AttributeError: 'TobiiProTracker' object has no attribute 't0' 

Make sure the eye tracker is connected properly to the pc and set-up with the Eye Tracker Manager. If this is the case, see below.

Somehow, the eye tracker is sometimes not found immediately. This is usually resolved by just running the task again. See discussion and solution here. The find_all_eyetrackers() function needs to be adjusted to solve the issue.