PID now per extruder. Fixed typo
This commit is contained in:
parent
0ac452e252
commit
6752cb2d9c
7 changed files with 125 additions and 72 deletions
|
@ -136,6 +136,17 @@
|
|||
// #define DEFAULT_Kd 440
|
||||
#endif // PIDTEMP
|
||||
|
||||
// PID parameters for 2nd extruder
|
||||
#define DEFAULT_Kp_E1 22.2
|
||||
#define DEFAULT_Ki_E1 1.08
|
||||
#define DEFAULT_Kd_E1 114
|
||||
|
||||
|
||||
// PID parameters for 3th extruder
|
||||
// #define DEFAULT_Kp_E2 22.2
|
||||
// #define DEFAULT_Ki_E2 1.08
|
||||
// #define DEFAULT_Kd_E2 114
|
||||
|
||||
// Bed Temperature Control
|
||||
// Select PID or bang-bang with PIDTEMPBED. If bang-bang, BED_LIMIT_SWITCHING will enable hysteresis
|
||||
//
|
||||
|
|
|
@ -143,10 +143,24 @@ void Config_PrintSettings()
|
|||
SERIAL_ECHO_START;
|
||||
SERIAL_ECHOLNPGM("PID settings:");
|
||||
SERIAL_ECHO_START;
|
||||
SERIAL_ECHOPAIR(" M301 P",Kp);
|
||||
SERIAL_ECHOPAIR(" I" ,Ki/PID_dT);
|
||||
SERIAL_ECHOPAIR(" D" ,Kd*PID_dT);
|
||||
SERIAL_ECHOPAIR(" M301 P",Kp[0]);
|
||||
SERIAL_ECHOPAIR(" I" ,Ki[0]/PID_dT);
|
||||
SERIAL_ECHOPAIR(" D" ,Kd[0]*PID_dT);
|
||||
SERIAL_ECHOLN("");
|
||||
#if EXTRUDERS > 1
|
||||
SERIAL_ECHOPAIR(" M301 P",Kp[1]);
|
||||
SERIAL_ECHOPAIR(" I" ,Ki[1]/PID_dT);
|
||||
SERIAL_ECHOPAIR(" D" ,Kd[1]*PID_dT);
|
||||
SERIAL_ECHOPGM(" T1");
|
||||
SERIAL_ECHOLN("");
|
||||
#endif
|
||||
#if EXTRUDERS > 2
|
||||
SERIAL_ECHOPAIR(" M301 P",Kp[2]);
|
||||
SERIAL_ECHOPAIR(" I" ,Ki[2]/PID_dT);
|
||||
SERIAL_ECHOPAIR(" D" ,Kd[2]*PID_dT);
|
||||
SERIAL_ECHOPGM(" T2");
|
||||
SERIAL_ECHOLN("");
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
@ -234,9 +248,19 @@ void Config_ResetDefault()
|
|||
absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED;
|
||||
#endif
|
||||
#ifdef PIDTEMP
|
||||
Kp = DEFAULT_Kp;
|
||||
Ki = (DEFAULT_Ki*PID_dT);
|
||||
Kd = (DEFAULT_Kd/PID_dT);
|
||||
Kp[0] = DEFAULT_Kp;
|
||||
Ki[0] = (DEFAULT_Ki*PID_dT);
|
||||
Kd[0] = (DEFAULT_Kd/PID_dT);
|
||||
#if EXTRUDERS > 1
|
||||
Kp[1] = DEFAULT_Kp_E1;
|
||||
Ki[1] = (DEFAULT_Ki_E1*PID_dT);
|
||||
Kd[1] = (DEFAULT_Kd_E1/PID_dT);
|
||||
#endif
|
||||
#if EXTRUDERS > 2
|
||||
Kp[2] = DEFAULT_Kp_E2;
|
||||
Ki[2] = (DEFAULT_Ki_E2*PID_dT);
|
||||
Kd[2] = (DEFAULT_Kd_E2/PID_dT);
|
||||
#endif
|
||||
#ifdef PID_ADD_EXTRUSION_RATE
|
||||
Kc = DEFAULT_Kc;
|
||||
#endif//PID_ADD_EXTRUSION_RATE
|
||||
|
|
|
@ -1401,20 +1401,23 @@ void process_commands()
|
|||
#ifdef PIDTEMP
|
||||
case 301: // M301
|
||||
{
|
||||
if(code_seen('P')) Kp = code_value();
|
||||
if(code_seen('I')) Ki = code_value()*PID_dT;
|
||||
if(code_seen('D')) Kd = code_value()/PID_dT;
|
||||
if(setTargetedHotend(301)){
|
||||
break;
|
||||
}
|
||||
if(code_seen('P')) Kp[tmp_extruder] = code_value();
|
||||
if(code_seen('I')) Ki[tmp_extruder] = code_value()*PID_dT;
|
||||
if(code_seen('D')) Kd[tmp_extruder] = code_value()/PID_dT;
|
||||
#ifdef PID_ADD_EXTRUSION_RATE
|
||||
if(code_seen('C')) Kc = code_value();
|
||||
#endif
|
||||
updatePID();
|
||||
SERIAL_PROTOCOL(MSG_OK);
|
||||
SERIAL_PROTOCOL(" p:");
|
||||
SERIAL_PROTOCOL(Kp);
|
||||
SERIAL_PROTOCOL(Kp[tmp_extruder]);
|
||||
SERIAL_PROTOCOL(" i:");
|
||||
SERIAL_PROTOCOL(Ki/PID_dT);
|
||||
SERIAL_PROTOCOL(Ki[tmp_extruder]/PID_dT);
|
||||
SERIAL_PROTOCOL(" d:");
|
||||
SERIAL_PROTOCOL(Kd*PID_dT);
|
||||
SERIAL_PROTOCOL(Kd[tmp_extruder]*PID_dT);
|
||||
#ifdef PID_ADD_EXTRUSION_RATE
|
||||
SERIAL_PROTOCOL(" c:");
|
||||
SERIAL_PROTOCOL(Kc*PID_dT);
|
||||
|
@ -1936,6 +1939,9 @@ bool setTargetedHotend(int code){
|
|||
case 109:
|
||||
SERIAL_ECHO(MSG_M109_INVALID_EXTRUDER);
|
||||
break;
|
||||
case 301:
|
||||
SERIAL_ECHO(MSG_M301_INVALID_EXTRUDER);
|
||||
break;
|
||||
}
|
||||
SERIAL_ECHOLN(tmp_extruder);
|
||||
return true;
|
||||
|
|
|
@ -139,6 +139,7 @@
|
|||
#define MSG_M105_INVALID_EXTRUDER "M105 Invalid extruder "
|
||||
#define MSG_ERR_NO_THERMISTORS "No thermistors - no temperature"
|
||||
#define MSG_M109_INVALID_EXTRUDER "M109 Invalid extruder "
|
||||
#define MSG_M301_INVALID_EXTRUDER "M301 Invalid extruder "
|
||||
#define MSG_HEATING "Heating..."
|
||||
#define MSG_HEATING_COMPLETE "Heating done."
|
||||
#define MSG_BED_HEATING "Bed Heating."
|
||||
|
@ -293,6 +294,7 @@
|
|||
#define MSG_M105_INVALID_EXTRUDER "M105 Niepoprawny ekstruder "
|
||||
#define MSG_ERR_NO_THERMISTORS "Brak termistorow - brak temperatury :("
|
||||
#define MSG_M109_INVALID_EXTRUDER "M109 Niepoprawny ekstruder "
|
||||
#define MSG_M301_INVALID_EXTRUDER "M301 Niepoprawny ekstruder "
|
||||
#define MSG_HEATING "Nagrzewanie ekstrudera..."
|
||||
#define MSG_HEATING_COMPLETE "Nagrzewanie ekstrudera zakonczone."
|
||||
#define MSG_BED_HEATING "Nagrzewanie loza..."
|
||||
|
@ -452,6 +454,7 @@
|
|||
#define MSG_M105_INVALID_EXTRUDER "M105 Extruder invalide"
|
||||
#define MSG_ERR_NO_THERMISTORS "Pas de thermistor, pas de temperature"
|
||||
#define MSG_M109_INVALID_EXTRUDER "M109 Extruder invalide "
|
||||
#define MSG_M301_INVALID_EXTRUDER "M301 Extruder invalide "
|
||||
#define MSG_HEATING "En chauffe..."
|
||||
#define MSG_HEATING_COMPLETE "Chauffe terminee."
|
||||
#define MSG_BED_HEATING "Chauffe du lit."
|
||||
|
@ -609,6 +612,7 @@
|
|||
#define MSG_M105_INVALID_EXTRUDER "M105 Invalid extruder "
|
||||
#define MSG_ERR_NO_THERMISTORS "No thermistors - no temp"
|
||||
#define MSG_M109_INVALID_EXTRUDER "M109 Invalid extruder "
|
||||
#define MSG_M301_INVALID_EXTRUDER "M301 Invalid extruder "
|
||||
#define MSG_HEATING "Heating..."
|
||||
#define MSG_HEATING_COMPLETE "Heating done."
|
||||
#define MSG_BED_HEATING "Bed Heating."
|
||||
|
@ -767,6 +771,7 @@
|
|||
#define MSG_M105_INVALID_EXTRUDER "M105 Extrusor Invalido "
|
||||
#define MSG_ERR_NO_THERMISTORS "No hay termistores - no temp"
|
||||
#define MSG_M109_INVALID_EXTRUDER "M109 Extrusor Invalido "
|
||||
#define MSG_M301_INVALID_EXTRUDER "M301 Extrusor Invalido "
|
||||
#define MSG_HEATING "Calentando..."
|
||||
#define MSG_HEATING_COMPLETE "Calentamiento Hecho."
|
||||
#define MSG_BED_HEATING "Calentando la base."
|
||||
|
@ -917,6 +922,7 @@
|
|||
#define MSG_M105_INVALID_EXTRUDER "M105 ошибка экструдера "
|
||||
#define MSG_ERR_NO_THERMISTORS "Нет термистра - нет температуры"
|
||||
#define MSG_M109_INVALID_EXTRUDER "M109 ошибка экструдера "
|
||||
#define MSG_M301_INVALID_EXTRUDER "M301 ошибка экструдера "
|
||||
#define MSG_HEATING "Нагрев... "
|
||||
#define MSG_HEATING_COMPLETE "Наргето. "
|
||||
#define MSG_BED_HEATING "Нагрев стола... "
|
||||
|
@ -1235,6 +1241,7 @@
|
|||
#define MSG_M105_INVALID_EXTRUDER "M105 Extrusor inválido "
|
||||
#define MSG_ERR_NO_THERMISTORS "Nao ha termistor - no temp"
|
||||
#define MSG_M109_INVALID_EXTRUDER "M109 Extrusor inválido "
|
||||
#define MSG_M301_INVALID_EXTRUDER "M301 Extrusor inválido "
|
||||
#define MSG_HEATING "Aquecendo..."
|
||||
#define MSG_HEATING_COMPLETE "Aquecido."
|
||||
#define MSG_BED_HEATING "Aquecendo a Base."
|
||||
|
|
|
@ -478,8 +478,8 @@ void check_axes_activity()
|
|||
if((DISABLE_Z) && (z_active == 0)) disable_z();
|
||||
if(DISABLE_E) {
|
||||
if(e0_active == 0) disable_e0();
|
||||
if(e1_active == 0) disable_e1();
|
||||
if(e2_active == 0) disable_e2();
|
||||
if(e1_active == 1) disable_e1();
|
||||
if(e2_active == 2) disable_e2();
|
||||
}
|
||||
#if FAN_PIN > -1
|
||||
#ifndef FAN_SOFT_PWM
|
||||
|
|
|
@ -34,6 +34,16 @@
|
|||
#include "temperature.h"
|
||||
#include "watchdog.h"
|
||||
|
||||
#if EXTRUDERS > 3
|
||||
# error Unsupported number of extruders
|
||||
#elif EXTRUDERS > 2
|
||||
# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1, v2, v3 }
|
||||
#elif EXTRUDERS > 1
|
||||
# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1, v2 }
|
||||
#else
|
||||
# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1 }
|
||||
#endif
|
||||
|
||||
//===========================================================================
|
||||
//=============================public variables============================
|
||||
//===========================================================================
|
||||
|
@ -45,9 +55,9 @@ int current_temperature_bed_raw = 0;
|
|||
float current_temperature_bed = 0;
|
||||
|
||||
#ifdef PIDTEMP
|
||||
float Kp=DEFAULT_Kp;
|
||||
float Ki=(DEFAULT_Ki*PID_dT);
|
||||
float Kd=(DEFAULT_Kd/PID_dT);
|
||||
float Kp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kp, DEFAULT_Kp_E1, DEFAULT_Kp_E2);
|
||||
float Ki[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Ki*PID_dT, DEFAULT_Ki_E1*PID_dT, DEFAULT_Ki_E2*PID_dT);
|
||||
float Kd[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kd/PID_dT, DEFAULT_Kd_E1/PID_dT, DEFAULT_Kd_E2/PID_dT);
|
||||
#ifdef PID_ADD_EXTRUSION_RATE
|
||||
float Kc=DEFAULT_Kc;
|
||||
#endif
|
||||
|
@ -102,15 +112,7 @@ static volatile bool temp_meas_ready = false;
|
|||
|
||||
|
||||
|
||||
#if EXTRUDERS > 3
|
||||
# error Unsupported number of extruders
|
||||
#elif EXTRUDERS > 2
|
||||
# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1, v2, v3 }
|
||||
#elif EXTRUDERS > 1
|
||||
# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1, v2 }
|
||||
#else
|
||||
# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1 }
|
||||
#endif
|
||||
|
||||
|
||||
// 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 );
|
||||
|
@ -292,7 +294,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
|
||||
|
@ -337,14 +339,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]);
|
||||
temp_dState[e] = pid_input;
|
||||
|
||||
pid_output = constrain(pTerm[e] + iTerm[e] - dTerm[e], 0, PID_MAX);
|
||||
|
@ -577,7 +579,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;
|
||||
|
|
|
@ -39,7 +39,10 @@ extern int target_temperature_bed;
|
|||
extern float current_temperature_bed;
|
||||
|
||||
#ifdef PIDTEMP
|
||||
extern float Kp,Ki,Kd,Kc;
|
||||
extern float Kp[EXTRUDERS];
|
||||
extern float Ki[EXTRUDERS];
|
||||
extern float Kd[EXTRUDERS];
|
||||
extern float Kc;
|
||||
#endif
|
||||
#ifdef PIDTEMPBED
|
||||
extern float bedKp,bedKi,bedKd;
|
||||
|
|
Reference in a new issue