diff --git a/klippy/extras/resonance_tester.py b/klippy/extras/resonance_tester.py index f5c64fedf8f2..24fbac30c4e1 100644 --- a/klippy/extras/resonance_tester.py +++ b/klippy/extras/resonance_tester.py @@ -85,6 +85,46 @@ def get_params(self): def get_max_freq(self): return self.freq_end +class VibrationsWithMotionTestGenerator: + def __init__(self, config): + self.vibration_generator = VibrationPulseTestGenerator(config) + self.motion_accel = config.getfloat('motion_accel', 400., above=0.) + self.motion_period = config.getfloat('motion_period', 1.2, above=0.) + def prepare_test(self, gcmd): + self.vibration_generator.prepare_test(gcmd) + self.motion_accel = gcmd.get_float("MOTION_ACCEL", + self.motion_accel, above=0.) + self.motion_period = gcmd.get_float("MOTION_PERIOD", + self.motion_period, above=0.) + def gen_test(self): + test_seq = self.vibration_generator.gen_test() + accel_fraction = 0.125 + t_rem = self.motion_period * accel_fraction + res = [] + last_t = 0. + sig = 1. + accel_fraction = 0.375 + for next_t, accel in test_seq: + t_seg = next_t - last_t + while t_rem <= t_seg: + last_t += t_rem + res.append((last_t, accel + self.motion_accel * sig)) + t_seg -= t_rem + t_rem = self.motion_period * accel_fraction + accel_fraction = 0.5 + sig = -sig + t_rem -= t_seg + res.append((next_t, accel + self.motion_accel * sig)) + last_t = next_t + return res + def get_params(self): + params = self.vibration_generator.get_params() + params.update({'motion_accel': self.motion_accel, + 'motion_period': self.motion_period}) + return params + def get_max_freq(self): + return self.freq_end + class ResonanceTestExecutor: def __init__(self, config): self.printer = config.get_printer() @@ -162,7 +202,11 @@ class ResonanceTester: def __init__(self, config): self.printer = config.get_printer() self.move_speed = config.getfloat('move_speed', 50., above=0.) - self.generator = VibrationPulseTestGenerator(config) + test_methods = { + 'vibrations': VibrationPulseTestGenerator, + 'sweeping_vibrations': VibrationsWithMotionTestGenerator} + test_method = config.getchoice('method', test_methods, 'vibrations') + self.generator = test_method(config) self.executor = ResonanceTestExecutor(config) if not config.get('accel_chip_x', None): self.accel_chip_names = [('xy', config.get('accel_chip').strip())] diff --git a/klippy/extras/shaper_calibrate.py b/klippy/extras/shaper_calibrate.py index 6891fefb3bf9..f497171f67c0 100644 --- a/klippy/extras/shaper_calibrate.py +++ b/klippy/extras/shaper_calibrate.py @@ -48,7 +48,9 @@ def normalize_to_frequencies(self): # Avoid division by zero errors psd /= self.freq_bins + .1 # Remove low-frequency noise - psd[self.freq_bins < MIN_FREQ] = 0. + low_freqs = self.freq_bins < 2. * MIN_FREQ + psd[low_freqs] *= self.numpy.exp( + -(2. * MIN_FREQ / (self.freq_bins[low_freqs] + .1))**2 + 1.) def get_psd(self, axis='all'): return self._psd_map[axis]