When the pilot is flying in ALTH or Loiter mode, my understanding is that the autopilot attempts to maintain the altitude using some sensor source set with EK3_SRCx_POSZ. So, presumably that altitude value is stored somewhere. Is there a way to get, and preferably, set that saved altitude value via script?
General code being something like:
β get altitude
local pilot_des_alt = ahrs:get_alt()
In general Lua scripts can only control the motion of a vehicle while it is in Guided mode similar to how the vehicle is controlled from a companion computer using mavlink.
The reason AP does it this way is that it means the pilot can always retake control from Lua scripts.