From 7da87a811f31fbb509ffbff2b58e2c8bde075635 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 e0e44c2053..4e8437927f 100644 --- a/libraries/AP_Arming/AP_Arming.cpp +++ b/libraries/AP_Arming/AP_Arming.cpp @@ -1516,16 +1516,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 @@ -1603,6 +1593,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; }