Skip to content

Commit

Permalink
🐛 Fix Bed/Chamber PID Autotune with MPCTEMP (#23983)
Browse files Browse the repository at this point in the history
  • Loading branch information
GMagician authored and thinkyhead committed Jun 4, 2022
1 parent a6ce9bf commit 6c557a2
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 96 deletions.
8 changes: 6 additions & 2 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,9 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
if (do_reset_timeout) gcode.reset_stepper_timeout(ms);

if (gcode.stepper_max_timed_out(ms)) {
SERIAL_ERROR_MSG(STR_KILL_INACTIVE_TIME, parser.command_ptr);
SERIAL_ERROR_START();
SERIAL_ECHOPGM(STR_KILL_PRE);
SERIAL_ECHOLNPGM(STR_KILL_INACTIVE_TIME, parser.command_ptr);
kill();
}

Expand Down Expand Up @@ -475,7 +477,9 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
// KILL the machine
// ----------------------------------------------------------------
if (killCount >= KILL_DELAY) {
SERIAL_ERROR_MSG(STR_KILL_BUTTON);
SERIAL_ERROR_START();
SERIAL_ECHOPGM(STR_KILL_PRE);
SERIAL_ECHOLNPGM(STR_KILL_BUTTON);
kill();
}
#endif
Expand Down
22 changes: 13 additions & 9 deletions Marlin/src/core/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,20 @@
#define STR_FILAMENT_CHANGE_INSERT_M108 "Insert filament and send M108"
#define STR_FILAMENT_CHANGE_WAIT_M108 "Send M108 to resume"

#define STR_STOP_BLTOUCH "!! STOP called because of BLTouch error - restart with M999"
#define STR_STOP_UNHOMED "!! STOP called because of unhomed error - restart with M999"
#define STR_KILL_INACTIVE_TIME "!! KILL caused by too much inactive time - current command: "
#define STR_KILL_BUTTON "!! KILL caused by KILL button/pin"
#define STR_STOP_PRE "!! STOP called because of "
#define STR_STOP_POST " error - restart with M999"
#define STR_STOP_BLTOUCH "BLTouch"
#define STR_STOP_UNHOMED "unhomed"
#define STR_KILL_PRE "!! KILL caused by "
#define STR_KILL_INACTIVE_TIME "too much inactive time - current command: "
#define STR_KILL_BUTTON "KILL button/pin"

// temperature.cpp strings
#define STR_PID_AUTOTUNE_START "PID Autotune start"
#define STR_PID_BAD_HEATER_ID "PID Autotune failed! Bad heater id"
#define STR_PID_TEMP_TOO_HIGH "PID Autotune failed! Temperature too high"
#define STR_PID_TIMEOUT "PID Autotune failed! timeout"
#define STR_PID_AUTOTUNE "PID Autotune"
#define STR_PID_AUTOTUNE_START " start"
#define STR_PID_BAD_HEATER_ID " failed! Bad heater id"
#define STR_PID_TEMP_TOO_HIGH " failed! Temperature too high"
#define STR_PID_TIMEOUT " failed! timeout"
#define STR_BIAS " bias: "
#define STR_D_COLON " d: "
#define STR_T_MIN " min: "
Expand All @@ -219,7 +223,7 @@
#define STR_KP " Kp: "
#define STR_KI " Ki: "
#define STR_KD " Kd: "
#define STR_PID_AUTOTUNE_FINISHED "PID Autotune finished! Put the last Kp, Ki and Kd constants from below into Configuration.h"
#define STR_PID_AUTOTUNE_FINISHED " finished! Put the last Kp, Ki and Kd constants from below into Configuration.h"
#define STR_PID_DEBUG " PID_DEBUG "
#define STR_PID_DEBUG_INPUT ": Input "
#define STR_PID_DEBUG_OUTPUT " Output "
Expand Down
15 changes: 4 additions & 11 deletions Marlin/src/feature/bltouch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,8 @@ bool BLTouch::deploy_proc() {
// Last attempt to DEPLOY
if (_deploy_query_alarm()) {
// The deploy might have failed or the probe is actually triggered (nozzle too low?) again
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch Recovery Failed");

SERIAL_ERROR_MSG(STR_STOP_BLTOUCH); // Tell the user something is wrong, needs action
stop(); // but it's not too bad, no need to kill, allow restart

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch Deploy Failed");
probe.probe_error_stop(); // Something is wrong, needs action, but not too bad, allow restart
return true; // Tell our caller we goofed in case he cares to know
}
}
Expand Down Expand Up @@ -153,12 +150,8 @@ bool BLTouch::stow_proc() {
// But one more STOW will catch that
// Last attempt to STOW
if (_stow_query_alarm()) { // so if there is now STILL an ALARM condition:

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch Recovery Failed");

SERIAL_ERROR_MSG(STR_STOP_BLTOUCH); // Tell the user something is wrong, needs action
stop(); // but it's not too bad, no need to kill, allow restart

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch Stow Failed");
probe.probe_error_stop(); // Something is wrong, needs action, but not too bad, allow restart
return true; // Tell our caller we goofed in case he cares to know
}
}
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/gcode/temp/M303.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void GcodeSuite::M303() {
case H_CHAMBER: default_temp = PREHEAT_1_TEMP_CHAMBER; break;
#endif
default:
SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
SERIAL_ECHOLNPGM(STR_PID_BAD_HEATER_ID);
TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_BAD_EXTRUDER_NUM));
TERN_(DWIN_LCD_PROUI, DWIN_PidTuning(PID_BAD_EXTRUDER_NUM));
Expand Down
12 changes: 4 additions & 8 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -2854,10 +2854,8 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#if ENABLED(DWIN_CREALITY_LCD)
#if DISABLED(SDSUPPORT)
#error "DWIN_CREALITY_LCD requires SDSUPPORT to be enabled."
#elif ENABLED(PID_EDIT_MENU)
#error "DWIN_CREALITY_LCD does not support PID_EDIT_MENU."
#elif ENABLED(PID_AUTOTUNE_MENU)
#error "DWIN_CREALITY_LCD does not support PID_AUTOTUNE_MENU."
#elif EITHER(PID_EDIT_MENU, PID_AUTOTUNE_MENU)
#error "DWIN_CREALITY_LCD does not support PID_EDIT_MENU or PID_AUTOTUNE_MENU."
#elif ENABLED(LEVEL_BED_CORNERS)
#error "DWIN_CREALITY_LCD does not support LEVEL_BED_CORNERS."
#elif BOTH(LCD_BED_LEVELING, PROBE_MANUALLY)
Expand All @@ -2866,10 +2864,8 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#elif ENABLED(DWIN_LCD_PROUI)
#if DISABLED(SDSUPPORT)
#error "DWIN_LCD_PROUI requires SDSUPPORT to be enabled."
#elif ENABLED(PID_EDIT_MENU)
#error "DWIN_LCD_PROUI does not support PID_EDIT_MENU."
#elif ENABLED(PID_AUTOTUNE_MENU)
#error "DWIN_LCD_PROUI does not support PID_AUTOTUNE_MENU."
#elif EITHER(PID_EDIT_MENU, PID_AUTOTUNE_MENU)
#error "DWIN_LCD_PROUI does not support PID_EDIT_MENU or PID_AUTOTUNE_MENU."
#elif ENABLED(LEVEL_BED_CORNERS)
#error "DWIN_LCD_PROUI does not support LEVEL_BED_CORNERS."
#elif BOTH(LCD_BED_LEVELING, PROBE_MANUALLY)
Expand Down
67 changes: 24 additions & 43 deletions Marlin/src/lcd/menu/menu_advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void menu_backlash();

