diff --git a/libraries/AP_Arming/AP_Arming.cpp b/libraries/AP_Arming/AP_Arming.cpp index d8345f1918..d2ab354bfa 100644 --- a/libraries/AP_Arming/AP_Arming.cpp +++ b/libraries/AP_Arming/AP_Arming.cpp @@ -1141,7 +1141,8 @@ bool AP_Arming::pre_arm_checks(bool report) & osd_checks(report) & visodom_checks(report) & aux_auth_checks(report) - & disarm_switch_checks(report); + & disarm_switch_checks(report) + & fence_checks(report); } bool AP_Arming::arm_checks(AP_Arming::Method method) @@ -1167,6 +1168,14 @@ bool AP_Arming::arm_checks(AP_Arming::Method method) return false; } } + + 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); + } + } // note that this will prepare AP_Logger to start logging // so should be the last check to be done before arming @@ -1235,6 +1244,13 @@ bool AP_Arming::disarm(const AP_Arming::Method method, bool do_disarm_checks) } #endif + AC_Fence *fence = AP::fence(); + if (fence != nullptr) { + if(fence->auto_enabled() == AC_Fence::AutoEnable::ONLY_WHEN_ARMED) { + fence->enable(false); + } + } + return true; }