Timestamps & external time sync
Use the Glove millisecond time model and, when needed, align it to an external absolute time reference.
Timestamps & external time sync
Regular Glove SDK timestamps use milliseconds. Call sync_time() only when the application must align with an external system or make several Glove sources share one absolute time reference. A regular standalone Glove application can keep the default time reference.
Newly generated device status timestamps and their Sample.source_time, CaptureResult.created_at, and CalibrationResult.created_at also follow the current synchronized reference. Previously published samples and saved results retain their original timestamps. Sample.observed_at, timeouts, and scheduling waits remain on the SDK monotonic clock and are unaffected by synchronization.
Time units
Regular timestamps in Glove frames, runtime state, capture, calibration and SDK-derived data use milliseconds; event-time fields ending in _us use microseconds. Do not read, store, subtract, or forward these fields as seconds.
Use timestamp_ms for external input. See ExternalGloveFrame for the complete field definition and Data channels & read methods for the available sources and read paths.
Time reference
Default time reference
Without sync_time(), the SDK uses host Unix milliseconds. When an external frame omits timestamp_ms, that frame follows the current shared Glove time reference.
Keep the default behavior when the application reads one or more gloves on the same host and does not need alignment with another system.
External time reference
Pass the absolute Unix time in milliseconds from the external clock to Glove.sync_time(). Synchronizing before start() is recommended:
Save the following code as time_sync.py. It uses host Unix milliseconds; replace the source of reference_time_ms when connecting an external clock.
import time
from threading import Event
from qnbot_sdk import Sdk
from qnbot_sdk.glove import GloveConfig
sdk = Sdk(devices=(GloveConfig(),))
glove = sdk.glove()
try:
glove.device().pose().subscribe(
lambda sample: print(sample.sequence, sample.source_time, sample.observed_at)
)
reference_time_ms = time.time() * 1_000.0
glove.sync_time(reference_time_ms)
glove.start()
Event().wait()
finally:
glove.close()The argument must be finite milliseconds. Run python time_sync.py with a glove connected to print the sample sequence, source time and observation time. Press Ctrl+C to stop.
Resynchronizing while running
Call sync_time() again when the external clock is updated. Subsequent Glove frames without an explicit timestamp advance from the new reference without resetting subscriptions or lifecycle state.
updated_reference_time_ms = time.time() * 1_000.0
glove.sync_time(updated_reference_time_ms)When resynchronizing at runtime, do not move reference_time_ms behind the previous frame submitted for the same external-input device.
External input requires strictly increasing timestamps; push_frame() rejects a frame when its SDK-generated timestamp is not greater than the previous frame's timestamp.
Timestamps
SDK-generated timestamps
The SDK stamps physical Glove frames from the current shared Glove time reference. SDK-derived results, such as skeleton poses, retain the time of the corresponding input frame. Applications read these timestamps and do not need to supply them.
External input also receives an SDK-generated timestamp when both timestamp_ms and timestamp_sec are omitted. Without sync_time(), it comes from host Unix milliseconds. After synchronization, the SDK calculates it as the most recent synchronization value plus the elapsed time and keeps values generated by the shared clock increasing.
External-input timestamps
Only an ExternalGloveFrame requires the application to decide whether to provide an explicit timestamp:
- An explicit
timestamp_mstakes precedence and is not overwritten by the shared time reference. - When only
timestamp_secis provided, the SDK retains compatibility with existing code by converting it astimestamp_ms = timestamp_sec * 1000. - When both fields are omitted, the SDK-generated timestamp described above is used.
Do not set timestamp_ms and timestamp_sec together; supplying both is an argument error. An explicit timestamp must be a finite millisecond value and strictly increasing for the same device. See External input for the complete configuration and frame constraints.
Shared status and record time
The status and record timestamps below share one time basis.
Status and SDK-timestamped Glove frames use the latest synchronization reference plus elapsed milliseconds.
Without explicit synchronization, the default is host Unix milliseconds. Newly completed Capture and Calibration results
read that current time basis for created_at; resynchronization during a workflow affects timestamps created afterwards.
Saved records and published samples keep their original timestamps. If resynchronization changes the reference, compare source times within each reference or convert them to a common clock before comparing across references.
observed_at and runtime waits/timeouts remain monotonic and are unaffected by sync_time().
Explicit ExternalGloveFrame.timestamp_ms values are not overwritten either.
Keep the original time basis when reading device-relative status timestamps from older SDK versions.
See Migration for the required actions.