def _poll(self): try: if self._eyegaze_control is None or not self.isRecordingEnabled(): return False logged_time = Computer.getTime() current_tracker_time = self.trackerSec() sample_count_available = self._eyegaze_control.iNPointsAvailable confidence_interval = logged_time - self._last_poll_time self._last_poll_time = logged_time if sample_count_available == 0: return True if self._eyegaze_control.iNBufferOverflow > 0: # Eye Samples were lost. # TBD what to do here (lof to dataStore log?, log to LC data file?) print2err( "\nWARNING: %d EyeGaze Eye Samples Have Been Lost.\n" % (self._eyegaze_control.iNBufferOverflow)) for i in range(sample_count_available): pEyeGaze.EgGetData(byref(self._eyegaze_control)) sample_data0 = self._eyegaze_control.pstEgData[0] device_event_timestamp = sample_data0.dGazeTimeSec event_delay = current_tracker_time - device_event_timestamp iohub_time = logged_time - event_delay pupil_measure1_type = EyeTrackerConstants.PUPIL_RADIUS_MM if self._camera_count == 1: #monocular event_type = EventConstants.MONOCULAR_EYE_SAMPLE eye = EyeTrackerConstants.UNKNOWN_MONOCULAR gaze_x, gaze_y = sample_data0.iIGaze, sample_data0.iJGaze pupil_measure1 = sample_data0.fPupilRadiusMm status = 0 if gaze_x != 0.0 and gaze_y != 0.0 and pupil_measure1 > 0.0: gaze_x, gaze_y = self._eyeTrackerToDisplayCoords( (gaze_x, gaze_y)) else: status = 2 gaze_x, gaze_y = EyeTrackerConstants.UNDEFINED, EyeTrackerConstants.UNDEFINED pupil_measure1 = 0 #status = int(sample_data0.bGazeVectorFound) monoSample = [ 0, # experiment_id (filled in by ioHub) 0, # session_id (filled in by ioHub) 0, #device id (always 0 now) Computer._getNextEventID(), event_type, device_event_timestamp, logged_time, iohub_time, confidence_interval, event_delay, 0, # ioHub filter id (always 0 now) eye, gaze_x, gaze_y, EyeTrackerConstants.UNDEFINED, # gaze z EyeTrackerConstants.UNDEFINED, # x eye pos in space EyeTrackerConstants.UNDEFINED, # y eye pos in space EyeTrackerConstants.UNDEFINED, # z eye pos in space EyeTrackerConstants.UNDEFINED, # eye angle in head x EyeTrackerConstants.UNDEFINED, # eye angle in head y EyeTrackerConstants. UNDEFINED, # uncalibrated x eye pos EyeTrackerConstants. UNDEFINED, # uncalibrated y eye pos pupil_measure1, pupil_measure1_type, EyeTrackerConstants.UNDEFINED, # pupil measure 2 EyeTrackerConstants. UNDEFINED, # pupil measure 2 type EyeTrackerConstants.UNDEFINED, # pixels per degree x EyeTrackerConstants.UNDEFINED, # pixels per degree y EyeTrackerConstants.UNDEFINED, # sample velocity x EyeTrackerConstants.UNDEFINED, # sample velocity y EyeTrackerConstants.UNDEFINED, # 2D sample velocity status ] if status == 0: self._latest_gaze_position = gaze_x, gaze_y else: self._latest_gaze_position = None self._latest_sample = monoSample self._addNativeEventToBuffer(monoSample) elif self._camera_count == 2: #binocular event_type = EventConstants.BINOCULAR_EYE_SAMPLE sample_data1 = self._eyegaze_control.pstEgData[1] sample_data4 = self._eyegaze_control.pstEgData[4] status = 0 left_pupil_measure1 = sample_data4.fPupilRadiusMm left_gaze_x, left_gaze_y = sample_data4.iIGaze, sample_data4.iJGaze if left_gaze_x != 0.0 and left_gaze_y != 0.0 and left_pupil_measure1 > 0.0: left_gaze_x, left_gaze_y = self._eyeTrackerToDisplayCoords( (left_gaze_x, left_gaze_y)) else: status = 20 left_pupil_measure1 = 0 left_gaze_x = EyeTrackerConstants.UNDEFINED left_gaze_y = EyeTrackerConstants.UNDEFINED right_gaze_x, right_gaze_y = sample_data1.iIGaze, sample_data1.iJGaze right_pupil_measure1 = sample_data1.fPupilRadiusMm if right_gaze_x != 0.0 and right_gaze_y != 0.0 and left_pupil_measure1 > 0.0: right_gaze_x, right_gaze_y = self._eyeTrackerToDisplayCoords( (right_gaze_x, right_gaze_y)) else: status += 2 right_pupil_measure1 = 0 right_gaze_x = EyeTrackerConstants.UNDEFINED right_gaze_y = EyeTrackerConstants.UNDEFINED #status = int(sample_data4.bGazeVectorFound*2+sample_data1.bGazeVectorFound) binocSample = [ 0, # experiment_id (filled in by ioHub) 0, # session_id (filled in by ioHub) 0, #device id (always 0 now) Computer._getNextEventID(), event_type, device_event_timestamp, logged_time, iohub_time, confidence_interval, event_delay, 0, # ioHub filter id (always 0 now) # LEFT EYE DATA left_gaze_x, left_gaze_y, EyeTrackerConstants.UNDEFINED, # gaze z EyeTrackerConstants.UNDEFINED, # x eye pos in space EyeTrackerConstants.UNDEFINED, # y eye pos in space EyeTrackerConstants.UNDEFINED, # z eye pos in space EyeTrackerConstants.UNDEFINED, # eye angle in head x EyeTrackerConstants.UNDEFINED, # eye angle in head y EyeTrackerConstants. UNDEFINED, # uncalibrated x eye pos EyeTrackerConstants. UNDEFINED, # uncalibrated y eye pos left_pupil_measure1, pupil_measure1_type, EyeTrackerConstants.UNDEFINED, # pupil measure 2 EyeTrackerConstants. UNDEFINED, # pupil measure 2 type EyeTrackerConstants.UNDEFINED, # pixels per degree x EyeTrackerConstants.UNDEFINED, # pixels per degree y EyeTrackerConstants.UNDEFINED, # sample velocity x EyeTrackerConstants.UNDEFINED, # sample velocity y EyeTrackerConstants.UNDEFINED, # 2D sample velocity right_gaze_x, right_gaze_y, EyeTrackerConstants.UNDEFINED, # gaze z EyeTrackerConstants.UNDEFINED, # x eye pos in space EyeTrackerConstants.UNDEFINED, # y eye pos in space EyeTrackerConstants.UNDEFINED, # z eye pos in space EyeTrackerConstants.UNDEFINED, # eye angle in head x EyeTrackerConstants.UNDEFINED, # eye angle in head y EyeTrackerConstants. UNDEFINED, # uncalibrated x eye pos EyeTrackerConstants. UNDEFINED, # uncalibrated y eye pos right_pupil_measure1, pupil_measure1_type, EyeTrackerConstants.UNDEFINED, # pupil measure 2 EyeTrackerConstants. UNDEFINED, # pupil measure 2 type EyeTrackerConstants.UNDEFINED, # pixels per degree x EyeTrackerConstants.UNDEFINED, # pixels per degree y EyeTrackerConstants.UNDEFINED, # sample velocity x EyeTrackerConstants.UNDEFINED, # sample velocity y EyeTrackerConstants.UNDEFINED, # 2D sample velocity status ] self._latest_sample = binocSample g = [0.0, 0.0] if right_pupil_measure1 > 0.0 and left_pupil_measure1 > 0.0: g = [(left_gaze_x + right_gaze_x) / 2.0, (left_gaze_y + right_gaze_y) / 2.0] elif left_pupil_measure1 > 0.0: g = [left_gaze_x, left_gaze_y] elif right_pupil_measure1 > 0.0: g = [right_gaze_x, right_gaze_y] self._latest_gaze_position = g self._addNativeEventToBuffer(binocSample) else: # WTF print2err( "ERROR: EyeGaze reported camers count is invalid: ", self._camera_count) # Code below can be reused if fixation event detection is added. # # elif isinstance(ne,pylink.EndFixationEvent): # etype=EventConstants.FIXATION_END # # estatus = ne.getStatus() # # which_eye=ne.getEye() # if which_eye: # which_eye=EyeTrackerConstants.RIGHT_EYE # else: # which_eye=EyeTrackerConstants.LEFT_EYE # # start_event_time= ne.getStartTime()*DEVICE_TIMEBASE_TO_SEC # end_event_time = ne.event_timestamp # event_duration = end_event_time-start_event_time # # fee=[0, # 0, # Computer._getNextEventID(), # etype, # ne.event_timestamp, # ne.logged_time, # ne.timestamp, # confidenceInterval, # ne.event_delay, # 0, # which_eye, # event_duration, # s_gaze[0], # s_gaze[1], # EyeTrackerConstants.UNDEFINED, # s_href[0], # s_href[1], # EyeTrackerConstants.UNDEFINED, # EyeTrackerConstants.UNDEFINED, # s_pupilsize, # EyeTrackerConstants.PUPIL_AREA, # EyeTrackerConstants.UNDEFINED, # EyeTrackerConstants.UNDEFINED, # s_ppd[0], # s_ppd[1], # EyeTrackerConstants.UNDEFINED, # EyeTrackerConstants.UNDEFINED, # s_vel, # e_gaze[0], # e_gaze[1], # EyeTrackerConstants.UNDEFINED, # e_href[0], # e_href[1], # EyeTrackerConstants.UNDEFINED, # EyeTrackerConstants.UNDEFINED, # e_pupilsize, # EyeTrackerConstants.PUPIL_AREA, # EyeTrackerConstants.UNDEFINED, # EyeTrackerConstants.UNDEFINED, # e_ppd[0], # e_ppd[1], # EyeTrackerConstants.UNDEFINED, # EyeTrackerConstants.UNDEFINED, # e_vel, # a_gaze[0], # a_gaze[1], # EyeTrackerConstants.UNDEFINED, # a_href[0], # a_href[1], # EyeTrackerConstants.UNDEFINED, # EyeTrackerConstants.UNDEFINED, # a_pupilsize, # EyeTrackerConstants.PUPIL_AREA, # EyeTrackerConstants.UNDEFINED, # EyeTrackerConstants.UNDEFINED, # EyeTrackerConstants.UNDEFINED, # EyeTrackerConstants.UNDEFINED, # EyeTrackerConstants.UNDEFINED, # EyeTrackerConstants.UNDEFINED, # a_vel, # EyeTrackerConstants.UNDEFINED, # EyeTrackerConstants.UNDEFINED, # peak_vel, # estatus # ] # #EyeTracker._eventArrayLengths['FIXATION_END']=len(fee) # self._addNativeEventToBuffer(fee) # elif isinstance(ne,pylink.StartFixationEvent): # etype=EventConstants.FIXATION_START # # which_eye=ne.getEye() # if which_eye: # which_eye=EyeTrackerConstants.RIGHT_EYE # else: # which_eye=EyeTrackerConstants.LEFT_EYE # # # se=[ # 0, # exp ID # 0, # sess ID # Computer._getNextEventID(), # event ID # etype, # event type # ne.event_timestamp, # ne.logged_time, # ne.timestamp, # confidenceInterval, # ne.event_delay, # 0, # which_eye, # eye # gaze[0], # gaze x # gaze[1], # gaze y # EyeTrackerConstants.UNDEFINED, # gaze z # href[0], # angle x # href[1], # angle y # EyeTrackerConstants.UNDEFINED, # raw x # EyeTrackerConstants.UNDEFINED, # raw y # pupil_size, # pupil area # EyeTrackerConstants.PUPIL_AREA, # pupil measure type 1 # EyeTrackerConstants.UNDEFINED, # pupil measure 2 # EyeTrackerConstants.UNDEFINED, # pupil measure 2 type # ppd[0], # ppd x # ppd[1], # ppd y # EyeTrackerConstants.UNDEFINED, # velocity x # EyeTrackerConstants.UNDEFINED, # velocity y # velocity, # velocity xy # estatus # status # ] # self._addNativeEventToBuffer(se) except Exception: print2err("ERROR occurred during poll:") printExceptionDetailsToStdErr()
# start recording eyegaze_control.bTrackingActive = True # For the example, collect 1000+ samples of data samples_rx = 0 rec_start = timeit.default_timer() MAX_SAMPLES = 100 while samples_rx < MAX_SAMPLES: # This is the 'doing something else' part in the example. time.sleep(0.005) # we'll use async. mode, getting avail samples # and then 'do something else'. while eyegaze_control.iNPointsAvailable: pEyeGaze.EgGetData(byref(eyegaze_control)) # assume monocular for this example only. ;) sample_data0 = eyegaze_control.pstEgData[0] stime = sample_data0.dGazeTimeSec current_time = (pEyeGaze.lct_TimerRead(None) / 1000000.0 ) - pEyeGaze.EgGetApplicationStartTimeSec() delay = current_time - stime gaze_x = sample_data0.iIGaze gaze_y = sample_data0.iJGaze print 'Sample Time: {0}\t{1}\t{2}\tX: {3}\tY: {4}\ti: {5}'.format( stime, current_time, delay, gaze_x, gaze_y, samples_rx) samples_rx += 1 if samples_rx > MAX_SAMPLES: break rec_end = timeit.default_timer()