🐛 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:
parent
24f8831021
commit
bc0d7d7140
@ -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) {
|
float get_pid_output(const float target, const float current) {
|
||||||
const float pid_error = target - current;
|
const float pid_error = target - current;
|
||||||
|
float output_pow;
|
||||||
if (!target || pid_error < -(PID_FUNCTIONAL_RANGE)) {
|
if (!target || pid_error < -(PID_FUNCTIONAL_RANGE)) {
|
||||||
pid_reset = true;
|
pid_reset = true;
|
||||||
return 0;
|
output_pow = 0;
|
||||||
}
|
}
|
||||||
else if (pid_error > PID_FUNCTIONAL_RANGE) {
|
else if (pid_error > PID_FUNCTIONAL_RANGE) {
|
||||||
pid_reset = true;
|
pid_reset = true;
|
||||||
return MAX_POW;
|
output_pow = MAX_POW;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
if (pid_reset) {
|
if (pid_reset) {
|
||||||
pid_reset = false;
|
pid_reset = false;
|
||||||
temp_iState = 0.0;
|
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_i = Ki * temp_iState;
|
||||||
work_d = work_d + PID_K2 * (Kd * (temp_dState - current) - work_d);
|
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;
|
temp_dState = current;
|
||||||
|
|
||||||
return constrain(work_p + work_i + work_d + float(MIN_POW), 0, MAX_POW);
|
return output_pow;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user