跳转到内容

PTP 与网络时间同步

当前的头戴采集设备靠线而不是靠网络让自己的各台相机保持同步。例如,RoboCap 的六相机帽子让六台相机全部 “from a single PWM frame-synchronization signal generated by the main controller and fanned out through a 1-to-6 clock buffer”(意为:由主控制器产生、经一个 1 分 6 时钟缓冲器扇出的单一 PWM 帧同步信号)来曝光(Ali et al., 2026),Meta 的 Ego-1K 采集设备在一台 Quest 3 头显周围布置了 “12 synchronized cameras”(意为:12 台同步的相机)(Lee et al., 2026)。这属于硬件同步,它留在佩戴者身上。

网络时间解决的是佩戴者周围的问题:第一人称与第三人称(ego-exo)采集空间中固定在房间里的相机、深度传感器,以及各自给自己的传感器打时间戳的多台录制计算机。本页深入讲解精确时间协议(Precision Time Protocol,PTP)及其 Linux 工具、缺少 PTP 硬件时作为后备方案的 chrony,以及以太网机器视觉相机如何利用 PTP 一起曝光。概览(含每种方法的精度数字)见软件同步与视觉同步和同步方法对比。偏移、漂移和抖动等术语的定义见为什么同步很重要。

实用指南的全部术语按主题分组集中在一处,见术语表。

术语 含义
PTP(IEEE 1588) 一种通过交换带时间戳的报文、在以太网上同步时钟的协议。相机和 Linux 工具实现的是 IEEE 1588-2008,“also known as PTP Version 2”(意为:也称为 PTP 第 2 版)(Basler)。
最高级主时钟(grandmaster clock) PTP 网络的根时间源,“often receiving highly accurate time information from sources like Global Positioning System (GPS) or atomic clocks”(意为:通常从全球定位系统(GPS)或原子钟等来源接收高精度的时间信息)(e-con Systems)。
普通时钟(ordinary clock) 只有一个 PTP 端口的终端设备,例如一台相机或一台录制 PC。
边界时钟(boundary clock) 有多个 PTP 端口的设备,例如 PTP 交换机,它在一个端口上从上游取得时间,在其他端口上向下提供时间。
透明时钟(transparent clock) 一种 PTP 交换机,它转发 PTP 报文,并按报文在它内部停留的时间对报文做修正。ptp4l 实现了端到端和对等两种变体(ptp4l(8))。
PHC(PTP 硬件时钟) 网卡自身上的一个时钟。使用硬件时间戳时,PTP 数据包在发送和接收的时刻由这个时钟打时间戳(Red Hat)。
时间同步(synchronise)与频率同步(syntonise) PTP 两者都做:它把每个本地时钟设置得 “as precisely as possible to the time of the master clock”(意为:尽可能精确地与主时钟的时间一致),并调整它的频率,使 “the duration of a second”(意为:一秒的时长)相同(Basler)。
E2E 延迟与 P2P 延迟 PTP 测量路径延迟的两种方式:在每台设备与主时钟之间做端到端测量(“delay request-response”(意为:延迟请求-响应)),或者逐段链路做对等测量(Basler)。
一步(one-step)与两步(two-step) 在一步方式下 “one message is sent”(意为:只发送一条报文),它自带发出时刻的时间戳;在两步方式下,由第二条报文携带这个时间戳(Basler)。
ARB 时间尺度 没有任何设备跟随世界时间(TAI 或 UTC)时,PTP 网络所运行的任意时间尺度。
定时动作命令(scheduled action command) GigE Vision 2.0 的一种命令,它让相机在给定的未来 PTP 时间执行动作,例如开始一次曝光。

PTP 如何校准一个网络中的各个时钟

Section titled “PTP 如何校准一个网络中的各个时钟”

没有同步时,每台相机从上电起靠自己的晶振计数。Sony 的工程师描述了联网相机会出现的结果:“these time stamps gradually go out of synchronization as time passes owing to discrepancies in the clocks’ frequencies”(意为:由于各时钟的频率存在差异,这些时间戳会随着时间推移逐渐失去同步)(Eikawa, 2017)。PTP 与主时钟交换带时间戳的报文,并修正其他每个时钟的偏移和速率。

