From d7b26a2205e1c7290aca6ce8502d6de7c938951a Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Tue, 3 Dec 2024 18:01:42 -0600 Subject: [PATCH] AC_AutoTune: fix tracking of maximum angular acceleration Issue introduced in https://github.com/ArduPilot/ardupilot/pull/27370 and partially fixed in https://github.com/ArduPilot/ardupilot/pull/27762, though evidently not properly tested. Failing to track the maximum can result in dangerously low values being calculated for `ATC_ACCEL_[RPY]_MAX` and the vehicle becoming unflyable. Make the variable a reference so that the maximum value is preserved between function calls. --- libraries/AC_AutoTune/AC_AutoTune_Multi.cpp | 2 +- libraries/AC_AutoTune/AC_AutoTune_Multi.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/AC_AutoTune/AC_AutoTune_Multi.cpp b/libraries/AC_AutoTune/AC_AutoTune_Multi.cpp index 5e7aa6c5d9..2f86b6d829 100644 --- a/libraries/AC_AutoTune/AC_AutoTune_Multi.cpp +++ b/libraries/AC_AutoTune/AC_AutoTune_Multi.cpp @@ -644,7 +644,7 @@ void AC_AutoTune_Multi::twitching_test_angle(float angle, float rate, float angl } // twitching_measure_acceleration - measure rate of change of measurement -void AC_AutoTune_Multi::twitching_measure_acceleration(float &accel_average, float rate, float rate_max) const +void AC_AutoTune_Multi::twitching_measure_acceleration(float &accel_average, float rate, float &rate_max) const { if (rate_max < rate) { rate_max = rate; diff --git a/libraries/AC_AutoTune/AC_AutoTune_Multi.h b/libraries/AC_AutoTune/AC_AutoTune_Multi.h index e89dd4c589..6987c1c252 100644 --- a/libraries/AC_AutoTune/AC_AutoTune_Multi.h +++ b/libraries/AC_AutoTune/AC_AutoTune_Multi.h @@ -156,7 +156,7 @@ private: void twitching_test_angle(float angle, float rate, float angle_target, float &meas_angle_min, float &meas_angle_max, float &meas_rate_min, float &meas_rate_max); // measure acceleration during twitch test - void twitching_measure_acceleration(float &accel_average, float rate, float rate_max) const; + void twitching_measure_acceleration(float &accel_average, float rate, float &rate_max) const; // updating_rate_d_up - increase D and adjust P to optimize the D term for a little bounce back // optimize D term while keeping the maximum just below the target by adjusting P