Skip to content

Commit

Permalink
fixed compatibility with Klipper < v0.12.0-239
Browse files Browse the repository at this point in the history
  • Loading branch information
Frix-x committed Dec 16, 2024
1 parent 6376c84 commit af7ffac
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions shaketune/helpers/resonance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,15 @@ def vibrate_axis(self, axis_direction, min_freq=None, max_freq=None, hz_per_sec=
s_accel = base_s_accel

if s_period > 0:
ConsoleOutput.print('Using pulse with sweeping acceleration test')
gen = SweepingVibrationGenerator(final_min_f, final_max_f, final_aph, final_hps, s_accel, s_period)
else:
ConsoleOutput.print('Using pulse-only test')
gen = BaseVibrationGenerator(final_min_f, final_max_f, final_aph, final_hps)

test_seq = gen.gen_test()
ConsoleOutput.print(f'Test sequence generated ({len(test_seq)} steps)')
ConsoleOutput.print(f'Test sequence: {test_seq}')
self._run_test_sequence(axis_direction, test_seq)
self.toolhead.wait_moves()

Expand All @@ -216,15 +220,19 @@ def _run_test_sequence(self, axis_direction, test_seq):
X, Y, Z, E = toolhead.get_position()

old_max_accel = toolhead_info['max_accel']
old_mcr = toolhead_info.get('minimum_cruise_ratio', 1.0)

# Set velocity limits
if test_seq:
max_accel = max(abs(a) for _, a, _ in test_seq)
else:
max_accel = old_max_accel # no moves, just default

gcode.run_script_from_command(f'SET_VELOCITY_LIMIT ACCEL={max_accel:.3f} MINIMUM_CRUISE_RATIO=0')
if 'minimum_cruise_ratio' in toolhead_info: # minimum_cruise_ratio found: Klipper >= v0.12.0-239
old_mcr = toolhead_info['minimum_cruise_ratio']
gcode.run_script_from_command(f'SET_VELOCITY_LIMIT ACCEL={max_accel} MINIMUM_CRUISE_RATIO=0')
else: # minimum_cruise_ratio not found: Klipper < v0.12.0-239
old_mcr = None
gcode.run_script_from_command(f'SET_VELOCITY_LIMIT ACCEL={max_accel}')

# Disable input shaper if present
input_shaper = self.toolhead.printer.lookup_object('input_shaper', None)
Expand Down Expand Up @@ -281,10 +289,11 @@ def _run_test_sequence(self, axis_direction, test_seq):
gcode.run_script_from_command(f'M204 S={old_max_accel:.3f}')
toolhead.move([X + ddX, Y + ddY, Z + ddZ, E], abs(last_v))

# Restore original limits
gcode.run_script_from_command(
f'SET_VELOCITY_LIMIT ACCEL={old_max_accel:.3f} MINIMUM_CRUISE_RATIO={old_mcr:.3f}'
)
# Restore the previous acceleration values
if old_mcr is not None: # minimum_cruise_ratio found: Klipper >= v0.12.0-239
gcode.run_script_from_command(f'SET_VELOCITY_LIMIT ACCEL={old_max_accel} MINIMUM_CRUISE_RATIO={old_mcr}')
else: # minimum_cruise_ratio not found: Klipper < v0.12.0-239
gcode.run_script_from_command(f'SET_VELOCITY_LIMIT ACCEL={old_max_accel}')

# Re-enable input shaper if disabled
if input_shaper is not None:
Expand Down

0 comments on commit af7ffac

Please sign in to comment.