This video shows the 250mm quadcopter from my previous post, holding altitude by means of its MaxBotix MB1242 ulatrasonic rangefinder (sonar). The Flip32 flight controller onboard is running a modified version of the Baseflight firmware to support the MB1242. Original Baseflight requires a barometer for alt-hold, and then fuses it with data from an HC-SR04 sonar if one is available. So I removed the baro requirement and replaced the HC-SR04 code with code that uses the MB1242.
The real-time plot (made in Python with RealTimePlotter) shows AGL (Above Ground Level) in centimeters (blue) as well as the desired altitude that locks in when I flip a switch on the transmitter (red). The desired altitude starts out with its value from a previous run, which has no effect until I hit the switch, at which point it resets to the current AGL. The bottom plot is the PID (Position / Integral / Derivative) -based correction to the throttle in support of altitude hold, which likewise has no effect until I hit the switch.
Although the vehicle holds low altitude (here, around a meter) pretty well, the values being displayed are quite a bit off from what you expect to see (vehicle is holding AGL at around 100cm, though reported AGL is 60cm, with locked-in AGL at 40cm). At higher altitudes, big transient jumps in the sonar-measured AGL can cause the vehicle to jump slightly. So my next steps are to (1) figure out the discrepancy between the observed behavior and displayed signals; (2) add an Extended Kalman Filter to smoothe out transient jumps in the sonar signal.