Skip to content

Commit

Permalink
temperature_probe: add max_valid_temp option
Browse files Browse the repository at this point in the history
Signed-off-by:  Eric Callahan <[email protected]>
  • Loading branch information
Arksine authored and KevinOConnor committed Sep 1, 2024
1 parent f71d2c7 commit 40d6a06
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions klippy/extras/temperature_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ def __init__(self, config, sensor):
self.cal_temp = config.getfloat("calibration_temp", 0.)
self.drift_calibration = None
self.calibration_samples = None
self.max_valid_temp = config.getfloat("max_validation_temp", 60.)
self.dc_min_temp = config.getfloat("drift_calibration_min_temp", 0.)
dc = config.getlists(
"drift_calibration", None, seps=(',', '\n'), parser=float
Expand All @@ -503,7 +504,8 @@ def __init__(self, config, sensor):
)
self.drift_calibration = [Polynomial2d(*coefs) for coefs in dc]
cal = self.drift_calibration
self._check_calibration(cal, self.dc_min_temp, config.error)
start_temp, end_temp = self.dc_min_temp, self.max_valid_temp
self._check_calibration(cal, start_temp, end_temp, config.error)
low_poly = self.drift_calibration[-1]
self.min_freq = min([low_poly(temp) for temp in range(121)])
cal_str = "\n".join([repr(p) for p in cal])
Expand Down Expand Up @@ -638,13 +640,15 @@ def finish_calibration(self, success):
"calbration error, not enough samples"
)
min_temp, _ = cal_samples[0][0]
max_temp, _ = cal_samples[-1][0]
polynomials = []
for i, coords in enumerate(cal_samples):
height = .05 + i * .5
poly = Polynomial2d.fit(coords)
polynomials.append(poly)
logging.info("Polynomial at Z=%.2f: %s" % (height, repr(poly)))
self._check_calibration(polynomials, min_temp)
end_vld_temp = max(self.max_valid_temp, max_temp)
self._check_calibration(polynomials, min_temp, end_vld_temp)
coef_cfg = "\n" + "\n".join([str(p) for p in polynomials])
configfile = self.printer.lookup_object('configfile')
configfile.set(self.name, "drift_calibration", coef_cfg)
Expand All @@ -656,10 +660,11 @@ def finish_calibration(self, success):
% (self.name, len(polynomials))
)

def _check_calibration(self, calibration, start_temp, error=None):
def _check_calibration(self, calibration, start_temp, end_temp, error=None):
error = error or self.printer.command_error
start = int(start_temp)
for temp in range(start, 121, 1):
end = int(end_temp) + 1
for temp in range(start, end, 1):
last_freq = calibration[0](temp)
for i, poly in enumerate(calibration[1:]):
next_freq = poly(temp)
Expand Down

0 comments on commit 40d6a06

Please sign in to comment.