Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@

//#define PID_EDIT_MENU // Add PID editing to the "Advanced Settings" menu. (~700 bytes of flash)
//#define PID_AUTOTUNE_MENU // Add PID auto-tuning to the "Advanced Settings" menu. (~250 bytes of flash)
//#define DISABLE_M303_AUTOTUNE // Disable the M303 PID autotune command to save ~2.7K bytes of flash.
#endif

// @section safety
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ void GcodeSuite::process_parsed_command(bool no_ok/*=false*/) {
case 302: M302(); break; // M302: Allow cold extrudes (set the minimum extrude temperature)
#endif

#if HAS_PID_HEATING
#if HAS_PID_AUTOTUNE
case 303: M303(); break; // M303: PID autotune
#endif

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ class GcodeSuite {
static void M302();
#endif

#if HAS_PID_HEATING
#if HAS_PID_AUTOTUNE
static void M303();
#endif

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/gcode/temp/M303.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "../../inc/MarlinConfig.h"

#if HAS_PID_HEATING
#if HAS_PID_AUTOTUNE

#include "../gcode.h"
#include "../queue.h" // for flush_tx
Expand Down Expand Up @@ -85,4 +85,4 @@ void GcodeSuite::M303() {
queue.flush_rx();
}

#endif // HAS_PID_HEATING
#endif // HAS_PID_AUTOTUNE
5 changes: 5 additions & 0 deletions Marlin/src/inc/Conditionals-5-post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2731,6 +2731,11 @@
#define HAS_PID_HEATING 1
#endif

// PID autotune (M303 command)
#if HAS_PID_HEATING && DISABLED(DISABLE_M303_AUTOTUNE)
#define HAS_PID_AUTOTUNE 1
#endif

// Thermal protection
#if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
#define WATCH_HOTENDS 1
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,12 @@ static_assert(NUM_SERVOS <= NUM_SERVO_PLUGS, "NUM_SERVOS (or some servo index) i
#endif
#endif


/* PID autotune (M303 command) */
#if ALL(PID_AUTOTUNE_MENU, DISABLE_M303_AUTOTUNE)
#error "Can't enable PID_AUTOTUNE_MENU and DISABLE_M303_AUTOTUNE at the same time."
#endif

/**
* Bed Heating Options - PID vs Limit Switching
*/
Expand Down
30 changes: 16 additions & 14 deletions Marlin/src/lcd/dwin/proui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1695,21 +1695,23 @@ void dwinLevelingDone() {

#if HAS_PID_HEATING

void dwinStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
hmiData.pidCycles = count;
switch (hid) {
#if ENABLED(PIDTEMP)
case 0 ... HOTENDS - 1: hmiData.hotendPIDT = temp; break;
#endif
#if ENABLED(PIDTEMPBED)
case H_BED: hmiData.bedPIDT = temp; break;
#endif
#if ENABLED(PIDTEMPCHAMBER)
case H_CHAMBER: hmiData.chamberPIDT = temp; break;
#endif
default: break;
#if HAS_PID_AUTOTUNE
void dwinStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
hmiData.pidCycles = count;
switch (hid) {
#if ENABLED(PIDTEMP)
case 0 ... HOTENDS - 1: hmiData.hotendPIDT = temp; break;
#endif
#if ENABLED(PIDTEMPBED)
case H_BED: hmiData.bedPIDT = temp; break;
#endif
#if ENABLED(PIDTEMPCHAMBER)
case H_CHAMBER: hmiData.chamberPIDT = temp; break;
#endif
default: break;
}
}
}
#endif

void dwinPIDTuning(tempcontrol_t result) {
hmiValue.tempControl = result;
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/lcd/dwin/proui/dwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ void drawMaxAccelMenu();
// PID
#if HAS_PID_HEATING
#include "../../../module/temperature.h"
void dwinStartM303(const int count, const heater_id_t hid, const celsius_t temp);
#if HAS_PID_AUTOTUNE
void dwinStartM303(const int count, const heater_id_t hid, const celsius_t temp);
#endif
void dwinPIDTuning(tempcontrol_t result);
#if ANY(PID_AUTOTUNE_MENU, PID_EDIT_MENU)
#if ENABLED(PIDTEMP)
Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/lcd/dwin/proui/proui_extui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,11 @@ namespace ExtUI {
}
}

void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
dwinStartM303(count, hid, temp);
}
#if HAS_PID_AUTOTUNE
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
dwinStartM303(count, hid, temp);
}
#endif

#endif

Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/lcd/extui/anycubic_chiron/chiron_extui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,11 @@ namespace ExtUI {
void onPIDTuning(const pidresult_t rst) {
// Called for temperature PID tuning result
}
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#if HAS_PID_AUTOTUNE
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#endif
#endif

#if ENABLED(MPC_AUTOTUNE)
Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/lcd/extui/anycubic_i3mega/anycubic_extui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,11 @@ namespace ExtUI {
void onPIDTuning(const pidresult_t rst) {
// Called for temperature PID tuning result
}
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#if HAS_PID_AUTOTUNE
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#endif
#endif

#if ENABLED(MPC_AUTOTUNE)
Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/lcd/extui/anycubic_vyper/vyper_extui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,11 @@ namespace ExtUI {
void onPIDTuning(const pidresult_t rst) {
// Called for temperature PID tuning result
}
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#if HAS_PID_AUTOTUNE
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#endif
#endif

#if ENABLED(MPC_AUTOTUNE)
Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/lcd/extui/dgus/dgus_extui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,11 @@ namespace ExtUI {
}
screen.gotoScreen(DGUS_SCREEN_MAIN);
}
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#if HAS_PID_AUTOTUNE
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#endif
#endif

#if ENABLED(MPC_AUTOTUNE)
Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/lcd/extui/dgus_e3s1pro/dgus_e3s1pro_extui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ namespace ExtUI {
// Called for temperature PID tuning result
screen.pidTuning(rst);
}
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#if HAS_PID_AUTOTUNE
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#endif
#endif

#if ENABLED(MPC_AUTOTUNE)
Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/lcd/extui/dgus_reloaded/dgus_reloaded_extui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,11 @@ namespace ExtUI {
// Called for temperature PID tuning result
screen.pidTuning(rst);
}
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#if HAS_PID_AUTOTUNE
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#endif
#endif

#if ENABLED(MPC_AUTOTUNE)
Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/lcd/extui/example/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@ namespace ExtUI {
case PID_DONE: break;
}
}
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#if HAS_PID_AUTOTUNE
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#endif
#endif

#if ENABLED(MPC_AUTOTUNE)
Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_extui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,11 @@ namespace ExtUI {
}
GOTO_SCREEN(StatusScreen);
}
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#if HAS_PID_AUTOTUNE
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#endif
#endif // HAS_PID_HEATING

#if ENABLED(MPC_AUTOTUNE)
Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/lcd/extui/ia_creality/ia_creality_extui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,11 @@ void onPostprocessSettings() {}
#endif
onStatusChanged(F("PID Tune Finished"));
}
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#if HAS_PID_AUTOTUNE
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#endif
#endif

