Quick Answer
An optical flow sensor tracks ground movement using a downward-facing camera, allowing drones to hold position without GPS. It works indoors, in urban canyons, and anywhere satellite signals are unreliable. The most common sensor is the PMW3901, paired with a ToF rangefinder for altitude data. ArduPilot and PX4 both support optical flow natively.
How Optical Flow Works
An optical flow sensor is essentially a mouse sensor pointed at the ground. It captures sequential images of the surface below and compares pixel shifts between frames. By measuring how the ground moves relative to the drone, the sensor calculates velocity in two axes (forward/back and left/right).
The raw output is pixel flow rate, which needs to be converted to actual ground speed. This requires knowing the distance to the ground, which is why optical flow sensors are almost always paired with a ranging sensor like a ToF (Time of Flight) module or LiDAR.
Without accurate altitude data, the flow calculations are meaningless. The Holybro PMW3901 uses a UART connection and requires a separate rangefinder for altitude. The MicoAir MTF-01P combines both optical flow and a 12-metre ranging sensor in one board, simplifying wiring.
When to Use Optical Flow Instead of GPS
GPS is the default positioning system for outdoor drones, but it has limitations. Optical flow fills specific gaps:
| Situation | GPS | Optical Flow |
|---|---|---|
| Open outdoor flying | Best choice | Not needed |
| Indoor warehouses | Unavailable | Works well |
| Under bridges or tunnels | Degraded | Maintains hold |
| Low-altitude indoor hover | Drifts | Stable hold |
| Urban canyon with poor sky view | Inaccurate | Helps supplement |
Optical flow is not a replacement for GPS. It works best at low altitudes (under 3 metres) over textured surfaces. Smooth floors, water, and featureless surfaces confuse the sensor. For outdoor autonomy where GPS is unreliable, a ToF rangefinder combined with optical flow provides reasonable positioning without satellites.
Key Optical Flow Sensors
| Sensor | Technology | Range | Interface | Best For |
|---|---|---|---|---|
| Holybro PMW3901 | Optical flow only | Requires external ToF | UART | ArduPilot/PX4 builds |
| MicoAir MTF-01P | Optical flow + 12m LiDAR | 0.03-12m | UART/CAN | All-in-one positioning |
The PMW3901 is the most widely supported option, with native drivers in ArduPilot and PX4. The MTF-01P is newer and combines both sensors on one board, reducing wiring complexity. Both are in the sensors collection.
Setting Up Optical Flow in ArduPilot
ArduPilot supports the PMW3901 directly. After wiring the sensor to a UART port on your flight controller:
- Set SERIALx_PROTOCOL to 9 (for MAVLink optical flow)
- Set FLOW_TYPE to 1 (for PMW3901 serial)
- Enable the rangefinder and configure RNGFNDx_TYPE for your ToF sensor
- Set EK2_GPS_TYPE to 3 or higher to allow non-GPS navigation sources
- Set FLOW_ENABLE to 1
For position hold without GPS, set ARMING_CHECK to disable GPS requirements, or use the FS_GCS_ENABLE failsafe for indoor use. PX4 setup follows a similar pattern with the EKF2_AID_MASK parameter controlling which sensor sources are used.
The setup process is straightforward if you are already familiar with ArduPilot configuration. The ArduPilot setup guide covers initial FC configuration, and GPS modules for drones explains positioning sensors in a broader context.
Companion Computers and Advanced Autonomy
For more advanced indoor navigation (mapping, obstacle avoidance, waypoint missions), an optical flow sensor alone is not enough. You need a companion computer running software like ROS or a custom mission planner.
The PX4 Vision V1.5 combines a companion computer with sensors in one development kit, designed for autonomous drone applications. Alternatively, the Pixhawk RPi CM4 Carrier Board lets you add a Raspberry Pi Compute Module to any Pixhawk-based build. The maker collection has several boards and kits for these kinds of projects.
Limitations to Keep in Mind
- Altitude ceiling. Optical flow accuracy drops above 3 metres. The sensor needs visible ground texture to work.
- Surface texture matters. Polished floors, carpets with repeating patterns, and water cause poor tracking. Textured concrete or asphalt works best.
- Lighting conditions. Very dark environments or direct bright sunlight can affect the sensor. Typical indoor lighting is fine.
- Drift over time. Without GPS to correct accumulated error, optical flow positioning will drift. It is best for short-duration holds and precise landing, not long autonomous missions.