Browse Source

Merge pull request #1344 from grob6000/independent_pid

Independent PID parameters for each extruder
pull/1/head
Bo Herrmannsen 10 years ago
parent
commit
ab074dac17
  1. 2
      Marlin/Configuration.h
  2. 185
      Marlin/ConfigurationStore.cpp
  3. 66
      Marlin/Marlin_main.cpp
  4. 8
      Marlin/language_ca.h
  5. 8
      Marlin/language_de.h
  6. 8
      Marlin/language_en.h
  7. 8
      Marlin/language_es.h
  8. 8
      Marlin/language_eu.h
  9. 8
      Marlin/language_fi.h
  10. 8
      Marlin/language_fr.h
  11. 8
      Marlin/language_it.h
  12. 8
      Marlin/language_nl.h
  13. 8
      Marlin/language_pl.h
  14. 8
      Marlin/language_pt.h
  15. 8
      Marlin/language_ru.h
  16. 36
      Marlin/temperature.cpp
  17. 9
      Marlin/temperature.h
  18. 59
      Marlin/ultralcd.cpp

2
Marlin/Configuration.h

@ -152,6 +152,8 @@
//#define PID_DEBUG // Sends debug data to the serial port.
//#define PID_OPENLOOP 1 // 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_PARAMS_PER_EXTRUDER // Uses separate PID parameters for each extruder (useful for mismatched extruders)
// Set/get with gcode: M301 E[extruder number, 0-2]
#define PID_FUNCTIONAL_RANGE 10 // If the temperature difference between the target temperature and the actual temperature
// is more then PID_FUNCTIONAL_RANGE then the PID will be shut off and the heater will be set to min/max.
#define PID_INTEGRAL_DRIVE_MAX PID_MAX //limit for the integral term

185
Marlin/ConfigurationStore.cpp

