How to Set Up Optical Flow & Rangefinder Sensors in iNav - Position/Altitude Hold for FPV Drones - Oscar Liang (2024)

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.

Table of Contents

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

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.

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.

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.

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.

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.

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.

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.

CLI Settings

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).

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.

Modes

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

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!

advancedinav

How to Set Up Optical Flow & Rangefinder Sensors in iNav - Position/Altitude Hold for FPV Drones - Oscar Liang (2024)

References

Top Articles
Latest Posts
Article information

Author: Nicola Considine CPA

Last Updated:

Views: 6428

Rating: 4.9 / 5 (49 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Nicola Considine CPA

Birthday: 1993-02-26

Address: 3809 Clinton Inlet, East Aleisha, UT 46318-2392

Phone: +2681424145499

Job: Government Technician

Hobby: Calligraphy, Lego building, Worldbuilding, Shooting, Bird watching, Shopping, Cooking

Introduction: My name is Nicola Considine CPA, I am a determined, witty, powerful, brainy, open, smiling, proud person who loves writing and wants to share my knowledge and understanding with you.