Skip to content

Commit

Permalink
resonance_tester: Support zero sweeping period
Browse files Browse the repository at this point in the history
This restores the previous test behavior. Also renamed the parameters
to use sweeping_ prefix to match the test name.

Signed-off-by: Dmitry Butyugin <[email protected]>
  • Loading branch information
dmbutyugin committed Nov 14, 2024
1 parent 42c62e2 commit adce95f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
15 changes: 8 additions & 7 deletions docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1820,13 +1820,14 @@ section of the measuring resonances guide for more information on
# hz_per_sec. Small values make the test slow, and the large values
# will decrease the precision of the test. The default value is 1.0
# (Hz/sec == sec^-2).
#motion_accel: 400
# An acceleration of slow moves. Available only for sweeping_vibrations
# test method. The default is 400 mm/sec^2.
#motion_period: 1.2
# A period of slow moves. Must not be set to a too small value in order
# to not poison the measurements. Available only for sweeping_vibrations
# test method. The default is 1.2 sec which is a good all-round choice.
#sweeping_accel: 400
# An acceleration of slow sweeping moves. Available only for
# sweeping_vibrations test method. The default is 400 mm/sec^2.
#sweeping_period: 1.2
# A period of slow sweeping moves. Must not be set to a too small
# value in order to not poison the measurements. Available only for
# sweeping_vibrations test method. The default is 1.2 sec which is
# a good all-round choice.
```

## Config file helpers
Expand Down
34 changes: 20 additions & 14 deletions klippy/extras/resonance_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,27 @@ def get_params(self):
def get_max_freq(self):
return self.freq_end

class VibrationsWithMotionTestGenerator:
class SweepingVibrationsTestGenerator:
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.)
self.sweeping_accel = config.getfloat('sweeping_accel', 400., above=0.)
self.sweeping_period = config.getfloat('sweeping_period', 1.2,
minval=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.)
self.test_sweeping_accel = gcmd.get_float(
"SWEEPING_ACCEL", self.sweeping_accel, above=0.)
self.test_sweeping_period = gcmd.get_float(
"SWEEPING_PERIOD", self.sweeping_period, minval=0.)
def gen_test(self):
test_seq = self.vibration_generator.gen_test()
accel_fraction = math.sqrt(2.0) * 0.125
t_rem = self.motion_period * accel_fraction
if self.test_sweeping_period:
t_rem = self.test_sweeping_period * accel_fraction
sweeping_accel = self.test_sweeping_accel
else:
t_rem = math.inf
sweeping_accel = 0.
res = []
last_t = 0.
sig = 1.
Expand All @@ -110,19 +116,19 @@ def gen_test(self):
t_seg = next_t - last_t
while t_rem <= t_seg:
last_t += t_rem
res.append((last_t, accel + self.motion_accel * sig))
res.append((last_t, accel + sweeping_accel * sig))
t_seg -= t_rem
t_rem = self.motion_period * accel_fraction
t_rem = self.test_sweeping_period * accel_fraction
accel_fraction = 0.5
sig = -sig
t_rem -= t_seg
res.append((next_t, accel + self.motion_accel * sig))
res.append((next_t, accel + sweeping_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})
params.update({'sweeping_accel': self.sweeping_accel,
'sweeping_period': self.sweeping_period})
return params
def get_max_freq(self):
return self.vibration_generator.get_max_freq()
Expand Down Expand Up @@ -206,7 +212,7 @@ def __init__(self, config):
self.move_speed = config.getfloat('move_speed', 50., above=0.)
test_methods = {
'vibrations': VibrationPulseTestGenerator,
'sweeping_vibrations': VibrationsWithMotionTestGenerator}
'sweeping_vibrations': SweepingVibrationsTestGenerator}
test_method = config.getchoice('method', test_methods, 'vibrations')
self.generator = test_method(config)
self.executor = ResonanceTestExecutor(config)
Expand Down

0 comments on commit adce95f

Please sign in to comment.