time_synchronization
首先官方Python - SDK reference guide中有一个time_synchronization_data.py的例子。官方注解如下:
You will get a callback when the computer and the eye trackers clocks gets synchronized. To handle normal drifts between clocks the clocks are checked on regular basis, and this results in that the time stamps are adjusted for the drifts in the data streams. This drift handling is done in real time.
The data received from this event could be used for an even more accurate drift adjustment in the post processing.
Callbacks will receive a TimeSynchronizationData object or a dictionary with values if as_dictionary is True.
中心思想能提高时间的漂移,提高时间同步的精度。
示例的代码,会间隔一段时间同时打印出三组时间戳
- system request time stamp
- device time stamp
- system response time stamp
此数据便是我们进行设备时间同步的关键依据。
- 但不理解的是这个模块内部运算规则是怎么进行的,三个时间戳间隔一段时间做差值进行比较?
- 哪一个时间戳是real time?
def execute(eyetracker):
time_synchronization_data(eyetracker)
# <BeginExample>
import time
import tobii_research as tr
def time_synchronization_data_callback(time_synchronization_data):
print(time_synchronization_data)
def time_synchronization_data(eyetracker):
print("Subscribing to time synchronization data for eye tracker with serial number {0}.".
format(eyetracker.serial_number))
eyetracker.subscribe_to(tr.EYETRACKER_TIME_SYNCHRONIZATION_DATA,
time_synchronization_data_callback, as_dictionary=True)
# Wait while some time synchronization data is collected.
time.sleep(2)
eyetracker.unsubscribe_from(tr.EYETRACKER_TIME_SYNCHRONIZATION_DATA,
time_synchronization_data_callback)
print("Unsubscribed from time synchronization data.")
利用这个模块,记录下三个时间戳,并将需要运行的程序放到subscribe_to 和 unsubscribe_from两行之间。
EYETRACKER_GAZE_DATA
眼动数据采集,主要EYETRACKER_GAZE_DATA函数实现,其中在每次采样的过程中gaze_data字典中会保存有采样的device time stamp 和 system time stamp,方便我们记录
import time
import tobii_research as tr
global_gaze_data = None
def gaze_data_callback(gaze_data):
global global_gaze_data
global_gaze_data = gaze_data
def gaze_data(eyetracker):
global global_gaze_data
print("Subscribing to gaze data for eye tracker with serial number {0}.".format(eyetracker.serial_number))
eyetracker.subscribe_to(tr.EYETRACKER_GAZE_DATA, gaze_data_callback, as_dictionary=True)
# Wait while some gaze data is collected.
time.sleep(2)
eyetracker.unsubscribe_from(tr.EYETRACKER_GAZE_DATA, gaze_data_callback)
print("Unsubscribed from gaze data.")
print("Last received gaze package:")
print(global_gaze_data)
get_system_time_stamp()
对于其他程序的运行,我们这里只需要使用tr.get_system_time_stamp()得到系统时间戳便可以为用于后期数据处理时的时间同步。
system_time_stamp = tr.get_system_time_stamp()