# Optical Flow

*Optical Flow* uses a downward facing camera and a downward facing distance sensor for velocity estimation.

@[youtube](https://youtu.be/aPQKgUof3Pc) *Video: PX4 holding position using the ARK Flow sensor for velocity estimation (in* [*Position Mode*](/px4-user-guide/flying/flight_modes/position_mc.md)*).*

## Setup

An Optical Flow setup requires a downward facing camera and a [distance sensor](/px4-user-guide/drone_parts/peripherals/rangefinders.md) (preferably a LiDAR). These can be connected via MAVLink, I2C or any other bus that supports the peripheral.

:::note If connected to PX4 via MAVLink the Optical Flow device must publish to the [OPTICAL\_FLOW\_RAD](https://mavlink.io/en/messages/common.html#OPTICAL_FLOW_RAD) topic, and the distance sensor must publish to the [DISTANCE\_SENSOR](https://mavlink.io/en/messages/common.html#DISTANCE_SENSOR) topic. :::

The output of the flow when moving in different directions must be as follows:

| Vehicle movement | Integrated flow |
| ---------------- | --------------- |
| Forwards         | + Y             |
| Backwards        | - Y             |
| Right            | - X             |
| Left             | + X             |

For pure rotations the `integrated_xgyro` and `integrated_x` (respectively `integrated_ygyro` and `integrated_y`) have to be the same.

An popular setup is the [PX4Flow](/px4-user-guide/drone_parts/peripherals/optical_flow/px4flow.md) and [Lidar-Lite](/px4-user-guide/drone_parts/peripherals/rangefinders/lidar_lite.md), as shown below.

![Optical flow lidar attached](/files/GBGiM7MiRveENZP8nnP3)

Sensor data from the optical flow device is fused with other velocity data sources. The approach used for fusing sensor data and any offsets from the center of the vehicle must be configured in the [estimator](#estimators).

## Flow Sensors/Cameras

### ARK Flow

[ARK Flow](/px4-user-guide/drone_parts/peripherals/optical_flow/ark_flow.md) is a [DroneCAN](/px4-user-guide/drone_parts/peripherals/dronecan.md) optical flow sensor, [distance sensor](/px4-user-guide/drone_parts/peripherals/rangefinders.md), and IMU. It has a PAW3902 optical flow sensor, Broadcom AFBR-S50LV85D 30 meter distance sensor, and BMI088 IMU.

### PMW3901-Based Sensors

[PMW3901](/px4-user-guide/drone_parts/peripherals/optical_flow/pmw3901.md) is an optical flow tracking sensor similar to what you would find in a computer mouse, but adapted to work between 80 mm and infinity. It is used in a number of products, including some from: Bitcraze, Tindie, Hex, Thone and Alientek.

### Other Cameras/Sensors

It is also possible to use a board/quad that has an integrated camera. For this the [Optical Flow repo](https://github.com/PX4/OpticalFlow) can be used (see also [snap\_cam](https://github.com/PX4/snap_cam)).

## Range Finders

You can use any supported [distance sensor](/px4-user-guide/drone_parts/peripherals/rangefinders.md). However we recommend using LIDAR rather than sonar sensors, because of their robustness and accuracy.

## Estimators

Estimators fuse data from the optical flow sensor and other sources. The settings for how fusing is done, and relative offsets to vehicle center must be specified for the estimator used.

The offsets are calculated relative to the vehicle orientation and center as shown below:

![Optical Flow offsets](/files/6D1FpxsoQ7TmnxVcCo3n)

Optical Flow based navigation is enabled by both the availableestimators: EKF2 and LPE (deprecated).

### Extended Kalman Filter (EKF2)

For optical flow fusion using EKF2, set [EKF2\_OF\_CTRL](/px4-user-guide/advanced_config/parameter_reference.md#EKF2_OF_CTRL).

If your optical flow sensor is offset from the vehicle centre, you can set this using the following parameters.

| Parameter                                                                                | Description                                                             |
| ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| [EKF2\_OF\_POS\_X](/px4-user-guide/advanced_config/parameter_reference.md#EKF2_OF_POS_X) | X position of optical flow focal point in body frame (default is 0.0m). |
| [EKF2\_OF\_POS\_Y](/px4-user-guide/advanced_config/parameter_reference.md#EKF2_OF_POS_Y) | Y position of optical flow focal point in body frame (default is 0.0m). |
| [EKF2\_OF\_POS\_Z](/px4-user-guide/advanced_config/parameter_reference.md#EKF2_OF_POS_Z) | Z position of optical flow focal point in body frame (default is 0.0m). |


---

# Agent Instructions: 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:

```
GET https://px4.gitbook.io/px4-user-guide/drone_parts/peripherals/optical_flow.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