// Helpers for editing PID Ki & Kd values
// grab the PID value out of the temp variable; scale it; then update the PID driver
void copy_and_scalePID_i(int16_t e) {
void copy_and_scalePID_i(const int8_t e) {
switch (e) {
#if ENABLED(PIDTEMPBED)
case H_BED: thermalManager.temp_bed.pid.Ki = scalePID_i(raw_Ki); break;
Expand All @@ -227,7 +227,7 @@ void menu_backlash();
break;
}
}
void copy_and_scalePID_d(int16_t e) {
void copy_and_scalePID_d(const int8_t e) {
switch (e) {
#if ENABLED(PIDTEMPBED)
case H_BED: thermalManager.temp_bed.pid.Kd = scalePID_d(raw_Kd); break;
Expand All @@ -243,30 +243,6 @@ void menu_backlash();
break;
}
}

#define _DEFINE_PIDTEMP_BASE_FUNCS(N) \
void copy_and_scalePID_i_E##N() { copy_and_scalePID_i(N); } \
void copy_and_scalePID_d_E##N() { copy_and_scalePID_d(N); }

#else

#define _DEFINE_PIDTEMP_BASE_FUNCS(N) //

#endif

#if ENABLED(PID_AUTOTUNE_MENU)
#define DEFINE_PIDTEMP_FUNCS(N) \
_DEFINE_PIDTEMP_BASE_FUNCS(N); \
void lcd_autotune_callback_E##N() { _lcd_autotune(heater_id_t(N)); }
#else
#define DEFINE_PIDTEMP_FUNCS(N) _DEFINE_PIDTEMP_BASE_FUNCS(N);
#endif

#if HAS_HOTEND
DEFINE_PIDTEMP_FUNCS(0);
#if ENABLED(PID_PARAMS_PER_HOTEND)
REPEAT_S(1, HOTENDS, DEFINE_PIDTEMP_FUNCS)
#endif
#endif

#if BOTH(AUTOTEMP, HAS_TEMP_HOTEND) || EITHER(PID_AUTOTUNE_MENU, PID_EDIT_MENU)
Expand All @@ -281,6 +257,7 @@ void menu_backlash();
void menu_advanced_temperature() {
START_MENU();
BACK_ITEM(MSG_ADVANCED_SETTINGS);

//
// Autotemp, Min, Max, Fact
//
Expand All @@ -300,14 +277,7 @@ void menu_backlash();
// PID-P E5, PID-I E5, PID-D E5, PID-C E5, PID Autotune E5
//

#if ENABLED(PID_EDIT_MENU)
#define _PID_EDIT_ITEMS_TMPL(N,T) \
raw_Ki = unscalePID_i(T.pid.Ki); \
raw_Kd = unscalePID_d(T.pid.Kd); \
EDIT_ITEM_FAST_N(float41sign, N, MSG_PID_P_E, &T.pid.Kp, 1, 9990); \
EDIT_ITEM_FAST_N(float52sign, N, MSG_PID_I_E, &raw_Ki, 0.01f, 9990, []{ copy_and_scalePID_i(N); }); \
EDIT_ITEM_FAST_N(float41sign, N, MSG_PID_D_E, &raw_Kd, 1, 9990, []{ copy_and_scalePID_d(N); })

#if BOTH(PIDTEMP, PID_EDIT_MENU)
#define __PID_HOTEND_MENU_ITEMS(N) \
raw_Ki = unscalePID_i(PID_PARAM(Ki, N)); \
raw_Kd = unscalePID_d(PID_PARAM(Kd, N)); \
Expand Down Expand Up @@ -337,17 +307,28 @@ void menu_backlash();

#endif

#if ENABLED(PID_AUTOTUNE_MENU)
#define HOTEND_PID_EDIT_MENU_ITEMS(N) \
_HOTEND_PID_EDIT_MENU_ITEMS(N); \
EDIT_ITEM_FAST_N(int3, N, MSG_PID_AUTOTUNE_E, &autotune_temp[N], 150, thermalManager.hotend_max_target(N), []{ _lcd_autotune(heater_id_t(MenuItemBase::itemIndex)); });
#else
#define HOTEND_PID_EDIT_MENU_ITEMS(N) _HOTEND_PID_EDIT_MENU_ITEMS(N);
#if ENABLED(PID_EDIT_MENU) && EITHER(PIDTEMPBED, PIDTEMPCHAMBER)
#define _PID_EDIT_ITEMS_TMPL(N,T) \
raw_Ki = unscalePID_i(T.pid.Ki); \
raw_Kd = unscalePID_d(T.pid.Kd); \
EDIT_ITEM_FAST_N(float41sign, N, MSG_PID_P_E, &T.pid.Kp, 1, 9990); \
EDIT_ITEM_FAST_N(float52sign, N, MSG_PID_I_E, &raw_Ki, 0.01f, 9990, []{ copy_and_scalePID_i(N); }); \
EDIT_ITEM_FAST_N(float41sign, N, MSG_PID_D_E, &raw_Kd, 1, 9990, []{ copy_and_scalePID_d(N); })
#endif

HOTEND_PID_EDIT_MENU_ITEMS(0);
#if ENABLED(PID_PARAMS_PER_HOTEND)
REPEAT_S(1, HOTENDS, HOTEND_PID_EDIT_MENU_ITEMS)
#if ENABLED(PIDTEMP)
#if ENABLED(PID_AUTOTUNE_MENU)
#define HOTEND_PID_EDIT_MENU_ITEMS(N) \
_HOTEND_PID_EDIT_MENU_ITEMS(N); \
EDIT_ITEM_FAST_N(int3, N, MSG_PID_AUTOTUNE_E, &autotune_temp[N], 150, thermalManager.hotend_max_target(N), []{ _lcd_autotune(heater_id_t(MenuItemBase::itemIndex)); });
#else
#define HOTEND_PID_EDIT_MENU_ITEMS(N) _HOTEND_PID_EDIT_MENU_ITEMS(N);
#endif

HOTEND_PID_EDIT_MENU_ITEMS(0);
#if ENABLED(PID_PARAMS_PER_HOTEND)
REPEAT_S(1, HOTENDS, HOTEND_PID_EDIT_MENU_ITEMS);
#endif
#endif

#if ENABLED(PIDTEMPBED)
Expand Down
25 changes: 18 additions & 7 deletions Marlin/src/module/probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,21 @@ FORCE_INLINE void probe_specific_action(const bool deploy) {

#endif

/**
* Print an error and stop()
*/
void Probe::probe_error_stop() {
SERIAL_ERROR_START();
SERIAL_ECHOPGM(STR_STOP_PRE);
#if EITHER(Z_PROBE_SLED, Z_PROBE_ALLEN_KEY)
SERIAL_ECHOPGM(STR_STOP_UNHOMED);
#elif ENABLED(BLTOUCH)
SERIAL_ECHOPGM(STR_STOP_BLTOUCH);
#endif
SERIAL_ECHOLNPGM(STR_STOP_POST);
stop();
}

/**
* Attempt to deploy or stow the probe
*
Expand Down Expand Up @@ -443,8 +458,7 @@ bool Probe::set_deployed(const bool deploy) {

#if EITHER(Z_PROBE_SLED, Z_PROBE_ALLEN_KEY)
if (homing_needed_error(TERN_(Z_PROBE_SLED, _BV(X_AXIS)))) {
SERIAL_ERROR_MSG(STR_STOP_UNHOMED);
stop();
probe_error_stop();
return true;
}
#endif
Expand Down Expand Up @@ -484,15 +498,12 @@ bool Probe::set_deployed(const bool deploy) {
}

/**
* @brief Used by run_z_probe to do a single Z probe move.
* @brief Move down until the probe triggers or the low limit is reached
* Used by run_z_probe to do a single Z probe move.
*
* @param z Z destination
* @param fr_mm_s Feedrate in mm/s
* @return true to indicate an error
*/

/**
* @brief Move down until the probe triggers or the low limit is reached
*
* @details Used by run_z_probe to get each bed Z height measurement.
* Sets current_position.z to the height where the probe triggered
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/module/probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class Probe {
static void preheat_for_probing(const celsius_t hotend_temp, const celsius_t bed_temp);
#endif

static void probe_error_stop();

static bool set_deployed(const bool deploy);

#if IS_KINEMATIC
Expand Down
Loading

0 comments on commit 6c557a2

Please sign in to comment.