From c0d2c15ac88dfdb9c8e9ba09351f29be4793e4af Mon Sep 17 00:00:00 2001 From: Iampete1 Date: Sun, 4 Aug 2024 23:37:09 +0100 Subject: [PATCH] Copter: autotune: allow access to autotune object and call through for disarm and aux function --- ArduCopter/AP_Arming.cpp | 8 ++------ ArduCopter/RC_Channel.cpp | 8 ++++++-- ArduCopter/mode.h | 8 +------- ArduCopter/mode_autotune.cpp | 10 ---------- 4 files changed, 9 insertions(+), 25 deletions(-) diff --git a/ArduCopter/AP_Arming.cpp b/ArduCopter/AP_Arming.cpp index 119971f059..eecef0394c 100644 --- a/ArduCopter/AP_Arming.cpp +++ b/ArduCopter/AP_Arming.cpp @@ -809,12 +809,8 @@ bool AP_Arming_Copter::disarm(const AP_Arming::Method method, bool do_disarm_che } #if AUTOTUNE_ENABLED == ENABLED - // save auto tuned parameters - if (copter.flightmode == &copter.mode_autotune) { - copter.mode_autotune.save_tuning_gains(); - } else { - copter.mode_autotune.reset(); - } + // Possibly save auto tuned parameters + copter.mode_autotune.autotune.disarmed(copter.flightmode == &copter.mode_autotune); #endif // we are not in the air diff --git a/ArduCopter/RC_Channel.cpp b/ArduCopter/RC_Channel.cpp index e0cf6905d3..0ae33562a8 100644 --- a/ArduCopter/RC_Channel.cpp +++ b/ArduCopter/RC_Channel.cpp @@ -76,7 +76,8 @@ void RC_Channel_Copter::init_aux_function(const AUX_FUNC ch_option, const AuxSwi // the following functions do not need to be initialised: case AUX_FUNC::ALTHOLD: case AUX_FUNC::AUTO: - case AUX_FUNC::AUTOTUNE: + case AUX_FUNC::AUTOTUNE_MODE: + case AUX_FUNC::AUTOTUNE_TEST_GAINS: case AUX_FUNC::BRAKE: case AUX_FUNC::CIRCLE: case AUX_FUNC::DRIFT: @@ -291,9 +292,12 @@ bool RC_Channel_Copter::do_aux_function(const AUX_FUNC ch_option, const AuxSwitc #endif #if AUTOTUNE_ENABLED == ENABLED - case AUX_FUNC::AUTOTUNE: + case AUX_FUNC::AUTOTUNE_MODE: do_aux_function_change_mode(Mode::Number::AUTOTUNE, ch_flag); break; + case AUX_FUNC::AUTOTUNE_TEST_GAINS: + copter.mode_autotune.autotune.do_aux_function(ch_flag); + break; #endif case AUX_FUNC::LAND: diff --git a/ArduCopter/mode.h b/ArduCopter/mode.h index 11b2a64410..0c8bc6b058 100644 --- a/ArduCopter/mode.h +++ b/ArduCopter/mode.h @@ -796,18 +796,12 @@ public: bool allows_arming(AP_Arming::Method method) const override { return false; } bool is_autopilot() const override { return false; } - void save_tuning_gains(); - void reset(); + AutoTune autotune; protected: const char *name() const override { return "AUTOTUNE"; } const char *name4() const override { return "ATUN"; } - -private: - - AutoTune autotune; - }; #endif diff --git a/ArduCopter/mode_autotune.cpp b/ArduCopter/mode_autotune.cpp index d7d0d2e470..04a2b88bda 100644 --- a/ArduCopter/mode_autotune.cpp +++ b/ArduCopter/mode_autotune.cpp @@ -118,19 +118,9 @@ void ModeAutoTune::run() autotune.run(); } -void ModeAutoTune::save_tuning_gains() -{ - autotune.save_tuning_gains(); -} - void ModeAutoTune::exit() { autotune.stop(); } -void ModeAutoTune::reset() -{ - autotune.reset(); -} - #endif // AUTOTUNE_ENABLED == ENABLED