Modifying Alt Hold to use custom altitude input data


I’m trying to modify the Alt Hold code to accept custom altitude data that another script would provide. So instead of getting the current altitude from the barometer/sonar, I’d like to feed alt hold with my own data (a postprocessed combination of multiple sensors). Also I’d like to precisely define the target altitude, rather than just set it to the current altitude, when alt hold is initially enabled.

Presumably at some level in the source code, there is a function to obtain the ‘Current altitude’, and also a variable which is set as the ‘Target Altitude’. If I could find these functions/variables, then it might be possible to modify the code. I would greatly appreciate if someone with an understanding of the code could help. Thanks in advance.

Probably better to just set up your custom altitude source with a driver (it’s really just a rangefinder after all).