🧑‍💻 Add Temperature::is_above_target

This commit is contained in:
Scott Lahteine
2023-01-03 19:40:23 -06:00
parent 984a758621
commit 0e72c90f49
3 changed files with 29 additions and 28 deletions

View File

@@ -1213,7 +1213,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp)
Popup_Handler(ETemp); Popup_Handler(ETemp);
else { else {
if (thermalManager.temp_hotend[0].is_below_target(-2)) { if (thermalManager.temp_hotend[0].is_below_target(2)) {
Popup_Handler(Heating); Popup_Handler(Heating);
thermalManager.wait_for_hotend(0); thermalManager.wait_for_hotend(0);
} }
@@ -1356,7 +1356,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
Popup_Handler(ETemp); Popup_Handler(ETemp);
} }
else { else {
if (thermalManager.temp_hotend[0].is_below_target(-2)) { if (thermalManager.temp_hotend[0].is_below_target(2)) {
Popup_Handler(Heating); Popup_Handler(Heating);
thermalManager.wait_for_hotend(0); thermalManager.wait_for_hotend(0);
Redraw_Menu(); Redraw_Menu();
@@ -1743,7 +1743,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp)
Popup_Handler(ETemp); Popup_Handler(ETemp);
else { else {
if (thermalManager.temp_hotend[0].is_below_target(-2)) { if (thermalManager.temp_hotend[0].is_below_target(2)) {
Popup_Handler(Heating); Popup_Handler(Heating);
thermalManager.wait_for_hotend(0); thermalManager.wait_for_hotend(0);
} }
@@ -1762,7 +1762,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
Popup_Handler(ETemp); Popup_Handler(ETemp);
} }
else { else {
if (thermalManager.temp_hotend[0].is_below_target(-2)) { if (thermalManager.temp_hotend[0].is_below_target(2)) {
Popup_Handler(Heating); Popup_Handler(Heating);
thermalManager.wait_for_hotend(0); thermalManager.wait_for_hotend(0);
} }
@@ -1780,7 +1780,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp)
Popup_Handler(ETemp); Popup_Handler(ETemp);
else { else {
if (thermalManager.temp_hotend[0].is_below_target(-2)) { if (thermalManager.temp_hotend[0].is_below_target(2)) {
Popup_Handler(Heating); Popup_Handler(Heating);
thermalManager.wait_for_hotend(0); thermalManager.wait_for_hotend(0);
} }
@@ -4505,7 +4505,7 @@ void CrealityDWINClass::Popup_Control() {
if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp)
Popup_Handler(ETemp); Popup_Handler(ETemp);
else { else {
if (thermalManager.temp_hotend[0].is_below_target(-2)) { if (thermalManager.temp_hotend[0].is_below_target(2)) {
Popup_Handler(Heating); Popup_Handler(Heating);
thermalManager.wait_for_hotend(0); thermalManager.wait_for_hotend(0);
} }

View File

@@ -1599,22 +1599,25 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
#endif #endif
#if HEATER_IDLE_HANDLER #if HEATER_IDLE_HANDLER
if (heater_idle[IDLE_INDEX_BED].timed_out) { const bool bed_timed_out = heater_idle[IDLE_INDEX_BED].timed_out;
if (bed_timed_out) {
temp_bed.soft_pwm_amount = 0; temp_bed.soft_pwm_amount = 0;
if (DISABLED(PIDTEMPBED)) WRITE_HEATER_BED(LOW); if (DISABLED(PIDTEMPBED)) WRITE_HEATER_BED(LOW);
} }
else #else
constexpr bool bed_timed_out = false;
#endif #endif
{
if (!bed_timed_out) {
#if ENABLED(PIDTEMPBED) #if ENABLED(PIDTEMPBED)
temp_bed.soft_pwm_amount = WITHIN(temp_bed.celsius, BED_MINTEMP, BED_MAXTEMP) ? (int)get_pid_output_bed() >> 1 : 0; temp_bed.soft_pwm_amount = WITHIN(temp_bed.celsius, BED_MINTEMP, BED_MAXTEMP) ? (int)get_pid_output_bed() >> 1 : 0;
#else #else
// Check if temperature is within the correct band // Check if temperature is within the correct band
if (WITHIN(temp_bed.celsius, BED_MINTEMP, BED_MAXTEMP)) { if (WITHIN(temp_bed.celsius, BED_MINTEMP, BED_MAXTEMP)) {
#if ENABLED(BED_LIMIT_SWITCHING) #if ENABLED(BED_LIMIT_SWITCHING)
if (temp_bed.celsius >= temp_bed.target + BED_HYSTERESIS) if (temp_bed.is_above_target((BED_HYSTERESIS) - 1))
temp_bed.soft_pwm_amount = 0; temp_bed.soft_pwm_amount = 0;
else if (temp_bed.is_below_target(-(BED_HYSTERESIS) + 1)) else if (temp_bed.is_below_target((BED_HYSTERESIS) - 1))
temp_bed.soft_pwm_amount = MAX_BED_POWER >> 1; temp_bed.soft_pwm_amount = MAX_BED_POWER >> 1;
#else // !PIDTEMPBED && !BED_LIMIT_SWITCHING #else // !PIDTEMPBED && !BED_LIMIT_SWITCHING
temp_bed.soft_pwm_amount = temp_bed.is_below_target() ? MAX_BED_POWER >> 1 : 0; temp_bed.soft_pwm_amount = temp_bed.is_below_target() ? MAX_BED_POWER >> 1 : 0;
@@ -1641,7 +1644,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
#endif #endif
#if ENABLED(THERMAL_PROTECTION_CHAMBER) #if ENABLED(THERMAL_PROTECTION_CHAMBER)
if (degChamber() > CHAMBER_MAXTEMP) maxtemp_error(H_CHAMBER); if (degChamber() > (CHAMBER_MAXTEMP)) maxtemp_error(H_CHAMBER);
#endif #endif
#if WATCH_CHAMBER #if WATCH_CHAMBER
@@ -1669,13 +1672,12 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
#if CHAMBER_FAN_MODE == 0 #if CHAMBER_FAN_MODE == 0
fan_chamber_pwm = CHAMBER_FAN_BASE; fan_chamber_pwm = CHAMBER_FAN_BASE;
#elif CHAMBER_FAN_MODE == 1 #elif CHAMBER_FAN_MODE == 1
fan_chamber_pwm = (temp_chamber.celsius > temp_chamber.target) ? (CHAMBER_FAN_BASE) + (CHAMBER_FAN_FACTOR) * (temp_chamber.celsius - temp_chamber.target) : 0; fan_chamber_pwm = temp_chamber.is_above_target() ? (CHAMBER_FAN_BASE) + (CHAMBER_FAN_FACTOR) * (temp_chamber.celsius - temp_chamber.target) : 0;
#elif CHAMBER_FAN_MODE == 2 #elif CHAMBER_FAN_MODE == 2
fan_chamber_pwm = (CHAMBER_FAN_BASE) + (CHAMBER_FAN_FACTOR) * ABS(temp_chamber.celsius - temp_chamber.target); fan_chamber_pwm = (CHAMBER_FAN_BASE) + (CHAMBER_FAN_FACTOR) * ABS(temp_chamber.celsius - temp_chamber.target);
if (temp_chamber.soft_pwm_amount) if (temp_chamber.soft_pwm_amount) fan_chamber_pwm += (CHAMBER_FAN_FACTOR) * 2;
fan_chamber_pwm += (CHAMBER_FAN_FACTOR) * 2;
#elif CHAMBER_FAN_MODE == 3 #elif CHAMBER_FAN_MODE == 3
fan_chamber_pwm = CHAMBER_FAN_BASE + _MAX((CHAMBER_FAN_FACTOR) * (temp_chamber.celsius - temp_chamber.target), 0); fan_chamber_pwm = (CHAMBER_FAN_BASE) + _MAX((CHAMBER_FAN_FACTOR) * (temp_chamber.celsius - temp_chamber.target), 0);
#endif #endif
NOMORE(fan_chamber_pwm, 255); NOMORE(fan_chamber_pwm, 255);
set_fan_speed(CHAMBER_FAN_INDEX, fan_chamber_pwm); set_fan_speed(CHAMBER_FAN_INDEX, fan_chamber_pwm);
@@ -1688,7 +1690,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
#ifndef MIN_COOLING_SLOPE_DEG_CHAMBER_VENT #ifndef MIN_COOLING_SLOPE_DEG_CHAMBER_VENT
#define MIN_COOLING_SLOPE_DEG_CHAMBER_VENT 1.5 #define MIN_COOLING_SLOPE_DEG_CHAMBER_VENT 1.5
#endif #endif
if (!flag_chamber_excess_heat && temp_chamber.celsius - temp_chamber.target >= HIGH_EXCESS_HEAT_LIMIT) { if (!flag_chamber_excess_heat && temp_chamber.is_above_target((HIGH_EXCESS_HEAT_LIMIT) - 1)) {
// Open vent after MIN_COOLING_SLOPE_TIME_CHAMBER_VENT seconds if the // Open vent after MIN_COOLING_SLOPE_TIME_CHAMBER_VENT seconds if the
// temperature didn't drop at least MIN_COOLING_SLOPE_DEG_CHAMBER_VENT // temperature didn't drop at least MIN_COOLING_SLOPE_DEG_CHAMBER_VENT
if (next_cool_check_ms_2 == 0 || ELAPSED(ms, next_cool_check_ms_2)) { if (next_cool_check_ms_2 == 0 || ELAPSED(ms, next_cool_check_ms_2)) {
@@ -1702,7 +1704,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
next_cool_check_ms_2 = 0; next_cool_check_ms_2 = 0;
old_temp = 9999; old_temp = 9999;
} }
if (flag_chamber_excess_heat && (temp_chamber.target - temp_chamber.celsius >= LOW_EXCESS_HEAT_LIMIT)) if (flag_chamber_excess_heat && temp_chamber.is_above_target((LOW_EXCESS_HEAT_LIMIT) - 1))
flag_chamber_excess_heat = false; flag_chamber_excess_heat = false;
#endif #endif
} }
@@ -1734,9 +1736,9 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
} }
else { else {
#if ENABLED(CHAMBER_LIMIT_SWITCHING) #if ENABLED(CHAMBER_LIMIT_SWITCHING)
if (temp_chamber.celsius >= temp_chamber.target + TEMP_CHAMBER_HYSTERESIS) if (temp_chamber.is_above_target((TEMP_CHAMBER_HYSTERESIS) - 1))
temp_chamber.soft_pwm_amount = 0; temp_chamber.soft_pwm_amount = 0;
else if (temp_chamber.is_below_target(-(TEMP_CHAMBER_HYSTERESIS) + 1)) else if (temp_chamber.is_below_target((TEMP_CHAMBER_HYSTERESIS) - 1))
temp_chamber.soft_pwm_amount = (MAX_CHAMBER_POWER) >> 1; temp_chamber.soft_pwm_amount = (MAX_CHAMBER_POWER) >> 1;
#else #else
temp_chamber.soft_pwm_amount = temp_chamber.is_below_target() ? (MAX_CHAMBER_POWER) >> 1 : 0; temp_chamber.soft_pwm_amount = temp_chamber.is_below_target() ? (MAX_CHAMBER_POWER) >> 1 : 0;
@@ -1788,20 +1790,18 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
if (temp_cooler.target == 0) temp_cooler.target = COOLER_MIN_TARGET; if (temp_cooler.target == 0) temp_cooler.target = COOLER_MIN_TARGET;
if (ELAPSED(ms, next_cooler_check_ms)) { if (ELAPSED(ms, next_cooler_check_ms)) {
next_cooler_check_ms = ms + COOLER_CHECK_INTERVAL; next_cooler_check_ms = ms + COOLER_CHECK_INTERVAL;
if (temp_cooler.celsius > temp_cooler.target) { if (temp_cooler.is_above_target()) { // too warm?
temp_cooler.soft_pwm_amount = temp_cooler.celsius > temp_cooler.target ? MAX_COOLER_POWER : 0; temp_cooler.soft_pwm_amount = MAX_COOLER_POWER;
flag_cooler_state = temp_cooler.soft_pwm_amount > 0 ? true : false; // used to allow M106 fan control when cooler is disabled
#if ENABLED(COOLER_FAN) #if ENABLED(COOLER_FAN)
int16_t fan_cooler_pwm = (COOLER_FAN_BASE) + (COOLER_FAN_FACTOR) * ABS(temp_cooler.celsius - temp_cooler.target); const int16_t fan_cooler_pwm = (COOLER_FAN_BASE) + (COOLER_FAN_FACTOR) * ABS(temp_cooler.celsius - temp_cooler.target);
NOMORE(fan_cooler_pwm, 255); set_fan_speed(COOLER_FAN_INDEX, _MIN(fan_cooler_pwm, 255)); // Set cooler fan pwm
set_fan_speed(COOLER_FAN_INDEX, fan_cooler_pwm); // Set cooler fan pwm
cooler_fan_flush_ms = ms + 5000; cooler_fan_flush_ms = ms + 5000;
#endif #endif
} }
else { else {
temp_cooler.soft_pwm_amount = 0; temp_cooler.soft_pwm_amount = 0;
#if ENABLED(COOLER_FAN) #if ENABLED(COOLER_FAN)
set_fan_speed(COOLER_FAN_INDEX, temp_cooler.celsius > temp_cooler.target - 2 ? COOLER_FAN_BASE : 0); set_fan_speed(COOLER_FAN_INDEX, temp_cooler.is_above_target(-2) ? COOLER_FAN_BASE : 0);
#endif #endif
WRITE_HEATER_COOLER(LOW); WRITE_HEATER_COOLER(LOW);
} }

View File

@@ -421,7 +421,8 @@ public:
typedef struct HeaterInfo : public TempInfo { typedef struct HeaterInfo : public TempInfo {
celsius_t target; celsius_t target;
uint8_t soft_pwm_amount; uint8_t soft_pwm_amount;
bool is_below_target(const celsius_t offs=0) const { return (celsius < (target + offs)); } bool is_below_target(const celsius_t offs=0) const { return (target - celsius > offs); } // celsius < target - offs
bool is_above_target(const celsius_t offs=0) const { return (celsius - target > offs); } // celsius > target + offs
} heater_info_t; } heater_info_t;
// A heater with PID stabilization // A heater with PID stabilization