Tobii眼动仪 python SDK 时间同步的技巧

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()
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值