From 9f4da8b80d01cdfc0558934145997ed990b5bff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Boisselier?= Date: Sun, 19 May 2024 11:36:27 +0200 Subject: [PATCH] added accel_per_hertz to the graphs --- shaketune/measurement/axes_input_shaper.py | 2 +- shaketune/measurement/belts_comparison.py | 4 +++ shaketune/post_processing/graph_belts.py | 5 ++-- shaketune/post_processing/graph_creator.py | 8 +++++- shaketune/post_processing/graph_shaper.py | 31 ++++++++++++++++------ 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/shaketune/measurement/axes_input_shaper.py b/shaketune/measurement/axes_input_shaper.py index 48b4d64..87d7734 100644 --- a/shaketune/measurement/axes_input_shaper.py +++ b/shaketune/measurement/axes_input_shaper.py @@ -60,7 +60,7 @@ def axes_shaper_calibration(gcmd, config, st_thread: ShakeTuneThread) -> None: # Configure the graph creator creator = st_thread.get_graph_creator() - creator.configure(scv, max_sm) + creator.configure(scv, max_sm, accel_per_hz) # set the needed acceleration values for the test toolhead_info = toolhead.get_status(systime) diff --git a/shaketune/measurement/belts_comparison.py b/shaketune/measurement/belts_comparison.py index e0d312d..047967d 100644 --- a/shaketune/measurement/belts_comparison.py +++ b/shaketune/measurement/belts_comparison.py @@ -56,6 +56,10 @@ def compare_belts_responses(gcmd, config, st_thread: ShakeTuneThread) -> None: toolhead.manual_move(point, feedrate_travel) + # Configure the graph creator + creator = st_thread.get_graph_creator() + creator.configure(accel_per_hz) + # set the needed acceleration values for the test toolhead_info = toolhead.get_status(systime) old_accel = toolhead_info['max_accel'] diff --git a/shaketune/post_processing/graph_belts.py b/shaketune/post_processing/graph_belts.py index 16858b1..ff6b506 100644 --- a/shaketune/post_processing/graph_belts.py +++ b/shaketune/post_processing/graph_belts.py @@ -452,7 +452,7 @@ def compute_signal_data(data, max_freq): ###################################################################### -def belts_calibration(lognames, klipperdir='~/klipper', max_freq=200.0, st_version=None): +def belts_calibration(lognames, klipperdir='~/klipper', max_freq=200.0, accel_per_hz=None, st_version='unknown'): global shaper_calibrate shaper_calibrate = setup_klipper_import(klipperdir) @@ -538,6 +538,7 @@ def main(): opts = optparse.OptionParser(usage) opts.add_option('-o', '--output', type='string', dest='output', default=None, help='filename of output graph') opts.add_option('-f', '--max_freq', type='float', default=200.0, help='maximum frequency to graph') + opts.add_option('--accel_per_hz', type='float', default=None, help='accel_per_hz used during the measurement') opts.add_option( '-k', '--klipper_dir', type='string', dest='klipperdir', default='~/klipper', help='main klipper directory' ) @@ -547,7 +548,7 @@ def main(): if options.output is None: opts.error('You must specify an output file.png to use the script (option -o)') - fig = belts_calibration(args, options.klipperdir, options.max_freq) + fig = belts_calibration(args, options.klipperdir, options.max_freq, options.accel_per_hz, 'unknown') fig.savefig(options.output, dpi=150) diff --git a/shaketune/post_processing/graph_creator.py b/shaketune/post_processing/graph_creator.py index 9316bcb..305eeb5 100644 --- a/shaketune/post_processing/graph_creator.py +++ b/shaketune/post_processing/graph_creator.py @@ -96,6 +96,9 @@ class BeltsGraphCreator(GraphCreator): self._setup_folder('belts') + def configure(self, accel_per_hz: float = None) -> None: + self._accel_per_hz = accel_per_hz + def create_graph(self) -> None: lognames = self._move_and_prepare_files( glob_pattern='shaketune-belt_*.csv', @@ -105,6 +108,7 @@ class BeltsGraphCreator(GraphCreator): fig = belts_calibration( lognames=[str(path) for path in lognames], klipperdir=str(self._config.klipper_folder), + accel_per_hz=self._accel_per_hz, st_version=self._version, ) self._save_figure_and_cleanup(fig, lognames) @@ -134,9 +138,10 @@ class ShaperGraphCreator(GraphCreator): self._setup_folder('shaper') - def configure(self, scv: float, max_smoothing: float = None) -> None: + def configure(self, scv: float, max_smoothing: float = None, accel_per_hz: float = None) -> None: self._scv = scv self._max_smoothing = max_smoothing + self._accel_per_hz = accel_per_hz def create_graph(self) -> None: if not self._scv: @@ -152,6 +157,7 @@ class ShaperGraphCreator(GraphCreator): klipperdir=str(self._config.klipper_folder), max_smoothing=self._max_smoothing, scv=self._scv, + accel_per_hz=self._accel_per_hz, st_version=self._version, ) self._save_figure_and_cleanup(fig, lognames, lognames[0].stem.split('_')[-1]) diff --git a/shaketune/post_processing/graph_shaper.py b/shaketune/post_processing/graph_shaper.py index ca89901..741a3af 100644 --- a/shaketune/post_processing/graph_shaper.py +++ b/shaketune/post_processing/graph_shaper.py @@ -294,7 +294,15 @@ def plot_spectrogram(ax, t, bins, pdata, peaks, max_freq): ###################################################################### -def shaper_calibration(lognames, klipperdir='~/klipper', max_smoothing=None, scv=5.0, max_freq=200.0, st_version=None): +def shaper_calibration( + lognames, + klipperdir='~/klipper', + max_smoothing=None, + scv=5.0, + max_freq=200.0, + accel_per_hz=None, + st_version='unknown', +): global shaper_calibrate shaper_calibrate = setup_klipper_import(klipperdir) @@ -359,19 +367,23 @@ def shaper_calibration(lognames, klipperdir='~/klipper', max_smoothing=None, scv dt = datetime.strptime(f'{filename_parts[1]} {filename_parts[2]}', '%Y%m%d %H%M%S') title_line2 = dt.strftime('%x %X') + ' -- ' + filename_parts[3].upper().split('.')[0] + ' axis' if compat: - title_line3 = '| Compatibility mode with older Klipper,' - title_line4 = '| and no custom S&T parameters are used!' + title_line3 = '| Older Klipper version detected, damping ratio' + title_line4 = '| and SCV are not used for filter recommendations!' + title_line5 = f'| Accel per Hz used: {accel_per_hz}' if accel_per_hz is not None else '' else: - title_line3 = '| Square corner velocity: ' + str(scv) + 'mm/s' - title_line4 = '| Max allowed smoothing: ' + str(max_smoothing) + title_line3 = f'| Square corner velocity: {scv}mm/s' + title_line4 = f'| Max allowed smoothing: {max_smoothing}' + title_line5 = f'| Accel per Hz used: {accel_per_hz}' if accel_per_hz is not None else '' except Exception: ConsoleOutput.print('Warning: CSV filename look to be different than expected (%s)' % (lognames[0])) title_line2 = lognames[0].split('/')[-1] title_line3 = '' title_line4 = '' + title_line5 = '' fig.text(0.12, 0.957, title_line2, ha='left', va='top', fontsize=16, color=KLIPPAIN_COLORS['dark_purple']) - fig.text(0.58, 0.960, title_line3, ha='left', va='top', fontsize=10, color=KLIPPAIN_COLORS['dark_purple']) - fig.text(0.58, 0.946, title_line4, ha='left', va='top', fontsize=10, color=KLIPPAIN_COLORS['dark_purple']) + fig.text(0.58, 0.965, title_line3, ha='left', va='top', fontsize=10, color=KLIPPAIN_COLORS['dark_purple']) + fig.text(0.58, 0.951, title_line4, ha='left', va='top', fontsize=10, color=KLIPPAIN_COLORS['dark_purple']) + fig.text(0.58, 0.919, title_line5, ha='left', va='top', fontsize=10, color=KLIPPAIN_COLORS['dark_purple']) # Plot the graphs plot_freq_response( @@ -401,6 +413,7 @@ def main(): opts.add_option( '--scv', '--square_corner_velocity', type='float', dest='scv', default=5.0, help='square corner velocity' ) + opts.add_option('--accel_per_hz', type='float', default=None, help='accel_per_hz used during the measurement') opts.add_option( '-k', '--klipper_dir', type='string', dest='klipperdir', default='~/klipper', help='main klipper directory' ) @@ -412,7 +425,9 @@ def main(): if options.max_smoothing is not None and options.max_smoothing < 0.05: opts.error('Too small max_smoothing specified (must be at least 0.05)') - fig = shaper_calibration(args, options.klipperdir, options.max_smoothing, options.scv, options.max_freq) + fig = shaper_calibration( + args, options.klipperdir, options.max_smoothing, options.scv, options.max_freq, options.accel_per_hz, 'unknown' + ) fig.savefig(options.output, dpi=150)