From cd772761b5c21951bc799b31aa41a282d5e4dd81 Mon Sep 17 00:00:00 2001 From: Henry Wurzburg Date: Sun, 17 Dec 2023 08:20:41 -0600 Subject: [PATCH] Plane:fix auto fence enable in Mode Takeoff --- ArduPlane/mode.h | 3 +++ ArduPlane/mode_takeoff.cpp | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ArduPlane/mode.h b/ArduPlane/mode.h index 2f745074c6f27..3a7e0b978898b 100644 --- a/ArduPlane/mode.h +++ b/ArduPlane/mode.h @@ -787,6 +787,9 @@ class ModeTakeoff: public Mode Location start_loc; bool _enter() override; +#if AP_FENCE_ENABLED + void _exit() override; +#endif }; #if HAL_SOARING_ENABLED diff --git a/ArduPlane/mode_takeoff.cpp b/ArduPlane/mode_takeoff.cpp index db212361c398e..144dcebb0e854 100644 --- a/ArduPlane/mode_takeoff.cpp +++ b/ArduPlane/mode_takeoff.cpp @@ -137,10 +137,6 @@ void ModeTakeoff::update() plane.next_WP_loc.alt += alt*100.0; plane.set_flight_stage(AP_FixedWing::FlightStage::NORMAL); - -#if AP_FENCE_ENABLED - plane.fence.auto_enable_fence_after_takeoff(); -#endif } if (plane.flight_stage == AP_FixedWing::FlightStage::TAKEOFF) { @@ -164,4 +160,11 @@ void ModeTakeoff::navigate() // Zero indicates to use WP_LOITER_RAD plane.update_loiter(0); } - +#if AP_FENCE_ENABLED +void ModeTakeoff::_exit() +{ + if (plane.is_flying() && plane.is_flying()) { + plane.fence.auto_enable_fence_after_takeoff(); + } +} +#endif