mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-11-29 23:07:42 +00:00
🐛 Fix / refactor shared PID (#24673)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
parent
f6d109287f
commit
094701cc71
@ -57,19 +57,18 @@ void GcodeSuite::M301() {
|
||||
|
||||
if (e < HOTENDS) { // catch bad input value
|
||||
|
||||
if (parser.seenval('P')) PID_PARAM(Kp, e) = parser.value_float();
|
||||
if (parser.seenval('I')) PID_PARAM(Ki, e) = scalePID_i(parser.value_float());
|
||||
if (parser.seenval('D')) PID_PARAM(Kd, e) = scalePID_d(parser.value_float());
|
||||
if (parser.seenval('P')) SET_HOTEND_PID(Kp, e, parser.value_float());
|
||||
if (parser.seenval('I')) SET_HOTEND_PID(Ki, e, parser.value_float());
|
||||
if (parser.seenval('D')) SET_HOTEND_PID(Kd, e, parser.value_float());
|
||||
|
||||
#if ENABLED(PID_EXTRUSION_SCALING)
|
||||
if (parser.seenval('C')) PID_PARAM(Kc, e) = parser.value_float();
|
||||
if (parser.seenval('C')) SET_HOTEND_PID(Kc, e, parser.value_float());
|
||||
if (parser.seenval('L')) thermalManager.lpq_len = parser.value_int();
|
||||
NOMORE(thermalManager.lpq_len, LPQ_MAX_LEN);
|
||||
NOLESS(thermalManager.lpq_len, 0);
|
||||
LIMIT(thermalManager.lpq_len, 0, LPQ_MAX_LEN);
|
||||
#endif
|
||||
|
||||
#if ENABLED(PID_FAN_SCALING)
|
||||
if (parser.seenval('F')) PID_PARAM(Kf, e) = parser.value_float();
|
||||
if (parser.seenval('F')) SET_HOTEND_PID(Kf, e, parser.value_float());
|
||||
#endif
|
||||
|
||||
thermalManager.updatePID();
|
||||
@ -83,6 +82,7 @@ void GcodeSuite::M301_report(const bool forReplay/*=true*/ E_OPTARG(const int8_t
|
||||
IF_DISABLED(HAS_MULTI_EXTRUDER, constexpr int8_t eindex = -1);
|
||||
HOTEND_LOOP() {
|
||||
if (e == eindex || eindex == -1) {
|
||||
const hotend_pid_t &pid = thermalManager.temp_hotend[e].pid;
|
||||
report_echo_start(forReplay);
|
||||
SERIAL_ECHOPGM_P(
|
||||
#if ENABLED(PID_PARAMS_PER_HOTEND)
|
||||
@ -90,16 +90,14 @@ void GcodeSuite::M301_report(const bool forReplay/*=true*/ E_OPTARG(const int8_t
|
||||
#else
|
||||
PSTR(" M301 P")
|
||||
#endif
|
||||
, PID_PARAM(Kp, e)
|
||||
, PSTR(" I"), unscalePID_i(PID_PARAM(Ki, e))
|
||||
, PSTR(" D"), unscalePID_d(PID_PARAM(Kd, e))
|
||||
, pid.p(), PSTR(" I"), pid.i(), PSTR(" D"), pid.d()
|
||||
);
|
||||
#if ENABLED(PID_EXTRUSION_SCALING)
|
||||
SERIAL_ECHOPGM_P(SP_C_STR, PID_PARAM(Kc, e));
|
||||
SERIAL_ECHOPGM_P(SP_C_STR, pid.c());
|
||||
if (e == 0) SERIAL_ECHOPGM(" L", thermalManager.lpq_len);
|
||||
#endif
|
||||
#if ENABLED(PID_FAN_SCALING)
|
||||
SERIAL_ECHOPGM(" F", PID_PARAM(Kf, e));
|
||||
SERIAL_ECHOPGM(" F", pid.f());
|
||||
#endif
|
||||
SERIAL_EOL();
|
||||
}
|
||||
|
@ -36,17 +36,17 @@
|
||||
*/
|
||||
void GcodeSuite::M304() {
|
||||
if (!parser.seen("PID")) return M304_report();
|
||||
if (parser.seenval('P')) thermalManager.temp_bed.pid.Kp = parser.value_float();
|
||||
if (parser.seenval('I')) thermalManager.temp_bed.pid.Ki = scalePID_i(parser.value_float());
|
||||
if (parser.seenval('D')) thermalManager.temp_bed.pid.Kd = scalePID_d(parser.value_float());
|
||||
if (parser.seenval('P')) thermalManager.temp_bed.pid.set_Kp(parser.value_float());
|
||||
if (parser.seenval('I')) thermalManager.temp_bed.pid.set_Ki(parser.value_float());
|
||||
if (parser.seenval('D')) thermalManager.temp_bed.pid.set_Kd(parser.value_float());
|
||||
}
|
||||
|
||||
void GcodeSuite::M304_report(const bool forReplay/*=true*/) {
|
||||
report_heading_etc(forReplay, F(STR_BED_PID));
|
||||
SERIAL_ECHOLNPGM(
|
||||
" M304 P", thermalManager.temp_bed.pid.Kp
|
||||
, " I", unscalePID_i(thermalManager.temp_bed.pid.Ki)
|
||||
, " D", unscalePID_d(thermalManager.temp_bed.pid.Kd)
|
||||
SERIAL_ECHOLNPGM(" M304"
|
||||
" P", thermalManager.temp_bed.pid.p()
|
||||
, " I", thermalManager.temp_bed.pid.i()
|
||||
, " D", thermalManager.temp_bed.pid.d()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -36,17 +36,17 @@
|
||||
*/
|
||||
void GcodeSuite::M309() {
|
||||
if (!parser.seen("PID")) return M309_report();
|
||||
if (parser.seen('P')) thermalManager.temp_chamber.pid.Kp = parser.value_float();
|
||||
if (parser.seen('I')) thermalManager.temp_chamber.pid.Ki = scalePID_i(parser.value_float());
|
||||
if (parser.seen('D')) thermalManager.temp_chamber.pid.Kd = scalePID_d(parser.value_float());
|
||||
if (parser.seenval('P')) thermalManager.temp_chamber.pid.set_Kp(parser.value_float());
|
||||
if (parser.seenval('I')) thermalManager.temp_chamber.pid.set_Ki(parser.value_float());
|
||||
if (parser.seenval('D')) thermalManager.temp_chamber.pid.set_Kd(parser.value_float());
|
||||
}
|
||||
|
||||
void GcodeSuite::M309_report(const bool forReplay/*=true*/) {
|
||||
report_heading_etc(forReplay, F(STR_CHAMBER_PID));
|
||||
SERIAL_ECHOLNPGM(
|
||||
" M309 P", thermalManager.temp_chamber.pid.Kp
|
||||
, " I", unscalePID_i(thermalManager.temp_chamber.pid.Ki)
|
||||
, " D", unscalePID_d(thermalManager.temp_chamber.pid.Kd)
|
||||
SERIAL_ECHOLNPGM(" M309"
|
||||
" P", thermalManager.temp_chamber.pid.p()
|
||||
, " I", thermalManager.temp_chamber.pid.i()
|
||||
, " D", thermalManager.temp_chamber.pid.d()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -2140,7 +2140,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
|
||||
case HOTENDPID_KP:
|
||||
if (draw) {
|
||||
Draw_Menu_Item(row, ICON_Version, F("Kp Value"));
|
||||
Draw_Float(thermalManager.temp_hotend[0].pid.Kp, row, false, 100);
|
||||
Draw_Float(thermalManager.temp_hotend[0].pid.p(), row, false, 100);
|
||||
}
|
||||
else
|
||||
Modify_Value(thermalManager.temp_hotend[0].pid.Kp, 0, 5000, 100, thermalManager.updatePID);
|
||||
@ -2148,7 +2148,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
|
||||
case HOTENDPID_KI:
|
||||
if (draw) {
|
||||
Draw_Menu_Item(row, ICON_Version, F("Ki Value"));
|
||||
Draw_Float(unscalePID_i(thermalManager.temp_hotend[0].pid.Ki), row, false, 100);
|
||||
Draw_Float(thermalManager.temp_hotend[0].pid.i(), row, false, 100);
|
||||
}
|
||||
else
|
||||
Modify_Value(thermalManager.temp_hotend[0].pid.Ki, 0, 5000, 100, thermalManager.updatePID);
|
||||
@ -2156,7 +2156,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
|
||||
case HOTENDPID_KD:
|
||||
if (draw) {
|
||||
Draw_Menu_Item(row, ICON_Version, F("Kd Value"));
|
||||
Draw_Float(unscalePID_d(thermalManager.temp_hotend[0].pid.Kd), row, false, 100);
|
||||
Draw_Float(thermalManager.temp_hotend[0].pid.d(), row, false, 100);
|
||||
}
|
||||
else
|
||||
Modify_Value(thermalManager.temp_hotend[0].pid.Kd, 0, 5000, 100, thermalManager.updatePID);
|
||||
@ -2207,7 +2207,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
|
||||
case BEDPID_KP:
|
||||
if (draw) {
|
||||
Draw_Menu_Item(row, ICON_Version, F("Kp Value"));
|
||||
Draw_Float(thermalManager.temp_bed.pid.Kp, row, false, 100);
|
||||
Draw_Float(thermalManager.temp_bed.pid.p(), row, false, 100);
|
||||
}
|
||||
else {
|
||||
Modify_Value(thermalManager.temp_bed.pid.Kp, 0, 5000, 100, thermalManager.updatePID);
|
||||
@ -2216,7 +2216,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
|
||||
case BEDPID_KI:
|
||||
if (draw) {
|
||||
Draw_Menu_Item(row, ICON_Version, F("Ki Value"));
|
||||
Draw_Float(unscalePID_i(thermalManager.temp_bed.pid.Ki), row, false, 100);
|
||||
Draw_Float(thermalManager.temp_bed.pid.i(), row, false, 100);
|
||||
}
|
||||
else
|
||||
Modify_Value(thermalManager.temp_bed.pid.Ki, 0, 5000, 100, thermalManager.updatePID);
|
||||
@ -2224,7 +2224,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
|
||||
case BEDPID_KD:
|
||||
if (draw) {
|
||||
Draw_Menu_Item(row, ICON_Version, F("Kd Value"));
|
||||
Draw_Float(unscalePID_d(thermalManager.temp_bed.pid.Kd), row, false, 100);
|
||||
Draw_Float(thermalManager.temp_bed.pid.d(), row, false, 100);
|
||||
}
|
||||
else
|
||||
Modify_Value(thermalManager.temp_bed.pid.Kd, 0, 5000, 100, thermalManager.updatePID);
|
||||
|
@ -2667,13 +2667,15 @@ void SetStepsY() { HMI_value.axis = Y_AXIS, SetPFloatOnClick( MIN_STEP, MAX_STEP
|
||||
void SetStepsZ() { HMI_value.axis = Z_AXIS, SetPFloatOnClick( MIN_STEP, MAX_STEP, UNITFDIGITS); }
|
||||
#if HAS_HOTEND
|
||||
void SetStepsE() { HMI_value.axis = E_AXIS; SetPFloatOnClick( MIN_STEP, MAX_STEP, UNITFDIGITS); }
|
||||
#if ENABLED(PIDTEMP)
|
||||
void SetHotendPidT() { SetPIntOnClick(MIN_ETEMP, MAX_ETEMP); }
|
||||
#endif
|
||||
#endif
|
||||
#if HAS_HEATED_BED
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
void SetBedPidT() { SetPIntOnClick(MIN_BEDTEMP, MAX_BEDTEMP); }
|
||||
#endif
|
||||
|
||||
#if HAS_HOTEND || HAS_HEATED_BED
|
||||
#if EITHER(PIDTEMP, PIDTEMPBED)
|
||||
void SetPidCycles() { SetPIntOnClick(3, 50); }
|
||||
void SetKp() { SetPFloatOnClick(0, 1000, 2); }
|
||||
void ApplyPIDi() {
|
||||
@ -3222,10 +3224,10 @@ void Draw_AdvancedSettings_Menu() {
|
||||
#if HAS_HOME_OFFSET
|
||||
MENU_ITEM_F(ICON_HomeOffset, MSG_SET_HOME_OFFSETS, onDrawSubMenu, Draw_HomeOffset_Menu);
|
||||
#endif
|
||||
#if HAS_HOTEND
|
||||
#if ENABLED(PIDTEMP)
|
||||
MENU_ITEM(ICON_PIDNozzle, F(STR_HOTEND_PID " Settings"), onDrawSubMenu, Draw_HotendPID_Menu);
|
||||
#endif
|
||||
#if HAS_HEATED_BED
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
MENU_ITEM(ICON_PIDbed, F(STR_BED_PID " Settings"), onDrawSubMenu, Draw_BedPID_Menu);
|
||||
#endif
|
||||
MENU_ITEM_F(ICON_FilSet, MSG_FILAMENT_SET, onDrawSubMenu, Draw_FilSet_Menu);
|
||||
@ -3668,10 +3670,10 @@ void Draw_Steps_Menu() {
|
||||
CurrentMenu->draw();
|
||||
}
|
||||
|
||||
#if HAS_HOTEND
|
||||
#if ENABLED(PIDTEMP)
|
||||
void Draw_HotendPID_Menu() {
|
||||
checkkey = Menu;
|
||||
if (SetMenu(HotendPIDMenu, F(STR_HOTEND_PID " Settings"),8)) {
|
||||
if (SetMenu(HotendPIDMenu, F(STR_HOTEND_PID " Settings"), 8)) {
|
||||
BACK_ITEM(Draw_AdvancedSettings_Menu);
|
||||
MENU_ITEM(ICON_PIDNozzle, F(STR_HOTEND_PID), onDrawMenuItem, HotendPID);
|
||||
EDIT_ITEM(ICON_PIDValue, F("Set" STR_KP), onDrawPFloat2Menu, SetKp, &thermalManager.temp_hotend[0].pid.Kp);
|
||||
@ -3687,10 +3689,10 @@ void Draw_Steps_Menu() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAS_HEATED_BED
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
void Draw_BedPID_Menu() {
|
||||
checkkey = Menu;
|
||||
if (SetMenu(BedPIDMenu, F(STR_BED_PID " Settings"),8)) {
|
||||
if (SetMenu(BedPIDMenu, F(STR_BED_PID " Settings"), 8)) {
|
||||
BACK_ITEM(Draw_AdvancedSettings_Menu);
|
||||
MENU_ITEM(ICON_PIDNozzle, F(STR_BED_PID), onDrawMenuItem,BedPID);
|
||||
EDIT_ITEM(ICON_PIDValue, F("Set" STR_KP), onDrawPFloat2Menu, SetKp, &thermalManager.temp_bed.pid.Kp);
|
||||
|
@ -264,7 +264,9 @@ void Draw_Motion_Menu();
|
||||
void Draw_Preheat1_Menu();
|
||||
void Draw_Preheat2_Menu();
|
||||
void Draw_Preheat3_Menu();
|
||||
#if ENABLED(PIDTEMP)
|
||||
void Draw_HotendPID_Menu();
|
||||
#endif
|
||||
#endif
|
||||
void Draw_Temperature_Menu();
|
||||
void Draw_MaxSpeed_Menu();
|
||||
@ -273,7 +275,7 @@ void Draw_MaxAccel_Menu();
|
||||
void Draw_MaxJerk_Menu();
|
||||
#endif
|
||||
void Draw_Steps_Menu();
|
||||
#if HAS_HEATED_BED
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
void Draw_BedPID_Menu();
|
||||
#endif
|
||||
#if EITHER(HAS_BED_PROBE, BABYSTEPPING)
|
||||
|
@ -421,16 +421,16 @@ void DGUSTxHandler::PIDKp(DGUS_VP &vp) {
|
||||
default: return;
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
case DGUS_Data::Heater::BED:
|
||||
value = ExtUI::getBedPIDValues_Kp();
|
||||
value = ExtUI::getBedPID_Kp();
|
||||
break;
|
||||
#endif
|
||||
#if ENABLED(PIDTEMP)
|
||||
case DGUS_Data::Heater::H0:
|
||||
value = ExtUI::getPIDValues_Kp(ExtUI::E0);
|
||||
value = ExtUI::getPID_Kp(ExtUI::E0);
|
||||
break;
|
||||
#if HAS_MULTI_HOTEND
|
||||
case DGUS_Data::Heater::H1:
|
||||
value = ExtUI::getPIDValues_Kp(ExtUI::E1);
|
||||
value = ExtUI::getPID_Kp(ExtUI::E1);
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
@ -447,16 +447,16 @@ void DGUSTxHandler::PIDKi(DGUS_VP &vp) {
|
||||
default: return;
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
case DGUS_Data::Heater::BED:
|
||||
value = ExtUI::getBedPIDValues_Ki();
|
||||
value = ExtUI::getBedPID_Ki();
|
||||
break;
|
||||
#endif
|
||||
#if ENABLED(PIDTEMP)
|
||||
case DGUS_Data::Heater::H0:
|
||||
value = ExtUI::getPIDValues_Ki(ExtUI::E0);
|
||||
value = ExtUI::getPID_Ki(ExtUI::E0);
|
||||
break;
|
||||
#if HAS_MULTI_HOTEND
|
||||
case DGUS_Data::Heater::H1:
|
||||
value = ExtUI::getPIDValues_Ki(ExtUI::E1);
|
||||
value = ExtUI::getPID_Ki(ExtUI::E1);
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
@ -473,16 +473,16 @@ void DGUSTxHandler::PIDKd(DGUS_VP &vp) {
|
||||
default: return;
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
case DGUS_Data::Heater::BED:
|
||||
value = ExtUI::getBedPIDValues_Kd();
|
||||
value = ExtUI::getBedPID_Kd();
|
||||
break;
|
||||
#endif
|
||||
#if ENABLED(PIDTEMP)
|
||||
case DGUS_Data::Heater::H0:
|
||||
value = ExtUI::getPIDValues_Kd(ExtUI::E0);
|
||||
value = ExtUI::getPID_Kd(ExtUI::E0);
|
||||
break;
|
||||
#if HAS_MULTI_HOTEND
|
||||
case DGUS_Data::Heater::H1:
|
||||
value = ExtUI::getPIDValues_Kd(ExtUI::E1);
|
||||
value = ExtUI::getPID_Kd(ExtUI::E1);
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
|
@ -459,17 +459,17 @@ void NextionTFT::PanelInfo(uint8_t req) {
|
||||
|
||||
case 37: // PID
|
||||
#if ENABLED(PIDTEMP)
|
||||
#define SEND_PID_INFO_0(A, B) SEND_VALasTXT(A, getPIDValues_K##B(E0))
|
||||
#define SEND_PID_INFO_0(A, B) SEND_VALasTXT(A, getPID_K##B(E0))
|
||||
#else
|
||||
#define SEND_PID_INFO_0(A, B) SEND_NA(A)
|
||||
#endif
|
||||
#if BOTH(PIDTEMP, HAS_MULTI_EXTRUDER)
|
||||
#define SEND_PID_INFO_1(A, B) SEND_VALasTXT(A, getPIDValues_K##B(E1))
|
||||
#define SEND_PID_INFO_1(A, B) SEND_VALasTXT(A, getPID_K##B(E1))
|
||||
#else
|
||||
#define SEND_PID_INFO_1(A, B) SEND_NA(A)
|
||||
#endif
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
#define SEND_PID_INFO_BED(A, B) SEND_VALasTXT(A, getBedPIDValues_K##B())
|
||||
#define SEND_PID_INFO_BED(A, B) SEND_VALasTXT(A, getBedPID_K##B())
|
||||
#else
|
||||
#define SEND_PID_INFO_BED(A, B) SEND_NA(A)
|
||||
#endif
|
||||
|
@ -976,32 +976,26 @@ namespace ExtUI {
|
||||
float getFeedrate_percent() { return feedrate_percentage; }
|
||||
|
||||
#if ENABLED(PIDTEMP)
|
||||
float getPIDValues_Kp(const extruder_t tool) { return PID_PARAM(Kp, tool); }
|
||||
float getPIDValues_Ki(const extruder_t tool) { return unscalePID_i(PID_PARAM(Ki, tool)); }
|
||||
float getPIDValues_Kd(const extruder_t tool) { return unscalePID_d(PID_PARAM(Kd, tool)); }
|
||||
float getPID_Kp(const extruder_t tool) { return thermalManager.temp_hotend[tool].pid.p(); }
|
||||
float getPID_Ki(const extruder_t tool) { return thermalManager.temp_hotend[tool].pid.i(); }
|
||||
float getPID_Kd(const extruder_t tool) { return thermalManager.temp_hotend[tool].pid.d(); }
|
||||
|
||||
void setPIDValues(const_float_t p, const_float_t i, const_float_t d, extruder_t tool) {
|
||||
thermalManager.temp_hotend[tool].pid.Kp = p;
|
||||
thermalManager.temp_hotend[tool].pid.Ki = scalePID_i(i);
|
||||
thermalManager.temp_hotend[tool].pid.Kd = scalePID_d(d);
|
||||
thermalManager.updatePID();
|
||||
void setPID(const_float_t p, const_float_t i, const_float_t d, extruder_t tool) {
|
||||
thermalManager.setPID(uint8_t(tool), p, i, d);
|
||||
}
|
||||
|
||||
void startPIDTune(const celsius_t temp, extruder_t tool) {
|
||||
thermalManager.PID_autotune(temp, (heater_id_t)tool, 8, true);
|
||||
thermalManager.PID_autotune(temp, heater_id_t(tool), 8, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
float getBedPIDValues_Kp() { return thermalManager.temp_bed.pid.Kp; }
|
||||
float getBedPIDValues_Ki() { return unscalePID_i(thermalManager.temp_bed.pid.Ki); }
|
||||
float getBedPIDValues_Kd() { return unscalePID_d(thermalManager.temp_bed.pid.Kd); }
|
||||
float getBedPID_Kp() { return thermalManager.temp_bed.pid.p(); }
|
||||
float getBedPID_Ki() { return thermalManager.temp_bed.pid.i(); }
|
||||
float getBedPID_Kd() { return thermalManager.temp_bed.pid.d(); }
|
||||
|
||||
void setBedPIDValues(const_float_t p, const_float_t i, const_float_t d) {
|
||||
thermalManager.temp_bed.pid.Kp = p;
|
||||
thermalManager.temp_bed.pid.Ki = scalePID_i(i);
|
||||
thermalManager.temp_bed.pid.Kd = scalePID_d(d);
|
||||
thermalManager.updatePID();
|
||||
void setBedPID(const_float_t p, const_float_t i, const_float_t d) {
|
||||
thermalManager.temp_bed.pid.set(p, i, d);
|
||||
}
|
||||
|
||||
void startBedPIDTune(const celsius_t temp) {
|
||||
|
@ -324,18 +324,18 @@ namespace ExtUI {
|
||||
#endif
|
||||
|
||||
#if ENABLED(PIDTEMP)
|
||||
float getPIDValues_Kp(const extruder_t);
|
||||
float getPIDValues_Ki(const extruder_t);
|
||||
float getPIDValues_Kd(const extruder_t);
|
||||
void setPIDValues(const_float_t, const_float_t , const_float_t , extruder_t);
|
||||
float getPID_Kp(const extruder_t);
|
||||
float getPID_Ki(const extruder_t);
|
||||
float getPID_Kd(const extruder_t);
|
||||
void setPID(const_float_t, const_float_t , const_float_t , extruder_t);
|
||||
void startPIDTune(const celsius_t, extruder_t);
|
||||
#endif
|
||||
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
float getBedPIDValues_Kp();
|
||||
float getBedPIDValues_Ki();
|
||||
float getBedPIDValues_Kd();
|
||||
void setBedPIDValues(const_float_t, const_float_t , const_float_t);
|
||||
float getBedPID_Kp();
|
||||
float getBedPID_Ki();
|
||||
float getBedPID_Kd();
|
||||
void setBedPID(const_float_t, const_float_t , const_float_t);
|
||||
void startBedPIDTune(const celsius_t);
|
||||
#endif
|
||||
|
||||
|
@ -209,37 +209,59 @@ void menu_backlash();
|
||||
|
||||
#if ENABLED(PID_EDIT_MENU)
|
||||
|
||||
float raw_Ki, raw_Kd; // place-holders for Ki and Kd edits
|
||||
// Placeholders for PID editing
|
||||
float raw_Kp, raw_Ki, raw_Kd;
|
||||
#if ENABLED(PID_EXTRUSION_SCALING)
|
||||
float raw_Kc;
|
||||
#endif
|
||||
#if ENABLED(PID_FAN_SCALING)
|
||||
float raw_Kf;
|
||||
#endif
|
||||
|
||||
// Helpers for editing PID Ki & Kd values
|
||||
// grab the PID value out of the temp variable; scale it; then update the PID driver
|
||||
void copy_and_scalePID_i(const int8_t e) {
|
||||
// Helpers for editing PID Kp, Ki and Kd values
|
||||
void apply_PID_p(const int8_t e) {
|
||||
switch (e) {
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
case H_BED: thermalManager.temp_bed.pid.Ki = scalePID_i(raw_Ki); break;
|
||||
case H_BED: thermalManager.temp_bed.pid.set_Ki(raw_Ki); break;
|
||||
#endif
|
||||
#if ENABLED(PIDTEMPCHAMBER)
|
||||
case H_CHAMBER: thermalManager.temp_chamber.pid.Ki = scalePID_i(raw_Ki); break;
|
||||
case H_CHAMBER: thermalManager.temp_chamber.pid.set_Ki(raw_Ki); break;
|
||||
#endif
|
||||
default:
|
||||
#if ENABLED(PIDTEMP)
|
||||
PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
|
||||
SET_HOTEND_PID(Kp, e, raw_Kp);
|
||||
thermalManager.updatePID();
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
void copy_and_scalePID_d(const int8_t e) {
|
||||
void apply_PID_i(const int8_t e) {
|
||||
switch (e) {
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
case H_BED: thermalManager.temp_bed.pid.Kd = scalePID_d(raw_Kd); break;
|
||||
case H_BED: thermalManager.temp_bed.pid.set_Ki(raw_Ki); break;
|
||||
#endif
|
||||
#if ENABLED(PIDTEMPCHAMBER)
|
||||
case H_CHAMBER: thermalManager.temp_chamber.pid.Kd = scalePID_d(raw_Kd); break;
|
||||
case H_CHAMBER: thermalManager.temp_chamber.pid.set_Ki(raw_Ki); break;
|
||||
#endif
|
||||
default:
|
||||
#if ENABLED(PIDTEMP)
|
||||
PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
|
||||
SET_HOTEND_PID(Ki, e, raw_Ki);
|
||||
thermalManager.updatePID();
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
void apply_PID_d(const int8_t e) {
|
||||
switch (e) {
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
case H_BED: thermalManager.temp_bed.pid.set_Kd(raw_Kd); break;
|
||||
#endif
|
||||
#if ENABLED(PIDTEMPCHAMBER)
|
||||
case H_CHAMBER: thermalManager.temp_chamber.pid.set_Kd(raw_Kd); break;
|
||||
#endif
|
||||
default:
|
||||
#if ENABLED(PIDTEMP)
|
||||
SET_HOTEND_PID(Kd, e, raw_Kd);
|
||||
thermalManager.updatePID();
|
||||
#endif
|
||||
break;
|
||||
@ -291,16 +313,18 @@ void menu_backlash();
|
||||
|
||||
#if BOTH(PIDTEMP, PID_EDIT_MENU)
|
||||
#define __PID_HOTEND_MENU_ITEMS(N) \
|
||||
raw_Ki = unscalePID_i(PID_PARAM(Ki, N)); \
|
||||
raw_Kd = unscalePID_d(PID_PARAM(Kd, N)); \
|
||||
EDIT_ITEM_FAST_N(float41sign, N, MSG_PID_P_E, &PID_PARAM(Kp, N), 1, 9990); \
|
||||
EDIT_ITEM_FAST_N(float52sign, N, MSG_PID_I_E, &raw_Ki, 0.01f, 9990, []{ copy_and_scalePID_i(N); }); \
|
||||
EDIT_ITEM_FAST_N(float41sign, N, MSG_PID_D_E, &raw_Kd, 1, 9990, []{ copy_and_scalePID_d(N); })
|
||||
raw_Kp = thermalManager.temp_hotend[N].pid.p(); \
|
||||
raw_Ki = thermalManager.temp_hotend[N].pid.i(); \
|
||||
raw_Kd = thermalManager.temp_hotend[N].pid.d(); \
|
||||
EDIT_ITEM_FAST_N(float41sign, N, MSG_PID_P_E, &raw_Kp, 1, 9990, []{ apply_PID_p(N); }); \
|
||||
EDIT_ITEM_FAST_N(float52sign, N, MSG_PID_I_E, &raw_Ki, 0.01f, 9990, []{ apply_PID_i(N); }); \
|
||||
EDIT_ITEM_FAST_N(float41sign, N, MSG_PID_D_E, &raw_Kd, 1, 9990, []{ apply_PID_d(N); })
|
||||
|
||||
#if ENABLED(PID_EXTRUSION_SCALING)
|
||||
#define _PID_HOTEND_MENU_ITEMS(N) \
|
||||
__PID_HOTEND_MENU_ITEMS(N); \
|
||||
EDIT_ITEM_N(float4, N, MSG_PID_C_E, &PID_PARAM(Kc, N), 1, 9990)
|
||||
raw_Kc = thermalManager.temp_hotend[N].pid.c(); \
|
||||
EDIT_ITEM_N(float4, N, MSG_PID_C_E, &raw_Kc, 1, 9990, []{ SET_HOTEND_PID(Kc, N, raw_Kc); thermalManager.updatePID(); });
|
||||
#else
|
||||
#define _PID_HOTEND_MENU_ITEMS(N) __PID_HOTEND_MENU_ITEMS(N)
|
||||
#endif
|
||||
@ -308,7 +332,8 @@ void menu_backlash();
|
||||
#if ENABLED(PID_FAN_SCALING)
|
||||
#define _HOTEND_PID_EDIT_MENU_ITEMS(N) \
|
||||
_PID_HOTEND_MENU_ITEMS(N); \
|
||||
EDIT_ITEM_N(float4, N, MSG_PID_F_E, &PID_PARAM(Kf, N), 1, 9990)
|
||||
raw_Kf = thermalManager.temp_hotend[N].pid.f(); \
|
||||
EDIT_ITEM_N(float4, N, MSG_PID_F_E, &raw_Kf, 1, 9990, []{ SET_HOTEND_PID(Kf, N, raw_Kf); thermalManager.updatePID(); });
|
||||
#else
|
||||
#define _HOTEND_PID_EDIT_MENU_ITEMS(N) _PID_HOTEND_MENU_ITEMS(N)
|
||||
#endif
|
||||
@ -321,11 +346,12 @@ void menu_backlash();
|
||||
|
||||
#if ENABLED(PID_EDIT_MENU) && EITHER(PIDTEMPBED, PIDTEMPCHAMBER)
|
||||
#define _PID_EDIT_ITEMS_TMPL(N,T) \
|
||||
raw_Ki = unscalePID_i(T.pid.Ki); \
|
||||
raw_Kd = unscalePID_d(T.pid.Kd); \
|
||||
EDIT_ITEM_FAST_N(float41sign, N, MSG_PID_P_E, &T.pid.Kp, 1, 9990); \
|
||||
EDIT_ITEM_FAST_N(float52sign, N, MSG_PID_I_E, &raw_Ki, 0.01f, 9990, []{ copy_and_scalePID_i(N); }); \
|
||||
EDIT_ITEM_FAST_N(float41sign, N, MSG_PID_D_E, &raw_Kd, 1, 9990, []{ copy_and_scalePID_d(N); })
|
||||
raw_Kp = T.pid.p(); \
|
||||
raw_Ki = T.pid.i(); \
|
||||
raw_Kd = T.pid.d(); \
|
||||
EDIT_ITEM_FAST_N(float41sign, N, MSG_PID_P_E, &raw_Kp, 1, 9990, []{ apply_PID_p(N); }); \
|
||||
EDIT_ITEM_FAST_N(float52sign, N, MSG_PID_I_E, &raw_Ki, 0.01f, 9990, []{ apply_PID_i(N); }); \
|
||||
EDIT_ITEM_FAST_N(float41sign, N, MSG_PID_D_E, &raw_Kd, 1, 9990, []{ apply_PID_d(N); })
|
||||
#endif
|
||||
|
||||
#if ENABLED(PIDTEMP)
|
||||
|
@ -364,18 +364,18 @@ typedef struct SettingsDataStruct {
|
||||
//
|
||||
// PIDTEMP
|
||||
//
|
||||
PIDCF_t hotendPID[HOTENDS]; // M301 En PIDCF / M303 En U
|
||||
raw_pidcf_t hotendPID[HOTENDS]; // M301 En PIDCF / M303 En U
|
||||
int16_t lpq_len; // M301 L
|
||||
|
||||
//
|
||||
// PIDTEMPBED
|
||||
//
|
||||
PID_t bedPID; // M304 PID / M303 E-1 U
|
||||
raw_pid_t bedPID; // M304 PID / M303 E-1 U
|
||||
|
||||
//
|
||||
// PIDTEMPCHAMBER
|
||||
//
|
||||
PID_t chamberPID; // M309 PID / M303 E-2 U
|
||||
raw_pid_t chamberPID; // M309 PID / M303 E-2 U
|
||||
|
||||
//
|
||||
// User-defined Thermistors
|
||||
@ -1052,27 +1052,20 @@ void MarlinSettings::postprocess() {
|
||||
//
|
||||
{
|
||||
_FIELD_TEST(hotendPID);
|
||||
HOTEND_LOOP() {
|
||||
PIDCF_t pidcf = {
|
||||
#if DISABLED(PIDTEMP)
|
||||
NAN, NAN, NAN,
|
||||
NAN, NAN
|
||||
#else
|
||||
PID_PARAM(Kp, e),
|
||||
unscalePID_i(PID_PARAM(Ki, e)),
|
||||
unscalePID_d(PID_PARAM(Kd, e)),
|
||||
PID_PARAM(Kc, e),
|
||||
PID_PARAM(Kf, e)
|
||||
raw_pidcf_t pidcf = { NAN, NAN, NAN, NAN, NAN };
|
||||
#endif
|
||||
HOTEND_LOOP() {
|
||||
#if ENABLED(PIDTEMP)
|
||||
const hotend_pid_t &pid = thermalManager.temp_hotend[e].pid;
|
||||
raw_pidcf_t pidcf = { pid.p(), pid.i(), pid.d(), pid.c(), pid.f() };
|
||||
#endif
|
||||
};
|
||||
EEPROM_WRITE(pidcf);
|
||||
}
|
||||
|
||||
_FIELD_TEST(lpq_len);
|
||||
#if DISABLED(PID_EXTRUSION_SCALING)
|
||||
const int16_t lpq_len = 20;
|
||||
#endif
|
||||
EEPROM_WRITE(TERN(PID_EXTRUSION_SCALING, thermalManager.lpq_len, lpq_len));
|
||||
const int16_t lpq_len = TERN(PID_EXTRUSION_SCALING, thermalManager.lpq_len, 20);
|
||||
EEPROM_WRITE(lpq_len);
|
||||
}
|
||||
|
||||
//
|
||||
@ -1080,17 +1073,12 @@ void MarlinSettings::postprocess() {
|
||||
//
|
||||
{
|
||||
_FIELD_TEST(bedPID);
|
||||
|
||||
const PID_t bed_pid = {
|
||||
#if DISABLED(PIDTEMPBED)
|
||||
NAN, NAN, NAN
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
const PID_t &pid = thermalManager.temp_bed.pid;
|
||||
const raw_pid_t bed_pid = { pid.p(), pid.i(), pid.d() };
|
||||
#else
|
||||
// Store the unscaled PID values
|
||||
thermalManager.temp_bed.pid.Kp,
|
||||
unscalePID_i(thermalManager.temp_bed.pid.Ki),
|
||||
unscalePID_d(thermalManager.temp_bed.pid.Kd)
|
||||
const raw_pid_t bed_pid = { NAN, NAN, NAN };
|
||||
#endif
|
||||
};
|
||||
EEPROM_WRITE(bed_pid);
|
||||
}
|
||||
|
||||
@ -1099,17 +1087,12 @@ void MarlinSettings::postprocess() {
|
||||
//
|
||||
{
|
||||
_FIELD_TEST(chamberPID);
|
||||
|
||||
const PID_t chamber_pid = {
|
||||
#if DISABLED(PIDTEMPCHAMBER)
|
||||
NAN, NAN, NAN
|
||||
#if ENABLED(PIDTEMPCHAMBER)
|
||||
const PID_t &pid = thermalManager.temp_chamber.pid;
|
||||
const raw_pid_t chamber_pid = { pid.p(), pid.i(), pid.d() };
|
||||
#else
|
||||
// Store the unscaled PID values
|
||||
thermalManager.temp_chamber.pid.Kp,
|
||||
unscalePID_i(thermalManager.temp_chamber.pid.Ki),
|
||||
unscalePID_d(thermalManager.temp_chamber.pid.Kd)
|
||||
const raw_pid_t chamber_pid = { NAN, NAN, NAN };
|
||||
#endif
|
||||
};
|
||||
EEPROM_WRITE(chamber_pid);
|
||||
}
|
||||
|
||||
@ -1117,10 +1100,8 @@ void MarlinSettings::postprocess() {
|
||||
// User-defined Thermistors
|
||||
//
|
||||
#if HAS_USER_THERMISTORS
|
||||
{
|
||||
_FIELD_TEST(user_thermistor);
|
||||
EEPROM_WRITE(thermalManager.user_thermistor);
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
@ -2003,17 +1984,11 @@ void MarlinSettings::postprocess() {
|
||||
//
|
||||
{
|
||||
HOTEND_LOOP() {
|
||||
PIDCF_t pidcf;
|
||||
raw_pidcf_t pidcf;
|
||||
EEPROM_READ(pidcf);
|
||||
#if ENABLED(PIDTEMP)
|
||||
if (!validating && !isnan(pidcf.Kp)) {
|
||||
// Scale PID values since EEPROM values are unscaled
|
||||
PID_PARAM(Kp, e) = pidcf.Kp;
|
||||
PID_PARAM(Ki, e) = scalePID_i(pidcf.Ki);
|
||||
PID_PARAM(Kd, e) = scalePID_d(pidcf.Kd);
|
||||
TERN_(PID_EXTRUSION_SCALING, PID_PARAM(Kc, e) = pidcf.Kc);
|
||||
TERN_(PID_FAN_SCALING, PID_PARAM(Kf, e) = pidcf.Kf);
|
||||
}
|
||||
if (!validating && !isnan(pidcf.p))
|
||||
thermalManager.temp_hotend[e].pid.set(pidcf);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -2035,15 +2010,11 @@ void MarlinSettings::postprocess() {
|
||||
// Heated Bed PID
|
||||
//
|
||||
{
|
||||
PID_t pid;
|
||||
raw_pid_t pid;
|
||||
EEPROM_READ(pid);
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
if (!validating && !isnan(pid.Kp)) {
|
||||
// Scale PID values since EEPROM values are unscaled
|
||||
thermalManager.temp_bed.pid.Kp = pid.Kp;
|
||||
thermalManager.temp_bed.pid.Ki = scalePID_i(pid.Ki);
|
||||
thermalManager.temp_bed.pid.Kd = scalePID_d(pid.Kd);
|
||||
}
|
||||
if (!validating && !isnan(pid.p))
|
||||
thermalManager.temp_bed.pid.set(pid);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -2051,15 +2022,11 @@ void MarlinSettings::postprocess() {
|
||||
// Heated Chamber PID
|
||||
//
|
||||
{
|
||||
PID_t pid;
|
||||
raw_pid_t pid;
|
||||
EEPROM_READ(pid);
|
||||
#if ENABLED(PIDTEMPCHAMBER)
|
||||
if (!validating && !isnan(pid.Kp)) {
|
||||
// Scale PID values since EEPROM values are unscaled
|
||||
thermalManager.temp_chamber.pid.Kp = pid.Kp;
|
||||
thermalManager.temp_chamber.pid.Ki = scalePID_i(pid.Ki);
|
||||
thermalManager.temp_chamber.pid.Kd = scalePID_d(pid.Kd);
|
||||
}
|
||||
if (!validating && !isnan(pid.p))
|
||||
thermalManager.temp_chamber.pid.set(pid);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -3142,11 +3109,13 @@ void MarlinSettings::reset() {
|
||||
#define PID_DEFAULT(N,E) DEFAULT_##N
|
||||
#endif
|
||||
HOTEND_LOOP() {
|
||||
PID_PARAM(Kp, e) = float(PID_DEFAULT(Kp, ALIM(e, defKp)));
|
||||
PID_PARAM(Ki, e) = scalePID_i(PID_DEFAULT(Ki, ALIM(e, defKi)));
|
||||
PID_PARAM(Kd, e) = scalePID_d(PID_DEFAULT(Kd, ALIM(e, defKd)));
|
||||
TERN_(PID_EXTRUSION_SCALING, PID_PARAM(Kc, e) = float(PID_DEFAULT(Kc, ALIM(e, defKc))));
|
||||
TERN_(PID_FAN_SCALING, PID_PARAM(Kf, e) = float(PID_DEFAULT(Kf, ALIM(e, defKf))));
|
||||
thermalManager.temp_hotend[e].pid.set(
|
||||
PID_DEFAULT(Kp, ALIM(e, defKp)),
|
||||
PID_DEFAULT(Ki, ALIM(e, defKi)),
|
||||
PID_DEFAULT(Kd, ALIM(e, defKd))
|
||||
OPTARG(PID_EXTRUSION_SCALING, PID_DEFAULT(Kc, ALIM(e, defKc)))
|
||||
OPTARG(PID_FAN_SCALING, PID_DEFAULT(Kf, ALIM(e, defKf)))
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -3160,9 +3129,7 @@ void MarlinSettings::reset() {
|
||||
//
|
||||
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
thermalManager.temp_bed.pid.Kp = DEFAULT_bedKp;
|
||||
thermalManager.temp_bed.pid.Ki = scalePID_i(DEFAULT_bedKi);
|
||||
thermalManager.temp_bed.pid.Kd = scalePID_d(DEFAULT_bedKd);
|
||||
thermalManager.temp_bed.pid.set(DEFAULT_bedKp, DEFAULT_bedKi, DEFAULT_bedKd);
|
||||
#endif
|
||||
|
||||
//
|
||||
@ -3170,9 +3137,7 @@ void MarlinSettings::reset() {
|
||||
//
|
||||
|
||||
#if ENABLED(PIDTEMPCHAMBER)
|
||||
thermalManager.temp_chamber.pid.Kp = DEFAULT_chamberKp;
|
||||
thermalManager.temp_chamber.pid.Ki = scalePID_i(DEFAULT_chamberKi);
|
||||
thermalManager.temp_chamber.pid.Kd = scalePID_d(DEFAULT_chamberKd);
|
||||
thermalManager.temp_chamber.pid.set(DEFAULT_chamberKp, DEFAULT_chamberKi, DEFAULT_chamberKd);
|
||||
#endif
|
||||
|
||||
//
|
||||
@ -3342,14 +3307,15 @@ void MarlinSettings::reset() {
|
||||
static_assert(COUNT(_filament_heat_capacity_permm) == HOTENDS, "FILAMENT_HEAT_CAPACITY_PERMM must have HOTENDS items.");
|
||||
|
||||
HOTEND_LOOP() {
|
||||
thermalManager.temp_hotend[e].constants.heater_power = _mpc_heater_power[e];
|
||||
thermalManager.temp_hotend[e].constants.block_heat_capacity = _mpc_block_heat_capacity[e];
|
||||
thermalManager.temp_hotend[e].constants.sensor_responsiveness = _mpc_sensor_responsiveness[e];
|
||||
thermalManager.temp_hotend[e].constants.ambient_xfer_coeff_fan0 = _mpc_ambient_xfer_coeff[e];
|
||||
MPC_t &constants = thermalManager.temp_hotend[e].constants;
|
||||
constants.heater_power = _mpc_heater_power[e];
|
||||
constants.block_heat_capacity = _mpc_block_heat_capacity[e];
|
||||
constants.sensor_responsiveness = _mpc_sensor_responsiveness[e];
|
||||
constants.ambient_xfer_coeff_fan0 = _mpc_ambient_xfer_coeff[e];
|
||||
#if ENABLED(MPC_INCLUDE_FAN)
|
||||
thermalManager.temp_hotend[e].constants.fan255_adjustment = _mpc_ambient_xfer_coeff_fan255[e] - _mpc_ambient_xfer_coeff[e];
|
||||
constants.fan255_adjustment = _mpc_ambient_xfer_coeff_fan255[e] - _mpc_ambient_xfer_coeff[e];
|
||||
#endif
|
||||
thermalManager.temp_hotend[e].constants.filament_heat_capacity_permm = _filament_heat_capacity_permm[e];
|
||||
constants.filament_heat_capacity_permm = _filament_heat_capacity_permm[e];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -597,7 +597,7 @@ volatile bool Temperature::raw_temps_ready = false;
|
||||
millis_t next_temp_ms = millis(), t1 = next_temp_ms, t2 = next_temp_ms;
|
||||
long t_high = 0, t_low = 0;
|
||||
|
||||
PID_t tune_pid = { 0, 0, 0 };
|
||||
raw_pid_t tune_pid = { 0, 0, 0 };
|
||||
celsius_float_t maxT = 0, minT = 10000;
|
||||
|
||||
const bool isbed = (heater_id == H_BED),
|
||||
@ -716,16 +716,16 @@ volatile bool Temperature::raw_temps_ready = false;
|
||||
pf = (ischamber || isbed) ? 0.2f : 0.6f,
|
||||
df = (ischamber || isbed) ? 1.0f / 3.0f : 1.0f / 8.0f;
|
||||
|
||||
tune_pid.Kp = Ku * pf;
|
||||
tune_pid.Ki = tune_pid.Kp * 2.0f / Tu;
|
||||
tune_pid.Kd = tune_pid.Kp * Tu * df;
|
||||
tune_pid.p = Ku * pf;
|
||||
tune_pid.i = tune_pid.p * 2.0f / Tu;
|
||||
tune_pid.d = tune_pid.p * Tu * df;
|
||||
|
||||
SERIAL_ECHOLNPGM(STR_KU, Ku, STR_TU, Tu);
|
||||
if (ischamber || isbed)
|
||||
SERIAL_ECHOLNPGM(" No overshoot");
|
||||
else
|
||||
SERIAL_ECHOLNPGM(STR_CLASSIC_PID);
|
||||
SERIAL_ECHOLNPGM(STR_KP, tune_pid.Kp, STR_KI, tune_pid.Ki, STR_KD, tune_pid.Kd);
|
||||
SERIAL_ECHOLNPGM(STR_KP, tune_pid.p, STR_KI, tune_pid.i, STR_KD, tune_pid.d);
|
||||
}
|
||||
}
|
||||
SHV((bias + d) >> 1);
|
||||
@ -795,39 +795,36 @@ volatile bool Temperature::raw_temps_ready = false;
|
||||
|
||||
#if EITHER(PIDTEMPBED, PIDTEMPCHAMBER)
|
||||
FSTR_P const estring = GHV(F("chamber"), F("bed"), FPSTR(NUL_STR));
|
||||
say_default_(); SERIAL_ECHOF(estring); SERIAL_ECHOLNPGM("Kp ", tune_pid.Kp);
|
||||
say_default_(); SERIAL_ECHOF(estring); SERIAL_ECHOLNPGM("Ki ", tune_pid.Ki);
|
||||
say_default_(); SERIAL_ECHOF(estring); SERIAL_ECHOLNPGM("Kd ", tune_pid.Kd);
|
||||
say_default_(); SERIAL_ECHOF(estring); SERIAL_ECHOLNPGM("Kp ", tune_pid.p);
|
||||
say_default_(); SERIAL_ECHOF(estring); SERIAL_ECHOLNPGM("Ki ", tune_pid.i);
|
||||
say_default_(); SERIAL_ECHOF(estring); SERIAL_ECHOLNPGM("Kd ", tune_pid.d);
|
||||
#else
|
||||
say_default_(); SERIAL_ECHOLNPGM("Kp ", tune_pid.Kp);
|
||||
say_default_(); SERIAL_ECHOLNPGM("Ki ", tune_pid.Ki);
|
||||
say_default_(); SERIAL_ECHOLNPGM("Kd ", tune_pid.Kd);
|
||||
say_default_(); SERIAL_ECHOLNPGM("Kp ", tune_pid.p);
|
||||
say_default_(); SERIAL_ECHOLNPGM("Ki ", tune_pid.i);
|
||||
say_default_(); SERIAL_ECHOLNPGM("Kd ", tune_pid.d);
|
||||
#endif
|
||||
|
||||
auto _set_hotend_pid = [](const uint8_t e, const PID_t &in_pid) {
|
||||
auto _set_hotend_pid = [](const uint8_t tool, const raw_pid_t &in_pid) {
|
||||
#if ENABLED(PIDTEMP)
|
||||
PID_PARAM(Kp, e) = in_pid.Kp;
|
||||
PID_PARAM(Ki, e) = scalePID_i(in_pid.Ki);
|
||||
PID_PARAM(Kd, e) = scalePID_d(in_pid.Kd);
|
||||
updatePID();
|
||||
#if ENABLED(PID_PARAMS_PER_HOTEND)
|
||||
thermalManager.temp_hotend[tool].pid.set(in_pid);
|
||||
#else
|
||||
UNUSED(e); UNUSED(in_pid);
|
||||
HOTEND_LOOP() thermalManager.temp_hotend[e].pid.set(in_pid);
|
||||
#endif
|
||||
updatePID();
|
||||
#endif
|
||||
UNUSED(tool); UNUSED(in_pid);
|
||||
};
|
||||
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
auto _set_bed_pid = [](const PID_t &in_pid) {
|
||||
temp_bed.pid.Kp = in_pid.Kp;
|
||||
temp_bed.pid.Ki = scalePID_i(in_pid.Ki);
|
||||
temp_bed.pid.Kd = scalePID_d(in_pid.Kd);
|
||||
auto _set_bed_pid = [](const raw_pid_t &in_pid) {
|
||||
temp_bed.pid.set(in_pid);
|
||||
};
|
||||
#endif
|
||||
|
||||
#if ENABLED(PIDTEMPCHAMBER)
|
||||
auto _set_chamber_pid = [](const PID_t &in_pid) {
|
||||
temp_chamber.pid.Kp = in_pid.Kp;
|
||||
temp_chamber.pid.Ki = scalePID_i(in_pid.Ki);
|
||||
temp_chamber.pid.Kd = scalePID_d(in_pid.Kd);
|
||||
auto _set_chamber_pid = [](const raw_pid_t &in_pid) {
|
||||
temp_chamber.pid.set(in_pid);
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -60,53 +60,6 @@ typedef enum : int8_t {
|
||||
H_NONE = -128
|
||||
} heater_id_t;
|
||||
|
||||
// PID storage
|
||||
typedef struct { float Kp, Ki, Kd; } PID_t;
|
||||
typedef struct { float Kp, Ki, Kd, Kc; } PIDC_t;
|
||||
typedef struct { float Kp, Ki, Kd, Kf; } PIDF_t;
|
||||
typedef struct { float Kp, Ki, Kd, Kc, Kf; } PIDCF_t;
|
||||
|
||||
typedef
|
||||
#if BOTH(PID_EXTRUSION_SCALING, PID_FAN_SCALING)
|
||||
PIDCF_t
|
||||
#elif ENABLED(PID_EXTRUSION_SCALING)
|
||||
PIDC_t
|
||||
#elif ENABLED(PID_FAN_SCALING)
|
||||
PIDF_t
|
||||
#else
|
||||
PID_t
|
||||
#endif
|
||||
hotend_pid_t;
|
||||
|
||||
#if ENABLED(PID_EXTRUSION_SCALING)
|
||||
typedef IF<(LPQ_MAX_LEN > 255), uint16_t, uint8_t>::type lpq_ptr_t;
|
||||
#endif
|
||||
|
||||
#define PID_PARAM(F,H) _PID_##F(TERN(PID_PARAMS_PER_HOTEND, H, 0 & H)) // Always use 'H' to suppress warning
|
||||
#define _PID_Kp(H) TERN(PIDTEMP, Temperature::temp_hotend[H].pid.Kp, NAN)
|
||||
#define _PID_Ki(H) TERN(PIDTEMP, Temperature::temp_hotend[H].pid.Ki, NAN)
|
||||
#define _PID_Kd(H) TERN(PIDTEMP, Temperature::temp_hotend[H].pid.Kd, NAN)
|
||||
#if ENABLED(PIDTEMP)
|
||||
#define _PID_Kc(H) TERN(PID_EXTRUSION_SCALING, Temperature::temp_hotend[H].pid.Kc, 1)
|
||||
#define _PID_Kf(H) TERN(PID_FAN_SCALING, Temperature::temp_hotend[H].pid.Kf, 0)
|
||||
#else
|
||||
#define _PID_Kc(H) 1
|
||||
#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
|
||||
float filament_heat_capacity_permm; // M306 H
|
||||
} MPC_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* States for ADC reading in the ISR
|
||||
*/
|
||||
@ -188,7 +141,15 @@ enum ADCSensorState : char {
|
||||
|
||||
#define ACTUAL_ADC_SAMPLES _MAX(int(MIN_ADC_ISR_LOOPS), int(SensorsReady))
|
||||
|
||||
//
|
||||
// PID
|
||||
//
|
||||
|
||||
typedef struct { float p, i, d; } raw_pid_t;
|
||||
typedef struct { float p, i, d, c, f; } raw_pidcf_t;
|
||||
|
||||
#if HAS_PID_HEATING
|
||||
|
||||
#define PID_K2 (1-float(PID_K1))
|
||||
#define PID_dT ((OVERSAMPLENR * float(ACTUAL_ADC_SAMPLES)) / (TEMP_TIMER_FREQUENCY))
|
||||
|
||||
@ -197,10 +158,116 @@ enum ADCSensorState : char {
|
||||
#define unscalePID_i(i) ( float(i) / PID_dT )
|
||||
#define scalePID_d(d) ( float(d) / PID_dT )
|
||||
#define unscalePID_d(d) ( float(d) * PID_dT )
|
||||
|
||||
typedef struct {
|
||||
float Kp, Ki, Kd;
|
||||
float p() const { return Kp; }
|
||||
float i() const { return unscalePID_i(Ki); }
|
||||
float d() const { return unscalePID_d(Kd); }
|
||||
float c() const { return 1; }
|
||||
float f() const { return 0; }
|
||||
void set_Kp(float p) { Kp = p; }
|
||||
void set_Ki(float i) { Ki = scalePID_i(i); }
|
||||
void set_Kd(float d) { Kd = scalePID_d(d); }
|
||||
void set_Kc(float) {}
|
||||
void set_Kf(float) {}
|
||||
void set(float p, float i, float d, float c=1, float f=0) { set_Kp(p); set_Ki(i); set_Kd(d); UNUSED(c); UNUSED(f); }
|
||||
void set(const raw_pid_t &raw) { set(raw.p, raw.i, raw.d); }
|
||||
void set(const raw_pidcf_t &raw) { set(raw.p, raw.i, raw.d); }
|
||||
} PID_t;
|
||||
|
||||
#endif
|
||||
|
||||
#if ENABLED(MPCTEMP)
|
||||
#if ENABLED(PIDTEMP)
|
||||
|
||||
typedef struct {
|
||||
float Kp, Ki, Kd, Kc;
|
||||
float p() const { return Kp; }
|
||||
float i() const { return unscalePID_i(Ki); }
|
||||
float d() const { return unscalePID_d(Kd); }
|
||||
float c() const { return Kc; }
|
||||
float f() const { return 0; }
|
||||
void set_Kp(float p) { Kp = p; }
|
||||
void set_Ki(float i) { Ki = scalePID_i(i); }
|
||||
void set_Kd(float d) { Kd = scalePID_d(d); }
|
||||
void set_Kc(float c) { Kc = c; }
|
||||
void set_Kf(float) {}
|
||||
void set(float p, float i, float d, float c=1, float f=0) { set_Kp(p); set_Ki(i); set_Kd(d); set_Kc(c); set_Kf(f); }
|
||||
void set(const raw_pid_t &raw) { set(raw.p, raw.i, raw.d); }
|
||||
void set(const raw_pidcf_t &raw) { set(raw.p, raw.i, raw.d, raw.c); }
|
||||
} PIDC_t;
|
||||
|
||||
typedef struct {
|
||||
float Kp, Ki, Kd, Kf;
|
||||
float p() const { return Kp; }
|
||||
float i() const { return unscalePID_i(Ki); }
|
||||
float d() const { return unscalePID_d(Kd); }
|
||||
float c() const { return 1; }
|
||||
float f() const { return Kf; }
|
||||
void set_Kp(float p) { Kp = p; }
|
||||
void set_Ki(float i) { Ki = scalePID_i(i); }
|
||||
void set_Kd(float d) { Kd = scalePID_d(d); }
|
||||
void set_Kc(float) {}
|
||||
void set_Kf(float f) { Kf = f; }
|
||||
void set(float p, float i, float d, float c=1, float f=0) { set_Kp(p); set_Ki(i); set_Kd(d); set_Kf(f); }
|
||||
void set(const raw_pid_t &raw) { set(raw.p, raw.i, raw.d); }
|
||||
void set(const raw_pidcf_t &raw) { set(raw.p, raw.i, raw.d, raw.f); }
|
||||
} PIDF_t;
|
||||
|
||||
typedef struct {
|
||||
float Kp, Ki, Kd, Kc, Kf;
|
||||
float p() const { return Kp; }
|
||||
float i() const { return unscalePID_i(Ki); }
|
||||
float d() const { return unscalePID_d(Kd); }
|
||||
float c() const { return Kc; }
|
||||
float f() const { return Kf; }
|
||||
void set_Kp(float p) { Kp = p; }
|
||||
void set_Ki(float i) { Ki = scalePID_i(i); }
|
||||
void set_Kd(float d) { Kd = scalePID_d(d); }
|
||||
void set_Kc(float c) { Kc = c; }
|
||||
void set_Kf(float f) { Kf = f; }
|
||||
void set(float p, float i, float d, float c=1, float f=0) { set_Kp(p); set_Ki(i); set_Kd(d); set_Kc(c); set_Kf(f); }
|
||||
void set(const raw_pid_t &raw) { set(raw.p, raw.i, raw.d); }
|
||||
void set(const raw_pidcf_t &raw) { set(raw.p, raw.i, raw.d, raw.c, raw.f); }
|
||||
} PIDCF_t;
|
||||
|
||||
typedef
|
||||
#if BOTH(PID_EXTRUSION_SCALING, PID_FAN_SCALING)
|
||||
PIDCF_t
|
||||
#elif ENABLED(PID_EXTRUSION_SCALING)
|
||||
PIDC_t
|
||||
#elif ENABLED(PID_FAN_SCALING)
|
||||
PIDF_t
|
||||
#else
|
||||
PID_t
|
||||
#endif
|
||||
hotend_pid_t;
|
||||
|
||||
#if ENABLED(PID_EXTRUSION_SCALING)
|
||||
typedef IF<(LPQ_MAX_LEN > 255), uint16_t, uint8_t>::type lpq_ptr_t;
|
||||
#endif
|
||||
|
||||
#if ENABLED(PID_PARAMS_PER_HOTEND)
|
||||
#define SET_HOTEND_PID(F,H,V) thermalManager.temp_hotend[H].pid.set_##F(V)
|
||||
#else
|
||||
#define SET_HOTEND_PID(F,_,V) do{ HOTEND_LOOP() thermalManager.temp_hotend[e].pid.set_##F(V); }while(0)
|
||||
#endif
|
||||
|
||||
#elif 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
|
||||
float filament_heat_capacity_permm; // M306 H
|
||||
} MPC_t;
|
||||
|
||||
#define MPC_dT ((OVERSAMPLENR * float(ACTUAL_ADC_SAMPLES)) / (TEMP_TIMER_FREQUENCY))
|
||||
|
||||
#endif
|
||||
|
||||
#if ENABLED(G26_MESH_VALIDATION) && EITHER(HAS_MARLINUI_MENU, EXTENSIBLE_UI)
|
||||
@ -218,7 +285,7 @@ public:
|
||||
inline void sample(const raw_adc_t s) { acc += s; }
|
||||
inline void update() { raw = acc; }
|
||||
void setraw(const raw_adc_t r) { raw = r; }
|
||||
raw_adc_t getraw() { return raw; }
|
||||
raw_adc_t getraw() const { return raw; }
|
||||
} temp_info_t;
|
||||
|
||||
#if HAS_TEMP_REDUNDANT
|
||||
@ -393,6 +460,7 @@ class Temperature {
|
||||
static const celsius_t hotend_maxtemp[HOTENDS];
|
||||
static celsius_t hotend_max_target(const uint8_t e) { return hotend_maxtemp[e] - (HOTEND_OVERSHOOT); }
|
||||
#endif
|
||||
|
||||
#if HAS_HEATED_BED
|
||||
static bed_info_t temp_bed;
|
||||
#endif
|
||||
@ -965,12 +1033,16 @@ class Temperature {
|
||||
static constexpr bool adaptive_fan_slowing = true;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Update the temp manager when PID values change
|
||||
*/
|
||||
// Update the temp manager when PID values change
|
||||
#if ENABLED(PIDTEMP)
|
||||
static void updatePID() {
|
||||
TERN_(PID_EXTRUSION_SCALING, pes_e_position = 0);
|
||||
static void updatePID() { TERN_(PID_EXTRUSION_SCALING, pes_e_position = 0); }
|
||||
static void setPID(const uint8_t hotend, const_float_t p, const_float_t i, const_float_t d) {
|
||||
#if ENABLED(PID_PARAMS_PER_HOTEND)
|
||||
temp_hotend[hotend].pid.set(p, i, d);
|
||||
#else
|
||||
HOTEND_LOOP() temp_hotend[e].pid.set(p, i, d);
|
||||
#endif
|
||||
updatePID();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -23,7 +23,7 @@ opt_enable USE_ZMAX_PLUG REPRAP_DISCOUNT_SMART_CONTROLLER LCD_PROGRESS_BAR LCD_P
|
||||
EEPROM_SETTINGS SDSUPPORT SD_REPRINT_LAST_SELECTED_FILE BINARY_FILE_TRANSFER \
|
||||
BLINKM PCA9533 PCA9632 RGB_LED RGB_LED_R_PIN RGB_LED_G_PIN RGB_LED_B_PIN LED_CONTROL_MENU \
|
||||
NEOPIXEL_LED NEOPIXEL_PIN CASE_LIGHT_ENABLE CASE_LIGHT_USE_NEOPIXEL CASE_LIGHT_MENU \
|
||||
PID_PARAMS_PER_HOTEND PID_AUTOTUNE_MENU PID_EDIT_MENU LCD_SHOW_E_TOTAL \
|
||||
PID_PARAMS_PER_HOTEND PID_AUTOTUNE_MENU PID_EDIT_MENU PID_EXTRUSION_SCALING LCD_SHOW_E_TOTAL \
|
||||
PRINTCOUNTER SERVICE_NAME_1 SERVICE_INTERVAL_1 LCD_BED_TRAMMING BED_TRAMMING_INCLUDE_CENTER \
|
||||
NOZZLE_PARK_FEATURE FILAMENT_RUNOUT_SENSOR FILAMENT_RUNOUT_DISTANCE_MM \
|
||||
ADVANCED_PAUSE_FEATURE FILAMENT_LOAD_UNLOAD_GCODES FILAMENT_UNLOAD_ALL_EXTRUDERS \
|
||||
|
Loading…
Reference in New Issue
Block a user