The PTP delay request-response exchange Two timelines running down the page, the master clock on the left and a camera's clock on the right. The master sends a Sync message at time t1 on its clock; the camera receives it at t2 on its own clock. In two-step mode a Follow_Up message then carries the exact value of t1. The camera sends a Delay_Req at t3; the master receives it at t4 and returns t4 in a Delay_Resp message. With all four timestamps the camera computes the mean path delay as ((t2 minus t1) plus (t4 minus t3)) divided by 2, and its offset from the master as ((t2 minus t1) minus (t4 minus t3)) divided by 2, then corrects its clock. The calculation assumes the delay is the same in both directions; any asymmetry, for example a switch that queues packets for varying times, turns into offset error. Master clock Camera clock t1 t2 t3 t4 Sync Follow_Up (carries t1) Delay_Req Delay_Resp (carries t4) time mean path delay [(t2 − t1) + (t4 − t3)] / 2 camera offset from master [(t2 − t1) − (t4 − t3)] / 2 Assumes the delay is equal both ways. Any asymmetry, such as a switch queuing packets for varying times, becomes offset error.
The IEEE 1588 delay request-response exchange. Four timestamps, two taken on each clock, give both the path delay and the camera's offset from the master, which the camera then corrects. The maths assumes the delay is the same in both directions, which is why non-PTP switches that queue packets unevenly show up as offset error.

各设备自动选举出一个主时钟。Basler:“The master clock is determined by several criteria. The criterion with the highest precedence is the device’s Priority 1 setting”(意为:主时钟由若干条准则决定。优先级最高的准则是设备的 Priority 1 设置),以及 “The network device with the lowest Priority 1 setting is the master clock”(意为:Priority 1 设置值最低的网络设备就是主时钟)(完整规则见 IEEE 1588-2008 第 7.6.2.2 条)。在 Basler ace 2 和 dart M 相机上,BslPtpPriority1 可以设为 “between 0 (highest priority) and 255 (lowest priority)”(意为:0(最高优先级)到 255(最低优先级)之间),用来强制或阻止某台相机成为主时钟;在其他 Basler 型号上,它 “is preset to 128 and can’t be changed”(意为:预设为 128,不能更改)(Basler)。要让一台 Linux PC 或一台 GPS 最高级主时钟胜出,就给它一个比相机更低的 Priority 1。

PTP 网络内部彼此一致,但不一定与外部世界一致。Basler:“If no device in the network is synchronized to a coordinated world time (e.g., TAI or UTC), the network will operate in the arbitrary timescale mode (ARB). In this mode, the epoch is arbitrary, as it is not bound to an absolute time.”(意为:如果网络中没有任何设备同步到某个协调的世界时间(例如 TAI 或 UTC),网络将运行在任意时间尺度模式(ARB)下。在这种模式下,纪元是任意的,因为它没有绑定到绝对时间。)SVS-Vistek 说的是同一点:“If a fixed relation to the real world time is to be established, a separate device based on Network Time Protocol (NTP) or Global Positioning System (GPS) must take over the function of the master”(意为:如果要与现实世界的时间建立固定关系,就必须由一台基于网络时间协议(NTP)或全球定位系统(GPS)的独立设备来承担主时钟的功能)(SVS-Vistek)。如果你需要把带 PTP 时间戳的房间视频与其他时钟上的设备对齐,要么用 GPS 或 NTP 给最高级主时钟提供时间,要么加一个每台设备都能看到的视觉同步事件。

为 GigE Vision 相机编写采集软件时,有两个细节很重要(Basler):

  • 时间戳位宽。“IEEE 1588 defines 80-bit timestamps for storing and transporting time information. Because GigE Vision uses 64-bit timestamps, the PTP timestamps are mapped to the 64-bit timestamps of GigE Vision.”(意为:IEEE 1588 定义了 80 位的时间戳来存储和传输时间信息。由于 GigE Vision 使用 64 位时间戳,PTP 时间戳被映射到 GigE Vision 的 64 位时间戳上。)
  • 计时节拍(tick)频率。“On ace Classic/U/L cameras, enabling PTP clock synchronization changes the camera’s internal tick frequency from 125 MHz (= 8 ns tick duration) to 1 GHz (= 1 ns tick duration)”(意为:在 ace Classic/U/L 相机上,启用 PTP 时钟同步会把相机内部的 tick 频率从 125 MHz(即每个 tick 8 ns)改为 1 GHz(即每个 tick 1 ns));“On other cameras, the tick frequency is always 1 GHz.”(意为:在其他相机上,tick 频率始终是 1 GHz。)把 tick 换算成秒的代码必须知道适用的是哪一种。

