Protect pid_tuning_finished behind temperature.cpp
Setting pid_tuning_finished can result in the heaters stuck to full power. As a result, we need to ensure that when PID management is disabled, heaters are also.
This commit is contained in:
parent
442b2e16de
commit
f1d88ebd40
@ -85,7 +85,17 @@ float current_temperature_bed = 0.0;
|
|||||||
#ifdef PIDTEMP
|
#ifdef PIDTEMP
|
||||||
float _Kp, _Ki, _Kd;
|
float _Kp, _Ki, _Kd;
|
||||||
int pid_cycle, pid_number_of_cycles;
|
int pid_cycle, pid_number_of_cycles;
|
||||||
bool pid_tuning_finished = true;
|
static bool pid_tuning_finished = true;
|
||||||
|
|
||||||
|
bool pidTuningRunning() {
|
||||||
|
return !pid_tuning_finished;
|
||||||
|
}
|
||||||
|
|
||||||
|
void preparePidTuning() {
|
||||||
|
// ensure heaters are disabled before we switch off PID management!
|
||||||
|
disable_heater();
|
||||||
|
pid_tuning_finished = false;
|
||||||
|
}
|
||||||
#endif //PIDTEMP
|
#endif //PIDTEMP
|
||||||
|
|
||||||
unsigned char soft_pwm_bed;
|
unsigned char soft_pwm_bed;
|
||||||
@ -207,8 +217,9 @@ bool checkAllHotends(void)
|
|||||||
// codegen bug causing a stack overwrite issue in process_commands()
|
// codegen bug causing a stack overwrite issue in process_commands()
|
||||||
void __attribute__((noinline)) PID_autotune(float temp, int extruder, int ncycles)
|
void __attribute__((noinline)) PID_autotune(float temp, int extruder, int ncycles)
|
||||||
{
|
{
|
||||||
|
preparePidTuning();
|
||||||
|
|
||||||
pid_number_of_cycles = ncycles;
|
pid_number_of_cycles = ncycles;
|
||||||
pid_tuning_finished = false;
|
|
||||||
float input = 0.0;
|
float input = 0.0;
|
||||||
pid_cycle=0;
|
pid_cycle=0;
|
||||||
bool heating = true;
|
bool heating = true;
|
||||||
@ -243,8 +254,6 @@ void __attribute__((noinline)) PID_autotune(float temp, int extruder, int ncycle
|
|||||||
|
|
||||||
SERIAL_ECHOLNPGM("PID Autotune start");
|
SERIAL_ECHOLNPGM("PID Autotune start");
|
||||||
|
|
||||||
disable_heater(); // switch off all heaters.
|
|
||||||
|
|
||||||
if (extruder<0)
|
if (extruder<0)
|
||||||
{
|
{
|
||||||
soft_pwm_bed = (MAX_BED_POWER)/2;
|
soft_pwm_bed = (MAX_BED_POWER)/2;
|
||||||
|
@ -84,11 +84,13 @@ extern bool bedPWMDisabled;
|
|||||||
#ifdef PIDTEMP
|
#ifdef PIDTEMP
|
||||||
extern int pid_cycle, pid_number_of_cycles;
|
extern int pid_cycle, pid_number_of_cycles;
|
||||||
extern float _Kp,_Ki,_Kd;
|
extern float _Kp,_Ki,_Kd;
|
||||||
extern bool pid_tuning_finished;
|
|
||||||
float scalePID_i(float i);
|
float scalePID_i(float i);
|
||||||
float scalePID_d(float d);
|
float scalePID_d(float d);
|
||||||
float unscalePID_i(float i);
|
float unscalePID_i(float i);
|
||||||
float unscalePID_d(float d);
|
float unscalePID_d(float d);
|
||||||
|
|
||||||
|
bool pidTuningRunning(); // returns true if PID tuning is still running
|
||||||
|
void preparePidTuning(); // non-blocking call to set "pidTuningRunning" to true immediately
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -1018,14 +1018,14 @@ void lcd_commands()
|
|||||||
lcd_commands_step = 3;
|
lcd_commands_step = 3;
|
||||||
}
|
}
|
||||||
if (lcd_commands_step == 3 && !blocks_queued()) { //PID calibration
|
if (lcd_commands_step == 3 && !blocks_queued()) { //PID calibration
|
||||||
pid_tuning_finished = false; // ensure we don't move to the next step early
|
preparePidTuning(); // ensure we don't move to the next step early
|
||||||
sprintf_P(cmd1, PSTR("M303 E0 S%3u"), pid_temp);
|
sprintf_P(cmd1, PSTR("M303 E0 S%3u"), pid_temp);
|
||||||
// setting the correct target temperature (for visualization) is done in PID_autotune
|
// setting the correct target temperature (for visualization) is done in PID_autotune
|
||||||
enquecommand(cmd1);
|
enquecommand(cmd1);
|
||||||
lcd_setstatuspgm(_i("PID cal."));////MSG_PID_RUNNING c=20
|
lcd_setstatuspgm(_i("PID cal."));////MSG_PID_RUNNING c=20
|
||||||
lcd_commands_step = 2;
|
lcd_commands_step = 2;
|
||||||
}
|
}
|
||||||
if (lcd_commands_step == 2 && pid_tuning_finished) { //saving to eeprom
|
if (lcd_commands_step == 2 && !pidTuningRunning()) { //saving to eeprom
|
||||||
custom_message_state = 0;
|
custom_message_state = 0;
|
||||||
lcd_setstatuspgm(_i("PID cal. finished"));////MSG_PID_FINISHED c=20
|
lcd_setstatuspgm(_i("PID cal. finished"));////MSG_PID_FINISHED c=20
|
||||||
setAllTargetHotends(0); // reset all hotends temperature including the number displayed on the main screen
|
setAllTargetHotends(0); // reset all hotends temperature including the number displayed on the main screen
|
||||||
|
Loading…
Reference in New Issue
Block a user