TM: Split default model parameters into a separate header
Preparation to support multiple default model parameter sets
This commit is contained in:
parent
d1ff728e4f
commit
a8f219259a
|
|
@ -5,6 +5,11 @@
|
|||
|
||||
#include "planner.h"
|
||||
|
||||
// shortcuts to get model defaults
|
||||
#define __TEMP_MODEL_DEF(MODEL, VAR) TEMP_MODEL_##MODEL##_##VAR
|
||||
#define _TEMP_MODEL_DEF(MODEL, VAR) __TEMP_MODEL_DEF(MODEL, VAR)
|
||||
#define TEMP_MODEL_DEF(VAR) _TEMP_MODEL_DEF(TEMP_MODEL_DEFAULT, VAR)
|
||||
|
||||
constexpr uint8_t TEMP_MODEL_CAL_S = 60; // Maximum recording length during calibration (s)
|
||||
constexpr uint8_t TEMP_MODEL_CAL_R_STEP = 4; // Fan interpolation steps during calibration
|
||||
constexpr float TEMP_MODEL_fE = 0.05; // error filter (1st-order IIR factor)
|
||||
|
|
@ -14,7 +19,7 @@ constexpr uint8_t TEMP_MODEL_MAX_LAG_SIZE = 8; // * TEMP_MGR_INTV = 2160
|
|||
|
||||
// resistance values for all fan levels
|
||||
constexpr uint8_t TEMP_MODEL_R_SIZE = (1 << FAN_SOFT_PWM_BITS);
|
||||
static const float TEMP_MODEL_R_DEFAULT[TEMP_MODEL_R_SIZE] PROGMEM = TEMP_MODEL_Rv;
|
||||
static const float TEMP_MODEL_R_DEFAULT[TEMP_MODEL_R_SIZE] PROGMEM = TEMP_MODEL_DEF(Rv);
|
||||
|
||||
namespace temp_model {
|
||||
|
||||
|
|
|
|||
|
|
@ -2606,17 +2606,17 @@ void temp_model_reset_settings()
|
|||
{
|
||||
TempMgrGuard temp_mgr_guard;
|
||||
|
||||
temp_model::data.P = TEMP_MODEL_P;
|
||||
temp_model::data.U = TEMP_MODEL_U;
|
||||
temp_model::data.V = TEMP_MODEL_V;
|
||||
temp_model::data.C = TEMP_MODEL_C;
|
||||
temp_model::data.fS = TEMP_MODEL_fS;
|
||||
temp_model::data.L = (uint16_t)(TEMP_MODEL_LAG / (TEMP_MGR_INTV * 1000) + 0.5) * (uint16_t)(TEMP_MGR_INTV * 1000);
|
||||
temp_model::data.P = TEMP_MODEL_DEF(P);
|
||||
temp_model::data.U = TEMP_MODEL_DEF(U);
|
||||
temp_model::data.V = TEMP_MODEL_DEF(V);
|
||||
temp_model::data.C = TEMP_MODEL_DEF(C);
|
||||
temp_model::data.fS = TEMP_MODEL_DEF(fS);
|
||||
temp_model::data.L = (uint16_t)(TEMP_MODEL_DEF(LAG) / (TEMP_MGR_INTV * 1000) + 0.5) * (uint16_t)(TEMP_MGR_INTV * 1000);
|
||||
for(uint8_t i = 0; i != TEMP_MODEL_R_SIZE; ++i)
|
||||
temp_model::data.R[i] = pgm_read_float(TEMP_MODEL_R_DEFAULT + i);
|
||||
temp_model::data.Ta_corr = TEMP_MODEL_Ta_corr;
|
||||
temp_model::data.warn = TEMP_MODEL_W;
|
||||
temp_model::data.err = TEMP_MODEL_E;
|
||||
temp_model::data.warn = TEMP_MODEL_DEF(W);
|
||||
temp_model::data.err = TEMP_MODEL_DEF(E);
|
||||
temp_model::warn_beep = true;
|
||||
temp_model::enabled = true;
|
||||
temp_model::reinitialize();
|
||||
|
|
@ -2629,11 +2629,11 @@ void temp_model_load_settings()
|
|||
|
||||
// handle upgrade from a model without UVDL (FW<3.13, TM VER<1): model is retro-compatible,
|
||||
// reset UV to an identity without doing any special handling
|
||||
eeprom_init_default_float((float*)EEPROM_TEMP_MODEL_U, TEMP_MODEL_U);
|
||||
eeprom_init_default_float((float*)EEPROM_TEMP_MODEL_V, TEMP_MODEL_V);
|
||||
eeprom_init_default_float((float*)EEPROM_TEMP_MODEL_D, TEMP_MODEL_fS);
|
||||
eeprom_init_default_word((uint16_t*)EEPROM_TEMP_MODEL_L, TEMP_MODEL_LAG);
|
||||
eeprom_init_default_byte((uint8_t*)EEPROM_TEMP_MODEL_VER, TEMP_MODEL_VER);
|
||||
eeprom_init_default_float((float*)EEPROM_TEMP_MODEL_U, TEMP_MODEL_DEF(U));
|
||||
eeprom_init_default_float((float*)EEPROM_TEMP_MODEL_V, TEMP_MODEL_DEF(V));
|
||||
eeprom_init_default_float((float*)EEPROM_TEMP_MODEL_D, TEMP_MODEL_DEF(fS));
|
||||
eeprom_init_default_word((uint16_t*)EEPROM_TEMP_MODEL_L, TEMP_MODEL_DEF(LAG));
|
||||
eeprom_init_default_byte((uint8_t*)EEPROM_TEMP_MODEL_VER, TEMP_MODEL_DEF(VER));
|
||||
|
||||
temp_model::enabled = eeprom_read_byte((uint8_t*)EEPROM_TEMP_MODEL_ENABLE);
|
||||
temp_model::data.P = eeprom_read_float((float*)EEPROM_TEMP_MODEL_P);
|
||||
|
|
@ -2844,10 +2844,10 @@ static bool autotune(int16_t cal_temp)
|
|||
for(uint8_t i = 0; i != 2; ++i) {
|
||||
const char* PROGMEM verb = (i == 0? PSTR("initial"): PSTR("refine"));
|
||||
target_temperature[0] = 0;
|
||||
if(current_temperature[0] >= TEMP_MODEL_CAL_Tl) {
|
||||
sprintf_P(tm_message, PSTR("TM: cool down <%dC"), TEMP_MODEL_CAL_Tl);
|
||||
if(current_temperature[0] >= TEMP_MODEL_CAL_T_low) {
|
||||
sprintf_P(tm_message, PSTR("TM: cool down <%dC"), TEMP_MODEL_CAL_T_low);
|
||||
lcd_setstatus_serial(tm_message);
|
||||
cooldown(TEMP_MODEL_CAL_Tl);
|
||||
cooldown(TEMP_MODEL_CAL_T_low);
|
||||
wait(10000);
|
||||
}
|
||||
|
||||
|
|
@ -2860,10 +2860,11 @@ static bool autotune(int16_t cal_temp)
|
|||
|
||||
// we need a high R value for the initial C guess
|
||||
if(isnan(temp_model::data.R[0]))
|
||||
temp_model::data.R[0] = TEMP_MODEL_Rh;
|
||||
temp_model::data.R[0] = TEMP_MODEL_CAL_R_high;
|
||||
|
||||
e = estimate(samples, &temp_model::data.C,
|
||||
TEMP_MODEL_Cl, TEMP_MODEL_Ch, TEMP_MODEL_C_thr, TEMP_MODEL_C_itr,
|
||||
TEMP_MODEL_CAL_C_low, TEMP_MODEL_CAL_C_high,
|
||||
TEMP_MODEL_CAL_C_thr, TEMP_MODEL_CAL_C_itr,
|
||||
0, current_temperature_ambient);
|
||||
if(isnan(e))
|
||||
return true;
|
||||
|
|
@ -2879,7 +2880,8 @@ static bool autotune(int16_t cal_temp)
|
|||
return true;
|
||||
|
||||
e = estimate(samples, &temp_model::data.R[0],
|
||||
TEMP_MODEL_Rl, TEMP_MODEL_Rh, TEMP_MODEL_R_thr, TEMP_MODEL_R_itr,
|
||||
TEMP_MODEL_CAL_R_low, TEMP_MODEL_CAL_R_high,
|
||||
TEMP_MODEL_CAL_R_thr, TEMP_MODEL_CAL_R_itr,
|
||||
0, current_temperature_ambient);
|
||||
if(isnan(e))
|
||||
return true;
|
||||
|
|
@ -2910,7 +2912,7 @@ static bool autotune(int16_t cal_temp)
|
|||
// a fixed fan pwm (the norminal value) is used here, as soft_pwm_fan will be modified
|
||||
// during fan measurements and we'd like to include that skew during normal operation.
|
||||
e = estimate(samples, &temp_model::data.R[i],
|
||||
TEMP_MODEL_Rl, temp_model::data.R[0], TEMP_MODEL_R_thr, TEMP_MODEL_R_itr,
|
||||
TEMP_MODEL_CAL_R_low, temp_model::data.R[0], TEMP_MODEL_CAL_R_thr, TEMP_MODEL_CAL_R_itr,
|
||||
i, current_temperature_ambient);
|
||||
if(isnan(e))
|
||||
return true;
|
||||
|
|
@ -2967,7 +2969,7 @@ void temp_model_autotune(int16_t temp, bool selftest)
|
|||
|
||||
// autotune
|
||||
SERIAL_ECHOLNPGM("TM: calibration start");
|
||||
temp_model_autotune_err = temp_model_cal::autotune(temp > 0 ? temp : TEMP_MODEL_CAL_Th);
|
||||
temp_model_autotune_err = temp_model_cal::autotune(temp > 0 ? temp : TEMP_MODEL_CAL_T_high);
|
||||
|
||||
// always reset temperature
|
||||
disable_heater();
|
||||
|
|
|
|||
|
|
@ -411,38 +411,26 @@
|
|||
#define TEMP_RUNAWAY_EXTRUDER_TIMEOUT 45
|
||||
|
||||
// model-based temperature check
|
||||
#define TEMP_MODEL 1 // enable model-based temperature checks
|
||||
#define TEMP_MODEL_VER 1 // model parameters version
|
||||
#define TEMP_MODEL_DEBUG 1 // extended runtime logging
|
||||
#define TEMP_MODEL 1 // enable model-based temperature checks
|
||||
#define TEMP_MODEL_DEBUG 1 // extended runtime logging
|
||||
|
||||
#define TEMP_MODEL_P 38. // heater power (W)
|
||||
#define TEMP_MODEL_U 0. // linear temperature coefficient (W/K/power)
|
||||
#define TEMP_MODEL_V 1. // linear temperature intercept (W/power)
|
||||
#define TEMP_MODEL_CAL_C_low 5 // C estimation lower limit
|
||||
#define TEMP_MODEL_CAL_C_high 20 // C estimation upper limit
|
||||
#define TEMP_MODEL_CAL_C_thr 0.01 // C estimation iteration threshold
|
||||
#define TEMP_MODEL_CAL_C_itr 30 // C estimation iteration limit
|
||||
|
||||
#define TEMP_MODEL_C 12.1 // initial guess for heatblock capacitance (J/K)
|
||||
#define TEMP_MODEL_Cl 5 // C estimation lower limit
|
||||
#define TEMP_MODEL_Ch 20 // C estimation upper limit
|
||||
#define TEMP_MODEL_C_thr 0.01 // C estimation iteration threshold
|
||||
#define TEMP_MODEL_C_itr 30 // C estimation iteration limit
|
||||
#define TEMP_MODEL_CAL_R_low 5 // R estimation lower limit
|
||||
#define TEMP_MODEL_CAL_R_high 50 // R estimation upper limit
|
||||
#define TEMP_MODEL_CAL_R_thr 0.01 // R estimation iteration threshold
|
||||
#define TEMP_MODEL_CAL_R_itr 30 // R estimation iteration limit
|
||||
|
||||
#define TEMP_MODEL_fS 0.065 // sim. 1st order IIR filter factor (f=100/27)
|
||||
#define TEMP_MODEL_LAG 2100 // sim. response lag (ms, 0-2160)
|
||||
#define TEMP_MODEL_CAL_T_low 50 // Default calibration cooling temperature (C)
|
||||
#define TEMP_MODEL_CAL_T_high 230 // Default calibration working temperature (C)
|
||||
|
||||
#define TEMP_MODEL_R 20.5 // initial guess for heatblock resistance (K/W)
|
||||
#define TEMP_MODEL_Rl 5 // R estimation lower limit
|
||||
#define TEMP_MODEL_Rh 50 // R estimation upper limit
|
||||
#define TEMP_MODEL_R_thr 0.01 // R estimation iteration threshold
|
||||
#define TEMP_MODEL_R_itr 30 // R estimation iteration limit
|
||||
#define TEMP_MODEL_Ta_corr -7 // Default ambient temperature correction
|
||||
|
||||
#define TEMP_MODEL_Ta_corr -7 // Default ambient temperature correction
|
||||
#define TEMP_MODEL_W 1.2 // Default warning threshold (K/s)
|
||||
#define TEMP_MODEL_E 1.74 // Default error threshold (K/s)
|
||||
|
||||
#define TEMP_MODEL_CAL_Th 230 // Default calibration working temperature (C)
|
||||
#define TEMP_MODEL_CAL_Tl 50 // Default calibration cooling temperature (C)
|
||||
|
||||
// fall-back resistance vector (R0-15)
|
||||
#define TEMP_MODEL_Rv {TEMP_MODEL_R, 18.4, 16.7, 15.2, 14.1, 13.3, 12.7, 12.1, 11.7, 11.3, 11., 10.8, 10.6, 10.4, 10.2, 10.1}
|
||||
#include "temp_model/e3d_v6.h"
|
||||
#define TEMP_MODEL_DEFAULT E3D_V6 // Default model parameters
|
||||
|
||||
|
||||
/*------------------------------------
|
||||
|
|
|
|||
|
|
@ -415,38 +415,26 @@
|
|||
#define TEMP_RUNAWAY_EXTRUDER_TIMEOUT 45
|
||||
|
||||
// model-based temperature check
|
||||
#define TEMP_MODEL 1 // enable model-based temperature checks
|
||||
#define TEMP_MODEL_VER 1 // model parameters version
|
||||
#define TEMP_MODEL_DEBUG 1 // extended runtime logging
|
||||
#define TEMP_MODEL 1 // enable model-based temperature checks
|
||||
#define TEMP_MODEL_DEBUG 1 // extended runtime logging
|
||||
|
||||
#define TEMP_MODEL_P 38. // heater power (W)
|
||||
#define TEMP_MODEL_U 0. // linear temperature coefficient (W/K/power)
|
||||
#define TEMP_MODEL_V 1. // linear temperature intercept (W/power)
|
||||
#define TEMP_MODEL_CAL_C_low 5 // C estimation lower limit
|
||||
#define TEMP_MODEL_CAL_C_high 20 // C estimation upper limit
|
||||
#define TEMP_MODEL_CAL_C_thr 0.01 // C estimation iteration threshold
|
||||
#define TEMP_MODEL_CAL_C_itr 30 // C estimation iteration limit
|
||||
|
||||
#define TEMP_MODEL_C 12.1 // initial guess for heatblock capacitance (J/K)
|
||||
#define TEMP_MODEL_Cl 5 // C estimation lower limit
|
||||
#define TEMP_MODEL_Ch 20 // C estimation upper limit
|
||||
#define TEMP_MODEL_C_thr 0.01 // C estimation iteration threshold
|
||||
#define TEMP_MODEL_C_itr 30 // C estimation iteration limit
|
||||
#define TEMP_MODEL_CAL_R_low 5 // R estimation lower limit
|
||||
#define TEMP_MODEL_CAL_R_high 50 // R estimation upper limit
|
||||
#define TEMP_MODEL_CAL_R_thr 0.01 // R estimation iteration threshold
|
||||
#define TEMP_MODEL_CAL_R_itr 30 // R estimation iteration limit
|
||||
|
||||
#define TEMP_MODEL_fS 0.065 // sim. 1st order IIR filter factor (f=100/27)
|
||||
#define TEMP_MODEL_LAG 2100 // sim. response lag (ms, 0-2160)
|
||||
#define TEMP_MODEL_CAL_T_low 50 // Default calibration cooling temperature (C)
|
||||
#define TEMP_MODEL_CAL_T_high 230 // Default calibration working temperature (C)
|
||||
|
||||
#define TEMP_MODEL_R 20.5 // initial guess for heatblock resistance (K/W)
|
||||
#define TEMP_MODEL_Rl 5 // R estimation lower limit
|
||||
#define TEMP_MODEL_Rh 50 // R estimation upper limit
|
||||
#define TEMP_MODEL_R_thr 0.01 // R estimation iteration threshold
|
||||
#define TEMP_MODEL_R_itr 30 // R estimation iteration limit
|
||||
#define TEMP_MODEL_Ta_corr -7 // Default ambient temperature correction
|
||||
|
||||
#define TEMP_MODEL_Ta_corr -7 // Default ambient temperature correction
|
||||
#define TEMP_MODEL_W 1.2 // Default warning threshold (K/s)
|
||||
#define TEMP_MODEL_E 1.74 // Default error threshold (K/s)
|
||||
|
||||
#define TEMP_MODEL_CAL_Th 230 // Default calibration working temperature (C)
|
||||
#define TEMP_MODEL_CAL_Tl 50 // Default calibration cooling temperature (C)
|
||||
|
||||
// fall-back resistance vector (R0-15)
|
||||
#define TEMP_MODEL_Rv {TEMP_MODEL_R, 18.4, 16.7, 15.2, 14.1, 13.3, 12.7, 12.1, 11.7, 11.3, 11., 10.8, 10.6, 10.4, 10.2, 10.1}
|
||||
#include "temp_model/e3d_v6.h"
|
||||
#define TEMP_MODEL_DEFAULT E3D_V6 // Default model parameters
|
||||
|
||||
|
||||
/*------------------------------------
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#define TEMP_MODEL_E3D_V6_VER 1 // model parameters version
|
||||
|
||||
#define TEMP_MODEL_E3D_V6_P 38. // heater power (W)
|
||||
#define TEMP_MODEL_E3D_V6_U 0. // linear temperature coefficient (W/K/power)
|
||||
#define TEMP_MODEL_E3D_V6_V 1. // linear temperature intercept (W/power)
|
||||
|
||||
#define TEMP_MODEL_E3D_V6_C 12.1 // initial guess for heatblock capacitance (J/K)
|
||||
#define TEMP_MODEL_E3D_V6_R 20.5 // initial guess for heatblock resistance (K/W)
|
||||
|
||||
#define TEMP_MODEL_E3D_V6_fS 0.065 // sim. 1st order IIR filter factor (f=100/27)
|
||||
#define TEMP_MODEL_E3D_V6_LAG 2100 // sim. response lag (ms, 0-2160)
|
||||
|
||||
#define TEMP_MODEL_E3D_V6_W 1.2 // Default warning threshold (K/s)
|
||||
#define TEMP_MODEL_E3D_V6_E 1.74 // Default error threshold (K/s)
|
||||
|
||||
// fall-back resistance vector (R0-15)
|
||||
#define TEMP_MODEL_E3D_V6_Rv {TEMP_MODEL_E3D_V6_R, 18.4, 16.7, 15.2, 14.1, 13.3, 12.7, 12.1, 11.7, 11.3, 11., 10.8, 10.6, 10.4, 10.2, 10.1}
|
||||
Loading…
Reference in New Issue