Make multiple PID parameters a config option
* Adds config parameter `PID_PARAMS_PER_EXTRUDER` - allows single PID parameters to be used where this would be preferable (e.g. dual identical extruders) * When disabled, will use `float Kp, Ki, Kd, Kc;` as before. Preprocessor macros used to switch between. * ultralcd.cpp defines extra menus for extra parameters only where required * M301 reports `e:xx` only if independent pid parameters enabled * EEPROM structure still leaves space for 3 extruders worth, when undef will save single parameter to all extruder positions, but only read the first * Switching off saves approx 330 B with no LCD enabled, 2634B with LCD (RRD) enabled: this is significant. * LCD modifications should be tested.
This commit is contained in:
@ -126,12 +126,21 @@ static volatile bool temp_meas_ready = false;
|
||||
#endif
|
||||
|
||||
#ifdef PIDTEMP
|
||||
#ifdef PID_PARAMS_PER_EXTRUDER
|
||||
float Kp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kp, DEFAULT_Kp, DEFAULT_Kp);
|
||||
float Ki[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Ki*PID_dT, DEFAULT_Ki*PID_dT, DEFAULT_Ki*PID_dT);
|
||||
float Kd[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kd / PID_dT, DEFAULT_Kd / PID_dT, DEFAULT_Kd / PID_dT);
|
||||
#ifdef PID_ADD_EXTRUSION_RATE
|
||||
float Kc[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kc, DEFAULT_Kc, DEFAULT_Kc);
|
||||
#endif
|
||||
#ifdef PID_ADD_EXTRUSION_RATE
|
||||
float Kc[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kc, DEFAULT_Kc, DEFAULT_Kc);
|
||||
#endif // PID_ADD_EXTRUSION_RATE
|
||||
#else //PID_PARAMS_PER_EXTRUDER
|
||||
float Kp = DEFAULT_Kp;
|
||||
float Ki = DEFAULT_Ki * PID_dT;
|
||||
float Kd = DEFAULT_Kd / PID_dT;
|
||||
#ifdef PID_ADD_EXTRUSION_RATE
|
||||
float Kc = DEFAULT_Kc;
|
||||
#endif // PID_ADD_EXTRUSION_RATE
|
||||
#endif // PID_PARAMS_PER_EXTRUDER
|
||||
#endif //PIDTEMP
|
||||
|
||||
// Init min and max temp with extreme values to prevent false errors during startup
|
||||
@ -343,7 +352,7 @@ void updatePID()
|
||||
{
|
||||
#ifdef PIDTEMP
|
||||
for(int e = 0; e < EXTRUDERS; e++) {
|
||||
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki[e];
|
||||
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e);
|
||||
}
|
||||
#endif
|
||||
#ifdef PIDTEMPBED
|
||||
@ -464,14 +473,14 @@ void manage_heater()
|
||||
temp_iState[e] = 0.0;
|
||||
pid_reset[e] = false;
|
||||
}
|
||||
pTerm[e] = Kp[e] * pid_error[e];
|
||||
pTerm[e] = PID_PARAM(Kp,e) * pid_error[e];
|
||||
temp_iState[e] += pid_error[e];
|
||||
temp_iState[e] = constrain(temp_iState[e], temp_iState_min[e], temp_iState_max[e]);
|
||||
iTerm[e] = Ki[e] * temp_iState[e];
|
||||
iTerm[e] = PID_PARAM(Ki,e) * temp_iState[e];
|
||||
|
||||
//K1 defined in Configuration.h in the PID settings
|
||||
#define K2 (1.0-K1)
|
||||
dTerm[e] = (Kd[e] * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]);
|
||||
dTerm[e] = (PID_PARAM(Kd,e) * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]);
|
||||
pid_output = pTerm[e] + iTerm[e] - dTerm[e];
|
||||
if (pid_output > PID_MAX) {
|
||||
if (pid_error[e] > 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration
|
||||
@ -811,7 +820,7 @@ void tp_init()
|
||||
maxttemp[e] = maxttemp[0];
|
||||
#ifdef PIDTEMP
|
||||
temp_iState_min[e] = 0.0;
|
||||
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki[e];
|
||||
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e);
|
||||
#endif //PIDTEMP
|
||||
#ifdef PIDTEMPBED
|
||||
temp_iState_min_bed = 0.0;
|
||||
|
Reference in New Issue
Block a user