> ## 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.

# GNSS and RTK

> GNSS receivers on a ground station or visor: fix and RTK state, a survey-in or fixed RTK base, moving-baseline heading, and RTCM correction injection.

`ados-gnss` reads the GNSS receivers attached to a ground station or a visor. It reports fix, position, RTK state and PPS lock for each receiver, runs an RTK base (survey-in or a known position), derives heading from two receivers, and forwards the base's RTCM3 corrections toward the paired drones.

It runs on the `ground_station` and `visor` profiles. A drone's own GNSS belongs to its flight controller.

## How the data moves

1. `ados-gnss` reads receiver bytes from a serial port, a UDP port, or the [sensor hub](https://docs.altnautica.com/drone-agent/sensors-and-clock.md)'s passthrough, and splits them into UBX, NMEA and RTCM3 frames.
2. It writes the receivers, base and heading state to `/run/ados/gnss.json` and serves it at `GET /api/v1/gnss`.
3. Serial and UDP receiver bytes go on the sensor bus as `gnss` frames. A base receiver's RTCM3 output goes on the bus as `rtcm` frames.
4. The MAVLink router injects `rtcm` frames to the flight controllers it reaches as `GPS_RTCM_DATA`, and a sensor hub forwards them to its own receiver.
5. PPS pulses are published as `sync` pairs, which the clock service uses as a time source.

## Configure receivers

Receivers are listed under `gnss.receivers` in `/etc/ados/config.yaml`:

```yaml theme={"theme":{"light":"github-light","dark":"github-dark"}}
gnss:
  receivers:
    - id: gnss0
      source: serial:/dev/ttyUSB0@38400
      port: usb
  pps_device: /dev/pps0
  heading:
    enabled: false
```

`source` takes one of these forms:

| `source` | Reads from |
| - | - |
| `hub` | The sensor hub's GNSS passthrough (the default). |
| `serial:<path>` or `serial:<path>@<baud>` | A serial device. Baud defaults to 38400. |
| `udp:<port>` | Datagrams on a local UDP port. Configuration writes go to the sender of the latest datagram. |
| `udp:<port>@<ip>:<port>` | The same, with configuration writes sent to a fixed peer. |

`port` names the receiver port the configuration is written to: `uart1` (default) or `usb`. Heading needs two receivers and `gnss.heading.enabled: true`.

## Read the state

```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/gnss
```

The response carries `present`, `receivers`, `base` and `heading`. When the service is not running or its sidecar is older than 5 seconds, `present` is `false`, `receivers` is empty and `base` and `heading` are `null`.

Each receiver:

| Field | Meaning |
| - | - |
| `id`, `source`, `model` | The configured receiver. |
| `fix` | `none`, `2d`, `3d`, `dgps`, `rtk_float` or `rtk_fixed`. |
| `rtk` | `none`, `float` or `fixed`. |
| `sats`, `hdop` | Satellites used and horizontal dilution. |
| `lat_deg`, `lon_deg`, `h_ellipsoid_m`, `h_msl_m` | Position. |
| `pps_locked` | Whether the PPS input is locked. |

`base` carries `mode`, `state` (`off`, `surveying`, `fixed` or `failed`), `elapsed_s`, `min_dur_s`, the current `accuracy_m` and `target_accuracy_m`, the `fixed` position once known, and `rtcm_out` (`msgs_per_s`, `bytes_total`, and `targets`, the number of linked peers).

`heading` carries `available`, `deg`, `accuracy_deg` and `baseline_m`.

## Run an RTK base

`PUT /api/v1/gnss/base` sets the base mode on the receiver at once, and once the service accepts it, saves it as `gnss.base` in the agent config so the next start applies it again.

> [tab] Survey-in
>
> ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
> curl -s -X PUT -H "X-ADOS-Key: $ADOS_KEY" -H "Content-Type: application/json" \
>   -d '{"mode": "survey", "min_dur_s": 300, "accuracy_m": 2.0}' \
>   http://192.168.1.50:8080/api/v1/gnss/base
> ```
>
> The survey runs until both the minimum duration and the target accuracy are met. Leave out `min_dur_s` or `accuracy_m` to keep the current values.

> [tab] Fixed position
>
> ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
> curl -s -X PUT -H "X-ADOS-Key: $ADOS_KEY" -H "Content-Type: application/json" \
>   -d '{"mode": "fixed", "lat_deg": 47.3977, "lon_deg": 8.5456, "h_ellipsoid_m": 488.2}' \
>   http://192.168.1.50:8080/api/v1/gnss/base
> ```

> [tab] Off
>
> ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
> curl -s -X PUT -H "X-ADOS-Key: $ADOS_KEY" -H "Content-Type: application/json" \
>   -d '{"mode": "off"}' http://192.168.1.50:8080/api/v1/gnss/base
> ```
>
> `off` stops the receiver's RTCM3 output.

A success returns the new `base` object. Errors use the body `{"error", "detail"}`:

| Status | `error` | Cause |
| - | - | - |
| 400 | `E_GNSS_BAD_REQUEST` | `mode` is not `off`, `survey` or `fixed`, or a field has the wrong type. |
| 409 | `E_GNSS_NO_RECEIVER` | No receiver can act as the base. |
| 409 | `E_GNSS_UNSUPPORTED` | The receiver cannot be configured as a base. |
| 500 | `E_CONFIG_WRITE` | The receiver took the mode but the config could not be saved. |
| 503 | `E_GNSS_UNAVAILABLE` | The GNSS service is not running, or did not answer within 3 seconds. |

## Inject corrections

`POST /api/v1/gnss/rtcm` takes raw RTCM3 bytes as the body, from an NTRIP client or any other correction source, and publishes them on the sensor bus. The reply counts the `GPS_RTCM_DATA` fragments the bytes make.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -s -X POST -H "X-ADOS-Key: $ADOS_KEY" --data-binary @corrections.rtcm3 \
  http://192.168.1.50:8080/api/v1/gnss/rtcm
# {"ok": true, "fragments": 3}
```

| Status | `error` | Cause |
| - | - | - |
| 400 | `E_RTCM_EMPTY` | Empty body. |
| 400 | `E_RTCM_INVALID` | No CRC-valid RTCM3 frame in the body. |
| 400 | `E_RTCM_TOO_LONG` | A frame is longer than the fragment limit allows. |
| 503 | `E_SENSOR_BUS_DOWN` | The sensor bus is not reachable. |

## Configuration reference

| Key | Type | Default | Allowed | Description |
| - | - | - | - | - |
| `gnss.base.accuracy_m` | number | `2` | >= 0 | Accuracy M |
| `gnss.base.h_ellipsoid_m` | number\|null | n/a | n/a | H Ellipsoid M |
| `gnss.base.lat_deg` | number\|null | n/a | -90 to 90 | Lat Deg |
| `gnss.base.lon_deg` | number\|null | n/a | -180 to 180 | Lon Deg |
| `gnss.base.min_dur_s` | integer | `300` | >= 1 | Min Dur S |
| `gnss.base.mode` | string | `"off"` | `"off"`, `"survey"`, `"fixed"` | Mode |
| `gnss.heading.enabled` | boolean | `false` | n/a | Enabled |
| `gnss.pps_device` | string\|null | n/a | n/a | Pps Device |
| `gnss.receivers` | array | `[]` | n/a | Receivers |
| `gnss.receivers[].id` | string | `"gnss0"` | n/a | Id |
| `gnss.receivers[].model` | string\|null | n/a | n/a | Model |
| `gnss.receivers[].port` | string | `"uart1"` | `"uart1"`, `"usb"` | Port |
| `gnss.receivers[].source` | string | `"hub"` | n/a | Source |


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