mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2026-01-06 06:37:43 -07:00
⚡️ Optimize PID, increase PID range (#27740)
This commit is contained in:
parent
b5d7b4aee6
commit
5e8a5230a3
3 changed files with 9 additions and 12 deletions
|
|
@ -899,7 +899,7 @@
|
|||
#if ANY(PIDTEMP, PIDTEMPBED, PIDTEMPCHAMBER)
|
||||
//#define PID_OPENLOOP // Puts PID in open loop. M104/M140 sets the output power from 0 to PID_MAX
|
||||
//#define SLOW_PWM_HEATERS // PWM with very low frequency (roughly 0.125Hz=8s) and minimum state time of approximately 1s useful for heaters driven by a relay
|
||||
#define PID_FUNCTIONAL_RANGE 10 // If the temperature difference between the target temperature and the actual temperature
|
||||
#define PID_FUNCTIONAL_RANGE 20 // If the temperature difference between the target temperature and the actual temperature
|
||||
// is more than PID_FUNCTIONAL_RANGE then the PID will be shut off and the heater will be set to min/max.
|
||||
|
||||
//#define PID_EDIT_MENU // Add PID editing to the "Advanced Settings" menu. (~700 bytes of flash)
|
||||
|
|
|
|||
|
|
@ -1312,9 +1312,9 @@ void RTS::handleData() {
|
|||
#endif
|
||||
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
case Hot_Bed_P: thermalManager.temp_bed.pid.Kp = float(recdat.data[0]) / 100.0f; break;
|
||||
case Hot_Bed_I: thermalManager.temp_bed.pid.Ki = float(recdat.data[0]) * 8.0f / 10000.0f; break;
|
||||
case Hot_Bed_D: thermalManager.temp_bed.pid.Kd = float(recdat.data[0]) / 0.8f; break;
|
||||
case Hot_Bed_P: thermalManager.temp_bed.pid.set_Kp(float(recdat.data[0]) / 100.0f); break;
|
||||
case Hot_Bed_I: thermalManager.temp_bed.pid.set_Ki(float(recdat.data[0]) * 8.0f / 10000.0f); break;
|
||||
case Hot_Bed_D: thermalManager.temp_bed.pid.set_Kd(float(recdat.data[0]) / 0.8f); break;
|
||||
#endif
|
||||
|
||||
#if HAS_X_AXIS
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;
|
|||
struct PID_t {
|
||||
protected:
|
||||
bool pid_reset = true;
|
||||
float temp_iState = 0.0f, temp_dState = 0.0f;
|
||||
float temp_dState = 0;
|
||||
float work_p = 0, work_i = 0, work_d = 0;
|
||||
|
||||
public:
|
||||
|
|
@ -217,17 +217,14 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;
|
|||
}
|
||||
else {
|
||||
if (pid_reset) {
|
||||
work_i = 0;
|
||||
work_d = 0;
|
||||
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);
|
||||
work_i = constrain(work_i + Ki * pid_error, 0, float(MAX_POW - MIN_POW));
|
||||
work_d += (Kd * (temp_dState - current) - work_d) * PID_K2;
|
||||
|
||||
output_pow = constrain(work_p + work_i + work_d + float(MIN_POW), 0, MAX_POW);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue