From b98d103a265ba67b8798864d1d1905aad2f4963d Mon Sep 17 00:00:00 2001 From: Zeanon Date: Mon, 17 Jun 2024 19:49:37 +0200 Subject: [PATCH] Make frequencies default on [resonance_tester] settings (#119) --- shaketune/commands/axes_shaper_calibration.py | 25 +++++++++---------- shaketune/commands/compare_belts_responses.py | 20 ++++++++------- shaketune/dummy_macros.cfg | 16 ++++++------ 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/shaketune/commands/axes_shaper_calibration.py b/shaketune/commands/axes_shaper_calibration.py index 6b919cf..f616e11 100644 --- a/shaketune/commands/axes_shaper_calibration.py +++ b/shaketune/commands/axes_shaper_calibration.py @@ -17,14 +17,20 @@ from .accelerometer import Accelerometer def axes_shaper_calibration(gcmd, config, st_process: ShakeTuneProcess) -> None: - min_freq = gcmd.get_float('FREQ_START', default=5, minval=1) - max_freq = gcmd.get_float('FREQ_END', default=133.33, minval=1) + printer = config.get_printer() + toolhead = printer.lookup_object('toolhead') + res_tester = printer.lookup_object('resonance_tester') + 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) 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() if axis_input not in {'x', 'y', 'all'}: raise gcmd.error('AXIS selection invalid. Should be either x, y, or all!') - scv = gcmd.get_float('SCV', default=None, minval=0) + scv = gcmd.get_float('SCV', default=toolhead_info['square_corner_velocity'], minval=0) max_sm = gcmd.get_float('MAX_SMOOTHING', default=None, minval=0) feedrate_travel = gcmd.get_float('TRAVEL_SPEED', default=120.0, minval=20.0) z_height = gcmd.get_float('Z_HEIGHT', default=None, minval=1) @@ -32,18 +38,11 @@ def axes_shaper_calibration(gcmd, config, st_process: ShakeTuneProcess) -> None: if accel_per_hz == '': accel_per_hz = None - printer = config.get_printer() - gcode = printer.lookup_object('gcode') - toolhead = printer.lookup_object('toolhead') - res_tester = printer.lookup_object('resonance_tester') - systime = printer.get_reactor().monotonic() - - if scv is None: - toolhead_info = toolhead.get_status(systime) - scv = toolhead_info['square_corner_velocity'] - if accel_per_hz is None: accel_per_hz = res_tester.test.accel_per_hz + + gcode = printer.lookup_object('gcode') + max_accel = max_freq * accel_per_hz # Move to the starting point diff --git a/shaketune/commands/compare_belts_responses.py b/shaketune/commands/compare_belts_responses.py index f2964f1..4342989 100644 --- a/shaketune/commands/compare_belts_responses.py +++ b/shaketune/commands/compare_belts_responses.py @@ -18,9 +18,14 @@ from .accelerometer import Accelerometer def compare_belts_responses(gcmd, config, st_process: ShakeTuneProcess) -> None: - min_freq = gcmd.get_float('FREQ_START', default=5.0, minval=1) - max_freq = gcmd.get_float('FREQ_END', default=133.33, minval=1) - hz_per_sec = gcmd.get_float('HZ_PER_SEC', default=1.0, minval=1) + printer = config.get_printer() + toolhead = printer.lookup_object('toolhead') + 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) + 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) z_height = gcmd.get_float('Z_HEIGHT', default=None, minval=1) @@ -28,14 +33,11 @@ def compare_belts_responses(gcmd, config, st_process: ShakeTuneProcess) -> None: if accel_per_hz == '': accel_per_hz = None - printer = config.get_printer() - gcode = printer.lookup_object('gcode') - toolhead = printer.lookup_object('toolhead') - res_tester = printer.lookup_object('resonance_tester') - systime = printer.get_reactor().monotonic() - if accel_per_hz is None: accel_per_hz = res_tester.test.accel_per_hz + + gcode = printer.lookup_object('gcode') + max_accel = max_freq * accel_per_hz # Configure the graph creator diff --git a/shaketune/dummy_macros.cfg b/shaketune/dummy_macros.cfg index 99a2501..8a9f4c9 100644 --- a/shaketune/dummy_macros.cfg +++ b/shaketune/dummy_macros.cfg @@ -45,15 +45,15 @@ gcode: [gcode_macro COMPARE_BELTS_RESPONSES] description: dummy gcode: - {% set freq_start = params.FREQ_START|default(5) %} - {% set freq_end = params.FREQ_END|default(133.33) %} + {% set freq_start = params.FREQ_START %} + {% set freq_end = params.FREQ_END %} {% set hz_per_sec = params.HZ_PER_SEC|default(1) %} {% set accel_per_hz = params.ACCEL_PER_HZ %} {% set travel_speed = params.TRAVEL_SPEED|default(120) %} {% set z_height = params.Z_HEIGHT %} {% set params_filtered = { - "FREQ_START": freq_start, - "FREQ_END": freq_end, + "FREQ_START": freq_start if freq_start is not none else '', + "FREQ_END": freq_end if freq_end is not none else '', "HZ_PER_SEC": hz_per_sec, "ACCEL_PER_HZ": accel_per_hz if accel_per_hz is not none else '', "TRAVEL_SPEED": travel_speed, @@ -65,8 +65,8 @@ gcode: [gcode_macro AXES_SHAPER_CALIBRATION] description: dummy gcode: - {% set freq_start = params.FREQ_START|default(5) %} - {% set freq_end = params.FREQ_END|default(133.33) %} + {% set freq_start = params.FREQ_START %} + {% set freq_end = params.FREQ_END %} {% set hz_per_sec = params.HZ_PER_SEC|default(1) %} {% set accel_per_hz = params.ACCEL_PER_HZ %} {% set axis = params.AXIS|default('all') %} @@ -75,8 +75,8 @@ gcode: {% set travel_speed = params.TRAVEL_SPEED|default(120) %} {% set z_height = params.Z_HEIGHT %} {% set params_filtered = { - "FREQ_START": freq_start, - "FREQ_END": freq_end, + "FREQ_START": freq_start if freq_start is not none else '', + "FREQ_END": freq_end if freq_end is not none else '', "HZ_PER_SEC": hz_per_sec, "ACCEL_PER_HZ": accel_per_hz if accel_per_hz is not none else '', "AXIS": axis,