Skip to content

Commit

Permalink
verify_heater: Scale hysteresis duration check
Browse files Browse the repository at this point in the history
If a heater falls out of the target range, accumulate the temperature
differences to determine if an error should be raised.  This should
make it less likely to report an error for heaters that drift slightly
out of range, and it should make error reporting faster for heaters
that rapidly fall out of range.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
  • Loading branch information
KevinOConnor committed Mar 11, 2018
1 parent 57d342b commit 849f4ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
17 changes: 10 additions & 7 deletions config/example-extras.cfg
Expand Up @@ -133,15 +133,18 @@
# The amount of time (in seconds) that the heating_gain must be met
# in before an error is raised. The default is 20 seconds for
# extruders and 60 seconds for heater_bed.
#hysteresis: 10
#hysteresis: 5
# The difference between the target temperature and the current
# temperature for the heater to be considered within range of the
# target temperature. The default is 10.
#check_time: 15
# The amount of time (in seconds) a heater that has reached the
# target temperature (as defined by the hysteresis field) may fall
# outside the target temperature range before an error is
# raised. The default is 15.
# target temperature. The default is 5.
#max_error: 120
# The maximum temperature difference a heater that falls outside the
# target temperature range may accumulate before an error is
# raised. For example, if the target temperature is 200, the
# hysteresis is 5, the max_error is 120, and the temperature is
# reported at 185 degrees for 12 seconds then an error would be
# raised (or 24 seconds at 190, or 120 seconds at 194, etc.). The
# default is 120.


# Multi-stepper axes. On a cartesian style printer, the stepper
Expand Down
13 changes: 7 additions & 6 deletions klippy/extras/verify_heater.py
Expand Up @@ -11,16 +11,16 @@ def __init__(self, config):
self.printer = config.get_printer()
self.heater_name = config.get_name().split()[1]
self.heater = None
self.hysteresis = config.getfloat('hysteresis', 10., above=0.)
self.check_time = config.getfloat('check_time', 15., minval=1.)
self.hysteresis = config.getfloat('hysteresis', 5., minval=0.)
self.max_error = config.getfloat('max_error', 120., minval=0.)
self.heating_gain = config.getfloat('heating_gain', 2., above=0.)
default_gain_time = 20.
if self.heater_name == 'heater_bed':
default_gain_time = 60.
self.check_gain_time = config.getfloat(
'check_gain_time', default_gain_time, minval=1.)
self.met_target = False
self.last_target = self.goal_temp = 0.
self.last_target = self.goal_temp = self.error = 0.
self.fault_systime = self.printer.get_reactor().NEVER
def printer_state(self, state):
if state == 'connect':
Expand All @@ -33,20 +33,21 @@ def check_event(self, eventtime):
temp, target = self.heater.get_temp(eventtime)
if temp >= target - self.hysteresis:
# Temperature near target - reset checks
if not self.met_target:
if not self.met_target and target:
logging.info("Heater %s within range of %.3f",
self.heater_name, target)
self.met_target = True
self.fault_systime = eventtime + self.check_time
self.error = 0.
elif self.met_target:
self.error += (target - self.hysteresis) - temp
if target != self.last_target:
# Target changed - reset checks
logging.info("Heater %s approaching new target of %.3f",
self.heater_name, target)
self.met_target = False
self.goal_temp = temp + self.heating_gain
self.fault_systime = eventtime + self.check_gain_time
elif eventtime >= self.fault_systime:
elif self.error >= self.max_error:
# Failure due to inability to maintain target temperature
return self.heater_fault()
elif temp >= self.goal_temp:
Expand Down

0 comments on commit 849f4ed

Please sign in to comment.