Add the ability to log continuously

TEMP_MODEL_LOGGING enables D70 to record precisely each cycle of the
temperature regulation for offline model simulation
This commit is contained in:
Yuri D'Elia 2022-06-14 12:11:58 +02:00
parent 690affe5a2
commit fabf511b97
4 changed files with 97 additions and 0 deletions

View file

@ -9144,6 +9144,14 @@ Sigma_Exit:
};
#endif
#ifdef TEMP_MODEL_LOGGING
case 70: {
if(code_seen('I'))
temp_model_log_enable(code_value_short());
break;
}
#endif
#ifdef HEATBED_ANALYSIS
/*!

View file

@ -500,6 +500,11 @@ void set_temp_error(TempErrorSource source, uint8_t index, TempErrorType type)
void handle_temp_error();
#ifdef TEMP_MODEL_LOGGING
static void temp_model_log_usr();
static void temp_model_log_isr();
#endif
void manage_heater()
{
#ifdef WATCHDOG
@ -520,6 +525,10 @@ void manage_heater()
// periodically check fans
checkFans();
#ifdef TEMP_MODEL_LOGGING
temp_model_log_usr();
#endif
}
#define PGM_RD_W(x) (short)pgm_read_word(&x)
@ -2200,6 +2209,10 @@ static void temp_mgr_isr()
check_temp_model(); // model-based heater check
#endif
#ifdef TEMP_MODEL_LOGGING
temp_model_log_isr();
#endif
// PID regulation
if (pid_tuning_finished)
temp_mgr_pid();
@ -2390,4 +2403,76 @@ static void check_temp_model()
set_temp_error(TempErrorSource::hotend, 0, TempErrorType::model);
}
}
#ifdef TEMP_MODEL_LOGGING
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;
} temp_model_log_buf;
static void temp_model_log_usr()
{
if(!temp_model_log_buf.enabled)
return;
uint8_t counter = temp_model_log_buf.entry.counter;
if (counter == temp_model_log_buf.serial)
return;
int8_t delta_ms;
uint8_t cur_pwm;
float cur_temp;
float cur_amb;
{
TempMgrGuard temp_mgr_guard;
delta_ms = temp_model_log_buf.entry.delta_ms;
counter = temp_model_log_buf.entry.counter;
cur_pwm = temp_model_log_buf.entry.cur_pwm;
cur_temp = temp_model_log_buf.entry.cur_temp;
cur_amb = temp_model_log_buf.entry.cur_amb;
}
uint8_t d = counter - temp_model_log_buf.serial;
temp_model_log_buf.serial = counter;
printf_P(PSTR("TML %d %d %x %lx %lx\n"), (unsigned)d - 1, (int)delta_ms + 1, (int)cur_pwm,
*(unsigned long*)&cur_temp, *(unsigned long*)&cur_amb);
}
static void temp_model_log_isr()
{
if(!temp_model_log_buf.enabled)
return;
uint32_t stamp = _millis();
uint8_t delta_ms = stamp - temp_model_log_buf.entry.stamp - (TEMP_MGR_INTV * 1000);
temp_model_log_buf.entry.stamp = stamp;
++temp_model_log_buf.entry.counter;
temp_model_log_buf.entry.delta_ms = delta_ms;
temp_model_log_buf.entry.cur_pwm = soft_pwm[0];
temp_model_log_buf.entry.cur_temp = current_temperature_isr[0];
temp_model_log_buf.entry.cur_amb = current_temperature_ambient_isr;
}
void temp_model_log_enable(bool enable)
{
if(enable) {
TempMgrGuard temp_mgr_guard;
temp_model_log_buf.entry.stamp = _millis();
}
temp_model_log_buf.enabled = enable;
}
#endif
#endif

View file

@ -228,6 +228,9 @@ FORCE_INLINE void autotempShutdown(){
}
void PID_autotune(float temp, int extruder, int ncycles);
#ifdef TEMP_MODEL_LOGGING
void temp_model_log_enable(bool enable);
#endif
#ifdef FAN_SOFT_PWM
extern unsigned char fanSpeedSoftPwm;

View file

@ -420,6 +420,7 @@
// model-based temperature check
#define TEMP_MODEL_CHECK 1
#define TEMP_MODEL_CHECK_WARN_ONLY 1
#define TEMP_MODEL_LOGGING 1
/*------------------------------------
MOTOR CURRENT SETTINGS