PTP 的精度取决于数据包在哪里被打上时间戳。Red Hat:“Hardware PTP support provides better accuracy since the NIC can time stamp the PTP packets at the exact moment they are sent and received while software PTP support requires additional processing of the PTP packets by the operating system.”(意为:硬件 PTP 支持的精度更好,因为网卡可以在 PTP 数据包发送和接收的确切时刻给它们打时间戳,而软件 PTP 支持需要操作系统对 PTP 数据包做额外处理。)有硬件支持时,“PTP is capable of sub-microsecond accuracy, which is far better than is normally obtainable with NTP”(意为:PTP 能达到亚微秒级精度,远好于 NTP 通常能达到的水平)(Red Hat)。Red Hat 没有给出软件时间戳的数字。

交换机和网卡同样重要。普通交换机让数据包排队的时间长短不一。Red Hat 警告说,非 PTP 硬件 “will often cause an increase in jitter or introduce an asymmetry in the delay resulting in synchronization inaccuracies”(意为:常常会使抖动增大,或在延迟中引入不对称,从而导致同步不准),并建议 “that all networking components between PTP clocks are PTP hardware enabled”(意为:PTP 时钟之间的所有网络组件都具备 PTP 硬件支持)。Basler 的建议相同:“For maximum precision, choose high-quality network hardware, use PTP-enabled network switches, and add an external PTP clock device with a GPS receiver to your network.”(意为:要获得最高精度,请选择高质量的网络硬件,使用支持 PTP 的网络交换机,并在网络中加入一台带 GPS 接收机的外部 PTP 时钟设备。)

协议设置必须在整个网络中一致。Basler 为其相机记载了三项:

设置 选项 Basler 的说法
延迟机制 E2E(默认)或 P2P “In most cases, use end-to-end delay measurement. Only use peer-to-peer if your entire network is set up for peer-to-peer delay measurement.”(意为:大多数情况下使用端到端延迟测量。只有当你的整个网络都按对等延迟测量来设置时,才使用对等方式。)使用 P2P 时,网络模式 “can’t be set to Hybrid”(意为:不能设为 Hybrid),并且相机 “always operates in two-step mode”(意为:始终以两步模式工作)。较早的型号固定为 E2E。
一步或两步 一步或两步 在 ace 2 和 dart M 上,“two-step operation is disabled by default”(意为:两步方式默认禁用);在其他型号上,“two-step operation is always enabled”(意为:两步方式始终启用)。
网络模式 Multicast(多播,默认)、Hybrid(混合)、Unicast(单播) Multicast “is the default mode and sufficient for most use cases”(意为:是默认模式,足以满足大多数使用场景)。Hybrid 混合使用多播和单播;“This saves network load”(意为:这样可以减轻网络负载)。Unicast 要求每台设备都 “support unicast negotiation”(意为:支持单播协商)。

在 Linux 上,PTP 靠 linuxptp 运行,它是 “a PTPv2 implementation according to the IEEE standard 1588 for Linux”(意为:按照 IEEE 1588 标准为 Linux 实现的 PTPv2)(Red Hat)。一台 Linux PC 可以是跟随网络的普通时钟,也可以是相机所跟随的最高级主时钟。

程序 它做什么(摘自 linuxptp 手册索引)
ptp4l 在网络端口上运行 PTP:“PTP Boundary/Ordinary/Transparent Clock”(意为:PTP 边界时钟/普通时钟/透明时钟)。
phc2sys “Synchronize two or more clocks”(意为:同步两个或更多时钟),通常是系统时钟和网卡的 PHC。
ts2phc “Synchronizes one or more PTP Hardware Clocks using external time stamps”(意为:使用外部时间戳同步一个或多个 PTP 硬件时钟),例如 GPS 秒脉冲的边沿。
pmc “PTP management client”(意为:PTP 管理客户端),用于查询正在运行的 ptp4l。
phc_ctl 直接控制一个 PHC。
hwstamp_ctl 设置 “time stamping policy at the driver level”(意为:驱动层的时间戳策略)。
timemaster 运行 “NTP with PTP as reference clocks”(意为:以 PTP 作为参考时钟的 NTP)。

用 ethtool -T eth3 查询网络接口(把 eth3 换成你的接口)。Red Hat 列出了需要查找的标志。硬件时间戳需要 SOF_TIMESTAMPING_RAW_HARDWARE、SOF_TIMESTAMPING_TX_HARDWARE 和 SOF_TIMESTAMPING_RX_HARDWARE;软件时间戳需要 SOF_TIMESTAMPING_SOFTWARE、SOF_TIMESTAMPING_TX_SOFTWARE 和 SOF_TIMESTAMPING_RX_SOFTWARE。输出中还给出网卡的 PTP Hardware Clock 索引;索引 0 就是设备 /dev/ptp0。

