Skip to content

Commit

Permalink
fixed compatibility with the new version of Klipper
Browse files Browse the repository at this point in the history
  • Loading branch information
Frix-x committed Dec 15, 2024
1 parent 2b4ea98 commit 58d4be6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
21 changes: 17 additions & 4 deletions shaketune/commands/axes_shaper_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
Expand Down
21 changes: 17 additions & 4 deletions shaketune/commands/compare_belts_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

This comment has been minimized.

Copy link
@rschaeuble

rschaeuble Dec 19, 2024

Looks like three times the same code.
It might be good to extract that into a function that is then called at the three call sites that need the data.

This comment has been minimized.

Copy link
@Frix-x

Frix-x Dec 19, 2024

Author Owner

Oh indeed, you're right 👍
If you want to open a PR, I'll merge it.

I'm currently working on the new sweeping test compatibility and will do this later if you've not done it in the meantime :)

This comment has been minimized.

Copy link
@rschaeuble

rschaeuble Dec 19, 2024

I'll be happy to, if you can wait until weekend ;-)
Won't find the time to implement and test it before then, as the printer is constantly busy.

This comment has been minimized.

Copy link
@rschaeuble

rschaeuble Dec 22, 2024

@Frix-x: what's the minimum supported Python version? I'm not sure which language features I may use.

This comment has been minimized.

Copy link
@Frix-x

Frix-x Dec 23, 2024

Author Owner

At the moment it's Python 3.9 as the minimum version so you should be pretty free to use most of the new stuff :)

This comment has been minimized.

Copy link
@rschaeuble

rschaeuble Dec 24, 2024

Here you are: #182

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)
Expand All @@ -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')

Expand Down Expand Up @@ -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):
Expand Down
13 changes: 11 additions & 2 deletions shaketune/commands/excitate_axis_at_freq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 58d4be6

Please sign in to comment.