Reference level for Sonar or LIDAR vs. barometric altitude

I'm unclear on how sonar and LIDAR are used for reference altitude readings as opposed to barometer-based altitude readings. I assume that sonar or LIDAR (when available) are used for altitude references below a certain altitude as determined from the barometer referenced from the ground at arming time (e.g. below 20 feet? Can this value be changed?) But what happens when sonar or LIDAR are in use in a situation with an intermediate obstacle? 

For example, assume you start at point A, rise to 15 feet altitude (with sonar or LIDAR enabled), and then head toward point B, also at 15 feet altitude referenced from the ground at arming time at point A. 

However, between A and B is a structure 10 feet tall. When the quad reaches the structure (again, still assuming sonar or LIDAR in use), will it rise up 15 feet above the structure, with the top of the structure being the new "ground" reference point, or will the quad fly level at 15 feet as referenced from the actual ground (so, 5 feet above the structure)? If the former behavior is the default, can the latter behavior be specified? Thanks!

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –


  • I have a similar question.

    During the attached flight, the copter suddenly landed during alt hold mode. It's not exactly visible on the graph, but I landed the copter manually and only then switched to stabilise mode at the end. You can see SAlt does not go back to 0.

    Could it be that it is still taking into account the barometer?


  • it will ignore the internal baro and rely upon either the sonar or lidar when your within the working range distance.   In short the craft will track the ground at the same "height directly below the sensor" irregardless of the barometric altitude reading.   Hopefully that answers your question.

    • Thanks. What is the "working range distance" default? Can it be user-adjusted via parameters or is it compiled in? If it's height directly below the sensor that matters, what is an appropriate strategy to maintain a *level* flight at a specified altitude referenced from the ground, when passing over lower, variable-height intermediate obstacles? Thanks again.

    • MR60

      Read the wiki might help find your answers:

      Sonar Maximum Altitude

      • When enabled Sonar is used as the means of determining altitude below Sonar Maximum Altitude, above that the barometer is used.
      • Sonar Maximum Altitude is calculated as 60 percent of the factory specified maximum Sonar range for the Sonar type selected.
      • Sonar is used for determining altitude only when the Sonar itself is detecting the ground and is below it’s Sonar Maximum Altitude.If the Sonar gets an unreliable return below the Sonar Maximum Altitude, it is ignored and the Barometer altitude is used
        • XL-EZ4 or XL-EZ0 have a Maximum range of 7.65 meters and a Sonar Maximum Altitude of 4.59 meters.
        • XL-EZLO have a Maximum range of 10.68 meters and a Sonar Maximum Altitude = 6.4 meters.
        • HRLV-EZ4 or HRLV-EZ0 with Maximum range of 5 meters and a Sonar Maximum Altitude of 3 meters.
        • LV-EZ4 or LV-EZ0 have a Maximum range of 6.45 meters and a Sonar Maximum Altitude = 3.87 meters.

      As for the LIDAR, you have the following parameters to configure:

      RNGFND_MAX_CM : max altitude

      RNGFND_MIN_CM : min altitude

    • Thanks. I had looked through the Wiki as usual, but missed this. Perhaps I was looking at an older version, there seem to be several floating around. This still doesn't really address the "level flight" issue though as far as I can tell. Essentially, I'd like to be able to use LIDAR to maintain precision level flight even when passing over lower obstacles, which would of course imply a calculation representing the difference between the original ground and the height of those intermediate obstacles.

This reply was deleted.