Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Adjust PID / MPC / ProUI
Browse files Browse the repository at this point in the history
Changes to simplify #25232 WIP
  • Loading branch information
thinkyhead committed Jan 15, 2023
1 parent d94defc commit 6fe387b
Show file tree
Hide file tree
Showing 34 changed files with 181 additions and 165 deletions.
6 changes: 2 additions & 4 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1429,12 +1429,10 @@

#endif // HAS_MARLINUI_MENU

#if ANY(HAS_DISPLAY, DWIN_LCD_PROUI, DWIN_CREALITY_LCD_JYERSUI)
#if HAS_DISPLAY
//#define SOUND_MENU_ITEM // Add a mute option to the LCD menu
#define SOUND_ON_DEFAULT // Buzzer/speaker default enabled state
#endif
#if EITHER(HAS_DISPLAY, DWIN_LCD_PROUI)
// The timeout to return to the status screen from sub-menus
//#define LCD_TIMEOUT_TO_STATUS 15000 // (ms)

Expand Down Expand Up @@ -1483,7 +1481,7 @@
#endif
#endif

#endif // HAS_DISPLAY || DWIN_LCD_PROUI
#endif // HAS_DISPLAY

// Add 'M73' to set print job progress, overrides Marlin's built-in estimate
//#define SET_PROGRESS_MANUALLY
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/geometry/M206_M428.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void GcodeSuite::M428() {
diff[i] = -current_position[i];
if (!WITHIN(diff[i], -20, 20)) {
SERIAL_ERROR_MSG(STR_ERR_M428_TOO_FAR);
LCD_ALERTMESSAGE_F("Err: Too far!");
LCD_ALERTMESSAGE(MSG_ERR_M428_TOO_FAR);
ERR_BUZZ();
return;
}
Expand Down
19 changes: 4 additions & 15 deletions Marlin/src/gcode/temp/M303.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ void GcodeSuite::M303() {
default:
SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
SERIAL_ECHOLNPGM(STR_PID_BAD_HEATER_ID);
TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_BAD_EXTRUDER_NUM));
TERN_(DWIN_LCD_PROUI, DWIN_PidTuning(PID_BAD_EXTRUDER_NUM));
TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_BAD_HEATER_ID));
TERN_(DWIN_PID_TUNE, DWIN_PidTuning(PID_BAD_HEATER_ID));
return;
}