终端窗口
# Hardware timestamping (the default), end-to-end delay (the default), log to stdout
ptp4l -i eth3 -m
# A card without hardware timestamping
ptp4l -i eth3 -m -S
# Peer-to-peer delay, only if every switch on the path supports it
ptp4l -i eth3 -m -P

摘自 ptp4l 手册:-i 指定一个端口,-m 把消息打印到标准输出,-H 和 -S 分别选择硬件时间戳和软件时间戳,-E 选择端到端延迟,“This is the default mechanism”(意为:这是默认机制)。-s 启用仅客户端模式,它使这台 PC 永远不会成为主时钟。Red Hat:“Do not run more than one service to set the system clock’s time at the same time”(意为:不要同时运行一个以上的服务来设置系统时钟的时间),所以要让 chronyd、ntpd 或 systemd-timesyncd 停止调节同一个时钟。

第 3 步:在网卡时钟和系统时钟之间搭桥

Section titled “第 3 步:在网卡时钟和系统时钟之间搭桥”

使用硬件时间戳时,ptp4l 调节的是网卡上的时钟,而不是计算机的系统时钟(CLOCK_REALTIME),而大多数录制软件给帧打时间戳用的正是后者。Red Hat:“The phc2sys program is needed only with hardware time stamping, for synchronizing the system clock to the PTP hardware clock on the network interface card”(意为:phc2sys 程序只在使用硬件时间戳时才需要,用于把系统时钟同步到网卡上的 PTP 硬件时钟)。方向取决于这台 PC 的角色(phc2sys 手册):

终端窗口
# PC follows the PTP network: copy the card's clock into the system clock,
# waiting until ptp4l is synchronised
phc2sys -s eth3 -w -m
# PC is the grandmaster for the cameras: copy the system clock into the card
phc2sys -c eth3 -s CLOCK_REALTIME -w -m
# Or let phc2sys follow ptp4l's port state and choose the direction itself
phc2sys -a -r

-s 指定源时钟,-c 指定要调节的时钟(默认是 CLOCK_REALTIME);-w 的意思是 “Wait until ptp4l is in a synchronized state”(意为:等待直到 ptp4l 处于已同步状态);-a 从正在运行的 ptp4l 读取各个时钟并跟随端口状态的变化,而且必须加上 -r 才会去调节系统时钟。

设置了 -u(汇总更新)后,phc2sys 打印汇总行,例如 Red Hat 的示例 rms 194 max 457 freq -37084 ± 174 delay 2753 ± 12。默认情况下它打印的是每个采样;phc2sys(8) man page 写道:“If zero, the individual samples are printed instead of the statistics.”(意为:如果为零,则打印各个采样而不是统计量。)以及 “The default is 0 (disabled).”(意为:默认值为 0(禁用)。)例如加上 -u 60,就可以每 60 次时钟更新得到一行汇总。在汇总行中,前两个值是汇总区间内偏移的 RMS 和最大值,单位为纳秒;freq 是频率修正量,单位为十亿分之一(ppb);delay 是读取网卡时钟所花的时间。在一次采集过程中要盯着 rms 和 max;最大值上升,或 ptp4l 日志中端口状态发生变化(例如离开 SLAVE),都标志着这一次录制的时间戳需要检查。

缺少 PTP 硬件时:使用 chrony 的 NTP

Section titled “缺少 PTP 硬件时:使用 chrony 的 NTP”

许多小型计算机和笔记本电脑没有硬件 PTP 支持,许多交换机也不支持 PTP。这时,NTP 的一种实现 chrony 就是让各台录制计算机保持一致的实用选择,而且在本地网络上,它能做得比 NTP 的名声更好。chrony FAQ 说,有了 “local hardware timestamping, good network switches, and even shorter polling intervals, a sub-microsecond accuracy and stability of a few tens of nanoseconds might be possible.”(意为:本地硬件时间戳、好的网络交换机,以及更短的轮询间隔,亚微秒级的精度和几十纳秒的稳定度是有可能达到的。)没有这些条件时,精度取决于网络抖动:在 chrony 自己的仿真对比中,网络抖动为 10 µs 时客户端的时钟误差是 35 ± 8 µs,抖动为 10 ms 时是 1603 ± 447 µs。

