# Timing And Latency

> Generated from repository source files. Do not edit this page directly; edit the source file listed below and rerun `vp run docs:generate`.

> Source: `system/timing-and-latency.md`

## Timing And Latency

Status: `runtime binding draft`

Timing fields should be logged through the runtime records in `system/runtime-interfaces.md` and the trial log schema in `experiments/templates/trial-log-schema.md`.

## Timebase Rule

Use `monotonic_ns` as the primary timebase for latency analysis. Use `wall_time_iso8601` only for human-readable audit trails. Evidence-producing multi-host sessions require a synchronization record that states the method, devices involved, estimated error bound, and failure rule.

## Timing Budget To Measure

| Segment | Metric |
| --- | --- |
| camera frame to YOLO output | detection latency |
| YOLO output to candidate freeze | candidate management latency |
| stimulus onset to EEG marker | sync latency |
| EEG window to SSVEP output | decoding latency |
| MI cue/window to mode command | decoding latency |
| fusion decision to robot command | control latency |
| robot plan to first movement | planning latency |
| approach to grasp completion | execution time |

## Latency Derivation

| Segment | Start Record | End Record | Required Output |
| --- | --- | --- | --- |
| detection latency | `VisionFrame.monotonic_ns` | `ObjectDetection.monotonic_ns` | per-frame detector latency |
| candidate freeze latency | latest input detection | `CandidateFreezeSet.monotonic_ns` | candidate-manager latency |
| stimulus sync latency | `StimulusBinding.monotonic_ns` | linked EEG marker/window start | stimulus-to-EEG sync estimate |
| SSVEP decoding latency | `EEGWindow` end time | `SSVEPDecision.monotonic_ns` | decoder latency |
| MI decoding latency | `EEGWindow` end time | `MIDecision.monotonic_ns` | decoder latency |
| fusion latency | latest accepted decoder decision | `FusedIntent.monotonic_ns` | arbitration latency |
| planning latency | `FusedIntent.monotonic_ns` | `RobotPlan.monotonic_ns` | planner latency |
| execution time | `RobotExecution.started_at` | `RobotExecution.ended_at` | robot execution time |

Hardware details are not yet known. Record EEG sampling rate, display refresh rate, camera frame rate, robot control period, and timestamp synchronization method before experiments.

Clock synchronization method and middleware logging behavior must be frozen in `experiments/pre-data-freeze-checklist.md`.
