WorldViz User Forum

WorldViz User Forum (
-   Vizard (
-   -   Unable to draw EyeLink drift correction to screen (

chris2307 08-06-2014 08:07 AM

Unable to draw EyeLink drift correction to screen
Hi all,

I am running an experiment in a loop. When a new trial begins, I would like to call the EyeLink 2 drift correction function. I've been able to call the menu for calibration before starting the experiment just fine.

The problem is that my function does run and the drift correction routine is initialised (I can see this from the EyeTracker PC). However, I am unable to get the eye tracker to override the screen in order to display the drift correction dot.

Instead, the experiment continues to be displayed on the screen, although is blocked whilst it waits for the drift correction routine to be exited.


import viz       
import os
import vizact
import viztask
import math
#import pyxid
import win32api
import win32con

sys.path.append(os.getcwd() + '/functions')

import LoadLevel
import screen
import Lights
import Physics
import EyeTracker
from text import Text
from movement import Movement
from toDataFile import toDataFile
from StaticVisualSearchTask import StaticVisualSearchTaskExperiment

userMovement = Movement(10)
text = Text()


experiment = StaticVisualSearchTaskExperiment()
toFile = toDataFile(experiment.getParticipantID())

def runExperiment():
        yield experiment.prepareTrial(experiment.currentPhase())
        toFile.newTrial(experiment.getTrialData(), experiment.getTrialNumber())

        while True:
                if(experiment.hasTrialEnded() == False):
                        if(experiment.isNewPhase() == True):
                                yield experiment.prepareTrial(experiment.currentPhase())
                                toFile.asRaw("" + str(experiment.currentPhase()) + "")
                        if(experiment.currentPhase() == 1):
                                yield experiment.runPhase1(JOY_YES = userMovement.returnButtonYES(), JOY_NO = userMovement.returnButtonNO())
                        elif(experiment.currentPhase() == 2):
                                yield experiment.runPhase2(JOY_YES = userMovement.returnButtonYES(), JOY_NO = userMovement.returnButtonNO())
                        elif(experiment.currentPhase() == 3):
                                yield experiment.runPhase3(JOY_YES = userMovement.returnButtonYES(), JOY_NO = userMovement.returnButtonNO())
                        if(experiment.hasExperimentEnded() == False):
                                yield EyeTracker.driftCorrection() # <------------------------------------------------- Here is where I attempt to carry out a drift correction
                                yield experiment.nextTrial()
                                yield experiment.prepareTrial(experiment.currentPhase())
                                toFile.newTrial(experiment.getTrialData(), experiment.getTrialNumber())
                                yield experiment.finish()



I'm hoping it is something obvious but if it's not, please let me know and I'll get more information put up on here.


Frank Verberne 08-06-2014 12:44 PM

Hi Chris,

I think your experiment is doing exactly what it is being told (as computer usually do;)!). I don't know the nature of your EyeTracker.drifCorrection function, but it appears to me that Vizard is waiting for something that never happens. Yield should only be used for functions that return something to yield for. My guess is that your function does not return a yieldable object, so Vizard will be stuck there. Just deleting yield in front of you EyeTracker.driftCorrection function might do the trick.

By the way, the viztask.schedule function only needs at least one yield statement. You have quite a few yield statements in your function, so beware that those functions are yieldable :)!

chris2307 08-06-2014 02:12 PM

Thanks for the reply :)

I've been trying it with and without the yield statement actually and I get the same results with both. Incidentally, the only reason the yield statement is in the example above is that it happened to be what I had just tested before posting!

The experiment actually does do what I tell it to (technically), it just doesn't draw to the screen. For example, when I call my drift correction function the experiment does stop (which is good). The EyeTracker does go in to drift correction mode. The only issue is that the drift correction screen is not drawn to the screen. I can only assume that something is blocking the EyeTracker from drawing to the screen which it should be capable of doing.

My EyeTracker.driftCorrection() function simply calls the line:


pylink.getEYELINK().doDriftCorrect(960, 540, 1, 1)
The third parameter specifies that the EyeTracker should draw to the screen for me and release the screen when finished.

chris2307 08-07-2014 06:04 AM

Okay, so I figured out why nothing was happening on the screen. I had missed out some code which should have been in my driftCorrection() function:


def driftCorrection():
        pylink.openGraphics((_display_width, _display_height))
        pylink.setCalibrationColors((255, 255, 255), (0, 0, 0))          #Sets the calibration target and background color
        pylink.setTargetSize(int(_display_width / 70.0), int(_display_width / 300.0));
        pylink.setCalibrationSounds("", "", "");
        pylink.setDriftCorrectSounds("", "off", "off");
        print "Called: Drift Correction"
        pylink.getEYELINK().doDriftCorrect(960, 540, 0, 0)

However, I now get a black screen SDL application which is separate from the Vizard application. Nothing happens and all keyboard input is blocked so I tab out of it and return the experiment where I can hit escape.

In the Vizard output box, I get the following error:

pylink.openGraphics((_display_width, _display_height))
RuntimeError: Could not initalize graphics

Unfortunately, this isn't helping me much because I run the exact same line of code when calling the calibration routine before the experiment.

chris2307 08-07-2014 08:05 AM

Sorry for the triple post!

So I have a solution although it's by no means elegant and I am sure there is another way around this.

I was getting the graphics error when trying to initialize the graphics when in fullscreen mode. I assume this is because Vizard has some kind of lock on the rendering loop and when trying to initialize a new window from within fullscreen mode, it fails.

I've got around the problem by toggling full screen mode OFF before the drift correction function is called and back ON once it has completed:



This is, as you can imagine, not the way I want to do things as it looks messy. I need the experiment to be full screen so starting in windowed mode isn't an option either.

Does anyone have any ideas?


chris2307 08-18-2014 05:38 AM

Bumping the thread as I've had no reply in over a week.

Any ideas on how I can get round this issue without switching to windowed mode at the end of every trial?

Jeff 08-18-2014 03:22 PM

You could try executing the function in a separate thread. If you've using a task for your program take a look at waitDirector.

All times are GMT -7. The time now is 06:29 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2022, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC