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 ground (so, 5 feet above the structure)? If the former behavior is the default, can the latter behavior be specified? Thanks!

I’m a bit curious about this as well, and need to do more testing and dive into the code now that I have a Lidar Lite.

I have a project where I’d like to launch a drone from a rooftop. If I rise to an altitude of 20ft off the rooftop, then fly over the edge , where I’m now 50ft above ground, will my drone decrease 30ft of altitude? Ideally, I’d like to reference altitude based off the initial home position (rooftop), but I suspect that without also integrating data from the baro/gps, there’s no way to know true altitude from Lidar - just the height above whatever’s below it.

[quote=“radionick”]I’m a bit curious about this as well, and need to do more testing and dive into the code now that I have a Lidar Lite.

I have a project where I’d like to launch a drone from a rooftop. If I rise to an altitude of 20ft off the rooftop, then fly over the edge , where I’m now 50ft above ground, will my drone decrease 30ft of altitude? Ideally, I’d like to reference altitude based off the initial home position (rooftop), but I suspect that without also integrating data from the baro/gps, there’s no way to know true altitude from Lidar - just the height above whatever’s below it.[/quote]

It may be that we’re actually defining a new flight mode here, a precision low-level flying mode that indeed uses both the baro and lidar (gps could also be used as a secondary check). I haven’t looked at the relevant section of code in detail yet, but what’s needed is to establish a desired “baseline” altitude and use that for reference in this mode (which itself could be used in another mode such as Auto, which apparently does not currently support sonar or lidar – I’m looking into enabling that also).

To use your type of example, we start on a rooftop. Use lidar to rise to a precision 10 feet (referenced from the roof). We save that value as our precision altitude baseline. We fly beyond the edge of the roof, which we’ll say is 15 feet high. Lidar now reads 25 feet since it can now see the ground.

How do we know from the lidar if we came to the edge of the roof and are now looking down 15 feet further at the ground, or if the copter just get blown upward 15 feet? That’s where the baro (and maybe the gps) come into play. For example, if the lidar suddenly shows that 15 foot change, but the baro has been relatively stable, we might assume that the lidar is registering a drop-off (e.g., from that roof) rather than a height change in the flyer itself (especially since a stable baro reading seems more reasonable to accept as valid than a suddenly changing one).

Lots of details but this seems like a practical route worth thinking about.

As a side note, the range finders are only used in AltHold, Loiter, PosHold modes. They’re not used in Guided, Auto, RTL.

In the former modes (AltHold, etc) the vehicle maintains a desired-rangefinder-alt as long as the ground (or something) is sensed below. During this time, that desired-rangefinder-alt and the actual range from the sensor are used to adjust the barometer+accel based altitude estimate. So in the example where the vehicle is flying 15m above the ground and then flies over a 10m object it will climb until it’s 15m above the object (i.e. 25m above the ground).

If the sensor ever loses contact with the ground for more than about 1 second it the desired-rangefinder-alt and actual sensor are not used. So in a different example, if the vehicle has a rangefinder with a range of 20m and the vehicle is flying 10m off the ground but then the vehicle flies off the edge of a cliff (which, for example, has say 100m dropoff) the vehicle will not descend. Instead it will keep flying at it’s current baro based altitude.

If the sensor regains contact with the ground (indicated by about 1 second of good sensor readings) it resets the desired-rangefinder-alt to the new sensor reading. So for example, if the vehicle has a range finder with a 20m range and we begin the example with the vehicle flying about 50m above the ground then the range finder is not used. If the ground is sloping upwards though in the direction the vehicle is flying, then when the ground reaches about 20m below the vehicle, the vehicle will suddenly see the ground and it will reset the desired-rangefinder-alt to 20m. It will then maintain that 20m altitude above the ground. I.e. if the ground continues to slope upwards the vehicle will maintain an alt of 20m above the ground.

[quote=“rmackay9”]
If the sensor regains contact with the ground (indicated by about 1 second of good sensor readings) it resets the desired-rangefinder-alt to the new sensor reading. So for example, if the vehicle has a range finder with a 20m range and we begin the example with the vehicle flying about 50m above the ground then the range finder is not used. If the ground is sloping upwards though in the direction the vehicle is flying, then when the ground reaches about 20m below the vehicle, the vehicle will suddenly see the ground and it will reset the desired-rangefinder-alt to 20m. It will then maintain that 20m altitude above the ground. I.e. if the ground continues to slope upwards the vehicle will maintain an alt of 20m above the ground.[/quote]
Thanks very much for these details. I’m curious what the rationale is for not using the sensors in Auto mode – where one would ordinarily think their additional accuracy would be particularly useful? And in a related context, what would be the best strategy to maintain level flight even over obstacles? So, in your example, where the vehicle is flying 15m above the ground and then flies over a 10m object, instead of climbing until it’s 15m above the object (i.e. 25m above the ground) it would instead maintain the level 15m altitude as it passes over the 10m object (that is, 5m above the object).

Thanks!