Skip to content

Commit

Permalink
🐛 Prevent MPC E-permm overrun in Load Filament (#25531)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
  • Loading branch information
pit3k and thinkyhead committed Apr 10, 2023
1 parent 01c91ef commit ce3a3f3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
5 changes: 5 additions & 0 deletions Marlin/src/feature/pause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ bool load_filament(const_float_t slow_load_length/*=0*/, const_float_t fast_load

TERN_(BELTPRINTER, do_blocking_move_to_xy(0.00, 50.00));

TERN_(MPCTEMP, MPC::e_paused = true);

// Slow Load filament
if (slow_load_length) unscaled_e_move(slow_load_length, FILAMENT_CHANGE_SLOW_LOAD_FEEDRATE);

Expand Down Expand Up @@ -297,6 +299,9 @@ bool load_filament(const_float_t slow_load_length/*=0*/, const_float_t fast_load
} while (TERN0(M600_PURGE_MORE_RESUMABLE, pause_menu_response == PAUSE_RESPONSE_EXTRUDE_MORE));

#endif

TERN_(MPCTEMP, MPC::e_paused = false);

TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_end());

return true;
Expand Down
17 changes: 9 additions & 8 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED);
hotend_info_t Temperature::temp_hotend[HOTENDS];
constexpr celsius_t Temperature::hotend_maxtemp[HOTENDS];

#if ENABLED(MPCTEMP)
bool MPC::e_paused; // = false
int32_t MPC::e_position; // = 0
#endif

// Sanity-check max readable temperatures
#define CHECK_MAXTEMP_(N,M,S) static_assert( \
S >= 998 || M <= _MAX(TT_NAME(S)[0].celsius, TT_NAME(S)[COUNT(TT_NAME(S)) - 1].celsius) - HOTEND_OVERSHOOT, \
Expand Down Expand Up @@ -588,10 +593,6 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED);

volatile bool Temperature::raw_temps_ready = false;

#if ENABLED(MPCTEMP)
int32_t Temperature::mpc_e_position; // = 0
#endif

#define TEMPDIR(N) ((TEMP_SENSOR_##N##_RAW_LO_TEMP) < (TEMP_SENSOR_##N##_RAW_HI_TEMP) ? 1 : -1)
#define TP_CMP(S,A,B) (TEMPDIR(S) < 0 ? ((A)<(B)) : ((A)>(B)))

Expand Down Expand Up @@ -1511,14 +1512,14 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {

if (this_hotend) {
const int32_t e_position = stepper.position(E_AXIS);
const float e_speed = (e_position - mpc_e_position) * planner.mm_per_step[E_AXIS] / MPC_dT;
const float e_speed = (e_position - MPC::e_position) * planner.mm_per_step[E_AXIS] / MPC_dT;

// The position can appear to make big jumps when, e.g., homing
if (fabs(e_speed) > planner.settings.max_feedrate_mm_s[E_AXIS])
mpc_e_position = e_position;
MPC::e_position = e_position;
else if (e_speed > 0.0f) { // Ignore retract/recover moves
ambient_xfer_coeff += e_speed * mpc.filament_heat_capacity_permm;
mpc_e_position = e_position;
if (!MPC::e_paused) ambient_xfer_coeff += e_speed * mpc.filament_heat_capacity_permm;
MPC::e_position = e_position;
}
}

Expand Down
8 changes: 3 additions & 5 deletions Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;

#elif ENABLED(MPCTEMP)

typedef struct {
typedef struct MPC {
static bool e_paused; // Pause E filament permm tracking
static int32_t e_position; // For E tracking
float heater_power; // M306 P
float block_heat_capacity; // M306 C
float sensor_responsiveness; // M306 R
Expand Down Expand Up @@ -716,10 +718,6 @@ class Temperature {
static hotend_watch_t watch_hotend[HOTENDS];
#endif

#if ENABLED(MPCTEMP)
static int32_t mpc_e_position;
#endif

#if HAS_HOTEND
static temp_range_t temp_range[HOTENDS];
#endif
Expand Down

0 comments on commit ce3a3f3

Please sign in to comment.