From 58d4be6f398d81c03a0e4debc6a06caedc8dc892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Boisselier?= Date: Sun, 15 Dec 2024 19:46:46 +0100 Subject: [PATCH] fixed compatibility with the new version of Klipper --- shaketune/commands/axes_shaper_calibration.py | 21 +++++++++++++++---- shaketune/commands/compare_belts_responses.py | 21 +++++++++++++++---- shaketune/commands/excitate_axis_at_freq.py | 13 ++++++++++-- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/shaketune/commands/axes_shaper_calibration.py b/shaketune/commands/axes_shaper_calibration.py index a4615cf..4c17586 100644 --- a/shaketune/commands/axes_shaper_calibration.py +++ b/shaketune/commands/axes_shaper_calibration.py @@ -23,8 +23,22 @@ def axes_shaper_calibration(gcmd, config, st_process: ShakeTuneProcess) -> None: systime = printer.get_reactor().monotonic() toolhead_info = toolhead.get_status(systime) - min_freq = gcmd.get_float('FREQ_START', default=res_tester.test.min_freq, minval=1) - max_freq = gcmd.get_float('FREQ_END', default=res_tester.test.max_freq, minval=1) + # Get the default values for the frequency range and the acceleration per Hz + if hasattr(res_tester, 'test'): + # Old Klipper code (before Dec 6, 2024: https://github.com/Klipper3d/klipper/commit/16b4b6b302ac3ffcd55006cd76265aad4e26ecc8) + default_min_freq = res_tester.test.min_freq + default_max_freq = res_tester.test.max_freq + default_accel_per_hz = res_tester.test.accel_per_hz + test_points = res_tester.test.get_start_test_points() + else: + # New Klipper code (after Dec 6, 2024) with the sweeping test + default_min_freq = res_tester.generator.vibration_generator.min_freq + default_max_freq = res_tester.generator.vibration_generator.max_freq + default_accel_per_hz = res_tester.generator.vibration_generator.accel_per_hz + test_points = res_tester.probe_points + + min_freq = gcmd.get_float('FREQ_START', default=default_min_freq, minval=1) + max_freq = gcmd.get_float('FREQ_END', default=default_max_freq, minval=1) hz_per_sec = gcmd.get_float('HZ_PER_SEC', default=1, minval=1) accel_per_hz = gcmd.get_float('ACCEL_PER_HZ', default=None) axis_input = gcmd.get('AXIS', default='all').lower() @@ -39,14 +53,13 @@ def axes_shaper_calibration(gcmd, config, st_process: ShakeTuneProcess) -> None: accel_per_hz = None if accel_per_hz is None: - accel_per_hz = res_tester.test.accel_per_hz + accel_per_hz = default_accel_per_hz gcode = printer.lookup_object('gcode') max_accel = max_freq * accel_per_hz # Move to the starting point - test_points = res_tester.test.get_start_test_points() if len(test_points) > 1: raise gcmd.error('Only one test point in the [resonance_tester] section is supported by Shake&Tune.') if test_points[0] == (-1, -1, -1): diff --git a/shaketune/commands/compare_belts_responses.py b/shaketune/commands/compare_belts_responses.py index d7a662d..7b0aefc 100644 --- a/shaketune/commands/compare_belts_responses.py +++ b/shaketune/commands/compare_belts_responses.py @@ -23,8 +23,22 @@ def compare_belts_responses(gcmd, config, st_process: ShakeTuneProcess) -> None: res_tester = printer.lookup_object('resonance_tester') systime = printer.get_reactor().monotonic() - min_freq = gcmd.get_float('FREQ_START', default=res_tester.test.min_freq, minval=1) - max_freq = gcmd.get_float('FREQ_END', default=res_tester.test.max_freq, minval=1) + # Get the default values for the frequency range and the acceleration per Hz + if hasattr(res_tester, 'test'): + # Old Klipper code (before Dec 6, 2024: https://github.com/Klipper3d/klipper/commit/16b4b6b302ac3ffcd55006cd76265aad4e26ecc8) + default_min_freq = res_tester.test.min_freq + default_max_freq = res_tester.test.max_freq + default_accel_per_hz = res_tester.test.accel_per_hz + test_points = res_tester.test.get_start_test_points() + else: + # New Klipper code (after Dec 6, 2024) with the sweeping test + default_min_freq = res_tester.generator.vibration_generator.min_freq + default_max_freq = res_tester.generator.vibration_generator.max_freq + default_accel_per_hz = res_tester.generator.vibration_generator.accel_per_hz + test_points = res_tester.probe_points + + min_freq = gcmd.get_float('FREQ_START', default=default_min_freq, minval=1) + max_freq = gcmd.get_float('FREQ_END', default=default_max_freq, minval=1) hz_per_sec = gcmd.get_float('HZ_PER_SEC', default=1, minval=1) accel_per_hz = gcmd.get_float('ACCEL_PER_HZ', default=None) feedrate_travel = gcmd.get_float('TRAVEL_SPEED', default=120.0, minval=20.0) @@ -34,7 +48,7 @@ def compare_belts_responses(gcmd, config, st_process: ShakeTuneProcess) -> None: accel_per_hz = None if accel_per_hz is None: - accel_per_hz = res_tester.test.accel_per_hz + accel_per_hz = default_accel_per_hz gcode = printer.lookup_object('gcode') @@ -63,7 +77,6 @@ def compare_belts_responses(gcmd, config, st_process: ShakeTuneProcess) -> None: accelerometer = Accelerometer(printer.lookup_object(accel_chip), printer.get_reactor()) # Move to the starting point - test_points = res_tester.test.get_start_test_points() if len(test_points) > 1: raise gcmd.error('Only one test point in the [resonance_tester] section is supported by Shake&Tune.') if test_points[0] == (-1, -1, -1): diff --git a/shaketune/commands/excitate_axis_at_freq.py b/shaketune/commands/excitate_axis_at_freq.py index c6f544f..14f574e 100644 --- a/shaketune/commands/excitate_axis_at_freq.py +++ b/shaketune/commands/excitate_axis_at_freq.py @@ -52,11 +52,20 @@ def excitate_axis_at_freq(gcmd, config, st_process: ShakeTuneProcess) -> None: res_tester = printer.lookup_object('resonance_tester') systime = printer.get_reactor().monotonic() + # Get the default values for the acceleration per Hz and the test points + if hasattr(res_tester, 'test'): + # Old Klipper code (before Dec 6, 2024: https://github.com/Klipper3d/klipper/commit/16b4b6b302ac3ffcd55006cd76265aad4e26ecc8) + default_accel_per_hz = res_tester.test.accel_per_hz + test_points = res_tester.test.get_start_test_points() + else: + # New Klipper code (after Dec 6, 2024) with the sweeping test + default_accel_per_hz = res_tester.generator.vibration_generator.accel_per_hz + test_points = res_tester.probe_points + if accel_per_hz is None: - accel_per_hz = res_tester.test.accel_per_hz + accel_per_hz = default_accel_per_hz # Move to the starting point - test_points = res_tester.test.get_start_test_points() if len(test_points) > 1: raise gcmd.error('Only one test point in the [resonance_tester] section is supported by Shake&Tune.') if test_points[0] == (-1, -1, -1):