Hardware requirements
To use optic flow capabilities of INAV you need two sensors - optic flow (to measure sliding)
and rangefinder (to measure distance to surface).
Tested sensors:
1. Combination of Cheerson CX-OF + VL53L0X laser rangefinder
2. MATEK Optic Flow / Lidar board
Connecting and configuring the hardware
The easiest to connect board in MATEK Optic Flow / Lidar - you need one Serial port to get all
of the data from the board (optic flow and rangefinder). The next paragraph applies to that
board.
After you connected the board you need to go to INAV Configurator and configure the Serial
port to MSP protocol and 115200 baud and select “MSP” for both Optic Flow and Rangefinder:
If you have connected and configured everything correctly, you should have all sensors active
and ready. At the bare minimum you should have Gyro, Accel, Baro, Flow and Sonar ready and
active to get optic flow working.
Aligning the hardware
As a first step, obviously, you should have your board aligned properly, accelerometer
calibrates and machine flight tested in ANGLE and ALTHOLD modes, without any modifiers
(sonar and flow). As with GPS/Baro-assisted modes good ANGLE performance is very
important.
Second step is aligning the optic flow sensor. This is a critical step that is equally important as
getting compass alignment right for GPS-enabled flights. With optical flow sensor misaligned
behavior of POSHOLD will be random.
Unfortunately, as of version 2.2.1 there is no GUI-friendly way to align the optic flow sensor, so
this step might be a bit complicated. First, go to CLI and set debug mode to FLOW_RAW:
set debug_mode = FLOW_RAW
save
Then, find a spot of well-lit and contrast terrain:
1. Optic flow needs contrast texture it can observe to measure motion. It won’t work on
solid color, low contract surface or in the low light.
2. Laser rangefinder needs a relatively reflective surface to work properly - it won’t work
over dark surface. Furry carpet is also not a very good example of terrain.
Open the “Sensors” tab. Then lift the quad 50-70cm over the surface and tilt it from one side to
the other by roll and then by pitch axis. The max tilt should be around 30-40 degrees, optic flow
should always be looking down at the surface. Make sure that you only tilt the quad without
moving it over the terrain. Observe the graphs and make sure Debug 0 looks similar to Debug 2
and Debug 1 is similar to Debug 3:
Change the “align_opflow” parameter in CLI and retry the procedure until your Debug 0 looks
similar to Debug 2 and Debug 1 is similar to Debug 3.
Because optic flow sensor is looking down, there are only 4 possible values of “align_opflow”
that make sense: CW0FLIP, CW90FLIP, CW180FLIP and CW270FLIP.
Note : that those values are relative to the FC board, not the frame, so if your FC is mounted
upside down, possible values would be CW0, CW90, CW180 and CW270.
Optic flow calibration
With INAV 2.2.1 this is easy - just go to Configurator, open the “Calibration” tab and follow
instructions for “Optic Flow Calibration”. You will have 30 seconds to tilt the quad in a way you
did in “Aligning the hardware” section. For MATEK Opflow board and Cheerson CX-OF sensor
(and probably other sensors based on PMW3901 chip) the optic flow scale (CLI variable
“opflow_scale”) value is 9-10.
Flight modes
There is no specific flight mode for optic flow. From flight modes perspective it’s the same
“POSHOLD” mode as you would use with GPS.
To enable terrain following altitude hold you need to enable “SURFACE” mode together with
“ALTHOLD” or “POSHOLD”. The “SURFACE” works as a modifier to altitude hold controller and
changes its behavior to use altitude above ground level (AGL) instead of altitude above launch
point.
If your machine doesn’t have a compass, you won’t be able to select “POSHOLD” in flight
modes. To override requirement for compass there is one important CLI parameter you need
to enable:
set inav_allow_dead_reckoning = ON
save
Keep in mind that dead reckoning may cause unexpected results when you actually use
compass. If you intend to fly with GPS and compass on the same machine - don’t enable this
parameter.
Tuning
Both terrain following and optic flow offer much better accuracy compared to GPS and
barometer, so PosXY, VelXY, PosZ and VelZ PIDs could be much higher than default ones.
Here are PID settings that were tested with success:
set nav_mc_vel_z_p = 150
set nav_mc_vel_z_i = 250
set nav_mc_vel_z_d = 25
set nav_mc_pos_xy_p = 80
set nav_mc_vel_xy_p = 50
set nav_mc_vel_xy_i = 40
set nav_mc_vel_xy_d = 60
save