> ## Documentation Index
> Fetch the complete documentation index at: https://docs.altnautica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Sensors and clock

> The sensor bus, the clock service that times every sample, the USB sensor hub, the rig file, and the sensor and clock routes.

Capture and navigation need every sample on one timeline: an IMU reading, a camera trigger and a GNSS fix taken at the same instant must carry the same timestamp, whichever device produced it. The agent does this with three pieces:

| Piece | Service | Job |
| - | - | - |
| Sensor bus | `ados-clock` | One local socket every producer publishes to and every reader subscribes to. |
| Clock | `ados-clock` | Fits each time source against the host clock and picks the timebase a capture records against. |
| Sensor hub | `ados-sensorhub` | Reads the USB sensor hub and puts its IMU, trigger, barometer, magnetometer and GNSS data on the bus. |

`ados-clock` runs on the `drone`, `ground_station` and `visor` profiles. `ados-sensorhub` runs on `drone` and `visor`.

## The sensor bus

The bus is the socket `/run/ados/sensing/sensors.sock`. Each frame is length-prefixed msgpack with a `kind` (`clock`, `imu`, `gnss`, `trigger`, `baro`, `mag`, `rtcm`, `sync`), a source id and a payload, and every sample is stamped on the host monotonic timebase.

| Producer | What it publishes |
| - | - |
| `ados-clock` | A `clock` frame once a second. |
| `ados-mavlink-router` | The flight controller's IMU and camera triggers. |
| `ados-sensorhub` | Hub IMU (`imu<id>`), triggers (`cam<i>`), barometer, magnetometer, raw GNSS, and `sync` pairs. |
| `ados-gnss` | Receiver bytes, base RTCM3 corrections and PPS `sync` pairs. See [GNSS and RTK](https://docs.altnautica.com/ground-agent/gnss-rtk.md). |

An extension reads the bus with the `sensor.stream.read` capability, which gives it the whole `/run/ados/sensing/` directory, so it follows the socket across restarts.

## The clock

`ados-clock` fits every source that publishes `sync` pairs (flight controller, sensor hub, GNSS PPS, simulator) against the host monotonic clock, and tracks the rate and freshness of every stream on the bus. Once a second it writes `/run/ados/sensing/clock.json` and `/run/ados/sensors.json`. A locked GNSS PPS source is also handed to chrony through its `SOCK` refclock, so the system clock follows it.

The timebase a capture session records against is the first of these that is locked:

| `timebase` | Source |
| - | - |
| `sim` | The simulator clock, while a simulation runs. |
| `gnss` | GNSS PPS. |
| `hub_freerun` | The sensor hub's own clock. |
| `host_monotonic` | Nothing is locked: the host clock. |

### `GET /api/v1/clock`

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -s -H "X-ADOS-Key: $ADOS_KEY" http://192.168.1.50:8080/api/v1/clock
```

| Field | Meaning |
| - | - |
| `present` | `false` when the clock service is absent or its sidecar is older than 5 seconds. |
| `timebase` | The selected timebase. |
| `locked` | Whether that timebase is locked. |
| `sigma_ns` | Its one-sigma uncertainty in nanoseconds, `-1` when unmeasured. |
| `t_ns`, `utc_ns` | The current session time, and UTC when known (`null` otherwise). |
| `sources` | One entry per source: `id`, `kind` (`fc`, `hub`, `gnss_pps`, `sim`), `locked`, `offset_ns`, `skew_ppm`, `sigma_ns`, `last_update_ns`. |

With the service absent the body is `present: false`, `timebase: host_monotonic`, `locked: false`, `sigma_ns: -1` and an empty `sources` list.

## The sensor hub

The ADOS Sensor Hub is a USB co-processor that samples IMUs, fires and timestamps camera triggers, and passes GNSS through. `ados-sensorhub` reads its packet stream over USB CDC-ACM or TCP, maps hub time onto the host clock, and publishes each packet on the bus. RTCM corrections on the bus are forwarded to the hub's receiver. The link state goes to `/run/ados/sensorhub.json` once a second.

| Key | Type | Default | Allowed | Description |
| - | - | - | - | - |
| `sensors.hub.exposure_us` | integer | `4000` | 0 to 1000000 | Exposure Us |
| `sensors.hub.gnss_forward` | boolean | `true` | n/a | Gnss Forward |
| `sensors.hub.imu_odr_hz` | integer | `1000` | `500`, `1000`, `2000` | Imu Odr Hz |
| `sensors.hub.rtcm_origins` | array | `["gnss","host"]` | n/a | Rtcm Origins |
| `sensors.hub.transport` | string | `"auto"` | n/a | Transport |
| `sensors.hub.trigger_hz` | integer | `20` | 0 to 1000 | Trigger Hz |

## The rig file

`/etc/ados/rig.json` describes the rig: its id, calibration version, and each sensor's id, kind, role and mount. The sensors table and the capture extension read it.

| Route | Effect |
| - | - |
| `PUT /api/v1/sensors/rig` | Validate a whole rig document and store it. |
| `POST /api/v1/sensors/rig/lidar` | Add an RPLIDAR C1 as `lidar0` from the built-in template. With no rig stored, it creates one holding only the lidar. |

Both validate the document before writing, store it atomically, and then reload `ados-sensorhub` so the hub picks up the new extrinsics. A success returns `{"ok": true, "rig_id", "calib_version"}`. An invalid rig is `E_RIG_INVALID`. The lidar add is refused with `409` when the rig already has a lidar, already has a sensor named `lidar0`, or the stored rig does not validate; nothing is changed.

## `GET /api/v1/sensors`

The live sensor table joins the bus streams with the rig file, the hub link, the clock and GNSS.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -s -H "X-ADOS-Key: $ADOS_KEY" http://192.168.1.50:8080/api/v1/sensors
```

| Field | Meaning |
| - | - |
| `present` | `false` when no sensor service runs. |
| `rig_id`, `calib_version` | From the rig file, `null` without one. |
| `hub` | The hub link: `connected`, `transport`, `fw`, `board`, `proto_ver`, `uptime_s`, `crc_errors`, `dropped`. `null` when no hub is configured. |
| `fc` | The flight controller link: `connected`, `autopilot`, and `highres_imu` (the flight controller streams its IMU on the bus). |
| `sensors` | One row per sensor, below. |
| `gnss` | The first receiver's `fix`, `sats`, `hdop` and `rtk`, or `null`. |
| `health` | The navigation sensors as the cockpits judge them: `flow`, `range`, `lidar`, `cameras`. |

Each sensor row has `id`, `kind` (`imu`, `camera`, `gnss`, `baro`, `mag`, `lidar`, `thermal`), `role`, `source` (`hub`, `fc`, `gnss`, `vision`, `lidar`), the measured `rate_hz` beside the configured `expected_hz`, `last_t_ns`, `age_ms` and the source clock's `sigma_ns`. A sensor in the rig file that is not streaming is still listed, at rate 0. A lidar lists the scan rate the navigation hub measures.

## Clock configuration

| Key | Type | Default | Allowed | Description |
| - | - | - | - | - |
| `clock.sim.latency_floor_ns` | integer\|null | n/a | 0 to 1000000000 | Latency Floor Ns |

`clock.sim.latency_floor_ns` is the measured minimum latency of the simulator's frame pipeline (encode, RTSP and decode), which one-way timing pairs cannot measure. When set, it is added to the simulator source's offset. When unset, the offset is left as measured and the published sigma carries a 30 ms bound instead.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.