Independent PID parameters for each extruder
* Variables Kp, Ki, Kd, Kc now arrays of size EXTRUDERS * M301 gains (optional, default=0) E parameter to define which extruder's settings to modify. Tested, works with Repetier Host's EEPROM config window, albeit only reads/updates settings for E0. * All Kp, Ki, Kd, Kc parameters saved in EEPROM (version now v14), up to 3 extruders supported (same as Marlin in general)
This commit is contained in:
@ -50,14 +50,6 @@ float current_temperature_bed = 0.0;
|
||||
int redundant_temperature_raw = 0;
|
||||
float redundant_temperature = 0.0;
|
||||
#endif
|
||||
#ifdef PIDTEMP
|
||||
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
|
||||
#endif //PIDTEMP
|
||||
|
||||
#ifdef PIDTEMPBED
|
||||
float bedKp=DEFAULT_bedKp;
|
||||
@ -133,6 +125,15 @@ static volatile bool temp_meas_ready = false;
|
||||
# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1 }
|
||||
#endif
|
||||
|
||||
#ifdef PIDTEMP
|
||||
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
|
||||
#endif //PIDTEMP
|
||||
|
||||
// Init min and max temp with extreme values to prevent false errors during startup
|
||||
static int minttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_RAW_LO_TEMP , HEATER_1_RAW_LO_TEMP , HEATER_2_RAW_LO_TEMP );
|
||||
static int maxttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_RAW_HI_TEMP , HEATER_1_RAW_HI_TEMP , HEATER_2_RAW_HI_TEMP );
|
||||
@ -342,7 +343,7 @@ void updatePID()
|
||||
{
|
||||
#ifdef PIDTEMP
|
||||
for(int e = 0; e < EXTRUDERS; e++) {
|
||||
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki;
|
||||
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki[e];
|
||||
}
|
||||
#endif
|
||||
#ifdef PIDTEMPBED
|
||||
@ -463,14 +464,14 @@ void manage_heater()
|
||||
temp_iState[e] = 0.0;
|
||||
pid_reset[e] = false;
|
||||
}
|
||||
pTerm[e] = Kp * pid_error[e];
|
||||
pTerm[e] = 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 * temp_iState[e];
|
||||
iTerm[e] = Ki[e] * temp_iState[e];
|
||||
|
||||
//K1 defined in Configuration.h in the PID settings
|
||||
#define K2 (1.0-K1)
|
||||
dTerm[e] = (Kd * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]);
|
||||
dTerm[e] = (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
|
||||
@ -810,7 +811,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;
|
||||
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki[e];
|
||||
#endif //PIDTEMP
|
||||
#ifdef PIDTEMPBED
|
||||
temp_iState_min_bed = 0.0;
|
||||
|
Reference in New Issue
Block a user