#if ENABLED(MPC_AUTOTUNE)
Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/lcd/extui/malyan/malyan_extui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,11 @@ namespace ExtUI {
}
}

void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#if HAS_PID_AUTOTUNE
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#endif

#endif

Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/lcd/extui/nextion/nextion_extui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ namespace ExtUI {
// Called for temperature PID tuning result
nextion.panelInfo(37);
}
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#if HAS_PID_AUTOTUNE
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp) {
// Called by M303 to update the UI
}
#endif
#endif

#if ENABLED(MPC_AUTOTUNE)
Expand Down
16 changes: 10 additions & 6 deletions Marlin/src/lcd/extui/ui_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,9 +935,11 @@ namespace ExtUI {
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);
}
#if HAS_PID_AUTOTUNE
void startPIDTune(const celsius_t temp, extruder_t tool) {
thermalManager.PID_autotune(temp, heater_id_t(tool), 8, true);
}
#endif
#endif

#if ENABLED(PIDTEMPBED)
Expand All @@ -949,9 +951,11 @@ namespace ExtUI {
thermalManager.temp_bed.pid.set(p, i, d);
}

void startBedPIDTune(const celsius_t temp) {
thermalManager.PID_autotune(temp, H_BED, 4, true);
}
#if HAS_PID_AUTOTUNE
void startBedPIDTune(const celsius_t temp) {
thermalManager.PID_autotune(temp, H_BED, 4, true);
}
#endif
#endif

void injectCommands_P(PGM_P const gcode) { queue.inject_P(gcode); }
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/lcd/extui/ui_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,9 @@ namespace ExtUI {
#endif
#if HAS_PID_HEATING
void onPIDTuning(const pidresult_t rst);
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp);
#if HAS_PID_AUTOTUNE
void onStartM303(const int count, const heater_id_t hid, const celsius_t temp);
#endif
#endif
#if ENABLED(MPC_AUTOTUNE)
void onMPCTuning(const mpcresult_t rst);
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ void Temperature::factory_reset() {

} // factory_reset

#if HAS_PID_HEATING
#if HAS_PID_AUTOTUNE

inline void say_default_() { SERIAL_ECHOPGM("#define DEFAULT_"); }

Expand Down Expand Up @@ -1031,7 +1031,7 @@ void Temperature::factory_reset() {
return;
}

#endif // HAS_PID_HEATING
#endif // HAS_PID_AUTOTUNE

#if ENABLED(MPC_AUTOTUNE)

Expand Down
10 changes: 6 additions & 4 deletions Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -1257,16 +1257,18 @@ class Temperature {

static bool tuning_idle(const millis_t &ms);

/**
* M303 PID auto-tuning for hotends or bed
*/
#if HAS_PID_HEATING

#if HAS_PID_DEBUG
static bool pid_debug_flag;
#endif

static void PID_autotune(const celsius_t target, const heater_id_t heater_id, const int8_t ncycles, const bool set_result=false);
/**
* M303 PID auto-tuning for hotends or bed
*/
#if HAS_PID_AUTOTUNE
static void PID_autotune(const celsius_t target, const heater_id_t heater_id, const int8_t ncycles, const bool set_result=false);
#endif // HAS_PID_AUTOTUNE

// Update the temp manager when PID values change
#if ENABLED(PIDTEMP)
Expand Down