Rename `temp_model.h` to `thermal_model.h`
`/temp_model` to `/thermal_model` `Temperature_model` to `Thermal_model` minor format in eeprom.h
This commit is contained in:
parent
940b18e0b2
commit
8ae0e1952e
|
|
@ -7332,7 +7332,7 @@ Sigma_Exit:
|
|||
|
||||
#ifdef THERMAL_MODEL
|
||||
/*!
|
||||
### M310 - Thermal model settings <a href="https://reprap.org/wiki/G-code#M310:_Temperature_model_settings">M310: Thermal model settings</a>
|
||||
### M310 - Thermal model settings <a href="https://reprap.org/wiki/G-code#M310:_Themal_model_settings">M310: Thermal model settings</a>
|
||||
#### Usage
|
||||
|
||||
M310 ; report values
|
||||
|
|
|
|||
|
|
@ -0,0 +1,125 @@
|
|||
// model-based temperature safety checker declarations
|
||||
#ifndef TEMP_MGR_INTV
|
||||
#error "this file is not a public interface, it should be used *only* within temperature.cpp!"
|
||||
#endif
|
||||
|
||||
#include "planner.h"
|
||||
|
||||
// shortcuts to get model defaults
|
||||
#define __THERMAL_MODEL_DEF(MODEL, VAR) THERMAL_MODEL_##MODEL##_##VAR
|
||||
#define _THERMAL_MODEL_DEF(MODEL, VAR) __THERMAL_MODEL_DEF(MODEL, VAR)
|
||||
#define THERMAL_MODEL_DEF(VAR) _THERMAL_MODEL_DEF(THERMAL_MODEL_DEFAULT, VAR)
|
||||
|
||||
constexpr uint8_t THERMAL_MODEL_CAL_S = 60; // Maximum recording length during calibration (s)
|
||||
constexpr uint8_t THERMAL_MODEL_CAL_R_STEP = 4; // Fan interpolation steps during calibration
|
||||
constexpr float THERMAL_MODEL_fE = 0.05; // error filter (1st-order IIR factor)
|
||||
|
||||
// transport delay buffer size (samples)
|
||||
constexpr uint8_t THERMAL_MODEL_MAX_LAG_SIZE = 8; // * TEMP_MGR_INTV = 2160
|
||||
|
||||
// resistance values for all fan levels
|
||||
constexpr uint8_t THERMAL_MODEL_R_SIZE = (1 << FAN_SOFT_PWM_BITS);
|
||||
static const float THERMAL_MODEL_R_DEFAULT[THERMAL_MODEL_R_SIZE] PROGMEM = THERMAL_MODEL_DEF(Rv);
|
||||
|
||||
namespace thermal_model {
|
||||
|
||||
struct model_data
|
||||
{
|
||||
// temporary buffers
|
||||
float dT_lag_buf[THERMAL_MODEL_MAX_LAG_SIZE]; // transport delay buffer
|
||||
uint8_t dT_lag_size = 0; // transport delay buffer size
|
||||
uint8_t dT_lag_idx = 0; // transport delay buffer index
|
||||
float dT_err_prev = 0; // previous temperature delta error
|
||||
float T_prev = 0; // last temperature extruder
|
||||
|
||||
// configurable parameters
|
||||
float P; // heater power (W)
|
||||
float U; // linear temperature coefficient (W/K/W)
|
||||
float V; // linear temperature intercept (W/W)
|
||||
float C; // heatblock capacitance (J/K)
|
||||
float fS; // sim. 1st order IIR filter factor (f=100/27)
|
||||
uint16_t L; // sim. response lag (ms)
|
||||
float R[THERMAL_MODEL_R_SIZE]; // heatblock resistance for all fan levels (K/W)
|
||||
float Ta_corr; // ambient temperature correction (K)
|
||||
|
||||
// thresholds
|
||||
float warn; // warning threshold (K/s)
|
||||
float err; // error threshold (K/s)
|
||||
|
||||
// status flags
|
||||
union
|
||||
{
|
||||
bool flags;
|
||||
struct
|
||||
{
|
||||
bool uninitialized: 1; // model is not initialized
|
||||
bool error: 1; // error threshold set
|
||||
bool warning: 1; // warning threshold set
|
||||
} flag_bits;
|
||||
};
|
||||
|
||||
// pre-computed values (initialized via reset)
|
||||
float C_i; // heatblock capacitance (precomputed dT/C)
|
||||
float warn_s; // warning threshold (per sample)
|
||||
float err_s; // error threshold (per sample)
|
||||
|
||||
// simulation functions
|
||||
void reset(uint8_t heater_pwm, uint8_t fan_pwm, float heater_temp, float ambient_temp);
|
||||
void step(uint8_t heater_pwm, uint8_t fan_pwm, float heater_temp, float ambient_temp);
|
||||
};
|
||||
|
||||
static bool enabled; // model check enabled
|
||||
static bool warn_beep = true; // beep on warning threshold
|
||||
static model_data data; // default heater data
|
||||
|
||||
static bool calibrated(); // return calibration/model validity status
|
||||
static void check(); // check and trigger errors or warnings based on current state
|
||||
|
||||
// warning state (updated from from isr context)
|
||||
volatile static struct
|
||||
{
|
||||
float dT_err; // temperature delta error (per sample)
|
||||
bool warning: 1; // warning condition
|
||||
bool assert: 1; // warning is still asserted
|
||||
} warning_state;
|
||||
|
||||
static void handle_warning(); // handle warnings from user context
|
||||
|
||||
#ifdef THERMAL_MODEL_DEBUG
|
||||
static struct
|
||||
{
|
||||
volatile struct
|
||||
{
|
||||
uint32_t stamp;
|
||||
int8_t delta_ms;
|
||||
uint8_t counter;
|
||||
uint8_t cur_pwm;
|
||||
float cur_temp;
|
||||
float cur_amb;
|
||||
} entry;
|
||||
|
||||
uint8_t serial;
|
||||
bool enabled;
|
||||
} log_buf;
|
||||
|
||||
static void log_usr(); // user log handler
|
||||
static void log_isr(); // isr log handler
|
||||
#endif
|
||||
|
||||
} // namespace thermal_model
|
||||
|
||||
namespace thermal_model_cal {
|
||||
|
||||
// recording scratch buffer
|
||||
struct rec_entry
|
||||
{
|
||||
float temp; // heater temperature
|
||||
uint8_t pwm; // heater PWM
|
||||
};
|
||||
|
||||
constexpr uint16_t REC_BUFFER_SIZE = THERMAL_MODEL_CAL_S / TEMP_MGR_INTV;
|
||||
static rec_entry* const rec_buffer = (rec_entry*)block_buffer; // oh-hey, free memory!
|
||||
static_assert(sizeof(rec_entry[REC_BUFFER_SIZE]) <= sizeof(block_buffer),
|
||||
"recording length too long to fit within available buffer");
|
||||
|
||||
} // namespace thermal_model_cal
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#define THERMAL_MODEL_E3D_V6_VER 1 // model parameters version
|
||||
|
||||
#define THERMAL_MODEL_E3D_V6_P 38. // heater power (W)
|
||||
#define THERMAL_MODEL_E3D_V6_U 0. // linear temperature coefficient (W/K/power)
|
||||
#define THERMAL_MODEL_E3D_V6_V 1. // linear temperature intercept (W/power)
|
||||
|
||||
#define THERMAL_MODEL_E3D_V6_C 12.1 // initial guess for heatblock capacitance (J/K)
|
||||
#define THERMAL_MODEL_E3D_V6_R 20.5 // initial guess for heatblock resistance (K/W)
|
||||
|
||||
#define THERMAL_MODEL_E3D_V6_fS 0.065 // sim. 1st order IIR filter factor (f=100/27)
|
||||
#define THERMAL_MODEL_E3D_V6_LAG 2100 // sim. response lag (ms, 0-2160)
|
||||
|
||||
#define THERMAL_MODEL_E3D_V6_W 1.2 // Default warning threshold (K/s)
|
||||
#define THERMAL_MODEL_E3D_V6_E 1.74 // Default error threshold (K/s)
|
||||
|
||||
// fall-back resistance vector (R0-15)
|
||||
#define THERMAL_MODEL_E3D_V6_Rv {THERMAL_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