> 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/edge-api/controlling-cyclops.md).

# Controlling Cyclops

Use these endpoints to stop Cyclops when you do not need it, for example to free the companion computer's resources, and to start it again before flight. The home position spoof is also on this page.

| Method | Path                               | Purpose                                         |
| ------ | ---------------------------------- | ----------------------------------------------- |
| `GET`  | `/api/v2/services/cyclops`         | Read whether Cyclops is running                 |
| `POST` | `/api/v2/services/cyclops/start`   | Start Cyclops                                   |
| `POST` | `/api/v2/services/cyclops/stop`    | Stop Cyclops                                    |
| `POST` | `/api/v2/services/cyclops/restart` | Restart Cyclops                                 |
| `POST` | `/api/gps/spoof` (port `5000`)     | Send the home position to the flight controller |

## Read whether Cyclops is running

`GET /api/v2/services/cyclops`

```bash
curl http://192.168.218.100:5050/api/v2/services/cyclops
```

```json
{
  "success": true,
  "data": {
    "name": "cyclops",
    "active": true,
    "enabled": true,
    "sub_state": "running",
    "health_status": "ok",
    "health_error": null,
    "health_fix": null
  }
}
```

| Field                        | Description                                                                                                 |
| ---------------------------- | ----------------------------------------------------------------------------------------------------------- |
| `active`                     | `true` while Cyclops is running.                                                                            |
| `enabled`                    | `true` if Cyclops starts automatically when the Cyclops computer boots.                                     |
| `sub_state`                  | Detailed state, for example `running`, `dead` (stopped), or `auto-restart`.                                 |
| `health_status`              | `ok` when everything Cyclops needs to start is in place. `prerequisites_missing` when something is missing. |
| `health_error`, `health_fix` | What is missing and how to fix it, when `health_status` is not `ok`.                                        |

For the reason Cyclops is unhealthy while it runs, use `vps_error` in [`GET /api/v2/state`](https://docs.theseus.us/cyclops/developers/edge-api/status-and-health.md#read-cyclops-health).

## Start, stop, or restart Cyclops

`POST /api/v2/services/cyclops/start`\
`POST /api/v2/services/cyclops/stop`\
`POST /api/v2/services/cyclops/restart`

No request body.

{% hint style="warning" %}
Only call these on the ground with the aircraft disarmed. While Cyclops is stopped or restarting, it sends no position to the flight controller. A start or restart takes several seconds, and Cyclops then needs time to initialize before it is ready.
{% endhint %}

```bash
curl -X POST http://192.168.218.100:5050/api/v2/services/cyclops/stop
```

```json
{
  "success": true,
  "message": "Service 'cyclops' stopped"
}
```

A stopped Cyclops stays stopped until you start it again or the Cyclops computer reboots. It starts automatically at the next boot. While it is stopped, `vps_error` in `GET /api/v2/state` is `20`.

Stopping Cyclops frees most of the compute it uses. The camera stream keeps running, because Cyclops needs it to start again. A recording in progress also keeps running; stop it separately if you want to (see [Recordings](https://docs.theseus.us/cyclops/developers/edge-api/recordings.md)).

The call returns once the action is done. Set your HTTP client timeout to at least 90 seconds. After a start or restart, watch `vps_error` in `GET /api/v2/state` until it returns to `0`.

### Errors

| Status         | Cause                                                                                                                                                                     |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `400`          | Cyclops cannot start because something it needs is missing, for example the camera stream or the flight controller heartbeat. The error message includes a suggested fix. |
| `403` or `500` | The device could not change the state of Cyclops. Retry, then power cycle the Cyclops computer if it keeps failing.                                                       |

## Send the home position to the flight controller (port 5000)

`POST /api/gps/spoof` on port `5000`

{% hint style="info" %}
This endpoint belongs to the legacy API on port `5000`. It may be replaced by a v2 endpoint in a later release.
{% endhint %}

Cyclops reports the [home position](https://docs.theseus.us/cyclops/developers/edge-api/home-position.md) to the flight controller as its current position for a set time. This gives the flight controller a starting position on the ground, so it can arm without GPS. Use it only if your release requires it.

{% hint style="warning" %}
Only use this on the ground with the aircraft disarmed. While it runs, the flight controller treats the home position as the aircraft's real position. Cyclops refuses the request if the flight controller reports that the aircraft is armed or airborne, or if its arm state is unknown.
{% endhint %}

Before you call it:

* Cyclops must be running.
* A home position must be set. See [Home position](https://docs.theseus.us/cyclops/developers/edge-api/home-position.md).
* The flight controller must be connected.

### Request body

| Field        | Type   | Description                                                            |
| ------------ | ------ | ---------------------------------------------------------------------- |
| `duration_s` | number | How long to send the home position, in seconds. Optional. Default `5`. |

```bash
curl -X POST http://192.168.218.100:5000/api/gps/spoof \
  -H "Content-Type: application/json" \
  -d '{"duration_s": 5}'
```

```json
{
  "success": true,
  "duration_s": 5.0,
  "lat": 32.8601,
  "lon": -117.2003
}
```

This endpoint always returns HTTP `200`. Check `success`. When it is `false`, `error` says why, for example:

```json
{
  "success": false,
  "error": "Cannot spoof GPS: the vehicle is armed"
}
```

Common reasons: Cyclops is not running, no home position is set, the aircraft is armed or airborne, or a spoof is already in progress.