@ -38,7 +38,7 @@ void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size)
// wrong data being written to the variables.
// ALSO: always make sure the variables in the Store and retrieve sections are in the same order.
#define EEPROM_VERSION "V13"
#define EEPROM_VERSION "V14"
#ifdef EEPROM_SETTINGS
void Config_StoreSettings()
@ -63,11 +63,11 @@ void Config_StoreSettings()
EEPROM_WRITE_VAR(i,delta_radius);
EEPROM_WRITE_VAR(i,delta_diagonal_rod);
EEPROM_WRITE_VAR(i,delta_segments_per_second);
#endif
#endif//DELTA
#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;
#endif
#endif//ULTIPANEL
EEPROM_WRITE_VAR(i,plaPreheatHotendTemp);
EEPROM_WRITE_VAR(i,plaPreheatHPBTemp);
EEPROM_WRITE_VAR(i,plaPreheatFanSpeed);
@ -76,37 +76,58 @@ void Config_StoreSettings()
EEPROM_WRITE_VAR(i,absPreheatFanSpeed);
EEPROM_WRITE_VAR(i,zprobe_zoffset);
#ifdef PIDTEMP
EEPROM_WRITE_VAR(i,Kp);
EEPROM_WRITE_VAR(i,Ki);
EEPROM_WRITE_VAR(i,Kd);
#else
float dummy = 0.0f;
for (int e = 0; e < 3; e++)
{
if (e < EXTRUDERS)
{
EEPROM_WRITE_VAR(i,PID_PARAM(Kp,e));
EEPROM_WRITE_VAR(i,PID_PARAM(Ki,e));
EEPROM_WRITE_VAR(i,PID_PARAM(Kd,e));
#ifdef PID_ADD_EXTRUSION_RATE
EEPROM_WRITE_VAR(i,PID_PARAM(Kc,e));
#else//PID_ADD_EXTRUSION_RATE
dummy = 1.0f; // 1.0 = default kc
EEPROM_WRITE_VAR(dummmy);
#endif//PID_ADD_EXTRUSION_RATE
}
else
{
dummy = 3000.0f;
EEPROM_WRITE_VAR(i, dummy);
dummy = 0.0f;
EEPROM_WRITE_VAR(i,dummy);
EEPROM_WRITE_VAR(i,dummy);
}
}
#else//PIDTEMP
float dummy = 3000.0f;
EEPROM_WRITE_VAR(i,dummy);
dummy = 0.0f;
EEPROM_WRITE_VAR(i,dummy);
EEPROM_WRITE_VAR(i,dummy);
#endif
#endif//PIDTEMP
#ifndef DOGLCD
int lcd_contrast = 32;
#endif
#endif//DOGLCD
EEPROM_WRITE_VAR(i,lcd_contrast);
#ifdef SCARA
EEPROM_WRITE_VAR(i,axis_scaling); // Add scaling for SCARA
#endif
#endif//SCARA
#ifdef FWRETRACT
EEPROM_WRITE_VAR(i,autoretract_enabled);
EEPROM_WRITE_VAR(i,retract_length);
#if EXTRUDERS > 1
EEPROM_WRITE_VAR(i,retract_length_swap);
#endif
#endif//EXTRUDERS > 1
EEPROM_WRITE_VAR(i,retract_feedrate);
EEPROM_WRITE_VAR(i,retract_zlift);
EEPROM_WRITE_VAR(i,retract_recover_length);
#if EXTRUDERS > 1
EEPROM_WRITE_VAR(i,retract_recover_length_swap);
#endif
#endif//EXTRUDERS > 1
EEPROM_WRITE_VAR(i,retract_recover_feedrate);
#endif
#endif//FWRETRACT
// Save filament sizes
EEPROM_WRITE_VAR(i, volumetric_enabled);
@ -115,8 +136,8 @@ void Config_StoreSettings()
EEPROM_WRITE_VAR(i, filament_size[1]);
#if EXTRUDERS > 2
EEPROM_WRITE_VAR(i, filament_size[2]);
#endif
#endif
#endif//EXTRUDERS > 2
#endif//EXTRUDERS > 1
char ver2[4]=EEPROM_VERSION;
i=EEPROM_OFFSET;
@ -149,7 +170,7 @@ SERIAL_ECHOLNPGM("Scaling factors:");
SERIAL_ECHOLN("");
SERIAL_ECHO_START;
#endif
#endif//SCARA
SERIAL_ECHOLNPGM("Maximum feedrates (mm/s):");
SERIAL_ECHO_START;
SERIAL_ECHOPAIR(" M203 X", max_feedrate[X_AXIS]);
@ -206,16 +227,16 @@ SERIAL_ECHOLNPGM("Scaling factors:");
SERIAL_ECHOPAIR(" R" ,delta_radius );
SERIAL_ECHOPAIR(" S" ,delta_segments_per_second );
SERIAL_ECHOLN("");
#endif
#endif//DELTA
#ifdef PIDTEMP
SERIAL_ECHO_START;
SERIAL_ECHOLNPGM("PID settings:");
SERIAL_ECHO_START;
SERIAL_ECHOPAIR(" M301 P",Kp);
SERIAL_ECHOPAIR(" I" ,unscalePID_i(Ki));
SERIAL_ECHOPAIR(" D" ,unscalePID_d(Kd));
SERIAL_ECHO_START;
SERIAL_ECHOPAIR(" M301 P", PID_PARAM(Kp,0)); // for compatibility with hosts, only echos values for E0
SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, 0)));
SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, 0)));
SERIAL_ECHOLN("");
#endif
#endif//PIDTEMP
#ifdef FWRETRACT
SERIAL_ECHO_START;
SERIAL_ECHOLNPGM("Retract: S=Length (mm) F:Speed (mm/m) Z: ZLift (mm)");
@ -244,7 +265,7 @@ SERIAL_ECHOLNPGM("Scaling factors:");
SERIAL_ECHO_START;
SERIAL_ECHOPAIR(" Swap rec. addl. length (mm): ", retract_recover_length_swap);
SERIAL_ECHOLN("");
#endif
#endif//EXTRUDERS > 1
SERIAL_ECHO_START;
if (volumetric_enabled) {
SERIAL_ECHOLNPGM("Filament settings:");
@ -259,14 +280,14 @@ SERIAL_ECHOLNPGM("Scaling factors:");
SERIAL_ECHO_START;
SERIAL_ECHOPAIR(" M200 T2 D", filament_size[2]);
SERIAL_ECHOLN("");
#endif
#endif
#endif//EXTRUDERS > 2
#endif//EXTRUDERS > 1
} else {
SERIAL_ECHOLNPGM("Filament settings: Disabled");
}
#endif
#endif//FWRETRACT
}
#endif
#endif//DISABLE_M503
#ifdef EEPROM_SETTINGS
@ -301,11 +322,11 @@ void Config_RetrieveSettings()
EEPROM_READ_VAR(i,delta_radius);
EEPROM_READ_VAR(i,delta_diagonal_rod);
EEPROM_READ_VAR(i,delta_segments_per_second);
#endif
#endif//DELTA
#ifndef ULTIPANEL
int plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed;
int absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed;
#endif
#endif//ULTIPANEL
EEPROM_READ_VAR(i,plaPreheatHotendTemp);
EEPROM_READ_VAR(i,plaPreheatHPBTemp);
EEPROM_READ_VAR(i,plaPreheatFanSpeed);
@ -313,35 +334,68 @@ void Config_RetrieveSettings()
EEPROM_READ_VAR(i,absPreheatHPBTemp);
EEPROM_READ_VAR(i,absPreheatFanSpeed);
EEPROM_READ_VAR(i,zprobe_zoffset);
#ifndef PIDTEMP
float Kp,Ki,Kd;
#endif
// do not need to scale PID values as the values in EEPROM are already scaled
EEPROM_READ_VAR(i,Kp);
EEPROM_READ_VAR(i,Ki);
EEPROM_READ_VAR(i,Kd);
#ifdef PIDTEMP
float dummy = 0.0f;
for (int e = 0; e < 3; e++) // 3 = max extruders supported by marlin
{
if (e < EXTRUDERS)
{
// do not need to scale PID values as the values in EEPROM are already scaled
EEPROM_READ_VAR(i,PID_PARAM(Kp,e));
EEPROM_READ_VAR(i,PID_PARAM(Ki,e));
EEPROM_READ_VAR(i,PID_PARAM(Kd,e));
#ifdef PID_ADD_EXTRUSION_RATE
EEPROM_READ_VAR(i,PID_PARAM(Kc,e));
#else//PID_ADD_EXTRUSION_RATE
EEPROM_READ_VAR(i,dummy);
#endif//PID_ADD_EXTRUSION_RATE
}
else
{
EEPROM_READ_VAR(i,dummy);
EEPROM_READ_VAR(i,dummy);
EEPROM_READ_VAR(i,dummy);
EEPROM_READ_VAR(i,dummy);
}
}
#else//PIDTEMP
// 4 x 3 = 12 slots for PID parameters
float dummy = 0.0f;
EEPROM_READ_VAR(i,dummy);
EEPROM_READ_VAR(i,dummy);
EEPROM_READ_VAR(i,dummy);
EEPROM_READ_VAR(i,dummy);
EEPROM_READ_VAR(i,dummy);
EEPROM_READ_VAR(i,dummy);
EEPROM_READ_VAR(i,dummy);
EEPROM_READ_VAR(i,dummy);
EEPROM_READ_VAR(i,dummy);
EEPROM_READ_VAR(i,dummy);
EEPROM_READ_VAR(i,dummy);
EEPROM_READ_VAR(i,dummy);
#endif//PIDTEMP
#ifndef DOGLCD
int lcd_contrast;
#endif
#endif//DOGLCD
EEPROM_READ_VAR(i,lcd_contrast);
#ifdef SCARA
EEPROM_READ_VAR(i,axis_scaling);
#endif
#endif//SCARA
#ifdef FWRETRACT
EEPROM_READ_VAR(i,autoretract_enabled);
EEPROM_READ_VAR(i,retract_length);
#if EXTRUDERS > 1
EEPROM_READ_VAR(i,retract_length_swap);
#endif
#endif//EXTRUDERS > 1
EEPROM_READ_VAR(i,retract_feedrate);
EEPROM_READ_VAR(i,retract_zlift);
EEPROM_READ_VAR(i,retract_recover_length);
#if EXTRUDERS > 1
EEPROM_READ_VAR(i,retract_recover_length_swap);
#endif
#endif//EXTRUDERS > 1
EEPROM_READ_VAR(i,retract_recover_feedrate);
#endif
#endif//FWRETRACT
EEPROM_READ_VAR(i, volumetric_enabled);
EEPROM_READ_VAR(i, filament_size[0]);
@ -349,8 +403,8 @@ void Config_RetrieveSettings()
EEPROM_READ_VAR(i, filament_size[1]);
#if EXTRUDERS > 2
EEPROM_READ_VAR(i, filament_size[2]);
#endif
#endif
#endif//EXTRUDERS > 2
#endif//EXTRUDERS > 1
calculate_volumetric_multipliers();
// Call updatePID (similar to when we have processed M301)
updatePID();
@ -363,9 +417,9 @@ void Config_RetrieveSettings()
}
#ifdef EEPROM_CHITCHAT
Config_PrintSettings();
#endif
#endif//EEPROM_CHITCHAT
}
#endif
#endif//EEPROM_SETTINGS
void Config_ResetDefault()
{
@ -379,7 +433,7 @@ void Config_ResetDefault()
max_acceleration_units_per_sq_second[i]=pgm_read_float(&tmp3[i]);
#ifdef SCARA
axis_scaling[i]=1;
#endif
#endif//SCARA
}
// steps per sq second need to be updated to agree with the units per sq second
@ -400,7 +454,7 @@ void Config_ResetDefault()
delta_diagonal_rod= DELTA_DIAGONAL_ROD;
delta_segments_per_second= DELTA_SEGMENTS_PER_SECOND;
recalc_delta_settings(delta_radius, delta_diagonal_rod);
#endif
#endif//DELTA
#ifdef ULTIPANEL
plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP;
plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP;
@ -408,24 +462,29 @@ void Config_ResetDefault()
absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP;
absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP;
absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED;
#endif
#endif//ULTIPANEL
#ifdef ENABLE_AUTO_BED_LEVELING
zprobe_zoffset = -Z_PROBE_OFFSET_FROM_EXTRUDER;
#endif
#endif//ENABLE_AUTO_BED_LEVELING
#ifdef DOGLCD
lcd_contrast = DEFAULT_LCD_CONTRAST;
#endif
#endif//DOGLCD
#ifdef PIDTEMP
Kp = DEFAULT_Kp;
Ki = scalePID_i(DEFAULT_Ki);
Kd = scalePID_d(DEFAULT_Kd);
#ifdef PID_PARAMS_PER_EXTRUDER
for (int e = 0; e < EXTRUDERS; e++)
#else // PID_PARAMS_PER_EXTRUDER
int e = 0; // only need to write once
#endif // PID_PARAMS_PER_EXTRUDER
{
PID_PARAM(Kp,e) = DEFAULT_Kp;
PID_PARAM(Ki,e) = scalePID_i(DEFAULT_Ki);
PID_PARAM(Kd,e) = scalePID_d(DEFAULT_Kd);
#ifdef PID_ADD_EXTRUSION_RATE
PID_PARAM(Kc,e) = DEFAULT_Kc;
#endif//PID_ADD_EXTRUSION_RATE
}
// call updatePID (similar to when we have processed M301)
updatePID();
#ifdef PID_ADD_EXTRUSION_RATE
Kc = DEFAULT_Kc;
#endif//PID_ADD_EXTRUSION_RATE
#endif//PIDTEMP
#ifdef FWRETRACT
@ -433,15 +492,15 @@ void Config_ResetDefault()
retract_length = RETRACT_LENGTH;
#if EXTRUDERS > 1
retract_length_swap = RETRACT_LENGTH_SWAP;
#endif
#endif//EXTRUDERS > 1
retract_feedrate = RETRACT_FEEDRATE;
retract_zlift = RETRACT_ZLIFT;
retract_recover_length = RETRACT_RECOVER_LENGTH;
#if EXTRUDERS > 1
retract_recover_length_swap = RETRACT_RECOVER_LENGTH_SWAP;
#endif
#endif//EXTRUDERS > 1
retract_recover_feedrate = RETRACT_RECOVER_FEEDRATE;
#endif
#endif//FWRETRACT
volumetric_enabled = false;
filament_size[0] = DEFAULT_NOMINAL_FILAMENT_DIA;
@ -449,8 +508,8 @@ void Config_ResetDefault()
filament_size[1] = DEFAULT_NOMINAL_FILAMENT_DIA;
#if EXTRUDERS > 2
filament_size[2] = DEFAULT_NOMINAL_FILAMENT_DIA;
#endif
#endif
#endif//EXTRUDERS > 2
#endif//EXTRUDERS > 1
calculate_volumetric_multipliers();
SERIAL_ECHO_START;

