From 16d617c62de2668c39335f9e21bc53f15b2dff54 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 8 Aug 2023 07:09:24 +1000 Subject: [PATCH] AP_Arming: fixed auto-enable of fence with forced arm when a user forced armed and had FENCE_AUTOENABLE=3 for enable on arming then the fence did not enable --- libraries/AP_Arming/AP_Arming.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/libraries/AP_Arming/AP_Arming.cpp b/libraries/AP_Arming/AP_Arming.cpp index be41dc85b5..1788d01c32 100644 --- a/libraries/AP_Arming/AP_Arming.cpp +++ b/libraries/AP_Arming/AP_Arming.cpp @@ -1479,16 +1479,6 @@ bool AP_Arming::arm_checks(AP_Arming::Method method) } } -#if AP_FENCE_ENABLED - AC_Fence *fence = AP::fence(); - if (fence != nullptr) { - // If a fence is set to auto-enable, turn on the fence - if(fence->auto_enabled() == AC_Fence::AutoEnable::ONLY_WHEN_ARMED) { - fence->enable(true); - } - } -#endif - // note that this will prepare AP_Logger to start logging // so should be the last check to be done before arming @@ -1565,6 +1555,19 @@ bool AP_Arming::arm(AP_Arming::Method method, const bool do_arming_checks) } #endif +#if AP_FENCE_ENABLED + if (armed) { + auto *fence = AP::fence(); + if (fence != nullptr) { + // If a fence is set to auto-enable, turn on the fence + if (fence->auto_enabled() == AC_Fence::AutoEnable::ONLY_WHEN_ARMED) { + fence->enable(true); + gcs().send_text(MAV_SEVERITY_INFO, "Fence: auto-enabled"); + } + } + } +#endif + return armed; }