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

# MAVLink commands

A ground station, or a script on the autopilot, can send these commands to the Cyclops computer over the same MAVLink link it uses for telemetry. Each command gets a `COMMAND_ACK`.

| Task                                              | Command                                        | Send to              |
| ------------------------------------------------- | ---------------------------------------------- | -------------------- |
| [Set the home position](#set-the-home-position)   | `COMMAND_LONG` `MAV_CMD_DO_SET_HOME` (179)     | Edge API (218 / 190) |
| [Read the home position](#read-the-home-position) | `COMMAND_LONG` `MAV_CMD_REQUEST_MESSAGE` (512) | Edge API (218 / 190) |
| [Start or stop the home spoof](#home-spoof)       | `COMMAND_LONG` 31005                           | Cyclops (218 / 191)  |

## Addresses

The Cyclops computer uses one system ID with two components:

| Component | Default | Setting                    |
| --------- | ------- | -------------------------- |
| System ID | `218`   | `mavproxy.source_system`   |
| Edge API  | `190`   | `mavproxy.mavproxy_compid` |
| Cyclops   | `191`   | `mavproxy.mvps_compid`     |

Read the values on your device with `vns-config get <setting>`.

{% hint style="info" %}
QGroundControl's custom Fly View actions send commands to the flight controller's system ID, so they can't address the Cyclops computer directly. Send the commands from your own ground station code, use the [Mission Planner plugin](https://docs.theseus.us/cyclops/autopilot-integration/ardupilot/mission-planner-plugin.md), or relay them through an autopilot script as in the [QGC home position sender](https://docs.theseus.us/cyclops/developers/qgc-home-position-sender.md).
{% endhint %}

## Set the home position

Sets the point Cyclops starts navigating from. Cyclops restarts to load it.

| Field                                | Value                                                                                             |
| ------------------------------------ | ------------------------------------------------------------------------------------------------- |
| `target_system` / `target_component` | `218` / `190`                                                                                     |
| `command`                            | `179` (`MAV_CMD_DO_SET_HOME`)                                                                     |
| `param1`                             | `0` (use the position given; `1` is refused)                                                      |
| `param5`                             | Latitude, degrees                                                                                 |
| `param6`                             | Longitude, degrees                                                                                |
| `param7`                             | `0` to take the altitude from the device's terrain data (recommended), or altitude in metres AMSL |

Latitude and longitude are plain degrees, not `degE7`. Only `COMMAND_LONG` is accepted.

| `COMMAND_ACK` result  | Meaning                                                                                                                                |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `MAV_RESULT_ACCEPTED` | The home position is saved and Cyclops is restarting.                                                                                  |
| `MAV_RESULT_DENIED`   | `param1` was `1`, or latitude or longitude is missing.                                                                                 |
| `MAV_RESULT_FAILED`   | The coordinates are invalid, or the terrain altitude could not be found (the point is outside the installed map, or no map is loaded). |

The restart can take up to a couple of minutes. Cyclops is ready again when its heartbeat (component 191) reports `MAV_STATE_STANDBY` and `VPS_ERR` is `0`. See [Monitoring VPS health over MAVLink](https://docs.theseus.us/vozilla-gcs-software/mavlink/monitoring-vps-health-over-mavlink.md).

{% hint style="warning" %}
Only send this on the ground with the aircraft disarmed. Cyclops restarts, and sends no position until it is running again.
{% endhint %}

```python
from pymavlink import mavutil

master = mavutil.mavlink_connection("udpout:192.168.218.100:14610")
master.mav.command_long_send(
    218, 190,                      # Cyclops system, Edge API component
    mavutil.mavlink.MAV_CMD_DO_SET_HOME, 0,
    0,                             # param1: use the position given
    0, 0, 0,
    37.4221234, -122.0839876,      # param5, param6: latitude, longitude in degrees
    0,                             # param7: altitude from the device's terrain data
)
print(master.recv_match(type="COMMAND_ACK", blocking=True, timeout=5))
```

Use the address that reaches the Cyclops computer in your setup.

## Read the home position

| Field                                | Value                             |
| ------------------------------------ | --------------------------------- |
| `target_system` / `target_component` | `218` / `190`                     |
| `command`                            | `512` (`MAV_CMD_REQUEST_MESSAGE`) |
| `param1`                             | `242` (`HOME_POSITION`)           |

If a home position is set, the Edge API replies with `MAV_RESULT_ACCEPTED` and a `HOME_POSITION` message: `latitude` and `longitude` in `degE7`, `altitude` in millimetres. If none is set, it replies `MAV_RESULT_FAILED`.

## Home spoof

Gives the flight controller a starting position at the home position, on the ground, so it can arm without GPS.

| Field                                | Value                                                         |
| ------------------------------------ | ------------------------------------------------------------- |
| `target_system` / `target_component` | `218` / `191`                                                 |
| `command`                            | `31005`                                                       |
| `param1`                             | Duration in seconds; `0` uses the device default (10 minutes) |
| `param2`                             | `0` to start, `1` to stop a running spoof                     |

The spoof uses the home position set on the device, so set it first. It ends one second after arming, on takeoff, when Cyclops starts sending its own position, when you stop it, or when the duration runs out.

`MAV_RESULT_ACCEPTED` means the spoof has started. It does not mean the flight controller has taken the position: check the flight controller's own position before arming. The spoof is refused while the aircraft is armed or flying, and while Cyclops is already sending a position.

{% hint style="warning" %}
Only use the spoof on the ground with the aircraft disarmed, and only if your release requires it.
{% endhint %}
