From f16ddb6647d8560aedce89a06894d5d78aaf5141 Mon Sep 17 00:00:00 2001 From: Harsh Date: Wed, 2 Oct 2024 21:12:54 +0530 Subject: [PATCH] Added functionality to prevent activating smartrtl even for disarmed copter --- ArduCopter/mode_smart_rtl.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ArduCopter/mode_smart_rtl.cpp b/ArduCopter/mode_smart_rtl.cpp index 4ef2160282..dc4272bcf9 100644 --- a/ArduCopter/mode_smart_rtl.cpp +++ b/ArduCopter/mode_smart_rtl.cpp @@ -11,6 +11,13 @@ bool ModeSmartRTL::init(bool ignore_checks) { + // Add check to prevent SmartRTL activation when disarmed + if (!motors->armed()) { + // Send a warning message to the GCS + GCS_SEND_TEXT(MAV_SEVERITY_WARNING, "Cannot engage SmartRTL while disarmed"); + return false; // Prevent initialization + } + if (g2.smart_rtl.is_active()) { // initialise waypoint and spline controller wp_nav->wp_and_spline_init(); @@ -174,8 +181,12 @@ void ModeSmartRTL::pre_land_position_run() // save current position for use by the smart_rtl flight mode void ModeSmartRTL::save_position() { - const bool should_save_position = motors->armed() && (copter.flightmode->mode_number() != Mode::Number::SMART_RTL); + // Prevent saving positions when the drone is disarmed + if (!motors->armed()) { + return; + } + const bool should_save_position = motors->armed() && (copter.flightmode->mode_number() != Mode::Number::SMART_RTL); copter.g2.smart_rtl.update(copter.position_ok(), should_save_position); }