采集空间通常没有可以依赖的互联网时间,所以由一台机器向其余机器提供时间。下面的配置指令来自 chrony.conf 手册:

# On the time server (one recording PC)
local stratum 8 # serve time even with no upstream source
allow 192.168.10.0/24 # let the capture subnet query this server
hwtimestamp * # use NIC hardware timestamps where supported
# On every other recording PC
server 192.168.10.1 iburst xleave
hwtimestamp *

iburst 让第一次更新更快;xleave “enables the interleaved mode of NTP”(意为:启用 NTP 的交错模式),它与硬件时间戳配合 “can significantly improve the accuracy and stability of the measurements”(意为:可以显著提高测量的精度和稳定度);hwtimestamp “enables hardware timestamping of NTP packets sent to and received from the specified network interface”(意为:对从指定网络接口发出和收到的 NTP 数据包启用硬件时间戳)。用 chronyc tracking 和 chronyc sources 检查结果(chronyc 手册)。

无论哪一种时钟同步,对齐的都是计算机的时钟。它不会对齐 USB 相机实际曝光的时刻:如果帧是在到达时打时间戳,为什么同步很重要中描述的 USB 延迟和操作系统延迟仍然存在。

在 GigE Vision 相机上启用并验证 PTP

Section titled “在 GigE Vision 相机上启用并验证 PTP”

Basler 的文档是最详细的公开流程,其他 GenICam 相机按各自的参数名执行类似的步骤(Basler):

  1. 启用 PTP。“When powering on the camera, PTP is always disabled. If you want to use PTP, you must enable it.”(意为:相机上电时,PTP 总是禁用的。如果要使用 PTP,必须启用它。)把 GevIEEE1588 设为 true(在 ace 2 和 dart M 上是 PtpEnable)。如果由外部设备担任主时钟,“Basler recommends an ANNOUNCE interval of 2 seconds and a SYNC interval of 0.5 seconds.”(意为:Basler 建议 ANNOUNCE 间隔为 2 秒,SYNC 间隔为 0.5 秒。)
  2. 等待。“Depending on your network setup, this may take a few seconds or minutes.”(意为:视你的网络配置而定,这可能需要几秒或几分钟。)
  3. 锁存一份快照。执行 GevIEEE1588DataSetLatch(或 PtpDataSetLatch),这样 “all parameter values in the latched data set refer to exactly the same point in time”(意为:锁存的数据集中的所有参数值对应的是完全相同的时间点)。读取 GevIEEE1588StatusLatched 而不是 GevIEEE1588Status,后者 “is not tied to the GevIEEE1588DataSetLatch command”(意为:与 GevIEEE1588DataSetLatch 命令没有关联)。
  4. 等到状态不再是 Initializing。
  5. 检查锁定。在 ace 2 和 dart M 上,“If the parameter value is Locked, the respective device should be sufficiently synchronized.”(意为:如果参数值为 Locked,相应的设备应该已经充分同步。)在其他相机上,从每台从设备读取 GevIEEE1588OffsetFromMaster,“until the highest offset from master is below a certain threshold (according to your requirements, e.g., 1 millisecond)”(意为:直到相对主时钟的最大偏移低于某个阈值(按你的要求确定,例如 1 毫秒))。由于伺服一直在调整,“the offset is not decreasing monotonically. Basler recommends that you check the maximum GevIEEE1588OffsetFromMaster parameter value within a given time window”(意为:偏移并不是单调减小的。Basler 建议你检查给定时间窗口内 GevIEEE1588OffsetFromMaster 参数的最大值)。阈值要根据你自己的误差预算来定。
参数 它报告或控制什么
GevIEEE1588 / PtpEnable 打开 PTP;每次上电时都是关闭的。
BslPtpPriority1 ace 2 和 dart M 上的 Priority 1,0 到 255;最低者胜出。
GevIEEE1588DataSetLatch / PtpDataSetLatch 对 PTP 状态取一份前后一致的快照。
GevIEEE1588StatusLatched 端口状态:Initializing、Faulty、Disabled、Listening、Pre_Master、Master、Passive、Uncalibrated 或 Slave。
PtpServoStatus 已同步时为 Locked,否则为 Unknown(ace 2 和 dart M)。
GevIEEE1588OffsetFromMaster “estimated temporal offset between the master clock and the clock of the current PTP device in ticks (1 tick = 1 nanosecond)”(意为:主时钟与当前 PTP 设备的时钟之间估计的时间偏移,以 tick 为单位(1 tick = 1 纳秒))。
GevIEEE1588ParentClockId / PtpGrandmasterClockID 当前主时钟或最高级主时钟的 ID。每台相机报告的应该是同一个。

