diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 4e64fcd2008e1..3e72a9f5c91ab 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -450,6 +450,9 @@ #define AUTOTEMP #if ENABLED(AUTOTEMP) #define AUTOTEMP_OLDWEIGHT 0.98 // Factor used to weight previous readings (0.0 < value < 1.0) + #define AUTOTEMP_MIN 210 + #define AUTOTEMP_MAX 250 + #define AUTOTEMP_FACTOR 0.1f // Turn on AUTOTEMP on M104/M109 by default using proportions set here //#define AUTOTEMP_PROPORTIONAL #if ENABLED(AUTOTEMP_PROPORTIONAL) diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 49fa1ea1a4a06..4d259be31b9a1 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -1551,6 +1551,21 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS #error "To use CHAMBER_LIMIT_SWITCHING you must disable PIDTEMPCHAMBER." #endif +/** + * AUTOTEMP + */ +#if ENABLED(AUTOTEMP) + #ifndef AUTOTEMP_MIN + #error "AUTOTEMP requires AUTOTEMP_MIN." + #elif !defined(AUTOTEMP_MAX) + #error "AUTOTEMP requires AUTOTEMP_MAX." + #elif !defined(AUTOTEMP_FACTOR) + #error "AUTOTEMP requires AUTOTEMP_FACTOR." + #elif AUTOTEMP_MAX < AUTOTEMP_MIN + #error "AUTOTEMP_MAX must be greater than or equal to AUTOTEMP_MIN." + #endif +#endif + /** * Features that require a min/max/specific steppers / axes to be enabled. */ diff --git a/Marlin/src/lcd/menu/menu_advanced.cpp b/Marlin/src/lcd/menu/menu_advanced.cpp index f56b4f899731a..8e1963afe593b 100644 --- a/Marlin/src/lcd/menu/menu_advanced.cpp +++ b/Marlin/src/lcd/menu/menu_advanced.cpp @@ -295,10 +295,9 @@ void menu_backlash(); // Autotemp, Min, Max, Fact // #if BOTH(AUTOTEMP, HAS_TEMP_HOTEND) - EDIT_ITEM(bool, MSG_AUTOTEMP, &planner.autotemp_enabled); - EDIT_ITEM(int3, MSG_MIN, &planner.autotemp_min, 0, thermalManager.hotend_max_target(0)); - EDIT_ITEM(int3, MSG_MAX, &planner.autotemp_max, 0, thermalManager.hotend_max_target(0)); - EDIT_ITEM(float42_52, MSG_FACTOR, &planner.autotemp_factor, 0, 10); + EDIT_ITEM(int3, MSG_MIN, &planner.autotemp.min, 0, thermalManager.hotend_max_target(0)); + EDIT_ITEM(int3, MSG_MAX, &planner.autotemp.max, 0, thermalManager.hotend_max_target(0)); + EDIT_ITEM(float42_52, MSG_FACTOR, &planner.autotemp.factor, 0, 10); #endif // diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index 8bbb8830018f5..8062c4030a1ea 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -198,13 +198,12 @@ float Planner::mm_per_step[DISTINCT_AXES]; // (mm) Millimeters per step constexpr bool Planner::leveling_active; #endif -skew_factor_t Planner::skew_factor; // Initialized by settings.load() +#if ENABLED(SKEW_CORRECTION) + skew_factor_t Planner::skew_factor; // Initialized by settings.load() +#endif #if ENABLED(AUTOTEMP) - celsius_t Planner::autotemp_max = 250, - Planner::autotemp_min = 210; - float Planner::autotemp_factor = 0.1f; - bool Planner::autotemp_enabled = false; + autotemp_t Planner::autotemp = { AUTOTEMP_MIN, AUTOTEMP_MAX, AUTOTEMP_FACTOR, false }; #endif // private: @@ -1434,8 +1433,8 @@ void Planner::check_axes_activity() { #if ENABLED(AUTOTEMP_PROPORTIONAL) void Planner::_autotemp_update_from_hotend() { const celsius_t target = thermalManager.degTargetHotend(active_extruder); - autotemp_min = target + AUTOTEMP_MIN_P; - autotemp_max = target + AUTOTEMP_MAX_P; + autotemp.min = target + AUTOTEMP_MIN_P; + autotemp.max = target + AUTOTEMP_MAX_P; } #endif @@ -1446,8 +1445,8 @@ void Planner::check_axes_activity() { */ void Planner::autotemp_update() { _autotemp_update_from_hotend(); - autotemp_factor = TERN(AUTOTEMP_PROPORTIONAL, AUTOTEMP_FACTOR_P, 0); - autotemp_enabled = autotemp_factor != 0; + autotemp.factor = TERN(AUTOTEMP_PROPORTIONAL, AUTOTEMP_FACTOR_P, 0); + autotemp.enabled = autotemp.factor != 0; } /** @@ -1457,13 +1456,13 @@ void Planner::check_axes_activity() { void Planner::autotemp_M104_M109() { _autotemp_update_from_hotend(); - if (parser.seenval('S')) autotemp_min = parser.value_celsius(); - if (parser.seenval('B')) autotemp_max = parser.value_celsius(); + if (parser.seenval('S')) autotemp.min = parser.value_celsius(); + if (parser.seenval('B')) autotemp.max = parser.value_celsius(); // When AUTOTEMP_PROPORTIONAL is enabled, F0 disables autotemp. // Normally, leaving off F also disables autotemp. - autotemp_factor = parser.seen('F') ? parser.value_float() : TERN(AUTOTEMP_PROPORTIONAL, AUTOTEMP_FACTOR_P, 0); - autotemp_enabled = autotemp_factor != 0; + autotemp.factor = parser.seen('F') ? parser.value_float() : TERN(AUTOTEMP_PROPORTIONAL, AUTOTEMP_FACTOR_P, 0); + autotemp.enabled = autotemp.factor != 0; } /** @@ -1474,8 +1473,8 @@ void Planner::check_axes_activity() { void Planner::autotemp_task() { static float oldt = 0.0f; - if (!autotemp_enabled) return; - if (thermalManager.degTargetHotend(active_extruder) < autotemp_min - 2) return; // Below the min? + if (!autotemp.enabled) return; + if (thermalManager.degTargetHotend(active_extruder) < autotemp.min - 2) return; // Below the min? float high = 0.0f; for (uint8_t b = block_buffer_tail; b != block_buffer_head; b = next_block_index(b)) { @@ -1486,8 +1485,8 @@ void Planner::check_axes_activity() { } } - float t = autotemp_min + high * autotemp_factor; - LIMIT(t, autotemp_min, autotemp_max); + float t = autotemp.min + high * autotemp.factor; + LIMIT(t, autotemp.min, autotemp.max); if (t < oldt) t = t * (1.0f - (AUTOTEMP_OLDWEIGHT)) + oldt * (AUTOTEMP_OLDWEIGHT); oldt = t; thermalManager.setTargetHotend(t, active_extruder); diff --git a/Marlin/src/module/planner.h b/Marlin/src/module/planner.h index dcfdb1c28e6be..04cde2381da2d 100644 --- a/Marlin/src/module/planner.h +++ b/Marlin/src/module/planner.h @@ -156,6 +156,14 @@ typedef struct { } block_flags_t; +#if ENABLED(AUTOTEMP) + typedef struct { + celsius_t min, max; + float factor; + bool enabled; + } autotemp_t; +#endif + #if ENABLED(LASER_FEATURE) typedef struct { @@ -326,25 +334,21 @@ typedef struct { }; #endif -#if DISABLED(SKEW_CORRECTION) - #define XY_SKEW_FACTOR 0 - #define XZ_SKEW_FACTOR 0 - #define YZ_SKEW_FACTOR 0 -#endif - -typedef struct { - #if ENABLED(SKEW_CORRECTION_GCODE) - float xy; - #if ENABLED(SKEW_CORRECTION_FOR_Z) - float xz, yz; +#if ENABLED(SKEW_CORRECTION) + typedef struct { + #if ENABLED(SKEW_CORRECTION_GCODE) + float xy; + #if ENABLED(SKEW_CORRECTION_FOR_Z) + float xz, yz; + #else + const float xz = XZ_SKEW_FACTOR, yz = YZ_SKEW_FACTOR; + #endif #else - const float xz = XZ_SKEW_FACTOR, yz = YZ_SKEW_FACTOR; + const float xy = XY_SKEW_FACTOR, + xz = XZ_SKEW_FACTOR, yz = YZ_SKEW_FACTOR; #endif - #else - const float xy = XY_SKEW_FACTOR, - xz = XZ_SKEW_FACTOR, yz = YZ_SKEW_FACTOR; - #endif -} skew_factor_t; + } skew_factor_t; +#endif #if ENABLED(DISABLE_INACTIVE_EXTRUDER) typedef IF<(BLOCK_BUFFER_SIZE > 64), uint16_t, uint8_t>::type last_move_t; @@ -476,7 +480,9 @@ class Planner { static xyze_pos_t position_cart; #endif - static skew_factor_t skew_factor; + #if ENABLED(SKEW_CORRECTION) + static skew_factor_t skew_factor; + #endif #if ENABLED(SD_ABORT_ON_ENDSTOP_HIT) static bool abort_on_endstop_hit; @@ -972,9 +978,7 @@ class Planner { #endif #if ENABLED(AUTOTEMP) - static celsius_t autotemp_min, autotemp_max; - static float autotemp_factor; - static bool autotemp_enabled; + static autotemp_t autotemp; static void autotemp_update(); static void autotemp_M104_M109(); static void autotemp_task(); diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index e051ecb1ac940..1b6f1574796fb 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -245,6 +245,14 @@ typedef struct SettingsDataStruct { // float planner_z_fade_height; // M420 Zn planner.z_fade_height + // + // AUTOTEMP + // + #if ENABLED(AUTOTEMP) + celsius_t planner_autotemp_max, planner_autotemp_min; + float planner_autotemp_factor; + #endif + // // MESH_BED_LEVELING // @@ -472,7 +480,9 @@ typedef struct SettingsDataStruct { // // SKEW_CORRECTION // - skew_factor_t planner_skew_factor; // M852 I J K + #if ENABLED(SKEW_CORRECTION) + skew_factor_t planner_skew_factor; // M852 I J K + #endif // // ADVANCED_PAUSE_FEATURE @@ -855,6 +865,16 @@ void MarlinSettings::postprocess() { EEPROM_WRITE(zfh); } + // + // AUTOTEMP + // + #if ENABLED(AUTOTEMP) + _FIELD_TEST(planner_autotemp_max); + EEPROM_WRITE(planner.autotemp.max); + EEPROM_WRITE(planner.autotemp.min); + EEPROM_WRITE(planner.autotemp.factor); + #endif + // // Mesh Bed Leveling // @@ -1453,8 +1473,10 @@ void MarlinSettings::postprocess() { // // Skew correction factors // - _FIELD_TEST(planner_skew_factor); - EEPROM_WRITE(planner.skew_factor); + #if ENABLED(SKEW_CORRECTION) + _FIELD_TEST(planner_skew_factor); + EEPROM_WRITE(planner.skew_factor); + #endif // // Advanced Pause filament load & unload lengths @@ -1803,6 +1825,15 @@ void MarlinSettings::postprocess() { // EEPROM_READ(TERN(ENABLE_LEVELING_FADE_HEIGHT, new_z_fade_height, dummyf)); + // + // AUTOTEMP + // + #if ENABLED(AUTOTEMP) + EEPROM_READ(planner.autotemp.max); + EEPROM_READ(planner.autotemp.min); + EEPROM_READ(planner.autotemp.factor); + #endif + // // Mesh (Manual) Bed Leveling // @@ -2423,6 +2454,7 @@ void MarlinSettings::postprocess() { // // Skew correction factors // + #if ENABLED(SKEW_CORRECTION) { skew_factor_t skew_factor; _FIELD_TEST(planner_skew_factor); @@ -2437,6 +2469,7 @@ void MarlinSettings::postprocess() { } #endif } + #endif // // Advanced Pause filament load & unload lengths @@ -2999,6 +3032,15 @@ void MarlinSettings::reset() { TERN_(ENABLE_LEVELING_FADE_HEIGHT, new_z_fade_height = (DEFAULT_LEVELING_FADE_HEIGHT)); TERN_(HAS_LEVELING, reset_bed_level()); + // + // AUTOTEMP + // + #if ENABLED(AUTOTEMP) + planner.autotemp.max = AUTOTEMP_MAX; + planner.autotemp.min = AUTOTEMP_MIN; + planner.autotemp.factor = AUTOTEMP_FACTOR; + #endif + // // X Axis Twist Compensation // diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 49233275e61ed..0ae9d31b056b4 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -2973,7 +2973,7 @@ void Temperature::init() { void Temperature::disable_all_heaters() { // Disable autotemp, unpause and reset everything - TERN_(AUTOTEMP, planner.autotemp_enabled = false); + TERN_(AUTOTEMP, planner.autotemp.enabled = false); TERN_(PROBING_HEATERS_OFF, pause_heaters(false)); #if HAS_HOTEND @@ -4048,7 +4048,7 @@ void Temperature::isr() { OPTARG(G26_CLICK_CAN_CANCEL, const bool click_to_cancel/*=false*/) ) { #if ENABLED(AUTOTEMP) - REMEMBER(1, planner.autotemp_enabled, false); + REMEMBER(1, planner.autotemp.enabled, false); #endif #if TEMP_RESIDENCY_TIME > 0