> 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/vehicle-and-camera.md).

# Vehicle and camera (port 5000)

{% hint style="info" %}
These endpoints belong to the legacy API on port `5000`. They may be replaced by v2 endpoints in a later release. Responses use the port `5000` format: check that `code` is `SUCCESS`.
{% endhint %}

Cyclops needs two configurations: a vehicle configuration, which describes how the camera is mounted relative to the flight controller, and a camera calibration. Use these endpoints to read, upload, and select them.

The easiest way to create both is in Vozilla. See [Vehicle configuration](https://docs.theseus.us/cyclops/uav-integration/vehicle-configuration.md) and [Camera calibration](https://docs.theseus.us/cyclops/uav-integration/camera-calibration.md). The endpoints below let your GCS install and select configurations you already have.

| Method | Path                   | Purpose                                 |
| ------ | ---------------------- | --------------------------------------- |
| `GET`  | `/api/vehicle/list`    | List vehicle configurations             |
| `GET`  | `/api/vehicle/current` | Read the active vehicle configuration   |
| `POST` | `/api/vehicle/upload`  | Upload a vehicle configuration          |
| `POST` | `/api/vehicle/set`     | Select the active vehicle configuration |
| `GET`  | `/api/camera/list`     | List camera calibrations                |
| `GET`  | `/api/camera/current`  | Read the active camera calibration      |
| `POST` | `/api/camera/upload`   | Upload a camera calibration             |
| `POST` | `/api/camera/set`      | Select the active camera calibration    |

All paths are on port `5000`, for example `http://192.168.218.100:5000/api/vehicle/list`.

## Vehicle configurations

### List vehicle configurations

`GET /api/vehicle/list`

```json
{
  "code": "SUCCESS",
  "data": [
    {
      "name": "my_quad",
      "is_system": false,
      "b_T_vb": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
    }
  ]
}
```

| Field       | Description                                                                            |
| ----------- | -------------------------------------------------------------------------------------- |
| `name`      | Configuration name. Use it to select the configuration.                                |
| `is_system` | `true` for configurations installed with Cyclops, `false` for uploaded ones.           |
| `b_T_vb`    | Camera mount transform. See [Vehicle configuration file](#vehicle-configuration-file). |

### Read the active vehicle configuration

`GET /api/vehicle/current`

```json
{
  "code": "SUCCESS",
  "data": {
    "current_vehicle": "my_quad"
  }
}
```

`current_vehicle` is `null` when none is selected.

### Vehicle configuration file

A YAML file. The key Cyclops needs is `b_T_vb`: 16 numbers that form a 4×4 transform in row-major order. The top-left 3×3 block is the camera rotation and the last column holds the camera position in meters. It describes the camera mount relative to the flight controller, in the flight controller's North-East-Down frame.

```yaml
b_T_vb: [1, 0, 0, 0,
         0, 1, 0, 0,
         0, 0, 1, 0,
         0, 0, 0, 1]
```

Create the values with the Vehicles page in Vozilla, then read them back with `GET /api/vehicle/list`. Do not derive them by hand.

### Upload a vehicle configuration

`POST /api/vehicle/upload`

The request body is the file content. Send the file name in a `filename` header, and set `Content-Type` to `application/json` or `application/octet-stream`. Do not send it as a form. It must end in `.yaml`, and the part before `.yaml` becomes the configuration name. JSON is valid YAML, so you can also send the content as JSON.

```bash
curl -X POST http://192.168.218.100:5000/api/vehicle/upload \
  -H "filename: my_quad.yaml" \
  -H "Content-Type: application/json" \
  --data-binary '{"b_T_vb": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]}'
```

```json
{
  "code": "SUCCESS",
  "message": "Successfully uploaded vehicle configuration my_quad.yaml",
  "filename": "my_quad.yaml",
  "size": 66
}
```

Uploading does not select the configuration. An upload with the same name replaces the existing file. The device only checks that the file is valid YAML, so check the values before you select it.

| Status | Cause                                                                         |
| ------ | ----------------------------------------------------------------------------- |
| `400`  | The `filename` header is missing, or the name does not end in `.yaml`.        |
| `500`  | The file is not valid YAML, or it could not be saved. `message` explains why. |

### Select the active vehicle configuration

`POST /api/vehicle/set`

{% hint style="warning" %}
This restarts Cyclops. Only call it on the ground with the aircraft disarmed. Cyclops sends no position to the flight controller while it restarts.
{% endhint %}

| Field    | Type   | Description                   |
| -------- | ------ | ----------------------------- |
| `params` | string | Configuration name. Required. |

```bash
curl -X POST http://192.168.218.100:5000/api/vehicle/set \
  -H "Content-Type: application/json" \
  -d '{"params": "my_quad"}'
```

```json
{
  "code": "SUCCESS",
  "data": {
    "current_vehicle": "my_quad",
    "message": "Vehicle parameters set to my_quad"
  }
}
```

Set your HTTP client timeout to at least 90 seconds.

| Status | Cause                                                                                                                                                                                                                             |
| ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `400`  | `params` is missing.                                                                                                                                                                                                              |
| `404`  | No configuration with that name exists.                                                                                                                                                                                           |
| `500`  | The configuration was selected, but Cyclops did not restart. Restart it with [`POST /api/v2/services/cyclops/restart`](https://docs.theseus.us/cyclops/developers/edge-api/controlling-cyclops.md#start-stop-or-restart-cyclops). |

## Camera calibrations

### List camera calibrations

`GET /api/camera/list`

```json
{
  "code": "SUCCESS",
  "data": [
    {
      "name": "boson_640",
      "is_system": false,
      "resolution": { "width": 640, "height": 512 },
      "intrinsics": { "fx": 411.37, "fy": 411.22, "cx": 317.80, "cy": 257.89, "k1": 0.133336, "k2": 0.0, "k3": 0.0, "k4": 0.52395 },
      "extrinsics": { "body_frame": { ... }, "imu_frame": { ... } }
    }
  ]
}
```

### Read the active camera calibration

`GET /api/camera/current`

```json
{
  "code": "SUCCESS",
  "data": {
    "current_camera": "boson_640"
  }
}
```

`current_camera` is `null` when none is selected.

### Upload a camera calibration

`POST /api/camera/upload`

Send the calibration as JSON with `Content-Type: application/json`.

| Field              | Type   | Description                                                                                                                                                                                                                                   |
| ------------------ | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name`             | string | Calibration name. Required.                                                                                                                                                                                                                   |
| `resolution`       | object | `width` and `height` of the camera image, in pixels. Required.                                                                                                                                                                                |
| `intrinsics`       | object | `fx`, `fy`, `cx`, `cy`, `k1`, `k2`, `k3`, `k4`, as produced by the calibration tools. Required. See [Manual camera calibration](https://docs.theseus.us/vozilla-gcs-software/vozilla-app/camera/manual-camera-calibration.md) for an example. |
| `extrinsics`       | object | Camera orientation block. Required. Copy it from an existing calibration in `GET /api/camera/list`.                                                                                                                                           |
| `distortion_model` | string | `fisheye_kb4` (default) or `pinhole_radtan`. Optional.                                                                                                                                                                                        |

```bash
curl -X POST http://192.168.218.100:5000/api/camera/upload \
  -H "Content-Type: application/json" \
  -d @boson_640.json
```

```json
{
  "code": "SUCCESS",
  "message": "Successfully uploaded camera configuration boson_640.yaml",
  "filename": "boson_640.yaml",
  "size": 512
}
```

The device checks the calibration before saving it. Uploading does not select the calibration. An upload with the same name replaces the existing calibration.

If the check fails, the response is HTTP `400` and lists the problems:

```json
{
  "code": "camera_config_upload_rejected",
  "message": "Camera configuration 'boson_640.yaml' failed upload validation",
  "validation_failed": true,
  "validation_errors": [
    { "code": "intrinsics_issue", "message": "...", "details": {} }
  ],
  "validation_warnings": []
}
```

### Select the active camera calibration

`POST /api/camera/set`

{% hint style="warning" %}
This restarts the camera stream. Only call it on the ground with the aircraft disarmed. Cyclops receives no camera images while the stream restarts.
{% endhint %}

| Field    | Type   | Description                 |
| -------- | ------ | --------------------------- |
| `params` | string | Calibration name. Required. |

```bash
curl -X POST http://192.168.218.100:5000/api/camera/set \
  -H "Content-Type: application/json" \
  -d '{"params": "boson_640"}'
```

```json
{
  "code": "SUCCESS",
  "data": {
    "current_camera": "boson_640",
    "message": "Camera parameters set to boson_640"
  }
}
```

| Status | Cause                                                                                                                                                           |
| ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `400`  | `params` is missing.                                                                                                                                            |
| `404`  | No calibration with that name exists.                                                                                                                           |
| `409`  | The calibration does not match the connected camera, for example a different resolution. The response lists the problems in the same format as a failed upload. |
| `500`  | The camera stream did not restart.                                                                                                                              |
