🐛 Fix PID upon entering PID_FUNCTIONAL_RANGE (#26926)

The PID algorithm did not cache the last seen temperature until it entered the PID_FUNCTIONAL_RANGE. This caused an incorrect output power to be calculated temporarily while the algorithm caught up.

This has likely always been a problem for bed and chamber PID. For the hotend this error was introduced in refactoring in commit 54e7b933cdb6d0bf0d69fd661b585100d76e3c88.
This commit is contained in:
Aron List 2024-04-21 03:18:49 +02:00 committed by GitHub
parent 24f8831021
commit bc0d7d7140
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -204,15 +204,16 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;
float get_pid_output(const float target, const float current) {
const float pid_error = target - current;
float output_pow;
if (!target || pid_error < -(PID_FUNCTIONAL_RANGE)) {
pid_reset = true;
return 0;
output_pow = 0;
}
else if (pid_error > PID_FUNCTIONAL_RANGE) {
pid_reset = true;
return MAX_POW;
output_pow = MAX_POW;
}
else {
if (pid_reset) {
pid_reset = false;
temp_iState = 0.0;
@ -226,9 +227,12 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;
work_i = Ki * temp_iState;
work_d = work_d + PID_K2 * (Kd * (temp_dState - current) - work_d);
output_pow = constrain(work_p + work_i + work_d + float(MIN_POW), 0, MAX_POW);
}
temp_dState = current;
return constrain(work_p + work_i + work_d + float(MIN_POW), 0, MAX_POW);
return output_pow;
}
};