probe_eddy_current: Scale intermediate values within the "tap" sos filter

Scale the internal mcu values to units of milli-hz to reduce the
chance of roundoff error in the internal calculations.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor
2026-04-13 01:06:28 -04:00
parent 9c3ba2e3a5
commit 6b4aeb4c44
2 changed files with 11 additions and 6 deletions

View File

@@ -148,7 +148,9 @@ class LDC1612:
self.batch_bulk.add_client(cb)
def lookup_sensor_error(self, error):
return self._sensor_errors.get(error, "Unknown ldc1612 error")
def convert_frequency(self, freq):
def convert_raw_to_frequency(self, raw_value):
return raw_value * self.freq_conv
def convert_frequency_to_raw(self, freq):
return int(freq / self.freq_conv + 0.5)
# Measurement decoding
def _convert_samples(self, samples):

View File

@@ -429,7 +429,7 @@ class EddyDescend:
sos_filter.set_offset_scale(0, 1.)
self._trigger_analog.set_raw_range(0, MAX_VALID_RAW_VALUE)
trigger_freq = self._calibration.height_to_freq(self._descend_z)
conv_freq = self._sensor_helper.convert_frequency(trigger_freq)
conv_freq = self._sensor_helper.convert_frequency_to_raw(trigger_freq)
self._trigger_analog.set_trigger('gt', conv_freq)
# Probe session interface
def start_probe_session(self, gcmd):
@@ -528,15 +528,18 @@ class EddyTap:
def _prep_trigger_analog_tap(self, gcmd):
if not self._tap_threshold:
raise self._printer.command_error("Tap not configured")
# Setup mcu filter (scale internal values to milli-hz)
sos_filter = self._trigger_analog.get_sos_filter()
sos_filter.set_filter_design(self._filter_design)
sos_filter.set_offset_scale(0, 1., auto_offset=True)
FRAC_HZ = 1000.
s = FRAC_HZ * self._sensor_helper.convert_raw_to_frequency(1)
sos_filter.set_offset_scale(0, s, auto_offset=True)
self._trigger_analog.set_raw_range(0, MAX_VALID_RAW_VALUE)
convert_frequency = self._sensor_helper.convert_frequency
# Set mcu trigger to tap_threshold
tap_threshold = gcmd.get_float("TAP_THRESHOLD",
self._tap_threshold, above=0.)
raw_threshold = convert_frequency(tap_threshold)
self._trigger_analog.set_trigger('diff_peak_gt', raw_threshold)
samp_thresh = int(FRAC_HZ * tap_threshold + 0.5)
self._trigger_analog.set_trigger('diff_peak_gt', samp_thresh)
self._current_tap_threshold = tap_threshold
# Measurement analysis to determine "tap" position
def _validate_samples_time(self, measures, start_time, end_time):