Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add autotemp to eeprom settings #25093

Merged
merged 9 commits into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,21 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_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 NUM_AXES
*/
Expand Down
7 changes: 3 additions & 4 deletions Marlin/src/lcd/menu/menu_advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

//
Expand Down
33 changes: 16 additions & 17 deletions Marlin/src/module/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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)) {
Expand All @@ -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);
Expand Down
46 changes: 25 additions & 21 deletions Marlin/src/module/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
48 changes: 45 additions & 3 deletions Marlin/src/module/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,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
//
Expand Down Expand Up @@ -470,7 +478,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
Expand Down Expand Up @@ -853,6 +863,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
//
Expand Down Expand Up @@ -1451,8 +1471,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
Expand Down Expand Up @@ -1801,6 +1823,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
//
Expand Down Expand Up @@ -2421,6 +2452,7 @@ void MarlinSettings::postprocess() {
//
// Skew correction factors
//
#if ENABLED(SKEW_CORRECTION)
{
skew_factor_t skew_factor;
_FIELD_TEST(planner_skew_factor);
Expand All @@ -2435,6 +2467,7 @@ void MarlinSettings::postprocess() {
}
#endif
}
#endif

//
// Advanced Pause filament load & unload lengths
Expand Down Expand Up @@ -2997,6 +3030,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
//
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2953,7 +2953,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
Expand Down Expand Up @@ -4028,7 +4028,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
Expand Down