How to Set Up Optical Flow & Rangefinder Sensors in iNav – Position/Altitude Hold for FPV Drones

by Oscar
Microair Mtf 01 Ranger Finder Optical Flow Sensor Module Install Geprc Cinebot25 Fpv Drone Cinewhoop Bottom

Flying an FPV drone in Position Hold and Altitude Hold modes can be significantly improved with the addition of Optical Flow and Sonar (rangefinder) sensors. These sensors help maintain a stable hover by providing precise data about the drone’s position and altitude. In this tutorial, I’ll guide you through setting up these sensors in iNav.

Some of the links on this page are affiliate links. I receive a commission (at no extra cost to you) if you make a purchase after clicking on one of these affiliate links. This helps support the free content for the community on this website. Please read our Affiliate Link Policy for more information.

This guide is based on the instructions provided by the manufacturer of the optical flow sensor I purchased. These steps might not work for other types of optical flow/sonar sensors.

Why Add a Rangefinder and Optical Flow Sensor?

Adding a rangefinder and optical flow sensor enhances your quadcopter’s stability and precision. The optical flow sensor works like the sensor in a computer mouse, capturing images of the ground to determine movement. The rangefinder (sonar) provides more accurate altitude measurements compared to a barometer, which is especially useful during landing, though the maximum effective altitude is often less than a few meters.

Required Components

You will need two things:

  • Optical Flow and Rangefinder Sensor
  • A drone with an iNav-compatible flight controller and a spare UART

Microair Mtf 01 Ranger Finder Optical Flow Sensor Module

I am using the MicroAir MTF-01, a rangefinder sensor with integrated Optical Flow capability. It’s a great module because the connection and setup are very straightforward, and it supports iNav. You can get the MTF-01 here:

I recommend getting the bundle that includes the USB to TTL programmer (FTDI adapter), as you might need it to change settings, or you can buy a generic one if that’s cheaper, also works fine: https://oscarliang.com/fpv-tools/#FTDI-Adapter

MTF-01 Specifications:

  • Supports Ardupilot, PX4, and iNav
  • PMW3901 optical flow sensor
  • High-performance TOF sensor
  • Output mode: UART
  • Output frequency: 100Hz
  • TOF Range: 0.02-8m
  • Range accuracy: 2%
  • Wavelength: 830-870nm
  • Resistance to ambient light: 70K Lux illumination
  • Distance FOV: 6°
  • Optical flow FOV: 42°
  • Ambient light demand of optical flow: >60Lux
  • Optical flow working distance: >80mm
  • Power consumption: 500mW
  • Operating voltage: 4.0- 5.5V
  • Module weight: 4.5g
  • Dimensions: 29 * 16.5 * 15mm

For the drone, I am using the GEPRC Cinebot25. I am not comfortable testing position hold indoors with any drones without prop guards, so a small cinewhoop is a perfect choice. See my review of this drone here: https://oscarliang.com/geprc-cinebot25/

However, the GEPRC flight controller does not support iNav (yet), so I had to swap it out with the Flywoo GN745 V3. Here are details about this FC and how I replaced it: https://oscarliang.com/flywoo-goku-gn745-aio-v3-fc/

New to iNav? Check out my beginner tutorial on how to set up iNav on an FPV drone: https://oscarliang.com/setup-inav-fpv-drone/

Step 1: Configuring the Module

The MTF-01 module supports the following output protocols:

  • Microlink: a custom protocol which supports FMT
  • MSP: supports iNav
  • Mavlink_APM: Mavlink protocol for Ardupilot
  • Mavlink_PX4: Mavlink protocol for Pixhawk 4

My unit was set to Microlink by default, so I had to change it to MSP protocol to work with iNav. You can easily switch the output protocol of the MTF-01 using the MicoAssistant software, but you will need a USB to TTL programmer.

Download MicoAssistant software: https://github.com/micoair/MTF-01_USER_MANUAL

Connect the MTF-01 to your PC using the USB to TTL module.

Microair Mtf 01 Ranger Finder Optical Flow Sensor Module Usb To Ttl Programmer

Open the MicoAssistant software, select the correct COM port in the upper right corner, set the baud rate to 115200, and click on the connection icon.

Microair Mtf 01 Ranger Finder Optical Flow Sensor Module Usb Microassistant Configure Connection

Once connected, click on the Setup Menu (gear icon), select the protocol you want to use (in this case, MSP), and then click the WRITE button.

Microair Mtf 01 Ranger Finder Optical Flow Sensor Module Usb Microassistant Configure Output Protocols Msp

