From 562050a8008480ca58333e50d9dd31bd3b6bbd60 Mon Sep 17 00:00:00 2001 From: Bill Geyer Date: Tue, 17 Jan 2023 23:31:52 -0500 Subject: [PATCH] Copter: make code work for manual autorotations outside SITL --- ArduCopter/config.h | 6 +++++- ArduCopter/heli.cpp | 29 +++++++++++++++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/ArduCopter/config.h b/ArduCopter/config.h index 9d1bb085ce..222a2355b3 100644 --- a/ArduCopter/config.h +++ b/ArduCopter/config.h @@ -288,12 +288,16 @@ ////////////////////////////////////////////////////////////////////////////// // Autorotate - autonomous auto-rotation - helicopters only -#if FRAME_CONFIG == HELI_FRAME +#if CONFIG_HAL_BOARD == HAL_BOARD_SITL + #if FRAME_CONFIG == HELI_FRAME #ifndef MODE_AUTOROTATE_ENABLED # define MODE_AUTOROTATE_ENABLED !HAL_MINIMIZE_FEATURES #endif #else # define MODE_AUTOROTATE_ENABLED DISABLED + #endif +#else + # define MODE_AUTOROTATE_ENABLED DISABLED #endif ////////////////////////////////////////////////////////////////////////////// diff --git a/ArduCopter/heli.cpp b/ArduCopter/heli.cpp index 000e05b31c..181c663e46 100644 --- a/ArduCopter/heli.cpp +++ b/ArduCopter/heli.cpp @@ -196,23 +196,32 @@ void Copter::heli_update_rotor_speed_targets() // to autorotation flight mode if manual collective is not being used. void Copter::heli_update_autorotation() { -#if MODE_AUTOROTATE_ENABLED == ENABLED // check if flying and interlock disengaged - if (!ap.land_complete && !motors->get_interlock() && g2.arot.is_enable()) { - if (!flightmode->has_manual_throttle()) { - // set autonomous autorotation flight mode - set_mode(Mode::Number::AUTOROTATE, ModeReason::AUTOROTATION_START); + if (!ap.land_complete && !motors->get_interlock()) { +#if MODE_AUTOROTATE_ENABLED == ENABLED + if (g2.arot.is_enable()) { + if (!flightmode->has_manual_throttle()) { + // set autonomous autorotation flight mode + set_mode(Mode::Number::AUTOROTATE, ModeReason::AUTOROTATION_START); + } + // set flag to facilitate both auto and manual autorotations + heli_flags.in_autorotation = true; + motors->set_in_autorotation(heli_flags.in_autorotation); + motors->set_enable_bailout(true); + } +#endif + if (flightmode->has_manual_throttle() && motors->arot_man_enabled()) { + // set flag to facilitate both auto and manual autorotations + heli_flags.in_autorotation = true; + motors->set_in_autorotation(heli_flags.in_autorotation); + motors->set_enable_bailout(true); } - // set flag to facilitate both auto and manual autorotations - heli_flags.in_autorotation = true; - motors->set_in_autorotation(heli_flags.in_autorotation); - motors->set_enable_bailout(true); } else { heli_flags.in_autorotation = false; motors->set_in_autorotation(heli_flags.in_autorotation); motors->set_enable_bailout(false); } -#endif + } // update collective low flag. Use a debounce time of 400 milliseconds.