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

# Home position

The home position is where Cyclops initializes at takeoff. Set it to the takeoff location before each flight from a new location. This is the same setting as [Home position](https://docs.theseus.us/vozilla-gcs-software/vozilla-app/maps/home-position.md) in Vozilla.

| Method | Path                           | Purpose                                   |
| ------ | ------------------------------ | ----------------------------------------- |
| `GET`  | `/api/v2/system/home-position` | Read the current home position            |
| `POST` | `/api/v2/system/home-position` | Set the home position and restart Cyclops |

The home position must be inside the active map on the Cyclops computer. Install and select the map first. See [Maps (port 5000)](https://docs.theseus.us/cyclops/developers/edge-api/maps-port-5000.md).

## Read the home position

`GET /api/v2/system/home-position`

```bash
curl http://192.168.218.100:5050/api/v2/system/home-position
```

```json
{
  "success": true,
  "data": {
    "home_position": {
      "lat": 32.8601,
      "lon": -117.2003,
      "alt": 112.4
    }
  }
}
```

| Field | Description                                                                   |
| ----- | ----------------------------------------------------------------------------- |
| `lat` | Latitude, in decimal degrees.                                                 |
| `lon` | Longitude, in decimal degrees.                                                |
| `alt` | Terrain elevation at the home position, in meters, taken from the active map. |

### Errors

| Status | Cause                                                   |
| ------ | ------------------------------------------------------- |
| `404`  | No home position has been set on this Cyclops computer. |

## Set the home position

`POST /api/v2/system/home-position`

Saves a new home position and restarts Cyclops so it uses it.

{% hint style="warning" %}
This call restarts Cyclops. Cyclops does not provide navigation while it restarts. Only set the home position on the ground, before takeoff.
{% endhint %}

### Request body

| Field | Type   | Description                                                |
| ----- | ------ | ---------------------------------------------------------- |
| `lat` | number | Latitude, in decimal degrees, from -90 to 90. Required.    |
| `lon` | number | Longitude, in decimal degrees, from -180 to 180. Required. |

You do not send an altitude. Cyclops looks up the terrain elevation at that point in the active map.

### Example

```bash
curl -X POST http://192.168.218.100:5050/api/v2/system/home-position \
  -H "Content-Type: application/json" \
  -d '{"lat": 32.8601, "lon": -117.2003}'
```

```json
{
  "success": true,
  "message": "Home position updated successfully",
  "data": {
    "home_position": {
      "lat": 32.8601,
      "lon": -117.2003,
      "alt": 112.4
    },
    "restarted_service": "cyclops"
  }
}
```

The call returns after Cyclops has been restarted, which can take several seconds. Set your HTTP client timeout to at least 90 seconds. After the call returns, watch `vps_error` in [`GET /api/v2/state`](https://docs.theseus.us/cyclops/developers/edge-api/status-and-health.md#read-cyclops-health) until it returns to `0`.

### Errors

| Status                                                                                             | Cause                                                                                                                                                                                         |
| -------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `400`                                                                                              | `lat` or `lon` is missing, not a number, or out of range.                                                                                                                                     |
| `500`                                                                                              | The terrain elevation could not be found at that point. The error message is `Failed to get elevation at home, are maps loaded?`. Check that a map is active and that the point is inside it. |
| `400`, `403`, or `500` with a message starting with `Updated home position, but failed to restart` | The home position was saved, but Cyclops did not restart. Check `GET /api/v2/state`, then retry or power cycle the Cyclops computer.                                                          |

{% hint style="info" %}
You can also set the home position over MAVLink with `MAV_CMD_DO_SET_HOME`. See [MAVLink commands](https://docs.theseus.us/cyclops/developers/mavlink-commands.md#set-the-home-position).
{% endhint %}