Step 2: Wiring the Sensors

Connect the four wires from the MicroAir MTF-01 sensor to any spare UART on your flight controller. I connected it to UART4 on my FC.

  • 5V to 5V
  • GND to GND
  • TX to RX
  • RX to TX

Note: If the rangefinder and optical flow sensor don’t get powered via the USB cable, you might have to plug in a battery to power these sensors.

Microair Mtf 01 Ranger Finder Optical Flow Sensor Module Wiring Diagram Flight Controller Fc Uart Tx Rx

Flywoo Goku Gn745 45a Aio V3 Fc Flight Controller Replace Geprc Cinebot25 Taker G4 Wiring Gps Optical Flow

Mount the sensor on the bottom of the quad, ensuring there’s nothing obstructing the view of the sensors. Use landing gears to ensure there’s sufficient clearance between the ground and the sensors during takeoff, ideally a couple of centimeters or more.

Microair Mtf 01 Ranger Finder Optical Flow Sensor Module Install Geprc Cinebot25 Fpv Drone Cinewhoop Bottom

Step 3: Configuring iNav

Before proceeding, remove the propellers from your quadcopter for safety. Connect the battery and then connect the flight controller to your computer.

Ports

Open iNav Configurator, go to the Ports tab, and configure the UART you wired up as MSP. Save and reboot.

Inav Configurator Ports Setup Ranger Finder Optical Flow Sensor Msp

Configuration

In the Configuration tab, find the “Sensors & buses” section. For Rangefinder and Optical Flow, set them to MSP. Save and reboot.

After rebooting, the “Flow” and “Sonar” sensor icons on the top of iNav Configurator should turn blue, indicating they are working correctly. If these sensors do not turn blue but red, check that the TX and RX wires are correctly connected and that the battery is powering the sensors.

Inav Configurator Configuration Setup Ranger Finder Optical Flow Sensor

CLI Settings

Inav Configurator Cli Setup Ranger Finder Optical Flow Sensor Pid

Copy and paste the following lines in the CLI (these are configurations suggested by the maker of MTF-01).

  • Dead Reckoning: by enabling iNav_allow_dead_reckoning in the CLI, it improve performance during brief GPS outages.
  • Maximum Height Setting: by setting the inav_max_surface_altitude in the CLI, it defines the maximum height at which the rangefinder is effective, in cm.

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
set debug_mode = FLOW_RAW
set inav_allow_dead_reckoning = ON
set nav_max_terrain_follow_alt = 200
set inav_max_surface_altitude = 200
save

Debug

In the Sensors tab, gently tilt the quad side to side and front to back. The waveform of Debug 0 should look similar to Debug 2, while Debug 1 should look similar to Debug 3.

Debug 0/1 represents the accelerometer readings, while 2/3 are from the optical flow sensor. This test verifies the orientation of the optical flow sensor. The amplitude might not be the same, but if they move in the opposite direction, you might need to change the configuration in MicroAssistant (or set align_opflow=cw180 in CLI).

Inav Configurator Debug Setup Ranger Finder Optical Flow Sensor

Calibration

Hold the drone around 50-60 cm above the ground and perform the optical flow sensor calibration in iNav Configurator. This involves gently tilting the quad side to side and front to back slightly and gently for about 30 seconds without any horizontal movements. Hit save and reboot when done.

MTF-01 recommends a scale value between 4 to 6. If you get a value outside this range, repeat the calibration at a better height with more steady hands.

Inav Configurator Calibration Setup Ranger Finder Optical Flow Sensor Scale

Modes

Assign a switch that can enable ANGLE, NAV POSHOLD (position hold), NAV ALTHOLD (altitude hold), HEADING HOLD, and SURFACE at the same time.

Inav Configurator Modes Setup Ranger Finder Optical Flow Sensor Altitude Position Hold

Step 4: Testing the Setup

  1. Arm the drone and lift it into a hover. If it doesn’t arm due to the lack of GPS lock, bypass this by pushing the throttle/yaw stick to the bottom right while arming.
  2. Switch to Position Hold mode and observe the stability.
  3. Switch to Altitude Hold mode and check the altitude stability.

Troubleshooting and Pro Tips

    • Sensor Initialization Failure: Ensure the wiring is correct and the sensors are powered.
    • Inaccurate Position Hold: Adjust the Optical Flow scaler value.
    • Altitude Drifting: Recheck the Rangefinder configuration and calibration.
    • Initialization Clearance: Ensure there is at least a couple of centimeters of clearance between the sensor and the ground when powering up the quadcopter to avoid incorrect readings.

