> 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/mavlink.md).

# MAVLink

Cyclops talks to PX4 over MAVLink 2 through the companion computer's MAVLink router. It needs a link that works both ways: it reads the flight controller's sensors and sends a position back.

<figure><img src="https://2060891120-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhzvlBbeiwnrjdGDAaBcQ%2Fuploads%2Fgit-blob-b6b56c12d5bbe896a3814f3dd3b559bb05517d2a%2Fcyclops-px4-system.svg?alt=media" alt="Cyclops on a PX4 aircraft: the camera sends video and the flight controller sends sensor data to Cyclops over MAVLink, and Cyclops sends a position back to EKF2."><figcaption><p>What Cyclops reads from PX4 and what it sends back.</p></figcaption></figure>

Cyclops works out where the aircraft is from the camera, the flight controller's IMU and a satellite map stored on the device. It sends that position back to PX4, but only while it trusts it. If it stops trusting it, it stops sending. See [Losing Cyclops in flight](https://docs.theseus.us/cyclops/autopilot-integration/px4/losing-cyclops-in-flight.md).

## What Cyclops reads from PX4

Cyclops asks PX4 for each stream with `SET_MESSAGE_INTERVAL` when it connects. You don't need to set any stream rates yourself.

* `HIGHRES_IMU` (200 Hz): gyro, accelerometer, magnetometer and barometric pressure
* `ATTITUDE` (50 Hz): roll, pitch and yaw
* `SCALED_PRESSURE` (50 Hz): barometric pressure and temperature
* `VFR_HUD` (50 Hz): airspeed, ground speed, heading and altitude
* `WIND` (2 Hz): wind speed and direction
* `LOCAL_POSITION_NED` (15 Hz): position and velocity relative to the EKF origin
* `EXTENDED_SYS_STATE` (15 Hz): landed state
* `GPS_GLOBAL_ORIGIN`: the EKF origin
* `RC_CHANNELS` (10 Hz): RC channel values
* `HEARTBEAT`: autopilot type, flight mode and armed state
* `TIMESYNC`: clock offset between PX4 and the companion computer
* `GPS_RAW_INT` (5 Hz): raw GPS fix. Logged only, never used for position.

If the link is busy, Cyclops lowers these rates, but it keeps each above a minimum (for example, 10 Hz for `HIGHRES_IMU`).

{% hint style="info" %}
PX4 1.16 fills the pressure fields of `HIGHRES_IMU` in pascals, although MAVLink says hectopascals. Cyclops corrects this for PX4 1.16. Newer PX4 code reports hectopascals, which is one reason we check each new version before you fly it.
{% endhint %}

## What Cyclops sends to PX4

| Message                     | When                                               | What it is                                                                                                                                             |
| --------------------------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `ODOMETRY`                  | In flight, at the VIO rate (typically 10 to 20 Hz) | The position for EKF2. See below.                                                                                                                      |
| `SET_GPS_GLOBAL_ORIGIN`     | On the ground, disarmed, only if PX4 has no origin | Sets where local position zero is                                                                                                                      |
| `COMMAND_LONG`              | At startup                                         | `SET_MESSAGE_INTERVAL` to request the streams above                                                                                                    |
| `HEARTBEAT`                 | 1 Hz                                               | Cyclops's state. See [Monitoring VPS health over MAVLink](https://docs.theseus.us/vozilla-gcs-software/mavlink/monitoring-vps-health-over-mavlink.md). |
| `NAMED_VALUE_INT` `VPS_ERR` | 1 Hz, while disarmed                               | Why Cyclops is in its current state. Sent by a separate service (component `190`), so it still arrives if Cyclops crashes. Not sent while armed.       |
| `STATUSTEXT`                | On changes                                         | Short messages for the pilot, for example `Cyclops: Health failed, GPS stopped`                                                                        |
| `TIMESYNC`, `SYSTEM_TIME`   | Continuously                                       | Clock alignment. PX4 only takes `SYSTEM_TIME` while its own clock is unset.                                                                            |

That's the complete list. Cyclops doesn't send `PARAM_SET`, so it never changes your parameters, and it doesn't change flight modes on PX4.

### Inside the `ODOMETRY` message

| Field                        | Value                                                                                                           |
| ---------------------------- | --------------------------------------------------------------------------------------------------------------- |
| `frame_id`, `child_frame_id` | `MAV_FRAME_LOCAL_NED`                                                                                           |
| `x`, `y`, `z`                | Position in metres, north-east-down from the EKF origin. PX4 only uses `x` and `y`.                             |
| `vx`, `vy`, `vz`             | Velocity in metres per second, north-east-down                                                                  |
| `q`, body rates              | `NaN`. Cyclops doesn't give PX4 attitude.                                                                       |
| `pose_covariance`            | Position noise. Small on the ground so EKF2 locks on quickly, then larger in flight.                            |
| `velocity_covariance`        | Velocity noise                                                                                                  |
| `reset_counter`              | Goes up by one each time the map matcher corrects the position, and once each time VIO recovers after a failure |
| `estimator_type`             | `MAV_ESTIMATOR_TYPE_VIO`                                                                                        |
| `quality`                    | `100` healthy, `25` degraded, `0` not known yet. When VIO has failed, nothing is sent at all.                   |

Two of these fields need explaining.

`reset_counter` is how Cyclops tells PX4 that a sudden jump in position is a correction, not a glitch. When the counter changes, PX4 moves its position straight to the new value instead of treating it as an outlier. So the counter doesn't change often: the map matcher corrects the position about once every 500 m of flight, and only when the camera actually matched the map.

`quality` lets PX4 refuse samples Cyclops already knows are bad. That only works if `EKF2_EV_QMIN` is set to `50`. See [PX4 Integration](https://docs.theseus.us/cyclops/autopilot-integration/px4.md#parameters).

## System ID

Cyclops only accepts messages from the system ID and component ID it is set up for. If the flight controller uses a different system ID, Cyclops ignores its heartbeat and reports `VPS_ERR` `1` (no autopilot heartbeat), even though the cable and router are fine. Set the system ID in Vozilla under *Settings > MAV*.
