> 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/non-gps-ekf-initialization-in-ardupilot/optical-flow.md).

# Optical Flow

This page features information on how to set up your autopilot to fuse the optical flow and synthetic rangefinder that cyclops provides.&#x20;

{% hint style="info" %}
This document assumes that you are using both the optical flow and synthetic rangefinder together. Your device can be configured to use an actual, more accurate, rangefinder if preferred.
{% endhint %}

{% stepper %}
{% step %}

### Ardupilot Parameters

Set these on the FC via Mission Planner / MAVProxy.

#### Optical flow

```
FLOW_TYPE        5      # MAVLink optical flow source
FLOW_FXSCALER    <computed below>
FLOW_FYSCALER    <computed below>
FLOW_ORIENT_YAW  0      # 0 if camera +X aligns with vehicle +X; 180 if reversed
FLOW_DELAY       30     # ms; bump to 50 if post-flight XKFR innovations are biased

EK3_FLOW_USE     1

## for the following params you may use a different source if wanted
EK3_SRC1_VELXY   5      # OPTFLOW
EK3_SRC1_POSXY   0      # none (flow gives velocity, not absolute position)
EK3_SRC1_POSZ    1      # baro
RC7_OPTION       90     # EKF_SOURCE_SET — flip SRC1↔SRC2 from the TX in flight
```

#### Synthetic Rangefinder

```
RNGFND1_TYPE     10     # MAVLink rangefinder
RNGFND1_ORIENT   25     # PITCH_270 (down) 
RNGFND1_ADDR     0      
RNGFND1_MIN_CM   5
RNGFND1_MAX_CM   <ceiling, e.g. 5000 for 50 m> 
## this value (MAX_CM) varies depending on you use case (see below)
```

{% hint style="warning" %}
When using VTOL drones, the MAX\_CM parameter should be \~30m higher than your transition altitude. For example, if transition from quad into forward flight at 50m, set the param to <8000> cm. However, for stol drones, this parameter should be dropped down to <3000 cm
{% endhint %}
{% endstep %}

{% step %}

### Compute the flow scalers

`oflow` sends `OPTICAL_FLOW` at 25 Hz, so `T = 1/25 = 0.04 s`, `T² = 0.0016`.

Read `fx`, `fy` (pixels) from the rectified camera intrinsics found on vozilla.

<figure><img src="/files/B3RSZxBchErY85CshZld" alt=""><figcaption></figcaption></figure>

```
SCALER = (1 / (f × 0.0016) − 1) × 1000
```

Round to integer. `FLOW_FXSCALER` uses `fx`, `FLOW_FYSCALER` uses `fy`.

| `f` (px) | Scaler |
| -------- | ------ |
| 320      | +953   |
| 514.57   | +214   |
| 800      | −219   |

{% hint style="warning" %}
AP rejects scalers outside roughly ±800 (true scale 0.20×–4.00×). If the formula gives something extreme, recheck `fx` / `fy` — you may be reading the raw sensor matrix instead of the rectified one.
{% endhint %}
{% endstep %}

{% step %}

### Bench Verification

Power up the FC and the companion. In Mission Planner, hit `Ctrl+F` → **MAVLink Inspector**.

Under **Vehicle 255** (the companion) you should see:

* `OPTICAL_FLOW` — `flow_x` / `flow_y` change when you wave a hand in front of the camera
* `DISTANCE_SENSOR` — `current_distance` roughly tracks `relative_alt` reported by the FC

Under **Vehicle 1** (the FC):

* `RANGEFINDER` reports a fresh distance
* Mission Planner → **Status** tab → `RNGFND1` and `OF` rows are live

If `OPTICAL_FLOW` or `DISTANCE_SENSOR` is missing under Vehicle 255: SSH to the NanoPi and run `journalctl -u oflow.service -f`. You should see `SEND OPTICAL_FLOW` and `SEND DISTANCE_SENSOR` lines. If `RECV GLOBAL_POSITION_INT` is also missing, MAVProxy isn't routing the FC stream to UDP `127.0.0.1:14555`.<br>
{% endstep %}

{% step %}

### GPS Spoof Params

#### VTOL

No need to set GPS parameters for VTOL drone.

#### STOL / fixed-wing (TALON)

```
GPS2_TYPE        14      # MAVLink
GPS_PRIMARY      1
```

{% endstep %}

{% step %}

### Flying Without GPS

The FC needs an EKF origin and home position before any GPS-denied mode (LOITER, FlowHold, etc.) will engage.

#### VTOL

Set the EKF origin and home position via Mission Planner. \
Optical flow + the synthetic rangefinder give EK3 enough to hold position during takeoff, and into forward flight.

#### STOL / fixed-wing (TALON)

Same as above, but EK3 also needs a few seconds of plausible position fix before it'll release for arming. Use the GPS spoof tool on vozilla:

1. Vozilla → Settings → Lab → GPS Spoof
2. Set Duration to 15
3. Click Spoof Home Position
4. Wait the full duration before arming
5. Arm, take off.

<figure><img src="/files/4DHQJlyNWSyOVYnrxJPX" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
To use GPS Spoof you must ensure you set the params appropriately. You need to GPS spoof to be able to use optical flow on STOL bird.
{% endhint %}
{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.theseus.us/cyclops/autopilot-integration/non-gps-ekf-initialization-in-ardupilot/optical-flow.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
