⚗️ Temperature Model Predictive Control (#23751)

This commit is contained in:
tombrazier
2022-04-01 08:14:14 +01:00
committed by Scott Lahteine
parent 8fb65211fc
commit 72b2e2b2c7
13 changed files with 566 additions and 32 deletions

View File

@@ -94,6 +94,18 @@ hotend_pid_t;
#define _PID_Kf(H) 0
#endif
#if ENABLED(MPCTEMP)
typedef struct {
float heater_power; // M306 P
float block_heat_capacity; // M306 C
float sensor_responsiveness; // M306 R
float ambient_xfer_coeff_fan0; // M306 A
#if ENABLED(MPC_INCLUDE_FAN)
float fan255_adjustment; // M306 F
#endif
} MPC_t;
#endif
/**
* States for ADC reading in the ISR
*/
@@ -177,7 +189,7 @@ enum ADCSensorState : char {
#if HAS_PID_HEATING
#define PID_K2 (1-float(PID_K1))
#define PID_dT ((OVERSAMPLENR * float(ACTUAL_ADC_SAMPLES)) / TEMP_TIMER_FREQUENCY)
#define PID_dT ((OVERSAMPLENR * float(ACTUAL_ADC_SAMPLES)) / (TEMP_TIMER_FREQUENCY))
// Apply the scale factors to the PID values
#define scalePID_i(i) ( float(i) * PID_dT )
@@ -186,6 +198,10 @@ enum ADCSensorState : char {
#define unscalePID_d(d) ( float(d) * PID_dT )
#endif
#if ENABLED(MPCTEMP)
#define MPC_dT ((OVERSAMPLENR * float(ACTUAL_ADC_SAMPLES)) / (TEMP_TIMER_FREQUENCY))
#endif
#if ENABLED(G26_MESH_VALIDATION) && EITHER(HAS_MARLINUI_MENU, EXTENSIBLE_UI)
#define G26_CLICK_CAN_CANCEL 1
#endif
@@ -223,8 +239,19 @@ struct PIDHeaterInfo : public HeaterInfo {
T pid; // Initialized by settings.load()
};
#if ENABLED(MPCTEMP)
struct MPCHeaterInfo : public HeaterInfo {
MPC_t constants;
float modeled_ambient_temp,
modeled_block_temp,
modeled_sensor_temp;
};
#endif
#if ENABLED(PIDTEMP)
typedef struct PIDHeaterInfo<hotend_pid_t> hotend_info_t;
#elif ENABLED(MPCTEMP)
typedef struct MPCHeaterInfo hotend_info_t;
#else
typedef heater_info_t hotend_info_t;
#endif
@@ -481,10 +508,14 @@ class Temperature {
#endif
#if ENABLED(PID_EXTRUSION_SCALING)
static int32_t last_e_position, lpq[LPQ_MAX_LEN];
static int32_t pes_e_position, lpq[LPQ_MAX_LEN];
static lpq_ptr_t lpq_ptr;
#endif
#if ENABLED(MPCTEMP)
static int32_t mpc_e_position;
#endif
#if HAS_HOTEND
static temp_range_t temp_range[HOTENDS];
#endif
@@ -924,12 +955,16 @@ class Temperature {
*/
#if ENABLED(PIDTEMP)
static void updatePID() {
TERN_(PID_EXTRUSION_SCALING, last_e_position = 0);
TERN_(PID_EXTRUSION_SCALING, pes_e_position = 0);
}
#endif
#endif
#if ENABLED(MPCTEMP)
void MPC_autotune();
#endif
#if ENABLED(PROBING_HEATERS_OFF)
static void pause_heaters(const bool p);
#endif