Conclusion

Adding the MTF-01 rangefinder and optical flow sensor to your iNav FPV drone is a straightforward process that significantly enhances the stability and precision of your drone in Position Hold and Altitude Hold modes, as well as landing accuracy. With these sensors, your quadcopter will perform more like a DJI camera drone, holding its position and altitude with greater precision. Happy flying!

Leave a Comment

By using this form, you agree with the storage and handling of your data by this website. Note that all comments are held for moderation before appearing.

15 comments

VanLaser 26th November 2024 - 10:28 pm

The last two CLI configuration settings, aren’t they a bit low? (2m instead of 6-8m)

Reply
Bentech 21st November 2024 - 1:48 am

Hi, why do you activate all these modes NAV POSHOLD, NAV ALTHOLD , HEADING HOLD, and SURFACE at the same time with one channel?
From my understanding NAV ALTHOLD and SURFACE can’t be use at the same time as one maintain the altitude based on the start point and the other one is following the terrain… both are conficting… I might be wrong. How did it work?
Also 1 more question, in ALTHOD, your altitude is totally locked right? Or can it be adjusted without to switch off the mode?

Reply
Ali 4th November 2024 - 3:22 am

HI oscar

what happens if I push the throttle, pitch, and roll sticks while ANGLE, NAV POSHOLD, NAV ALTHOLD, HEADING HOLD, and SURFACE are enabled at the same time?

Reply
101 12th October 2024 - 10:21 am

According to the instructions for MTF-01 iNav installs should be mounted with the two big sensors towards the front of the drone and for Ardu to the back. I would attach a picture if I could but in your photo it’s in the wrong direction.
I also want to say thank you so much for all your amazing information. I appreciate all of it!
You need build a drone that’s a DJI replacement – A 5 to 7 inch with optical flow (MTF01P for 10 to 12m), and a 2 or 3 axis gimbal front camera, maybe with walksnail moonlight. All using iNav. Boom the first DJI replacement finally.

Reply
Jungle Boy 7th October 2024 - 3:28 am

I would like to ask you. I want to use a optical flow along with a GPS in my quad. I know that the default P gains for POS and VEL are too low and should be increased. Once I raise this P gain, do this increase affect the GPS navigation, like oversaturate or can both share the same parameter?

Reply
lars 10th September 2024 - 9:23 am

Hey oscar,
Nice build, i try to build a nearly similar build with this goku flywoo f745aio.
But when i switched from betaflight(in betaflight all worked fine) to inav i lost motor 2. I try it 4x times and everytime the same resuld. Maybe i get the wrong firmware. In betaflight is the target the flywoo f745 aio, in inav i didnt found this target and i took the flywoo f745. Is this wrong?so please Can you send me your inav flywoo aio .hex . That would be nice. Thanx and greetz from hamburg

Reply
Chetan 4th September 2024 - 8:38 pm

Hi Oscar, my debug 0&2, 1&3 don’t match. Also, I plan on using Luna & Matek 3901 together. Is that possible?

Reply
bobby 3rd July 2024 - 12:38 am

cant use bluetooth (uart 4) if I use the mtf-01 ( uart 3) if I try both uart 4 and uart 3 at same time all ports are cleared and need set back up

Reply
Achim 30th June 2024 - 10:10 pm

Thank you Oscar!
I try to setup a Matek OPTICAL FLOW 3901-L0X. Is there a possibility to mount it 90 degrees so that the direction arrow points to the side?
Regards!

Reply
Oscar 1st July 2024 - 4:27 pm

have you tried using the CLI command align_opflow?

Reply
MicratheneFPV 26th June 2024 - 6:38 pm

Hi Oscar, is it mandatory to place it horizontally or can it be installed at an angle to the ground? It is for a drone with tilted motors that flies inclined at hovering.

Reply
Oscar 27th June 2024 - 5:28 pm

To be honest I’m not entirely sure, but I think the sonar sensor has to be relatively level to work since it relies on bounce-back signal? The optical flow sensor might be more forgiving with tilt angle since it just compares pictures it takes.

Reply
Milosz 26th June 2024 - 7:41 am

Great stuff. One more feature like DJI emergency break and we are at home. Waiting for that moment

Reply
Harel 25th June 2024 - 4:30 pm

Thanks for this guide Oscar, i was looking for something like that and it seemed that there isn’t that much info about this online, then you posted this.
do you know any similar sensors that work in higher altitude? like 50m?

Reply
Oscar 25th June 2024 - 4:51 pm

At that altitude, barometer is ideal.

Reply