diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 4d6f64e87418..82b107ae44c9 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -691,6 +691,7 @@ * @section mpctemp */ #if ENABLED(MPCTEMP) + //#define MPC_AUTOTUNE // Include a method to do MPC auto-tuning (~5664-5882 bytes of flash) //#define MPC_EDIT_MENU // Add MPC editing to the "Advanced Settings" menu. (~1300 bytes of flash) //#define MPC_AUTOTUNE_MENU // Add MPC auto-tuning to the "Advanced Settings" menu. (~350 bytes of flash) diff --git a/Marlin/src/core/language.h b/Marlin/src/core/language.h index d231a7d3e9cb..bf309293ac6c 100644 --- a/Marlin/src/core/language.h +++ b/Marlin/src/core/language.h @@ -230,10 +230,9 @@ #define STR_PID_DEBUG_INPUT ": Input " #define STR_PID_DEBUG_OUTPUT " Output " #define STR_INVALID_EXTRUDER_NUM " - Invalid extruder number !" -#define STR_MPC_AUTOTUNE "MPC Autotune" -#define STR_MPC_AUTOTUNE_START " start for " STR_E -#define STR_MPC_AUTOTUNE_INTERRUPTED " interrupted!" -#define STR_MPC_AUTOTUNE_FINISHED " finished! Put the constants below into Configuration.h" +#define STR_MPC_AUTOTUNE_START "MPC Autotune start for " STR_E +#define STR_MPC_AUTOTUNE_INTERRUPTED "MPC Autotune interrupted!" +#define STR_MPC_AUTOTUNE_FINISHED "MPC Autotune finished! Put the constants below into Configuration.h" #define STR_MPC_COOLING_TO_AMBIENT "Cooling to ambient" #define STR_MPC_HEATING_PAST_200 "Heating to over 200C" #define STR_MPC_MEASURING_AMBIENT "Measuring ambient heatloss at " diff --git a/Marlin/src/gcode/temp/M306.cpp b/Marlin/src/gcode/temp/M306.cpp index 928f375c3897..d0c005ea4eb1 100644 --- a/Marlin/src/gcode/temp/M306.cpp +++ b/Marlin/src/gcode/temp/M306.cpp @@ -33,8 +33,6 @@ * * E Extruder index. (Default: Active Extruder) * - * T Autotune the specified or active extruder. - * * Set MPC values manually for the specified or active extruder: * A Ambient heat transfer coefficient (no fan). * C Block heat capacity. @@ -42,6 +40,9 @@ * H Filament heat capacity per mm. * P Heater power. * R Sensor responsiveness (= transfer coefficient / heat capcity). + * + * With MPC_AUTOTUNE: + * T Autotune the specified or active extruder. */ void GcodeSuite::M306() { @@ -51,12 +52,14 @@ void GcodeSuite::M306() { return; } - if (parser.seen_test('T')) { - LCD_MESSAGE(MSG_MPC_AUTOTUNE); - thermalManager.MPC_autotune(e); - ui.reset_status(); - return; - } + #if ENABLED(MPC_AUTOTUNE) + if (parser.seen_test('T')) { + LCD_MESSAGE(MSG_MPC_AUTOTUNE); + thermalManager.MPC_autotune(e); + ui.reset_status(); + return; + } + #endif if (parser.seen("ACFPRH")) { MPC_t &mpc = thermalManager.temp_hotend[e].mpc; diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 0031e17eeaeb..dc9849399ce2 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -1471,6 +1471,10 @@ #define HAS_PID_DEBUG 1 #endif +#if DISABLED(MPC_AUTOTUNE) + #undef MPC_AUTOTUNE_MENU +#endif + /** * TFT Displays * diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index c41f87c85958..a054f9084061 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -2499,7 +2499,7 @@ #if EITHER(PIDTEMP, PIDTEMPBED) #define DWIN_PID_TUNE 1 #endif - #if EITHER(DWIN_PID_TUNE, MPCTEMP) && DISABLED(DISABLE_TUNING_GRAPH) + #if EITHER(DWIN_PID_TUNE, MPC_AUTOTUNE) && DISABLED(DISABLE_TUNING_GRAPH) #define SHOW_TUNING_GRAPH 1 #endif #endif diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index a795bfb93fe6..cd4c4efee2db 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -1560,6 +1560,10 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS */ #if BOTH(PIDTEMP, MPCTEMP) #error "Only enable PIDTEMP or MPCTEMP, but not both." + #undef MPCTEMP + #undef MPC_AUTOTUNE + #undef MPC_EDIT_MENU + #undef MPC_AUTOTUNE_MENU #endif #if ENABLED(MPC_INCLUDE_FAN) diff --git a/Marlin/src/lcd/e3v2/proui/dwin.cpp b/Marlin/src/lcd/e3v2/proui/dwin.cpp index 6be56b0dedd2..b0d1fb3ff6e1 100644 --- a/Marlin/src/lcd/e3v2/proui/dwin.cpp +++ b/Marlin/src/lcd/e3v2/proui/dwin.cpp @@ -266,7 +266,7 @@ MenuClass *MaxAccelMenu = nullptr; MenuClass *MaxJerkMenu = nullptr; #endif MenuClass *StepsMenu = nullptr; -#if ENABLED(MPCTEMP) +#if EITHER(MPC_EDIT_MENU, MPC_AUTOTUNE_MENU) MenuClass *HotendMPCMenu = nullptr; #endif #if ENABLED(PIDTEMP) @@ -1480,46 +1480,59 @@ void DWIN_LevelingDone() { DWINUI::ClearMainArea(); Draw_Popup_Bkgd(); - #if ENABLED(MPCTEMP) - - switch (HMI_value.pidresult) { + switch (HMI_value.pidresult) { + default: return; + #if ENABLED(MPC_AUTOTUNE) case MPCTEMP_START: - _maxtemp = thermalManager.hotend_maxtemp[0]; - _target = 200; DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 100, GET_TEXT_F(MSG_MPC_AUTOTUNE)); DWINUI::Draw_String(HMI_data.PopupTxt_Color, gfrm.x, gfrm.y - DWINUI::fontHeight() - 4, F("MPC target: Celsius")); - DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 120, F("for Nozzle is running.")); break; - case PIDTEMPBED_START: - _maxtemp = BED_MAXTEMP; - _target = HMI_data.BedPidT; + #endif + #if EITHER(PIDTEMP, PIDTEMPBED) + TERN_(PIDTEMP, case PIDTEMP_START:) + TERN_(PIDTEMPBED, case PIDTEMPBED_START:) DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 100, GET_TEXT_F(MSG_PID_AUTOTUNE)); DWINUI::Draw_String(HMI_data.PopupTxt_Color, gfrm.x, gfrm.y - DWINUI::fontHeight() - 4, F("PID target: Celsius")); - DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 120, F("for BED is running.")); break; - default: return; - } - - #else // PID + #endif + } - DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 100, GET_TEXT_F(MSG_PID_AUTOTUNE)); - DWINUI::Draw_String(HMI_data.PopupTxt_Color, gfrm.x, gfrm.y - DWINUI::fontHeight() - 4, F("PID target: Celsius")); + switch (HMI_value.pidresult) { + default: break; + #if EITHER(PIDTEMP, MPC_AUTOTUNE) + TERN_(PIDTEMP, case PIDTEMP_START:) + TERN_(MPC_AUTOTUNE, case MPCTEMP_START:) + DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 120, F("for Nozzle is running.")); + break; + #endif + #if ENABLED(PIDTEMPBED) + case PIDTEMPBED_START: + DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 120, F("for BED is running.")); + break; + #endif + } - switch (HMI_value.pidresult) { + switch (HMI_value.pidresult) { + default: break; + #if ENABLED(MPC_AUTOTUNE) + case MPCTEMP_START: + _maxtemp = thermalManager.hotend_maxtemp[0]; + _target = 200; + break; + #endif + #if ENABLED(PIDTEMP) case PIDTEMP_START: _maxtemp = thermalManager.hotend_maxtemp[0]; _target = HMI_data.HotendPidT; - DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 120, F("for Nozzle is running.")); break; + #endif + #if ENABLED(PIDTEMPBED) case PIDTEMPBED_START: _maxtemp = BED_MAXTEMP; _target = HMI_data.BedPidT; - DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 120, F("for BED is running.")); break; - default: return; - } - - #endif // PID + #endif + } plot.Draw(gfrm, _maxtemp, _target); DWINUI::Draw_Int(HMI_data.PopupTxt_Color, 3, gfrm.x + 90, gfrm.y - DWINUI::fontHeight() - 4, _target); @@ -1587,7 +1600,7 @@ void DWIN_LevelingDone() { #endif // DWIN_PID_TUNE -#if ENABLED(MPCTEMP) +#if ENABLED(MPC_AUTOTUNE) void DWIN_MPCTuning(tempcontrol_t result) { HMI_value.pidresult = result; @@ -1607,7 +1620,7 @@ void DWIN_LevelingDone() { break; case MPC_INTERRUPTED: checkkey = last_checkkey; - DWIN_Popup_Confirm(ICON_TempTooHigh, GET_TEXT_F(MSG_ERROR), F(STR_MPC_AUTOTUNE STR_MPC_AUTOTUNE_INTERRUPTED)); + DWIN_Popup_Confirm(ICON_TempTooHigh, GET_TEXT_F(MSG_ERROR), F(STR_MPC_AUTOTUNE_INTERRUPTED)); ui.reset_alert_level(); break; case MPC_DONE: @@ -1622,7 +1635,7 @@ void DWIN_LevelingDone() { } } -#endif // MPCTEMP +#endif // MPC_AUTOTUNE // Started a Print Job void DWIN_Print_Started() { @@ -3090,8 +3103,8 @@ void Draw_AdvancedSettings_Menu() { #if ENABLED(PIDTEMP) MENU_ITEM_F(ICON_PIDNozzle, STR_HOTEND_PID " Settings", onDrawSubMenu, Draw_HotendPID_Menu); #endif - #if ENABLED(MPCTEMP) - MENU_ITEM_F(ICON_MPCNozzle, STR_MPC_AUTOTUNE " Settings", onDrawSubMenu, Draw_HotendMPC_Menu); + #if EITHER(MPC_EDIT_MENU, MPC_AUTOTUNE_MENU) + MENU_ITEM_F(ICON_MPCNozzle, "MPC Settings", onDrawSubMenu, Draw_HotendMPC_Menu); #endif #if ENABLED(PIDTEMPBED) MENU_ITEM_F(ICON_PIDBed, STR_BED_PID " Settings", onDrawSubMenu, Draw_BedPID_Menu); @@ -3524,37 +3537,45 @@ void Draw_Steps_Menu() { #endif -#if ENABLED(MPCTEMP) +#if EITHER(MPC_EDIT_MENU, MPC_AUTOTUNE_MENU) - void HotendMPC() { thermalManager.MPC_autotune(active_extruder); } - void SetHeaterPower() { SetPFloatOnClick(1, 200, 1); } - void SetBlkHeatCapacity() { SetPFloatOnClick(0, 40, 2); } - void SetSensorRespons() { SetPFloatOnClick(0, 1, 4); } - void SetAmbientXfer() { SetPFloatOnClick(0, 1, 4); } - #if ENABLED(MPC_INCLUDE_FAN) - void onDrawFanAdj(MenuItemClass* menuitem, int8_t line) { onDrawFloatMenu(menuitem, line, 4, thermalManager.temp_hotend[0].fanCoefficient()); } - void ApplyFanAdj() { thermalManager.temp_hotend[0].applyFanAdjustment(MenuData.Value / POW(10, 4)); } - void SetFanAdj() { SetFloatOnClick(0, 1, 4, thermalManager.temp_hotend[0].fanCoefficient(), ApplyFanAdj); } + #if ENABLED(MPC_AUTOTUNE_MENU) + void HotendMPC() { thermalManager.MPC_autotune(active_extruder); } + #endif + #if ENABLED(MPC_EDIT_MENU) + void SetHeaterPower() { SetPFloatOnClick(1, 200, 1); } + void SetBlkHeatCapacity() { SetPFloatOnClick(0, 40, 2); } + void SetSensorResponse() { SetPFloatOnClick(0, 1, 4); } + void SetAmbientXfer() { SetPFloatOnClick(0, 1, 4); } + #if ENABLED(MPC_INCLUDE_FAN) + void onDrawFanAdj(MenuItemClass* menuitem, int8_t line) { onDrawFloatMenu(menuitem, line, 4, thermalManager.temp_hotend[0].fanCoefficient()); } + void ApplyFanAdj() { thermalManager.temp_hotend[0].applyFanAdjustment(MenuData.Value / POW(10, 4)); } + void SetFanAdj() { SetFloatOnClick(0, 1, 4, thermalManager.temp_hotend[0].fanCoefficient(), ApplyFanAdj); } + #endif #endif void Draw_HotendMPC_Menu() { checkkey = Menu; - if (SET_MENU_F(HotendMPCMenu, STR_MPC_AUTOTUNE " Settings", 7)) { + if (SET_MENU_F(HotendMPCMenu, "MPC Settings", 7)) { MPC_t &mpc = thermalManager.temp_hotend[0].mpc; BACK_ITEM(Draw_AdvancedSettings_Menu); - MENU_ITEM(ICON_MPCNozzle, MSG_MPC_AUTOTUNE, onDrawMenuItem, HotendMPC); - EDIT_ITEM(ICON_MPCHeater, MSG_MPC_POWER, onDrawPFloatMenu, SetHeaterPower, &mpc.heater_power); - EDIT_ITEM(ICON_MPCHeatCap, MSG_MPC_BLOCK_HEAT_CAPACITY, onDrawPFloat2Menu, SetBlkHeatCapacity, &mpc.block_heat_capacity); - EDIT_ITEM(ICON_MPCValue, MSG_SENSOR_RESPONSIVENESS, onDrawPFloat4Menu, SetSensorRespons, &mpc.sensor_responsiveness); - EDIT_ITEM(ICON_MPCValue, MSG_MPC_AMBIENT_XFER_COEFF, onDrawPFloat4Menu, SetAmbientXfer, &mpc.ambient_xfer_coeff_fan0); - #if ENABLED(MPC_INCLUDE_FAN) - EDIT_ITEM(ICON_MPCFan, MSG_MPC_AMBIENT_XFER_COEFF_FAN, onDrawFanAdj, SetFanAdj, &mpc.fan255_adjustment); + #if ENABLED(MPC_AUTOTUNE_MENU) + MENU_ITEM(ICON_MPCNozzle, MSG_MPC_AUTOTUNE, onDrawMenuItem, HotendMPC); + #endif + #if ENABLED(MPC_EDIT_MENU) + EDIT_ITEM(ICON_MPCHeater, MSG_MPC_POWER, onDrawPFloatMenu, SetHeaterPower, &mpc.heater_power); + EDIT_ITEM(ICON_MPCHeatCap, MSG_MPC_BLOCK_HEAT_CAPACITY, onDrawPFloat2Menu, SetBlkHeatCapacity, &mpc.block_heat_capacity); + EDIT_ITEM(ICON_MPCValue, MSG_SENSOR_RESPONSIVENESS, onDrawPFloat4Menu, SetSensorResponse, &mpc.sensor_responsiveness); + EDIT_ITEM(ICON_MPCValue, MSG_MPC_AMBIENT_XFER_COEFF, onDrawPFloat4Menu, SetAmbientXfer, &mpc.ambient_xfer_coeff_fan0); + #if ENABLED(MPC_INCLUDE_FAN) + EDIT_ITEM(ICON_MPCFan, MSG_MPC_AMBIENT_XFER_COEFF_FAN, onDrawFanAdj, SetFanAdj, &mpc.fan255_adjustment); + #endif #endif } UpdateMenu(HotendMPCMenu); } -#endif // MPCTEMP +#endif // MPC_EDIT_MENU || MPC_AUTOTUNE_MENU #if ENABLED(PIDTEMPBED) diff --git a/Marlin/src/lcd/e3v2/proui/dwin.h b/Marlin/src/lcd/e3v2/proui/dwin.h index 112df5cae144..4197da4390a7 100644 --- a/Marlin/src/lcd/e3v2/proui/dwin.h +++ b/Marlin/src/lcd/e3v2/proui/dwin.h @@ -74,7 +74,7 @@ enum processID : uint8_t { NothingToDo }; -#if EITHER(DWIN_PID_TUNE, MPCTEMP) +#if EITHER(DWIN_PID_TUNE, MPC_AUTOTUNE) enum tempcontrol_t : uint8_t { #if DWIN_PID_TUNE @@ -85,7 +85,7 @@ enum processID : uint8_t { PID_TEMP_TOO_HIGH, PID_TUNING_TIMEOUT, #endif - #if ENABLED(MPCTEMP) + #if ENABLED(MPC_AUTOTUNE) MPC_DONE, MPCTEMP_START, MPC_TEMP_ERROR, @@ -384,7 +384,9 @@ void Draw_Steps_Menu(); #endif // MPC -#if ENABLED(MPCTEMP) - void DWIN_MPCTuning(tempcontrol_t result); +#if EITHER(MPC_EDIT_MENU, MPC_AUTOTUNE_MENU) void Draw_HotendMPC_Menu(); #endif +#if ENABLED(MPC_AUTOTUNE) + void DWIN_MPCTuning(tempcontrol_t result); +#endif diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index b5726902561b..bc978077f00f 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -580,7 +580,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 @@ -925,7 +924,7 @@ volatile bool Temperature::raw_temps_ready = false; #endif // HAS_PID_HEATING -#if ENABLED(MPCTEMP) +#if ENABLED(MPC_AUTOTUNE) #if EITHER(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) #define SINGLEFAN 1 @@ -951,7 +950,6 @@ volatile bool Temperature::raw_temps_ready = false; TERN(DWIN_CREALITY_LCD, DWIN_Update(), ui.update()); if (!wait_for_heatup) { - SERIAL_ECHOPGM(STR_MPC_AUTOTUNE); SERIAL_ECHOLNPGM(STR_MPC_AUTOTUNE_INTERRUPTED); TERN_(DWIN_LCD_PROUI, DWIN_MPCTuning(MPC_INTERRUPTED)); return true; @@ -981,7 +979,6 @@ volatile bool Temperature::raw_temps_ready = false; } } on_exit(e); - SERIAL_ECHOPGM(STR_MPC_AUTOTUNE); SERIAL_ECHOLNPGM(STR_MPC_AUTOTUNE_START, e); MPCHeaterInfo &hotend = temp_hotend[e]; MPC_t &mpc = hotend.mpc; @@ -1150,7 +1147,6 @@ volatile bool Temperature::raw_temps_ready = false; mpc.block_heat_capacity = mpc.ambient_xfer_coeff_fan0 / block_responsiveness; mpc.sensor_responsiveness = block_responsiveness / (1.0f - (ambient_temp - asymp_temp) * exp(-block_responsiveness * t1_time) / (t1 - asymp_temp)); - SERIAL_ECHOPGM(STR_MPC_AUTOTUNE); SERIAL_ECHOLNPGM(STR_MPC_AUTOTUNE_FINISHED); TERN_(DWIN_LCD_PROUI, DWIN_MPCTuning(MPC_DONE)); @@ -1171,7 +1167,7 @@ volatile bool Temperature::raw_temps_ready = false; TERN_(HAS_FAN, SERIAL_ECHOLNPAIR_F("MPC_AMBIENT_XFER_COEFF_FAN255 ", ambient_xfer_coeff_fan255, 4)); } -#endif // MPCTEMP +#endif // MPC_AUTOTUNE int16_t Temperature::getHeaterPower(const heater_id_t heater_id) { switch (heater_id) { @@ -1509,7 +1505,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id) { 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; - // The position can appear to make big jumps when, e.g. homing + // 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; else if (e_speed > 0.0f) { // Ignore retract/recover moves diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index b7f388cbb6e4..4178973a9d8b 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -1194,7 +1194,7 @@ class Temperature { #endif - #if ENABLED(MPCTEMP) + #if ENABLED(MPC_AUTOTUNE) void MPC_autotune(const uint8_t e); #endif diff --git a/buildroot/tests/BIGTREE_GTR_V1_0 b/buildroot/tests/BIGTREE_GTR_V1_0 index e0769b6a106c..8f69f5b06912 100755 --- a/buildroot/tests/BIGTREE_GTR_V1_0 +++ b/buildroot/tests/BIGTREE_GTR_V1_0 @@ -40,7 +40,7 @@ opt_set MOTHERBOARD BOARD_BTT_GTR_V1_0 SERIAL_PORT -1 \ MPC_AMBIENT_XFER_COEFF '{ 0.068f, 0.068f, 0.068f }' \ MPC_AMBIENT_XFER_COEFF_FAN255 '{ 0.097f, 0.097f, 0.097f }' \ FILAMENT_HEAT_CAPACITY_PERMM '{ 5.6e-3f, 3.6e-3f, 5.6e-3f }' -opt_enable SWITCHING_TOOLHEAD TOOL_SENSOR MPCTEMP MPC_EDIT_MENU MPC_AUTOTUNE_MENU +opt_enable SWITCHING_TOOLHEAD TOOL_SENSOR MPCTEMP MPC_EDIT_MENU MPC_AUTOTUNE MPC_AUTOTUNE_MENU opt_disable PIDTEMP exec_test $1 $2 "BigTreeTech GTR | MPC | Switching Toolhead | Tool Sensors" "$3" diff --git a/buildroot/tests/STM32F103RE_creality b/buildroot/tests/STM32F103RE_creality index 8910db00175c..a05f1d96bebb 100755 --- a/buildroot/tests/STM32F103RE_creality +++ b/buildroot/tests/STM32F103RE_creality @@ -28,7 +28,7 @@ opt_set PREHEAT_3_LABEL '"CUSTOM"' PREHEAT_3_TEMP_HOTEND 240 PREHEAT_3_TEMP_BED exec_test $1 $2 "Ender-3 S1 with ProUI (PIDTEMP)" "$3" opt_disable PIDTEMP -opt_enable MPCTEMP +opt_enable MPCTEMP MPC_AUTOTUNE exec_test $1 $2 "Ender-3 S1 with ProUI (MPCTEMP)" "$3" restore_configs