Terrain Following (in AltHold, Loiter, etc)

Copter support “terrain following” in nearly all modes including pilot controlled modes like AltHold, Loiter and PosHold and also fully autonomous modes including AUTO and Guided.

This page describes the setup for pilot controlled modes (AltHold, Loiter, PosHold, etc). For autonomous modes please see the terrain following for autonomous modes wiki page.

Setup and Configuration

  • Connect a downward facing lidar or sonar to the vehicle
  • If necessary adjust the RNGFND_GAIN parameter to increase or decrease the response to changes in reported altitude from the range finder
  • An auxiliary switch can be configured to turn on/off use of the rangefinder


Do not set the EK2_ALT_SOURCE or EK3_ALT_SOURCE parameters. These parameters should be left at “0” (barometer).

Do not set the EK2_RNG_USE_HGT or EK3_RNG_USE_HGT parameters. These parameters should be left at “-1”.

How does it work?

  • When the rangefinder can “see” the ground, the pilot’s throttle stick adjusts the target altitude above the terrain (i.e. the attitude corrected distance from the range finder)
  • When the vehicle climbs out of the rangefinder’s range the pilot’s stick returns to directly controlling the vehicle’s target climb rate (i.e. EKF estimated climb rate based on barometer and accelerometer). When the vehicle comes back within the range of the ground, the target altitude above the terrain is reset to the current altitude above terrain.