-- This script allows for best effort return for quadplanes
-- on loss of forward motor
-- When an engine failure is detected (RPM and Vibration values drop below a certain threshold), the aircraft will:
-- Send a warning ground station
-- Start prioritizing airspeed completely
-- Glide back towards the home location or rally point, monitoring the distance away from the point as well as Altitude.
-- If the aircraft drops below a predetermined minimum altitude, QLAND mode is engaged and the aircraft lands at its current position.
-- If the aircraft arrives within Q_FW_LND_APR_RAD of the return point before dropping below the minimum altitude, it should loiter down to the minimum altitude before switching to QRTL and landing.
-- consider engine stopped when vibe is low and RPM low for more than 4s
localENGINE_STOPPED_MS=4000
-- RPM threshold below which engine may be stopped
localRPM_LOW_THRESH=500
-- vibration threshold below which engine may be stopped
localVIBE_LOW_THRESH=2
-- altitude threshold for QLAND
localLOW_ALT_THRESH=70
-- when below MIN_AIRSPEED assume we are not in forward flight
localMIN_AIRSPEED=5
-- time when engine stopped
localengine_stop_ms=-1
localengine_stopped=false
-- have we triggered failsafe? Only trigger once
localtriggered_failsafe=false
-- flight mode numbers for plane
localMODE_AUTO=10
localMODE_RTL=11
localMODE_QLAND=20
localMODE_QRTL=21
-- update engine running status
functioncheck_engine()
ifnotarming:is_armed()then
engine_stopped=false
engine_stop_ms=-1
returntrue
end
localrpm=RPM:get_rpm(0)
localvibe=ahrs:get_vibration():length()
-- if either RPM is high or vibe is high then assume engine is running