> For the complete documentation index, see [llms.txt](https://docs.theseus.us/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.theseus.us/cyclops/autopilot-integration/px4/losing-cyclops-in-flight.md).

# Losing Cyclops in flight

When Cyclops detects that its position can no longer be trusted, it stops sending a position to PX4. The aircraft then has no position source, so it drops into a mode that doesn't need one, such as Altitude mode, and the pilot flies by hand until Cyclops recovers.

This page lists what to do, what to set up beforehand, and how to recognise each step.

## What to do when Cyclops fails

1. **Cyclops stops sending a position.** It does this as soon as it detects the failure, so PX4 never fuses a bad position. The ground station shows `Cyclops: Health failed, GPS stopped`.
2. **The aircraft switches to Altitude mode.** If you were flying in Position mode, PX4 does this by itself. If the aircraft was in Mission, Hold or RTL, switch to Altitude mode yourself straight away. Those modes need a position, and without one PX4 falls back to landing or descending where it is.
3. **Fly by hand.** Altitude mode holds height and heading but not position, so the aircraft drifts with the wind. Keep it under control and keep the camera pointing at the ground. Cyclops restarts its tracking in the air on its own.
4. **Go back to Position mode once Cyclops is back.** When Cyclops has been healthy for 5 seconds, it sends a position again and the ground station shows `Cyclops: Ready for arming`. PX4 now has a position again, and you can switch back to Position mode or resume the mission.

If Cyclops doesn't come back, stay in Altitude mode and land by hand.

{% hint style="info" %}
`Cyclops: Ready for arming` is the same message Cyclops sends on the ground. In flight it means "I'm sending a position again".
{% endhint %}

<figure><img src="https://2060891120-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhzvlBbeiwnrjdGDAaBcQ%2Fuploads%2Fgit-blob-594b44cc33210b8daa90155f599e56c924f4634c%2Fcyclops-px4-recovery-states.svg?alt=media" alt="Cyclops states: Starting, Ready, Active, Degraded, Failed and Not running, with what the heartbeat, VPS_ERR and position output show in each."><figcaption><p>Cyclops states, and what PX4 and the ground station see in each.</p></figcaption></figure>

## Set up before you fly

* **`COM_POSCTL_NAVL` = `0`** (the PX4 default). This makes PX4 drop from Position mode to Altitude mode when it loses its position. With `1`, it lands instead.
* **`EKF2_EV_QMIN` = `50`.** Cyclops marks its position as degraded the moment something looks wrong. With this setting PX4 stops using it straight away, instead of waiting until Cyclops stops sending.
* **The pilot can fly the aircraft by hand in Altitude mode.** Practise the switch to Altitude mode and back to Position mode with GPS before you rely on it.
* **Test it once.** With GPS available as a backup, stop the Cyclops service in flight and check that the aircraft and the pilot do what you expect.

Cyclops never changes the flight mode on PX4. Everything after "Cyclops stops sending a position" is done by PX4's own failsafes and by the pilot. If your aircraft has its own failsafe logic, it can watch the Cyclops heartbeat (see below) and act on it.

## How to tell what Cyclops is doing

Cyclops reports its state in its MAVLink `HEARTBEAT`, a `VPS_ERR` code, and short `STATUSTEXT` messages to the ground station. `VPS_ERR` is not sent while the aircraft is armed, so in flight you only get the heartbeat and `STATUSTEXT`. The `VPS_ERR` values in the table appear after landing and disarming. The codes are listed in full in [Monitoring VPS health over MAVLink](https://docs.theseus.us/vozilla-gcs-software/mavlink/monitoring-vps-health-over-mavlink.md).

| What happened                          | `HEARTBEAT` `system_status` | `VPS_ERR`    | Ground station message                |
| -------------------------------------- | --------------------------- | ------------ | ------------------------------------- |
| Sending a position                     | `ACTIVE` (4)                | `0`          |                                       |
| Stopped sending a position             | `CRITICAL` (5)              | `13`         | `Cyclops: Health failed, GPS stopped` |
| Sending a position again               | `ACTIVE` (4)                | `0`          | `Cyclops: Ready for arming`           |
| Lost the link to the flight controller | `BOOT` (1)                  | `11`         | `VPS: MAVLink lost, waiting...`       |
| Cyclops crashed                        | no heartbeat                | `30` to `50` |                                       |

For your own failsafe logic, watch the Cyclops heartbeat (system ID `218`, component `191`). Treat `system_status` `CRITICAL`, or no Cyclops heartbeat for more than 3 seconds, as "Cyclops is not giving PX4 a position".

## Details

**When Cyclops stops.** Cyclops checks every VIO update. If tracking is lost or the estimate looks wrong, it marks its position as degraded (`ODOMETRY` quality `25`), which PX4 ignores when `EKF2_EV_QMIN` is `50`. If it doesn't recover within 2 seconds, Cyclops stops sending `ODOMETRY` altogether.

**When Cyclops comes back.** Cyclops needs 5 seconds of healthy tracking in a row before it sends a position again. Any bad update restarts the count, so a VIO that keeps flickering between good and bad never reaches PX4. When it does come back, Cyclops tells PX4 this is a reset (the `reset_counter` in `ODOMETRY` goes up). PX4 moves straight to the new position, so the aircraft's position can jump at that moment. The next map match corrects any error that is left.

**If Cyclops crashes.** The system restarts it within 2 seconds, and it carries on from its last map correction. Tracking still has to start again in the air before a position comes back, so follow the same steps as above. After 5 crashes in 5 minutes, or after a license or configuration error, Cyclops stays stopped.

**If the flight controller reboots.** Cyclops waits for it to come back. It never sets a new EKF origin while the aircraft is armed. Land, and power-cycle the flight controller and the companion computer together before the next flight.
