Skip to content

Commit

Permalink
🩹 PID / MPC heating followup
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored and EvilGremlin committed May 17, 2023
1 parent 394b8c5 commit ae02b1a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
17 changes: 10 additions & 7 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,11 +907,10 @@ volatile bool Temperature::raw_temps_ready = false;
SERIAL_ECHOPGM(STR_MPC_AUTOTUNE);
SERIAL_ECHOLNPGM(STR_MPC_AUTOTUNE_INTERRUPTED);
TERN_(DWIN_LCD_PROUI, DWIN_MPCTuning(MPC_INTERRUPTED));
return false;
return true;
}

wait_for_heatup = false;
return true;
return false;
};

struct OnExit {
Expand Down Expand Up @@ -964,7 +963,7 @@ volatile bool Temperature::raw_temps_ready = false;

wait_for_heatup = true;
for (;;) { // Can be interrupted with M108
if (!housekeeping(ms, current_temp, next_report_ms)) return;
if (housekeeping(ms, current_temp, next_report_ms)) return;

if (ELAPSED(ms, next_test_ms)) {
if (current_temp >= ambient_temp) {
Expand All @@ -975,6 +974,7 @@ volatile bool Temperature::raw_temps_ready = false;
next_test_ms += 10000UL;
}
}
wait_for_heatup = false;

#if HAS_FAN
set_fan_speed(EITHER(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder, 0);
Expand All @@ -986,7 +986,7 @@ volatile bool Temperature::raw_temps_ready = false;
SERIAL_ECHOLNPGM(STR_MPC_HEATING_PAST_200);
TERN(DWIN_LCD_PROUI, LCD_ALERTMESSAGE(MSG_MPC_HEATING_PAST_200), LCD_MESSAGE(MSG_HEATING));
hotend.target = 200.0f; // So M105 looks nice
hotend.soft_pwm_amount = MPC_MAX >> 1;
hotend.soft_pwm_amount = (MPC_MAX) >> 1;
const millis_t heat_start_time = next_test_ms = ms;
celsius_float_t temp_samples[16];
uint8_t sample_count = 0;
Expand All @@ -995,7 +995,7 @@ volatile bool Temperature::raw_temps_ready = false;

wait_for_heatup = true;
for (;;) { // Can be interrupted with M108
if (!housekeeping(ms, current_temp, next_report_ms)) return;
if (housekeeping(ms, current_temp, next_report_ms)) return;

if (ELAPSED(ms, next_test_ms)) {
// Record samples between 100C and 200C
Expand All @@ -1017,6 +1017,8 @@ volatile bool Temperature::raw_temps_ready = false;
next_test_ms += 1000UL * sample_distance;
}
}
wait_for_heatup = false;

hotend.soft_pwm_amount = 0;

// Calculate physical constants from three equally-spaced samples
Expand Down Expand Up @@ -1052,7 +1054,7 @@ volatile bool Temperature::raw_temps_ready = false;

wait_for_heatup = true;
for (;;) { // Can be interrupted with M108
if (!housekeeping(ms, current_temp, next_report_ms)) return;
if (housekeeping(ms, current_temp, next_report_ms)) return;

if (ELAPSED(ms, next_test_ms)) {
hotend.soft_pwm_amount = (int)get_pid_output_hotend(active_extruder) >> 1;
Expand Down Expand Up @@ -1082,6 +1084,7 @@ volatile bool Temperature::raw_temps_ready = false;
break;
}
}
wait_for_heatup = false;

const float power_fan0 = total_energy_fan0 * 1000 / test_duration;
mpc.ambient_xfer_coeff_fan0 = power_fan0 / (hotend.target - ambient_temp);
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,12 @@ class Temperature {
static void auto_job_check_timer(const bool can_start, const bool can_stop);
#endif

#if ENABLED(TEMP_TUNING_MAINTAIN_FAN)
static bool adaptive_fan_slowing;
#elif ENABLED(ADAPTIVE_FAN_SLOWING)
static constexpr bool adaptive_fan_slowing = true;
#endif

/**
* Perform auto-tuning for hotend or bed in response to M303
*/
Expand All @@ -1173,12 +1179,6 @@ class Temperature {

static void PID_autotune(const celsius_t target, const heater_id_t heater_id, const int8_t ncycles, const bool set_result=false);

#if ENABLED(TEMP_TUNING_MAINTAIN_FAN)
static bool adaptive_fan_slowing;
#elif ENABLED(ADAPTIVE_FAN_SLOWING)
static constexpr bool adaptive_fan_slowing = true;
#endif

// Update the temp manager when PID values change
#if ENABLED(PIDTEMP)
static void updatePID() { HOTEND_LOOP() temp_hotend[e].pid.reset(); }
Expand Down

0 comments on commit ae02b1a

Please sign in to comment.