From 0ac452e2524df00d4dd97d4dfecd6d346592e4d7 Mon Sep 17 00:00:00 2001 From: Erik vd Zalm Date: Sun, 6 Jan 2013 13:37:01 +0100 Subject: [PATCH 1/2] Disable is now multi extruder compatible. M84 got a T option. --- Marlin/Configuration.h | 2 +- Marlin/Configuration_adv.h | 2 +- Marlin/Marlin_main.cpp | 22 ++++++++++++++++++---- Marlin/planner.cpp | 25 +++++++++++++++---------- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index d7d35d240..080462d25 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -46,7 +46,7 @@ // 301 = Rambo #ifndef MOTHERBOARD -#define MOTHERBOARD 7 +#define MOTHERBOARD 34 #endif diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index b74f74ad8..7c770cfc1 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -71,7 +71,7 @@ //=========================================================================== // This defines the number of extruders -#define EXTRUDERS 1 +#define EXTRUDERS 2 #define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 1dc4c2103..e387de8d2 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1181,10 +1181,24 @@ void process_commands() if(code_seen('Z')) disable_z(); #if ((E0_ENABLE_PIN != X_ENABLE_PIN) && (E1_ENABLE_PIN != Y_ENABLE_PIN)) // Only enable on boards that have seperate ENABLE_PINS if(code_seen('E')) { - disable_e0(); - disable_e1(); - disable_e2(); - } + if(code_seen('T')) { + tmp_extruder = code_value(); + if(tmp_extruder >= EXTRUDERS) { + SERIAL_ECHO_START; + SERIAL_ECHOLN(MSG_INVALID_EXTRUDER); + } + else { + if(tmp_extruder == 0) disable_e0(); + else if(tmp_extruder == 1) disable_e1(); + else if(tmp_extruder == 2) disable_e2(); + } + } + else { + disable_e0(); + disable_e1(); + disable_e2(); + } + } #endif } } diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 66809a10a..18256fc75 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -437,7 +437,9 @@ void check_axes_activity() unsigned char x_active = 0; unsigned char y_active = 0; unsigned char z_active = 0; - unsigned char e_active = 0; + unsigned char e0_active = 0; + unsigned char e1_active = 0; + unsigned char e2_active = 0; unsigned char fan_speed = 0; unsigned char tail_fan_speed = 0; block_t *block; @@ -452,7 +454,11 @@ void check_axes_activity() if(block->steps_x != 0) x_active++; if(block->steps_y != 0) y_active++; if(block->steps_z != 0) z_active++; - if(block->steps_e != 0) e_active++; + if(block->steps_e != 0) { + if(block->active_extruder == 0) e0_active++; + if(block->active_extruder == 1) e1_active++; + if(block->active_extruder == 2) e2_active++; + } if(block->fan_speed != 0) fan_speed++; block_index = (block_index+1) & (BLOCK_BUFFER_SIZE - 1); } @@ -470,11 +476,10 @@ void check_axes_activity() if((DISABLE_X) && (x_active == 0)) disable_x(); if((DISABLE_Y) && (y_active == 0)) disable_y(); if((DISABLE_Z) && (z_active == 0)) disable_z(); - if((DISABLE_E) && (e_active == 0)) - { - disable_e0(); - disable_e1(); - disable_e2(); + if(DISABLE_E) { + if(e0_active == 0) disable_e0(); + if(e1_active == 0) disable_e1(); + if(e2_active == 0) disable_e2(); } #if FAN_PIN > -1 #ifndef FAN_SOFT_PWM @@ -597,9 +602,9 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa // Enable all if(block->steps_e != 0) { - enable_e0(); - enable_e1(); - enable_e2(); + if(extruder == 0) enable_e0(); + if(extruder == 1) enable_e1(); + if(extruder == 2) enable_e2(); } if (block->steps_e == 0) From 6752cb2d9ce085ed1df760475adac46a959009c4 Mon Sep 17 00:00:00 2001 From: Erik vd Zalm Date: Sun, 6 Jan 2013 14:26:23 +0100 Subject: [PATCH 2/2] PID now per extruder. Fixed typo --- Marlin/Configuration.h | 11 ++++ Marlin/ConfigurationStore.cpp | 110 +++++++++++++++++++++------------- Marlin/Marlin_main.cpp | 18 ++++-- Marlin/language.h | 11 +++- Marlin/planner.cpp | 4 +- Marlin/temperature.cpp | 38 ++++++------ Marlin/temperature.h | 5 +- 7 files changed, 125 insertions(+), 72 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 080462d25..94bacabc3 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -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 // diff --git a/Marlin/ConfigurationStore.cpp b/Marlin/ConfigurationStore.cpp index 6d4777701..2c11244d7 100644 --- a/Marlin/ConfigurationStore.cpp +++ b/Marlin/ConfigurationStore.cpp @@ -3,26 +3,26 @@ #include "temperature.h" #include "ultralcd.h" #include "ConfigurationStore.h" - -void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size) -{ - do - { - eeprom_write_byte((unsigned char*)pos, *value); - pos++; - value++; + +void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size) +{ + do + { + eeprom_write_byte((unsigned char*)pos, *value); + pos++; + value++; }while(--size); -} +} #define EEPROM_WRITE_VAR(pos, value) _EEPROM_writeData(pos, (uint8_t*)&value, sizeof(value)) -void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) -{ - do - { - *value = eeprom_read_byte((unsigned char*)pos); - pos++; - value++; +void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) +{ + do + { + *value = eeprom_read_byte((unsigned char*)pos); + pos++; + value++; }while(--size); -} +} #define EEPROM_READ_VAR(pos, value) _EEPROM_readData(pos, (uint8_t*)&value, sizeof(value)) //====================================================================================== @@ -43,7 +43,7 @@ void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) void Config_StoreSettings() { char ver[4]= "000"; - int i=EEPROM_OFFSET; + int i=EEPROM_OFFSET; EEPROM_WRITE_VAR(i,ver); // invalidate data first EEPROM_WRITE_VAR(i,axis_steps_per_unit); EEPROM_WRITE_VAR(i,max_feedrate); @@ -58,8 +58,8 @@ void Config_StoreSettings() EEPROM_WRITE_VAR(i,max_e_jerk); EEPROM_WRITE_VAR(i,add_homeing); #ifndef ULTIPANEL - int plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP, plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP, plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED; - int absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP, absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP, absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED; + int plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP, plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP, plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED; + int absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP, absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP, absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED; #endif EEPROM_WRITE_VAR(i,plaPreheatHotendTemp); EEPROM_WRITE_VAR(i,plaPreheatHPBTemp); @@ -75,7 +75,7 @@ void Config_StoreSettings() EEPROM_WRITE_VAR(i,3000); EEPROM_WRITE_VAR(i,0); EEPROM_WRITE_VAR(i,0); - #endif + #endif char ver2[4]=EEPROM_VERSION; i=EEPROM_OFFSET; EEPROM_WRITE_VAR(i,ver2); // validate data @@ -105,7 +105,7 @@ void Config_PrintSettings() SERIAL_ECHOPAIR(" Z", max_feedrate[2] ); SERIAL_ECHOPAIR(" E", max_feedrate[3]); SERIAL_ECHOLN(""); - + SERIAL_ECHO_START; SERIAL_ECHOLNPGM("Maximum Acceleration (mm/s2):"); SERIAL_ECHO_START; @@ -120,7 +120,7 @@ void Config_PrintSettings() SERIAL_ECHOPAIR(" M204 S",acceleration ); SERIAL_ECHOPAIR(" T" ,retract_acceleration); SERIAL_ECHOLN(""); - + SERIAL_ECHO_START; SERIAL_ECHOLNPGM("Advanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum xY jerk (mm/s), Z=maximum Z jerk (mm/s)"); SERIAL_ECHO_START; @@ -131,7 +131,7 @@ void Config_PrintSettings() SERIAL_ECHOPAIR(" Z" ,max_z_jerk); SERIAL_ECHOPAIR(" E" ,max_e_jerk); SERIAL_ECHOLN(""); - + SERIAL_ECHO_START; SERIAL_ECHOLNPGM("Home offset (mm):"); SERIAL_ECHO_START; @@ -143,11 +143,25 @@ 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 @@ -161,7 +175,7 @@ void Config_RetrieveSettings() EEPROM_READ_VAR(i,stored_ver); //read stored version // SERIAL_ECHOLN("Version: [" << ver << "] Stored version: [" << stored_ver << "]"); if (strncmp(ver,stored_ver,3) == 0) - { + { // version number match EEPROM_READ_VAR(i,axis_steps_per_unit); EEPROM_READ_VAR(i,max_feedrate); @@ -176,15 +190,15 @@ void Config_RetrieveSettings() EEPROM_READ_VAR(i,max_e_jerk); EEPROM_READ_VAR(i,add_homeing); #ifndef ULTIPANEL - int plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed; - int absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed; + int plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed; + int absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed; #endif EEPROM_READ_VAR(i,plaPreheatHotendTemp); EEPROM_READ_VAR(i,plaPreheatHPBTemp); EEPROM_READ_VAR(i,plaPreheatFanSpeed); EEPROM_READ_VAR(i,absPreheatHotendTemp); EEPROM_READ_VAR(i,absPreheatHPBTemp); - EEPROM_READ_VAR(i,absPreheatFanSpeed); + EEPROM_READ_VAR(i,absPreheatFanSpeed); #ifndef PIDTEMP float Kp,Ki,Kd; #endif @@ -195,17 +209,17 @@ void Config_RetrieveSettings() SERIAL_ECHO_START; SERIAL_ECHOLNPGM("Stored settings retreived:"); } - else - { - Config_ResetDefault(); - SERIAL_ECHO_START; - SERIAL_ECHOLN("Using Default settings:"); - } + else + { + Config_ResetDefault(); + SERIAL_ECHO_START; + SERIAL_ECHOLN("Using Default settings:"); + } Config_PrintSettings(); } -#endif - -void Config_ResetDefault() +#endif + +void Config_ResetDefault() { float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT; float tmp2[]=DEFAULT_MAX_FEEDRATE; @@ -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 diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index e387de8d2..a64156c28 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -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; diff --git a/Marlin/language.h b/Marlin/language.h index 97e8f9d83..575c78d39 100644 --- a/Marlin/language.h +++ b/Marlin/language.h @@ -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." @@ -570,7 +573,7 @@ #define MSG_NO_CARD "Keine SDKarte" #define MSG_DWELL "Warten..." #define MSG_USERWAIT "Warte auf Nutzer..." - #define MSG_RESUMING "Druck fortsetzung" + #define MSG_RESUMING "Druck fortsetzung" #define MSG_NO_MOVE "Kein Zug." #define MSG_PART_RELEASE "Stepper tlw frei" #define MSG_KILLED "KILLED" @@ -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." @@ -916,7 +921,8 @@ #define MSG_M104_INVALID_EXTRUDER "M104 ошибка экструдера " #define MSG_M105_INVALID_EXTRUDER "M105 ошибка экструдера " #define MSG_ERR_NO_THERMISTORS "Нет термистра - нет температуры" -#define MSG_M109_INVALID_EXTRUDER "M109 ошибка экструдера " +#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." diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 18256fc75..4fd37b187 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -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 diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 6093c9934..178ce2b26 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -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============================ //=========================================================================== @@ -44,10 +54,10 @@ float current_temperature[EXTRUDERS] = { 0 }; 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); +#ifdef PIDTEMP + 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; diff --git a/Marlin/temperature.h b/Marlin/temperature.h index feffcbd41..331191687 100644 --- a/Marlin/temperature.h +++ b/Marlin/temperature.h @@ -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;