🩹 Fix PID / MPC tune background tasks (#26652)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
parent
12d7995a18
commit
25caae1e8c
|
@ -628,6 +628,36 @@ volatile bool Temperature::raw_temps_ready = false;
|
||||||
* Class and Instance Methods
|
* Class and Instance Methods
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if ANY(HAS_PID_HEATING, MPC_AUTOTUNE)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the minimal required activities during a tuning loop.
|
||||||
|
* TODO: Allow tuning routines to call idle() for more complete keepalive.
|
||||||
|
*/
|
||||||
|
bool Temperature::tuning_idle(const millis_t &ms) {
|
||||||
|
|
||||||
|
// Run HAL idle tasks
|
||||||
|
hal.idletask();
|
||||||
|
|
||||||
|
const bool temp_ready = updateTemperaturesIfReady();
|
||||||
|
|
||||||
|
#if HAS_FAN_LOGIC
|
||||||
|
if (temp_ready) manage_extruder_fans(ms);
|
||||||
|
#else
|
||||||
|
UNUSED(ms);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Run Controller Fan check (normally handled by manage_inactivity)
|
||||||
|
TERN_(USE_CONTROLLER_FAN, controllerFan.update());
|
||||||
|
|
||||||
|
// Run UI update
|
||||||
|
ui.update();
|
||||||
|
|
||||||
|
return temp_ready;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HAS_PID_HEATING
|
#if HAS_PID_HEATING
|
||||||
|
|
||||||
inline void say_default_() { SERIAL_ECHOPGM("#define DEFAULT_"); }
|
inline void say_default_() { SERIAL_ECHOPGM("#define DEFAULT_"); }
|
||||||
|
@ -727,7 +757,11 @@ volatile bool Temperature::raw_temps_ready = false;
|
||||||
|
|
||||||
const millis_t ms = millis();
|
const millis_t ms = millis();
|
||||||
|
|
||||||
if (updateTemperaturesIfReady()) { // temp sample ready
|
// Run minimal necessary machine tasks
|
||||||
|
const bool temp_ready = tuning_idle(ms);
|
||||||
|
|
||||||
|
// If a new sample has arrived process things
|
||||||
|
if (temp_ready) {
|
||||||
|
|
||||||
// Get the current temperature and constrain it
|
// Get the current temperature and constrain it
|
||||||
current_temp = GHV(degChamber(), degBed(), degHotend(heater_id));
|
current_temp = GHV(degChamber(), degBed(), degHotend(heater_id));
|
||||||
|
@ -738,8 +772,6 @@ volatile bool Temperature::raw_temps_ready = false;
|
||||||
ONHEATING(start_temp, current_temp, target);
|
ONHEATING(start_temp, current_temp, target);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TERN_(HAS_FAN_LOGIC, manage_extruder_fans(ms));
|
|
||||||
|
|
||||||
if (heating && current_temp > target && ELAPSED(ms, t2 + 5000UL)) {
|
if (heating && current_temp > target && ELAPSED(ms, t2 + 5000UL)) {
|
||||||
heating = false;
|
heating = false;
|
||||||
SHV((bias - d) >> 1);
|
SHV((bias - d) >> 1);
|
||||||
|
@ -885,12 +917,6 @@ volatile bool Temperature::raw_temps_ready = false;
|
||||||
|
|
||||||
goto EXIT_M303;
|
goto EXIT_M303;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run HAL idle tasks
|
|
||||||
hal.idletask();
|
|
||||||
|
|
||||||
// Run UI update
|
|
||||||
ui.update();
|
|
||||||
}
|
}
|
||||||
wait_for_heatup = false;
|
wait_for_heatup = false;
|
||||||
|
|
||||||
|
@ -1142,10 +1168,11 @@ volatile bool Temperature::raw_temps_ready = false;
|
||||||
constexpr millis_t report_interval_ms = 1000UL;
|
constexpr millis_t report_interval_ms = 1000UL;
|
||||||
curr_time_ms = millis();
|
curr_time_ms = millis();
|
||||||
|
|
||||||
if (updateTemperaturesIfReady()) { // temp sample ready
|
// Run minimal necessary machine tasks
|
||||||
current_temp = degHotend(e);
|
const bool temp_ready = tuning_idle(curr_time_ms);
|
||||||
TERN_(HAS_FAN_LOGIC, manage_extruder_fans(curr_time_ms));
|
|
||||||
}
|
// Set MPC temp if a new sample is ready
|
||||||
|
if (temp_ready) current_temp = degHotend(e);
|
||||||
|
|
||||||
if (ELAPSED(curr_time_ms, next_report_ms)) {
|
if (ELAPSED(curr_time_ms, next_report_ms)) {
|
||||||
next_report_ms += report_interval_ms;
|
next_report_ms += report_interval_ms;
|
||||||
|
@ -1153,9 +1180,6 @@ volatile bool Temperature::raw_temps_ready = false;
|
||||||
SERIAL_EOL();
|
SERIAL_EOL();
|
||||||
}
|
}
|
||||||
|
|
||||||
hal.idletask();
|
|
||||||
ui.update();
|
|
||||||
|
|
||||||
if (!wait_for_heatup) {
|
if (!wait_for_heatup) {
|
||||||
SERIAL_ECHOLNPGM(STR_MPC_AUTOTUNE_INTERRUPTED);
|
SERIAL_ECHOLNPGM(STR_MPC_AUTOTUNE_INTERRUPTED);
|
||||||
TERN_(DWIN_LCD_PROUI, dwinMPCTuning(MPC_INTERRUPTED));
|
TERN_(DWIN_LCD_PROUI, dwinMPCTuning(MPC_INTERRUPTED));
|
||||||
|
|
|
@ -1197,6 +1197,8 @@ class Temperature {
|
||||||
static constexpr bool adaptive_fan_slowing = true;
|
static constexpr bool adaptive_fan_slowing = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static bool tuning_idle(const millis_t &ms);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* M303 PID auto-tuning for hotends or bed
|
* M303 PID auto-tuning for hotends or bed
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue