This requires a sonar or something similar. A sonar sends a sound pulse and measures the time it takes to bounce back.
Sonar only works when within range of the ground (a few meters). That range depends on what the ground is made of. Soft thick grass has short range. Cement has long range.
I wrote some test code that uses sonar and when the sonar is within range (the sonar tells you if it within range) then the absolute altitude was changed into altitude above ground. The result was that you could fly up and down a hill or steps using the current altitude hold/vario flight modes.
I found that you cannot use a cheap sensor because the prop noise fools a cheap sensor that is out of range into saying that it is staying at that max range instead of saying it is out of range. I bought a good sensor that uses some of the same technology that cars with radars use to avoid hearing other similar cars, but had moved on to other projects by the time it arrived.
A quick search on the wiki returned these links which themselves contain some links:
theothercliff (me) video of climbing stairs and link to code repo
(look earlier in this thread for some links)
https://forum.librepilot.org/index.php?topic=3390.msg23410#msg23410mr_w sonar code branch and discussion
(I think it only updates the sonar altitude number which is not currently used for flying?)
https://forum.librepilot.org/index.php?topic=767.msg5504#msg5504