Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CONTROLLER_FAN check to PID autotune #26652

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 40 additions & 16 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,36 @@ volatile bool Temperature::raw_temps_ready = false;
* 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

inline void say_default_() { SERIAL_ECHOPGM("#define DEFAULT_"); }
Expand Down Expand Up @@ -727,7 +757,11 @@ volatile bool Temperature::raw_temps_ready = false;

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
current_temp = GHV(degChamber(), degBed(), degHotend(heater_id));
Expand All @@ -738,8 +772,6 @@ volatile bool Temperature::raw_temps_ready = false;
ONHEATING(start_temp, current_temp, target);
#endif

TERN_(HAS_FAN_LOGIC, manage_extruder_fans(ms));

if (heating && current_temp > target && ELAPSED(ms, t2 + 5000UL)) {
heating = false;
SHV((bias - d) >> 1);
Expand Down Expand Up @@ -885,12 +917,6 @@ volatile bool Temperature::raw_temps_ready = false;

goto EXIT_M303;
}

// Run HAL idle tasks
hal.idletask();

// Run UI update
ui.update();
}
wait_for_heatup = false;

Expand Down Expand Up @@ -1142,20 +1168,18 @@ volatile bool Temperature::raw_temps_ready = false;
constexpr millis_t report_interval_ms = 1000UL;
curr_time_ms = millis();

if (updateTemperaturesIfReady()) { // temp sample ready
current_temp = degHotend(e);
TERN_(HAS_FAN_LOGIC, manage_extruder_fans(curr_time_ms));
}
// Run minimal necessary machine tasks
const bool temp_ready = tuning_idle(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)) {
next_report_ms += report_interval_ms;
print_heater_states(e);
SERIAL_EOL();
}

hal.idletask();
ui.update();

if (!wait_for_heatup) {
SERIAL_ECHOLNPGM(STR_MPC_AUTOTUNE_INTERRUPTED);
TERN_(DWIN_LCD_PROUI, dwinMPCTuning(MPC_INTERRUPTED));
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,8 @@ class Temperature {
static constexpr bool adaptive_fan_slowing = true;
#endif

static bool tuning_idle(const millis_t &ms);

/**
* M303 PID auto-tuning for hotends or bed
*/
Expand Down
Loading