Skip to content

Commit

Permalink
resonance_tester: Added vibrations test with motion
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Butyugin <[email protected]>
  • Loading branch information
dmbutyugin committed Sep 30, 2024
1 parent 99dec31 commit 10cf416
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
46 changes: 45 additions & 1 deletion klippy/extras/resonance_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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())]
Expand Down
4 changes: 3 additions & 1 deletion klippy/extras/shaper_calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit 10cf416

Please sign in to comment.