0
0
Fork 0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2025-03-13 09:49:56 +00:00

🐛 Fix PID upon entering PID_FUNCTIONAL_RANGE ()

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 54e7b933cd.
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,31 +204,35 @@ 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;
work_d = 0.0;
}
if (pid_reset) {
pid_reset = false;
temp_iState = 0.0;
work_d = 0.0;
const float max_power_over_i_gain = float(MAX_POW) / Ki - float(MIN_POW);
temp_iState = constrain(temp_iState + pid_error, 0, max_power_over_i_gain);
work_p = Kp * pid_error;
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);
}
const float max_power_over_i_gain = float(MAX_POW) / Ki - float(MIN_POW);
temp_iState = constrain(temp_iState + pid_error, 0, max_power_over_i_gain);
work_p = Kp * pid_error;
work_i = Ki * temp_iState;
work_d = work_d + PID_K2 * (Kd * (temp_dState - current) - work_d);
temp_dState = current;
return constrain(work_p + work_i + work_d + float(MIN_POW), 0, MAX_POW);
return output_pow;
}
};