公共的 PTP 时钟给出的是同步的时间戳,不是同步的曝光(见“同步”的两种含义)。两台自由运行的 30 fps 相机,即使时钟完全一致,曝光的相位仍然可以毫无关系,所以它们最接近的两帧最多可相差半个帧周期:33.3 / 2 = 16.7 ms。

GigE Vision 增加了一种解决办法。早先的动作命令是同时发给所有相机的,但 “there were still some inconclusive elements, such as delays in network propagation and delays in firmware processing”(意为:仍然存在一些不确定的因素,例如网络传播的延迟和固件处理的延迟)。GigE Vision 2.0 把它们与 IEEE 1588 结合起来,于是每台相机被告知的是一个执行动作的时间,而不是在数据包到达时就执行(Eikawa, 2017)。Basler 列出的 PTP 在其相机上启用的功能有 “Periodic Signal”(意为:周期信号)、“Scheduled Action Commands”(意为:定时动作命令)和 “Synchronous Free Run”(意为:同步自由运行)。

已发表的数字都是厂商的说法:

  • Sony。对于曝光起点与最高级主时钟对齐的自由运行相机:“Although this is affected by the network environment, it is ideally possible for exposure synchronous control to be performed within 1μs”(意为:虽然这会受网络环境影响,但理想情况下曝光同步控制可以做到 1μs 以内),图注为 “it is possible to drive exposure synchronization to within ±1μs”(意为:可以把曝光同步做到 ±1μs 以内)(Eikawa, 2017)。
  • SVS-Vistek。“The maximum deviation that can be achieved is 10 µs, which enables very precise synchronization of all devices involved”(意为:可以达到的最大偏差为 10 µs,这使所有相关设备能够非常精确地同步)(SVS-Vistek)。

Sony 指出,使用以太网供电(Power over Ethernet)时,“only one cable is required for exposure synchronization, image output and the power supply.”(意为:曝光同步、图像输出和供电只需要一根线缆。)

  • 没有即时触发。SVS-Vistek:“It is necessary to know the future time of triggering (ad-hoc event-based triggering is not possible)”(意为:必须知道未来的触发时间(无法做临时的、基于事件的触发)),以及 “A common immediate trigger (“NOW I want to trigger all cameras”) is not supported by PTP.“(意为:PTP 不支持公共的即时触发(“我现在就要触发所有相机”)。)事件驱动的采集仍然需要一根线。
  • 不支持 PTP 的设备。2017 年,Sony 把相机的通用输出与 PTP 时间关联起来这件事描述为一项计划(“Sony is planning to link the new camera series to GPO”(意为:Sony 正计划把新的相机系列与 GPO 关联起来)),而不是已经发货的功能,所以要核实你的相机的输出能做什么。反过来,GPS 接收机或微控制器的秒脉冲信号可以通过 ts2phc 校准一台 Linux 最高级主时钟的网卡;PPS 见硬件同步页面。

这些提示词要的是你自己能检查的代码;在信任输出之前先读一遍。

用 pypylon 写一个 Python 脚本,打开找到的每一台 Basler GigE 相机,启用 PTP
(ace 2 / dart M 上用 PtpEnable,其他型号上用 GevIEEE1588),然后阻塞,直到
所有相机都已同步,检查方法按 Basler 文档的做法:执行 DataSetLatch 命令,读取
GevIEEE1588StatusLatched 并等到它不再是 Initializing;在有 PtpServoStatus 的
相机上等待它变为 Locked;否则每秒采样一次 GevIEEE1588OffsetFromMaster
(1 tick = 1 ns),只有当滚动窗口内的最大绝对偏移一直低于阈值时才算通过。
阈值、窗口长度和总超时时间都作为必填的命令行参数,不设默认值。检查所有相机
报告的 GevIEEE1588ParentClockId 相同,等待期间打印一张状态表,超时则以错误
退出。
写一个 Python 脚本,解析一次采集过程中记录的 `ptp4l -m` 和 `phc2sys -m` 日志,
外加一个记录每次录制开始和结束时间的 CSV。提取随时间变化的偏移(ns)、频率
(ppb)和延迟,以及每一次端口状态变化。对每一次录制,报告偏移的 RMS 和最大
绝对值以及任何状态变化,并标记出最大偏移超过命令行给定阈值的录制。每次录制
保存一张图。