Skip to content

Commit

Permalink
♻️ Encapsulate PID in class (#24389)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jul 15, 2022
1 parent 6789559 commit e4f85e8
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 298 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ void idle(bool no_stepper_sleep/*=false*/) {
manage_inactivity(no_stepper_sleep);

// Manage Heaters (and Watchdog)
thermalManager.manage_heater();
thermalManager.task();

// Max7219 heartbeat, animation, etc
TERN_(MAX7219_DEBUG, max7219.idle_tasks());
Expand Down
4 changes: 0 additions & 4 deletions Marlin/src/core/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,6 @@
#define STR_PID_DEBUG " PID_DEBUG "
#define STR_PID_DEBUG_INPUT ": Input "
#define STR_PID_DEBUG_OUTPUT " Output "
#define STR_PID_DEBUG_PTERM " pTerm "
#define STR_PID_DEBUG_ITERM " iTerm "
#define STR_PID_DEBUG_DTERM " dTerm "
#define STR_PID_DEBUG_CTERM " cTerm "
#define STR_INVALID_EXTRUDER_NUM " - Invalid extruder number !"
#define STR_MPC_AUTOTUNE "MPC Autotune"
#define STR_MPC_AUTOTUNE_START " start for " STR_E
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/core/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ void safe_delay(millis_t ms) {
while (ms > 50) {
ms -= 50;
delay(50);
thermalManager.manage_heater();
thermalManager.task();
}
delay(ms);
thermalManager.manage_heater(); // This keeps us safe if too many small safe_delay() calls are made
thermalManager.task(); // This keeps us safe if too many small safe_delay() calls are made
}

// A delay to provide brittle hosts time to receive bytes
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/motion/G2_G3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void plan_arc(

for (uint16_t i = 1; i < segments; i++) { // Iterate (segments-1) times

thermalManager.manage_heater();
thermalManager.task();
const millis_t ms = millis();
if (ELAPSED(ms, next_idle_ms)) {
next_idle_ms = ms + 200UL;
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ inline bool process_line_done(uint8_t &sis, char (&buff)[MAX_CMD_SIZE], int &ind
buff[ind] = '\0'; // Of course, I'm a Terminator.
const bool is_empty = (ind == 0); // An empty line?
if (is_empty)
thermalManager.manage_heater(); // Keep sensors satisfied
thermalManager.task(); // Keep sensors satisfied
else
ind = 0; // Start a new line
return is_empty; // Inform the caller
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/lcd/e3v2/jyersui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp)
Popup_Handler(ETemp);
else {
if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target - 2) {
if (thermalManager.temp_hotend[0].is_below_target(-2)) {
Popup_Handler(Heating);
thermalManager.wait_for_hotend(0);
}
Expand Down Expand Up @@ -1345,7 +1345,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
Popup_Handler(ETemp);
}
else {
if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target - 2) {
if (thermalManager.temp_hotend[0].is_below_target(-2)) {
Popup_Handler(Heating);
thermalManager.wait_for_hotend(0);
Redraw_Menu();
Expand Down Expand Up @@ -1732,7 +1732,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp)
Popup_Handler(ETemp);
else {
if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target - 2) {
if (thermalManager.temp_hotend[0].is_below_target(-2)) {
Popup_Handler(Heating);
thermalManager.wait_for_hotend(0);
}
Expand All @@ -1751,7 +1751,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
Popup_Handler(ETemp);
}
else {
if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target - 2) {
if (thermalManager.temp_hotend[0].is_below_target(-2)) {
Popup_Handler(Heating);
thermalManager.wait_for_hotend(0);
}
Expand All @@ -1769,7 +1769,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp)
Popup_Handler(ETemp);
else {
if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target - 2) {
if (thermalManager.temp_hotend[0].is_below_target(-2)) {
Popup_Handler(Heating);
thermalManager.wait_for_hotend(0);
}
Expand Down Expand Up @@ -4404,7 +4404,7 @@ void CrealityDWINClass::Popup_Control() {
if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp)
Popup_Handler(ETemp);
else {
if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target - 2) {
if (thermalManager.temp_hotend[0].is_below_target(-2)) {
Popup_Handler(Heating);
thermalManager.wait_for_hotend(0);
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/ui_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ namespace ExtUI {
}

void yield() {
if (!flags.printer_killed) thermalManager.manage_heater();
if (!flags.printer_killed) thermalManager.task();
}

void enableHeater(const extruder_t extruder) {
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/libs/buzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void Buzzer::tone(const uint16_t duration, const uint16_t frequency/*=0*/) {
if (!ui.sound_on) return;
while (buffer.isFull()) {
tick();
thermalManager.manage_heater();
thermalManager.task();
}
tone_t tone = { duration, frequency };
buffer.enqueue(tone);
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) {
next_idle_ms = ms + 200UL;
return idle();
}
thermalManager.manage_heater(); // Returns immediately on most calls
thermalManager.task(); // Returns immediately on most calls
}

#if IS_KINEMATIC
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/planner_bezier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void cubic_b_spline(

for (float t = 0; t < 1;) {

thermalManager.manage_heater();
thermalManager.task();
millis_t now = millis();
if (ELAPSED(now, next_idle_ms)) {
next_idle_ms = now + 200UL;
Expand Down
Loading

0 comments on commit e4f85e8

Please sign in to comment.