66
Marlin/Marlin_main.cpp

@ -3196,30 +3196,52 @@ Sigma_Exit:
#endif // M300
#ifdef PIDTEMP
case 301: // M301
{
if(code_seen('P')) Kp = code_value();
if(code_seen('I')) Ki = scalePID_i(code_value());
if(code_seen('D')) Kd = scalePID_d(code_value());
case 301: // M301
{
#ifdef PID_ADD_EXTRUSION_RATE
if(code_seen('C')) Kc = code_value();
#endif
// multi-extruder PID patch: M301 updates or prints a single extruder's PID values
// default behaviour (omitting E parameter) is to update for extruder 0 only
int e = 0; // extruder being updated
if (code_seen('E'))
{
e = (int)code_value();
}
if (e < EXTRUDERS) // catch bad input value
{
if (code_seen('P')) PID_PARAM(Kp,e) = code_value();
if (code_seen('I')) PID_PARAM(Ki,e) = scalePID_i(code_value());
if (code_seen('D')) PID_PARAM(Kd,e) = scalePID_d(code_value());
#ifdef PID_ADD_EXTRUSION_RATE
if (code_seen('C')) PID_PARAM(Kc,e) = code_value();
#endif
updatePID();
SERIAL_PROTOCOL(MSG_OK);
#ifdef PID_PARAMS_PER_EXTRUDER
SERIAL_PROTOCOL(" e:"); // specify extruder in serial output
SERIAL_PROTOCOL(e);
#endif // PID_PARAMS_PER_EXTRUDER
SERIAL_PROTOCOL(" p:");
SERIAL_PROTOCOL(PID_PARAM(Kp,e));
SERIAL_PROTOCOL(" i:");
SERIAL_PROTOCOL(unscalePID_i(PID_PARAM(Ki,e)));
SERIAL_PROTOCOL(" d:");
SERIAL_PROTOCOL(unscalePID_d(PID_PARAM(Kd,e)));
#ifdef PID_ADD_EXTRUSION_RATE
SERIAL_PROTOCOL(" c:");
//Kc does not have scaling applied above, or in resetting defaults
SERIAL_PROTOCOL(PID_PARAM(Kc,e));
#endif
SERIAL_PROTOCOLLN("");
}
else
{
SERIAL_ECHO_START;
SERIAL_ECHOLN(MSG_INVALID_EXTRUDER);
}
updatePID();
SERIAL_PROTOCOL(MSG_OK);
SERIAL_PROTOCOL(" p:");
SERIAL_PROTOCOL(Kp);
SERIAL_PROTOCOL(" i:");
SERIAL_PROTOCOL(unscalePID_i(Ki));
SERIAL_PROTOCOL(" d:");
SERIAL_PROTOCOL(unscalePID_d(Kd));
#ifdef PID_ADD_EXTRUSION_RATE
SERIAL_PROTOCOL(" c:");
//Kc does not have scaling applied above, or in resetting defaults
SERIAL_PROTOCOL(Kc);
#endif
SERIAL_PROTOCOLLN("");
}
break;
#endif //PIDTEMP

8
Marlin/language_ca.h

@ -67,6 +67,14 @@
#define MSG_PID_I "PID-I"
#define MSG_PID_D "PID-D"
#define MSG_PID_C "PID-C"
#define MSG_PID_P1 "PID-P E2"
#define MSG_PID_I1 "PID-I E2"
#define MSG_PID_D1 "PID-D E2"
#define MSG_PID_C1 "PID-C E2"
#define MSG_PID_P2 "PID-P E3"
#define MSG_PID_I2 "PID-I E3"
#define MSG_PID_D2 "PID-D E3"
#define MSG_PID_C2 "PID-C E3"
#define MSG_ACC "Accel"
#define MSG_VXY_JERK "Vxy-jerk"
#define MSG_VZ_JERK "Vz-jerk"

8
Marlin/language_de.h

@ -67,6 +67,14 @@
#define MSG_PID_I "PID-I"
#define MSG_PID_D "PID-D"
#define MSG_PID_C "PID-C"
#define MSG_PID_P1 "PID-P E2"
#define MSG_PID_I1 "PID-I E2"
#define MSG_PID_D1 "PID-D E2"
#define MSG_PID_C1 "PID-C E2"
#define MSG_PID_P2 "PID-P E3"
#define MSG_PID_I2 "PID-I E3"
#define MSG_PID_D2 "PID-D E3"
#define MSG_PID_C2 "PID-C E3"
#define MSG_ACC "Acc"
#define MSG_VXY_JERK "Vxy-jerk"
#define MSG_VZ_JERK "Vz-jerk"

8
Marlin/language_en.h

@ -67,6 +67,14 @@
#define MSG_PID_I "PID-I"
#define MSG_PID_D "PID-D"
#define MSG_PID_C "PID-C"
#define MSG_PID_P1 "PID-P E2"
#define MSG_PID_I1 "PID-I E2"
#define MSG_PID_D1 "PID-D E2"
#define MSG_PID_C1 "PID-C E2"
#define MSG_PID_P2 "PID-P E3"
#define MSG_PID_I2 "PID-I E3"
#define MSG_PID_D2 "PID-D E3"
#define MSG_PID_C2 "PID-C E3"
#define MSG_ACC "Accel"
#define MSG_VXY_JERK "Vxy-jerk"
#define MSG_VZ_JERK "Vz-jerk"

8
Marlin/language_es.h

@ -67,6 +67,14 @@
#define MSG_PID_I "PID-I"
#define MSG_PID_D "PID-D"
#define MSG_PID_C "PID-C"
#define MSG_PID_P1 "PID-P E2"
#define MSG_PID_I1 "PID-I E2"
#define MSG_PID_D1 "PID-D E2"
#define MSG_PID_C1 "PID-C E2"
#define MSG_PID_P2 "PID-P E3"
#define MSG_PID_I2 "PID-I E3"
#define MSG_PID_D2 "PID-D E3"
#define MSG_PID_C2 "PID-C E3"
#define MSG_ACC "Acel"
#define MSG_VXY_JERK "Vxy-jerk"
#define MSG_VZ_JERK "Vz-jerk"

8
Marlin/language_eu.h

@ -67,6 +67,14 @@
#define MSG_PID_I "PID-I"
#define MSG_PID_D "PID-D"
#define MSG_PID_C "PID-C"
#define MSG_PID_P1 "PID-P E2"
#define MSG_PID_I1 "PID-I E2"
#define MSG_PID_D1 "PID-D E2"
#define MSG_PID_C1 "PID-C E2"
#define MSG_PID_P2 "PID-P E3"
#define MSG_PID_I2 "PID-I E3"
#define MSG_PID_D2 "PID-D E3"
#define MSG_PID_C2 "PID-C E3"
#define MSG_ACC "Azelerazioa"
#define MSG_VXY_JERK "Vxy-astindua"
#define MSG_VZ_JERK "Vz-astindua"

8
Marlin/language_fi.h

@ -67,6 +67,14 @@
#define MSG_PID_I "PID-I"
#define MSG_PID_D "PID-D"
#define MSG_PID_C "PID-C"
#define MSG_PID_P1 "PID-P E2"
#define MSG_PID_I1 "PID-I E2"
#define MSG_PID_D1 "PID-D E2"
#define MSG_PID_C1 "PID-C E2"
#define MSG_PID_P2 "PID-P E3"
#define MSG_PID_I2 "PID-I E3"
#define MSG_PID_D2 "PID-D E3"
#define MSG_PID_C2 "PID-C E3"
#define MSG_ACC "Kiihtyv"
#define MSG_VXY_JERK "Vxy-jerk"
#define MSG_VZ_JERK "Vz-jerk"

8
Marlin/language_fr.h

@ -67,6 +67,14 @@
#define MSG_PID_I "PID-I"
#define MSG_PID_D "PID-D"
#define MSG_PID_C "PID-C"
#define MSG_PID_P1 "PID-P E2"
#define MSG_PID_I1 "PID-I E2"
#define MSG_PID_D1 "PID-D E2"
#define MSG_PID_C1 "PID-C E2"
#define MSG_PID_P2 "PID-P E3"
#define MSG_PID_I2 "PID-I E3"
#define MSG_PID_D2 "PID-D E3"
#define MSG_PID_C2 "PID-C E3"
#define MSG_ACC "Accel"
#define MSG_VXY_JERK "Vxy-jerk"
#define MSG_VZ_JERK "Vz-jerk"

8
Marlin/language_it.h

@ -67,6 +67,14 @@
#define MSG_PID_I "PID-I"
#define MSG_PID_D "PID-D"
#define MSG_PID_C "PID-C"
#define MSG_PID_P1 "PID-P E2"
#define MSG_PID_I1 "PID-I E2"
#define MSG_PID_D1 "PID-D E2"
#define MSG_PID_C1 "PID-C E2"
#define MSG_PID_P2 "PID-P E3"
#define MSG_PID_I2 "PID-I E3"
#define MSG_PID_D2 "PID-D E3"
#define MSG_PID_C2 "PID-C E3"
#define MSG_ACC "Accel."
#define MSG_VXY_JERK "Vxy-jerk"
#define MSG_VZ_JERK "Vz-jerk"

8
Marlin/language_nl.h

@ -67,6 +67,14 @@
#define MSG_PID_I "PID-I"
#define MSG_PID_D "PID-D"
#define MSG_PID_C "PID-C"
#define MSG_PID_P1 "PID-P E2"
#define MSG_PID_I1 "PID-I E2"
#define MSG_PID_D1 "PID-D E2"
#define MSG_PID_C1 "PID-C E2"
#define MSG_PID_P2 "PID-P E3"
#define MSG_PID_I2 "PID-I E3"
#define MSG_PID_D2 "PID-D E3"
#define MSG_PID_C2 "PID-C E3"
#define MSG_ACC "Versn"
#define MSG_VXY_JERK "Vxy-jerk"
#define MSG_VZ_JERK "Vz-jerk"

8
Marlin/language_pl.h

@ -67,6 +67,14 @@
#define MSG_PID_I "PID-I"
#define MSG_PID_D "PID-D"
#define MSG_PID_C "PID-C"
#define MSG_PID_P1 "PID-P E2"
#define MSG_PID_I1 "PID-I E2"
#define MSG_PID_D1 "PID-D E2"
#define MSG_PID_C1 "PID-C E2"
#define MSG_PID_P2 "PID-P E3"
#define MSG_PID_I2 "PID-I E3"
#define MSG_PID_D2 "PID-D E3"
#define MSG_PID_C2 "PID-C E3"
#define MSG_ACC "Przyspieszenie"
#define MSG_VXY_JERK "Zryw Vxy"
#define MSG_VZ_JERK "Zryw Vz"

8
Marlin/language_pt.h

@ -67,6 +67,14 @@
#define MSG_PID_I "PID-I: "
#define MSG_PID_D "PID-D: "
#define MSG_PID_C "PID-C: "
#define MSG_PID_P1 "PID-P E2: "
#define MSG_PID_I1 "PID-I E2: "
#define MSG_PID_D1 "PID-D E2: "
#define MSG_PID_C1 "PID-C E2: "
#define MSG_PID_P2 "PID-P E3: "
#define MSG_PID_I2 "PID-I E3: "
#define MSG_PID_D2 "PID-D E3: "
#define MSG_PID_C2 "PID-C E3: "
#define MSG_ACC "Acc:"
#define MSG_VXY_JERK "Vxy-jerk: "
#define MSG_VZ_JERK "Vz-jerk"

8
Marlin/language_ru.h

@ -69,6 +69,14 @@
#define MSG_PID_I "PID-I: "
#define MSG_PID_D "PID-D: "
#define MSG_PID_C "PID-C: "
#define MSG_PID_P1 "PID-P E2: "
#define MSG_PID_I1 "PID-I E2: "
#define MSG_PID_D1 "PID-D E2: "
#define MSG_PID_C1 "PID-C E2: "
#define MSG_PID_P2 "PID-P E3: "
#define MSG_PID_I2 "PID-I E3: "
#define MSG_PID_D2 "PID-D E3: "
#define MSG_PID_C2 "PID-C E3: "
#define MSG_ACC "Acc:"
#define MSG_VXY_JERK "Vxy-jerk: "
#define MSG_VZ_JERK "Vz-jerk"

36
Marlin/temperature.cpp

@ -51,14 +51,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;
@ -134,6 +126,24 @@ static volatile bool temp_meas_ready = false;
# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1 }
#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 // 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
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 );
@ -343,7 +353,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 / PID_PARAM(Ki,e);
}
#endif
#ifdef PIDTEMPBED
@ -464,14 +474,14 @@ void manage_heater()
temp_iState[e] = 0.0;
pid_reset[e] = false;
}
pTerm[e] = Kp * 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 * 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 * (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 +821,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 / PID_PARAM(Ki,e);
#endif //PIDTEMP
#ifdef PIDTEMPBED
temp_iState_min_bed = 0.0;

9
Marlin/temperature.h

@ -58,7 +58,14 @@ extern float current_temperature_bed;
#endif
#ifdef PIDTEMP
extern float Kp,Ki,Kd,Kc;
#ifdef PID_PARAMS_PER_EXTRUDER
extern float Kp[EXTRUDERS], Ki[EXTRUDERS], Kd[EXTRUDERS], Kc[EXTRUDERS]; // one param per extruder
#define PID_PARAM(param,e) param[e] // use macro to point to array value
#else
extern float Kp, Ki, Kd, Kc; // one param per extruder - saves 20 or 36 bytes of ram (inc array pointer)
#define PID_PARAM(param, e) param // use macro to point directly to value
#endif // PID_PARAMS_PER_EXTRUDER
float scalePID_i(float i);
float scalePID_d(float d);
float unscalePID_i(float i);

59
Marlin/ultralcd.cpp

@ -185,8 +185,9 @@ void* editValue;
int32_t minEditValue, maxEditValue;
menuFunc_t callbackFunc;
// place-holders for Ki and Kd edits
// place-holders for Ki and Kd edits, and the extruder # being edited
float raw_Ki, raw_Kd;
int pid_current_extruder;
static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder=0, const bool feedback=true) {
if (currentMenu != menu) {
@ -765,12 +766,6 @@ static void lcd_control_menu()
static void lcd_control_temperature_menu()
{
#ifdef PIDTEMP
// set up temp variables - undo the default scaling
raw_Ki = unscalePID_i(Ki);
raw_Kd = unscalePID_d(Kd);
#endif
START_MENU();
MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
#if TEMP_SENSOR_0 != 0
@ -793,13 +788,45 @@ static void lcd_control_temperature_menu()
MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
#endif
#ifdef PIDTEMP
MENU_ITEM_EDIT(float52, MSG_PID_P, &Kp, 1, 9990);
// i is typically a small value so allows values below 1
MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I, &raw_Ki, 0.01, 9990, copy_and_scalePID_i);
MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D, &raw_Kd, 1, 9990, copy_and_scalePID_d);
# ifdef PID_ADD_EXTRUSION_RATE
MENU_ITEM_EDIT(float3, MSG_PID_C, &Kc, 1, 9990);
# endif//PID_ADD_EXTRUSION_RATE
// set up temp variables - undo the default scaling
pid_current_extruder = 0;
raw_Ki = unscalePID_i(PID_PARAM(Ki,0));
raw_Kd = unscalePID_d(PID_PARAM(Kd,0));
MENU_ITEM_EDIT(float52, MSG_PID_P, &PID_PARAM(Kp,0), 1, 9990);
// i is typically a small value so allows values below 1
MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I, &raw_Ki, 0.01, 9990, copy_and_scalePID_i);
MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D, &raw_Kd, 1, 9990, copy_and_scalePID_d);
#ifdef PID_ADD_EXTRUSION_RATE
MENU_ITEM_EDIT(float3, MSG_PID_C, &PID_PARAM(Kc,0), 1, 9990);
#endif//PID_ADD_EXTRUSION_RATE
#ifdef PID_PARAMS_PER_EXTRUDER
#if EXTRUDERS > 1
// set up temp variables - undo the default scaling
pid_current_extruder = 0;
raw_Ki = unscalePID_i(PID_PARAM(Ki,1));
raw_Kd = unscalePID_d(PID_PARAM(Kd,1));
MENU_ITEM_EDIT(float52, MSG_PID_P1, &PID_PARAM(Kp,1), 1, 9990);
// i is typically a small value so allows values below 1
MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I1, &raw_Ki, 0.01, 9990, copy_and_scalePID_i);
MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D1, &raw_Kd, 1, 9990, copy_and_scalePID_d);
#ifdef PID_ADD_EXTRUSION_RATE
MENU_ITEM_EDIT(float3, MSG_PID_C1, &PID_PARAM(Kc,1), 1, 9990);
#endif//PID_ADD_EXTRUSION_RATE
#endif//EXTRUDERS > 1
#if EXTRUDERS > 2
// set up temp variables - undo the default scaling
pid_current_extruder = 0;
raw_Ki = unscalePID_i(PID_PARAM(Ki,2));
raw_Kd = unscalePID_d(PID_PARAM(Kd,2));
MENU_ITEM_EDIT(float52, MSG_PID_P2, &PID_PARAM(Kp,2), 1, 9990);
// i is typically a small value so allows values below 1
MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I2, &raw_Ki, 0.01, 9990, copy_and_scalePID_i);
MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D2, &raw_Kd, 1, 9990, copy_and_scalePID_d);
#ifdef PID_ADD_EXTRUSION_RATE
MENU_ITEM_EDIT(float3, MSG_PID_C2, &PID_PARAM(Kc,2), 1, 9990);
#endif//PID_ADD_EXTRUSION_RATE
#endif//EXTRUDERS > 2
#endif // PID_PARAMS_PER_EXTRUDER
#endif//PIDTEMP
MENU_ITEM(submenu, MSG_PREHEAT_PLA_SETTINGS, lcd_control_temperature_preheat_pla_settings_menu);
MENU_ITEM(submenu, MSG_PREHEAT_ABS_SETTINGS, lcd_control_temperature_preheat_abs_settings_menu);
@ -1706,7 +1733,7 @@ char *ftostr52(const float &x)
void copy_and_scalePID_i()
{
#ifdef PIDTEMP
Ki = scalePID_i(raw_Ki);
PID_PARAM(Ki, pid_current_extruder) = scalePID_i(raw_Ki);
updatePID();
#endif
}
@ -1716,7 +1743,7 @@ void copy_and_scalePID_i()
void copy_and_scalePID_d()
{
#ifdef PIDTEMP
Kd = scalePID_d(raw_Kd);
PID_PARAM(Kd, pid_current_extruder) = scalePID_d(raw_Kd);
updatePID();
#endif
}

Loading…
Cancel
Save