aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/calibrate_shaper.py
diff options
context:
space:
mode:
authorDmitry Butyugin <dmbutyugin@google.com>2020-12-05 23:48:03 +0100
committerKevinOConnor <kevin@koconnor.net>2020-12-19 11:58:35 -0500
commit5ccc17042c03667e41abf770b3087294a4f78810 (patch)
tree13850cda299063fc79fe20cca7fd7ca7072972c0 /scripts/calibrate_shaper.py
parentf84a570dde9bbab7b3f176c2a1e14ff80b56ecc2 (diff)
downloadkutter-5ccc17042c03667e41abf770b3087294a4f78810.tar.gz
kutter-5ccc17042c03667e41abf770b3087294a4f78810.tar.xz
kutter-5ccc17042c03667e41abf770b3087294a4f78810.zip
scripts: Small improvements for input shaper and accelerometer scripts
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
Diffstat (limited to 'scripts/calibrate_shaper.py')
-rwxr-xr-xscripts/calibrate_shaper.py47
1 files changed, 25 insertions, 22 deletions
diff --git a/scripts/calibrate_shaper.py b/scripts/calibrate_shaper.py
index 22b32b23..82c15ed1 100755
--- a/scripts/calibrate_shaper.py
+++ b/scripts/calibrate_shaper.py
@@ -7,11 +7,14 @@
# This file may be distributed under the terms of the GNU GPLv3 license.
from __future__ import print_function
import optparse, os, sys
+from textwrap import wrap
import numpy as np, matplotlib
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)),
'..', 'klippy', 'extras'))
from shaper_calibrate import CalibrationData, ShaperCalibrate
+MAX_TITLE_LENGTH=65
+
def parse_log(logname):
with open(logname) as f:
for header in f:
@@ -61,7 +64,7 @@ def calibrate_shaper(datas, csv_output):
# Plot frequency response and suggested input shapers
######################################################################
-def plot_freq_response(calibration_data, shapers_vals,
+def plot_freq_response(lognames, calibration_data, shapers_vals,
selected_shaper, max_freq):
freqs = calibration_data.freq_bins
psd = calibration_data.psd_sum[freqs <= max_freq]
@@ -83,10 +86,8 @@ def plot_freq_response(calibration_data, shapers_vals,
ax.plot(freqs, py, label='Y', color='green')
ax.plot(freqs, pz, label='Z', color='blue')
- if shapers_vals:
- ax.set_title("Frequency response and shapers")
- else:
- ax.set_title("Frequency response")
+ title = "Frequency response and shapers (%s)" % (', '.join(lognames))
+ ax.set_title("\n".join(wrap(title, MAX_TITLE_LENGTH)))
ax.xaxis.set_minor_locator(matplotlib.ticker.AutoMinorLocator())
ax.yaxis.set_minor_locator(matplotlib.ticker.AutoMinorLocator())
ax.xaxis.set_minor_locator(matplotlib.ticker.AutoMinorLocator())
@@ -94,23 +95,25 @@ def plot_freq_response(calibration_data, shapers_vals,
ax.ticklabel_format(axis='y', style='scientific', scilimits=(0,0))
ax.grid(which='major', color='grey')
ax.grid(which='minor', color='lightgrey')
- ax.legend(loc='upper right', prop=fontP)
- if shapers_vals:
- ax2 = ax.twinx()
- ax2.set_ylabel('Shaper vibration reduction (ratio)')
- best_shaper_vals = None
- for name, freq, vals in shapers_vals:
- label = "%s (%.1f Hz)" % (name.upper(), freq)
- linestyle = 'dotted'
- if name == selected_shaper:
- label += ' (selected)'
- linestyle = 'dashdot'
- best_shaper_vals = vals
- ax2.plot(freqs, vals, label=label, linestyle=linestyle)
- ax.plot(freqs, psd * best_shaper_vals,
- label='After\nshaper', color='cyan')
- ax2.legend(loc='upper left', prop=fontP)
+ ax2 = ax.twinx()
+ ax2.set_ylabel('Shaper vibration reduction (ratio)')
+ best_shaper_vals = None
+ for name, freq, vals in shapers_vals:
+ label = "%s (%.1f Hz)" % (name.upper(), freq)
+ linestyle = 'dotted'
+ if name == selected_shaper:
+ linestyle = 'dashdot'
+ best_shaper_vals = vals
+ ax2.plot(freqs, vals, label=label, linestyle=linestyle)
+ ax.plot(freqs, psd * best_shaper_vals,
+ label='After\nshaper', color='cyan')
+ # A hack to add a human-readable shaper recommendation to legend
+ ax2.plot([], [], ' ',
+ label="Recommended shaper: %s" % (selected_shaper.upper()))
+
+ ax.legend(loc='upper left', prop=fontP)
+ ax2.legend(loc='upper right', prop=fontP)
fig.tight_layout()
return fig
@@ -152,7 +155,7 @@ def main():
# Draw graph
setup_matplotlib(options.output is not None)
- fig = plot_freq_response(calibration_data, shapers_vals,
+ fig = plot_freq_response(args, calibration_data, shapers_vals,
selected_shaper, options.max_freq)
# Show graph