diff --git a/libraries/APM_Control/AP_AutoTune.cpp b/libraries/APM_Control/AP_AutoTune.cpp index 939047c611..c84fc5b6f2 100644 --- a/libraries/APM_Control/AP_AutoTune.cpp +++ b/libraries/APM_Control/AP_AutoTune.cpp @@ -58,6 +58,9 @@ extern const AP_HAL::HAL& hal; // ratio of I to P #define AUTOTUNE_I_RATIO 0.75 +// time constant of rate trim loop +#define TRIM_TCONST 1.0f + // overshoot threshold #define AUTOTUNE_OVERSHOOT 1.1 @@ -365,7 +368,8 @@ void AP_AutoTune::update(AP_Logger::PID_Info &pinfo, float scaler) rpid.ff().set(FF); rpid.kP().set(P); rpid.kD().set(D); - rpid.kI().set(P*AUTOTUNE_I_RATIO); + rpid.kI().set(MAX(P*AUTOTUNE_I_RATIO, (FF / TRIM_TCONST))); + current.FF = FF; current.P = P; current.I = rpid.kI().get(); @@ -509,6 +513,10 @@ void AP_AutoTune::update_rmax(void) target_tau = tuning_table[level-1].tau; } + if (level > 0) { + target_tau = 1.0f / ((1.0f / target_tau) + (current.I / current.FF)); + } + if (current.rmax_pos == 0) { // conservative initial value current.rmax_pos.set(75);