From 5d46e0c64e010382c51e1fd5230098d0e540fc69 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <andrew@tridgell.net> Date: Fri, 19 Jul 2024 07:33:48 +1000 Subject: [PATCH] Plane: reset previous mode fence breach when disarmed when we are disarmed or we are not in fence breach and we are not flying then reset the previous mode fence reason state so that a new flight will get the correct fence breach action behaviour --- ArduPlane/fence.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ArduPlane/fence.cpp b/ArduPlane/fence.cpp index 5bc3ab93ff..930a348440 100644 --- a/ArduPlane/fence.cpp +++ b/ArduPlane/fence.cpp @@ -39,10 +39,23 @@ void Plane::fence_check() return; } + const bool armed = arming.is_armed(); + + /* + if we are either disarmed or we are currently not in breach and + we are not flying then clear the state associated with the + previous mode breach handling. This allows the fence state + machine to reset at the end of a fence breach action such as an + RTL and autoland + */ + if (!armed || (new_breaches == 0 && !plane.is_flying())) { + plane.previous_mode_reason = ModeReason::UNKNOWN; + } + // we still don't do anything when disarmed, but we do check for fence breaches. // fence pre-arm check actually checks if any fence has been breached // that's not ever going to be true if we don't call check on AP_Fence while disarmed - if (!arming.is_armed()) { + if (!armed) { return; }