Expand All @@ -78,20 +78,9 @@ void GcodeSuite::M303() {
const celsius_t temp = seenS ? parser.value_celsius() : default_temp;
const bool u = parser.boolval('U');

#if ENABLED(DWIN_LCD_PROUI) && EITHER(PIDTEMP, PIDTEMPBED)
if (seenC) HMI_data.PidCycles = c;
if (seenS) {
switch (hid) {
OPTCODE(PIDTEMP, case 0 ... HOTENDS - 1: HMI_data.HotendPidT = temp; break)
OPTCODE(PIDTEMPBED, case H_BED: HMI_data.BedPidT = temp; break)
default: break;
}
}
#endif
TERN_(DWIN_PID_TUNE, DWIN_StartM303(seenC, c, seenS, hid, temp));

#if DISABLED(BUSY_WHILE_HEATING)
KEEPALIVE_STATE(NOT_BUSY);
#endif
IF_DISABLED(BUSY_WHILE_HEATING, KEEPALIVE_STATE(NOT_BUSY));

LCD_MESSAGE(MSG_PID_AUTOTUNE);
thermalManager.PID_autotune(temp, hid, c, u);
Expand Down
28 changes: 14 additions & 14 deletions Marlin/src/gcode/temp/M306.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ void GcodeSuite::M306() {

if (parser.seen("ACFPRH")) {
const heater_id_t hid = (heater_id_t)parser.intval('E', 0);
MPC_t &constants = thermalManager.temp_hotend[hid].constants;
if (parser.seenval('P')) constants.heater_power = parser.value_float();
if (parser.seenval('C')) constants.block_heat_capacity = parser.value_float();
if (parser.seenval('R')) constants.sensor_responsiveness = parser.value_float();
if (parser.seenval('A')) constants.ambient_xfer_coeff_fan0 = parser.value_float();
MPC_t &mpc = thermalManager.temp_hotend[hid].mpc;
if (parser.seenval('P')) mpc.heater_power = parser.value_float();
if (parser.seenval('C')) mpc.block_heat_capacity = parser.value_float();
if (parser.seenval('R')) mpc.sensor_responsiveness = parser.value_float();
if (parser.seenval('A')) mpc.ambient_xfer_coeff_fan0 = parser.value_float();
#if ENABLED(MPC_INCLUDE_FAN)
if (parser.seenval('F')) constants.fan255_adjustment = parser.value_float() - constants.ambient_xfer_coeff_fan0;
if (parser.seenval('F')) mpc.applyFanAdjustment(parser.value_float());
#endif
if (parser.seenval('H')) constants.filament_heat_capacity_permm = parser.value_float();
if (parser.seenval('H')) mpc.filament_heat_capacity_permm = parser.value_float();
return;
}

Expand All @@ -71,16 +71,16 @@ void GcodeSuite::M306_report(const bool forReplay/*=true*/) {
report_heading(forReplay, F("Model predictive control"));
HOTEND_LOOP() {
report_echo_start(forReplay);
MPC_t& constants = thermalManager.temp_hotend[e].constants;
MPC_t &mpc = thermalManager.temp_hotend[e].mpc;
SERIAL_ECHOPGM(" M306 E", e);
SERIAL_ECHOPAIR_F(" P", constants.heater_power, 2);
SERIAL_ECHOPAIR_F(" C", constants.block_heat_capacity, 2);
SERIAL_ECHOPAIR_F(" R", constants.sensor_responsiveness, 4);
SERIAL_ECHOPAIR_F(" A", constants.ambient_xfer_coeff_fan0, 4);
SERIAL_ECHOPAIR_F(" P", mpc.heater_power, 2);
SERIAL_ECHOPAIR_F(" C", mpc.block_heat_capacity, 2);
SERIAL_ECHOPAIR_F(" R", mpc.sensor_responsiveness, 4);
SERIAL_ECHOPAIR_F(" A", mpc.ambient_xfer_coeff_fan0, 4);
#if ENABLED(MPC_INCLUDE_FAN)
SERIAL_ECHOPAIR_F(" F", constants.ambient_xfer_coeff_fan0 + constants.fan255_adjustment, 4);
SERIAL_ECHOPAIR_F(" F", mpc.fanCoefficient(), 4);
#endif
SERIAL_ECHOPAIR_F(" H", constants.filament_heat_capacity_permm, 4);
SERIAL_ECHOPAIR_F(" H", mpc.filament_heat_capacity_permm, 4);
SERIAL_EOL();
}
}
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,9 @@
// PID heating
#if ANY(PIDTEMP, PIDTEMPBED, PIDTEMPCHAMBER)
#define HAS_PID_HEATING 1
#if ENABLED(DWIN_LCD_PROUI) && EITHER(PIDTEMP, PIDTEMPBED)
#define DWIN_PID_TUNE 1
#endif
#endif

// Thermal protection
Expand Down
37 changes: 26 additions & 11 deletions Marlin/src/lcd/e3v2/proui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1500,9 +1500,10 @@ void DWIN_LevelingDone() {

// PID process

#if HAS_PIDPLOT
#if BOTH(HAS_PIDPLOT, DWIN_PID_TUNE)

void DWIN_Draw_PIDPopup() {
frame_rect_t gfrm = {40, 180, DWIN_WIDTH - 80, 120};
frame_rect_t gfrm = { 40, 180, DWIN_WIDTH - 80, 120 };
DWINUI::ClearMainArea();
Draw_Popup_Bkgd();
DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 100, GET_TEXT_F(MSG_PID_AUTOTUNE));
Expand All @@ -1525,9 +1526,21 @@ void DWIN_LevelingDone() {
default: break;
}
}

#endif

#if EITHER(PIDTEMP, PIDTEMPBED)
#if DWIN_PID_TUNE

void DWIN_StartM303(const bool seenC, const int c, const bool seenS, const heater_id_t hid, const celsius_t temp) {
if (seenC) HMI_data.PidCycles = c;
if (seenS) {
switch (hid) {
OPTCODE(PIDTEMP, case 0 ... HOTENDS - 1: HMI_data.HotendPidT = temp; break)
OPTCODE(PIDTEMPBED, case H_BED: HMI_data.BedPidT = temp; break)
default: break;
}
}
}

void DWIN_PidTuning(pidresult_t result) {
HMI_value.pidresult = result;
Expand All @@ -1541,9 +1554,9 @@ void DWIN_LevelingDone() {
DWIN_Draw_Popup(ICON_TempTooHigh, GET_TEXT_F(MSG_PID_AUTOTUNE), F("for Nozzle is running."));
#endif
break;
case PID_BAD_EXTRUDER_NUM:
case PID_BAD_HEATER_ID:
checkkey = last_checkkey;
DWIN_Popup_Confirm(ICON_TempTooLow, GET_TEXT_F(MSG_PID_AUTOTUNE_FAILED), GET_TEXT_F(MSG_BAD_EXTRUDER_NUM));
DWIN_Popup_Confirm(ICON_TempTooLow, GET_TEXT_F(MSG_PID_AUTOTUNE_FAILED), GET_TEXT_F(MSG_BAD_HEATER_ID));
break;
#endif
#if ENABLED(PIDTEMPBED)
Expand All @@ -1568,11 +1581,13 @@ void DWIN_LevelingDone() {
checkkey = last_checkkey;
DWIN_Popup_Confirm(ICON_TempTooLow, GET_TEXT_F(MSG_PID_AUTOTUNE), GET_TEXT_F(MSG_BUTTON_DONE));
break;
default: checkkey = last_checkkey; break;
default:
checkkey = last_checkkey;
break;
}
}

#endif // PIDTEMP || PIDTEMPBED
#endif // DWIN_PID_TUNE

// Started a Print Job
void DWIN_Print_Started() {
Expand Down Expand Up @@ -1667,7 +1682,7 @@ void DWIN_SetDataDefaults() {
DWINUI::SetColors(HMI_data.Text_Color, HMI_data.Background_Color, HMI_data.StatusBg_Color);
TERN_(PIDTEMP, HMI_data.HotendPidT = DEF_HOTENDPIDT);
TERN_(PIDTEMPBED, HMI_data.BedPidT = DEF_BEDPIDT);
TERN_(HAS_PID_HEATING, HMI_data.PidCycles = DEF_PIDCYCLES);
TERN_(DWIN_PID_TUNE, HMI_data.PidCycles = DEF_PIDCYCLES);
#if ENABLED(PREVENT_COLD_EXTRUSION)
HMI_data.ExtMinT = EXTRUDE_MINTEMP;
ApplyExtMinT();
Expand Down Expand Up @@ -2057,7 +2072,7 @@ void SetMoveZ() { HMI_value.axis = Z_AXIS; SetPFloatOnClick(Z_MIN_POS, Z_MAX_POS
}
#endif

#if EITHER(PIDTEMP, PIDTEMPBED)
#if DWIN_PID_TUNE
void SetPID(celsius_t t, heater_id_t h) {
char cmd[53] = "";
char str_1[5] = "", str_2[5] = "";
Expand Down Expand Up @@ -2523,7 +2538,7 @@ void SetStepsZ() { HMI_value.axis = Z_AXIS, SetPFloatOnClick( MIN_STEP, MAX_STEP
void SetBedPidT() { SetPIntOnClick(MIN_BEDTEMP, MAX_BEDTEMP); }
#endif

#if EITHER(PIDTEMP, PIDTEMPBED)
#if DWIN_PID_TUNE
void SetPidCycles() { SetPIntOnClick(3, 50); }
void SetKp() { SetPFloatOnClick(0, 1000, 2); }
void ApplyPIDi() {
Expand Down Expand Up @@ -2694,7 +2709,7 @@ void onDrawGetColorItem(MenuItemClass* menuitem, int8_t line) {
DWIN_Draw_HLine(HMI_data.SplitLine_Color, 16, MYPOS(line + 1), 240);
}

#if EITHER(PIDTEMP, PIDTEMPBED)
#if DWIN_PID_TUNE
void onDrawPIDi(MenuItemClass* menuitem, int8_t line) { onDrawFloatMenu(menuitem, line, 2, unscalePID_i(*(float*)static_cast<MenuItemPtrClass*>(menuitem)->value)); }
void onDrawPIDd(MenuItemClass* menuitem, int8_t line) { onDrawFloatMenu(menuitem, line, 2, unscalePID_d(*(float*)static_cast<MenuItemPtrClass*>(menuitem)->value)); }
#endif
Expand Down
27 changes: 14 additions & 13 deletions Marlin/src/lcd/e3v2/proui/dwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ enum processID : uint8_t {
enum pidresult_t : uint8_t {
PIDTEMP_START = 0,
PIDTEMPBED_START,
PID_BAD_EXTRUDER_NUM,
PID_BAD_HEATER_ID,
PID_TEMP_TOO_HIGH,
PID_TUNING_TIMEOUT,
PID_DONE,
Expand Down Expand Up @@ -107,14 +107,14 @@ typedef struct {
uint16_t Coordinate_Color;

// Temperatures
#if ENABLED(PIDTEMP)
int16_t HotendPidT = DEF_HOTENDPIDT;
#endif
#if ENABLED(PIDTEMPBED)
int16_t BedPidT = DEF_BEDPIDT;
#endif
#if (HAS_HOTEND || HAS_HEATED_BED) && HAS_PID_HEATING
#if DWIN_PID_TUNE
int16_t PidCycles = DEF_PIDCYCLES;
#if ENABLED(PIDTEMP)
int16_t HotendPidT = DEF_HOTENDPIDT;
#endif
#if ENABLED(PIDTEMPBED)
int16_t BedPidT = DEF_BEDPIDT;
#endif
#endif
#if ENABLED(PREVENT_COLD_EXTRUSION)
int16_t ExtMinT = EXTRUDE_MINTEMP;
Expand All @@ -141,8 +141,8 @@ static constexpr size_t eeprom_data_size = sizeof(HMI_data_t);

typedef struct {
int8_t Color[3]; // Color components
#if HAS_PID_HEATING
tempcontrol_t pidresult = PID_DONE;
#if DWIN_PID_TUNE
pidresult_t pidresult = PID_DONE;
#endif
uint8_t Select = 0; // Auxiliary selector variable
AxisEnum axis = X_AXIS; // Axis Select
Expand Down Expand Up @@ -358,13 +358,14 @@ void Draw_Steps_Menu();
#endif

// PID
#if HAS_PID_HEATING
void DWIN_PidTuning(tempcontrol_t result);
#if DWIN_PID_TUNE
#include "../../../module/temperature.h"
void DWIN_StartM303(const bool seenC, const int c, const bool seenS, const heater_id_t hid, const celsius_t temp);
void DWIN_PidTuning(pidresult_t result);
#if ENABLED(PIDTEMP)
void Draw_HotendPID_Menu();
#endif
#if ENABLED(PIDTEMPBED)
void Draw_BedPID_Menu();
#endif
#endif
#endif
2 changes: 1 addition & 1 deletion Marlin/src/lcd/e3v2/proui/plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void PlotClass::Draw(const frame_rect_t frame, const float max, const float ref)
DWIN_Draw_HLine(Color_Red, frame.x, r, frame.w);
}

void PlotClass::Update(const float value) {
void PlotClass::Update(const_float_t value) {
if (!scale) return;
uint16_t y = round((y2) - value * scale);
if (grphpoints < grphframe.w) {
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/e3v2/proui/plot.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
class PlotClass {
public:
void Draw(frame_rect_t frame, float max, float ref = 0);
void Update(float value);
void Update(const_float_t value);
};

extern PlotClass Plot;
4 changes: 2 additions & 2 deletions Marlin/src/lcd/extui/dgus/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,11 @@ void DGUSScreenHandler::DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var)

// Don't let the user in the dark why there is no reaction.
if (!ExtUI::isMediaInserted()) {
setstatusmessagePGM(GET_TEXT(MSG_NO_MEDIA));
setstatusmessage(GET_TEXT_F(MSG_NO_MEDIA));
return;
}
if (card.flag.abort_sd_printing) {
setstatusmessagePGM(GET_TEXT(MSG_MEDIA_ABORTING));
setstatusmessage(GET_TEXT_F(MSG_MEDIA_ABORTING));
return;
}
}
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/lcd/extui/dgus/DGUSScreenHandlerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class DGUSScreenHandler {
static void setstatusmessage(const char *msg);
// The same for messages from Flash
static void setstatusmessagePGM(PGM_P const msg);
static void setstatusmessage(FSTR_P const fmsg) { setstatusmessagePGM(FTOP(fmsg)); }
// Callback for VP "Display wants to change screen on idle printer"
static void ScreenChangeHookIfIdle(DGUS_VP_Variable &var, void *val_ptr);
// Callback for VP "Screen has been changed"
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/lcd/extui/dgus/dgus_extui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,19 @@ namespace ExtUI {
// Called for temperature PID tuning result
switch (rst) {
case PID_STARTED:
ScreenHandler.setstatusmessagePGM(GET_TEXT(MSG_PID_AUTOTUNE));
ScreenHandler.setstatusmessage(GET_TEXT_F(MSG_PID_AUTOTUNE));
break;
case PID_BAD_EXTRUDER_NUM:
ScreenHandler.setstatusmessagePGM(GET_TEXT(MSG_PID_BAD_EXTRUDER_NUM));
case PID_BAD_HEATER_ID:
ScreenHandler.setstatusmessage(GET_TEXT_F(MSG_PID_BAD_HEATER_ID));
break;
case PID_TEMP_TOO_HIGH:
ScreenHandler.setstatusmessagePGM(GET_TEXT(MSG_PID_TEMP_TOO_HIGH));
ScreenHandler.setstatusmessage(GET_TEXT_F(MSG_PID_TEMP_TOO_HIGH));
break;
case PID_TUNING_TIMEOUT:
ScreenHandler.setstatusmessagePGM(GET_TEXT(MSG_PID_TIMEOUT));
ScreenHandler.setstatusmessage(GET_TEXT_F(MSG_PID_TIMEOUT));
break;
case PID_DONE:
ScreenHandler.setstatusmessagePGM(GET_TEXT(MSG_PID_AUTOTUNE_DONE));
ScreenHandler.setstatusmessage(GET_TEXT_F(MSG_PID_AUTOTUNE_DONE));
break;
}
ScreenHandler.GotoScreen(DGUSLCD_SCREEN_MAIN);
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ void DGUSScreenHandler::FilamentRunout(const ExtUI::extruder_t extruder) {
case ExtUI::PID_STARTED:
SetStatusMessage(GET_TEXT_F(MSG_PID_AUTOTUNE));
break;
case ExtUI::PID_BAD_EXTRUDER_NUM:
SetStatusMessage(GET_TEXT_F(MSG_PID_BAD_EXTRUDER_NUM));
case ExtUI::PID_BAD_HEATER_ID:
SetStatusMessage(GET_TEXT_F(MSG_PID_BAD_HEATER_ID));
break;
case ExtUI::PID_TEMP_TOO_HIGH:
SetStatusMessage(GET_TEXT_F(MSG_PID_TEMP_TOO_HIGH));
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ class DGUSScreenHandler {
static void SetMessageLine(const char* msg, uint8_t line);
static void SetMessageLinePGM(PGM_P msg, uint8_t line);

static void SetStatusMessage(const char* msg, const millis_t duration = DGUS_STATUS_EXPIRATION_MS);
static void SetStatusMessage(FSTR_P const msg, const millis_t duration = DGUS_STATUS_EXPIRATION_MS);
static void SetStatusMessage(const char* msg, const millis_t duration=DGUS_STATUS_EXPIRATION_MS);
static void SetStatusMessage(FSTR_P const msg, const millis_t duration=DGUS_STATUS_EXPIRATION_MS);

static void ShowWaitScreen(DGUS_Screen return_screen, bool has_continue = false);
static void ShowWaitScreen(DGUS_Screen return_screen, bool has_continue=false);

static DGUS_Screen GetCurrentScreen();
static void TriggerScreenChange(DGUS_Screen screen);
Expand Down Expand Up @@ -115,7 +115,7 @@ class DGUSScreenHandler {
static const DGUS_Addr* FindScreenAddrList(DGUS_Screen screen);
static bool CallScreenSetup(DGUS_Screen screen);

static void MoveToScreen(DGUS_Screen screen, bool abort_wait = false);
static void MoveToScreen(DGUS_Screen screen, bool abort_wait=false);
static bool SendScreenVPData(DGUS_Screen screen, bool complete_update);

static bool settings_ready;
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/lcd/extui/example/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ namespace ExtUI {
void onPidTuning(const result_t rst) {
// Called for temperature PID tuning result
switch (rst) {
case PID_STARTED: break;
case PID_BAD_EXTRUDER_NUM: break;
case PID_TEMP_TOO_HIGH: break;
case PID_TUNING_TIMEOUT: break;
case PID_DONE: break;
case PID_STARTED: break;
case PID_BAD_HEATER_ID: break;
case PID_TEMP_TOO_HIGH: break;
case PID_TUNING_TIMEOUT: break;
case PID_DONE: break;
}
}
#endif
Expand Down
Loading

0 comments on commit 6fe387b

Please sign in to comment.