mirror of
https://github.com/QIDITECH/klipper.git
synced 2026-01-31 07:58:42 +03:00
plus4的klipper版本
This commit is contained in:
@@ -17,35 +17,50 @@ MAX_TITLE_LENGTH=65
|
||||
def parse_log(logname, opts):
|
||||
with open(logname) as f:
|
||||
for header in f:
|
||||
if not header.startswith('#'):
|
||||
if header.startswith('#'):
|
||||
continue
|
||||
if header.startswith('freq,psd_x,psd_y,psd_z,psd_xyz'):
|
||||
# Processed power spectral density file
|
||||
break
|
||||
if not header.startswith('freq,psd_x,psd_y,psd_z,psd_xyz'):
|
||||
# Raw accelerometer data
|
||||
return np.loadtxt(logname, comments='#', delimiter=',')
|
||||
# Power spectral density data or shaper calibration data
|
||||
opts.error("File %s does not contain raw accelerometer data and therefore "
|
||||
"is not supported by graph_accelerometer.py script. Please use "
|
||||
"calibrate_shaper.py script to process it instead." % (logname,))
|
||||
# Parse power spectral density data
|
||||
data = np.loadtxt(logname, skiprows=1, comments='#', delimiter=',')
|
||||
calibration_data = shaper_calibrate.CalibrationData(
|
||||
freq_bins=data[:,0], psd_sum=data[:,4],
|
||||
psd_x=data[:,1], psd_y=data[:,2], psd_z=data[:,3])
|
||||
calibration_data.set_numpy(np)
|
||||
return calibration_data
|
||||
|
||||
######################################################################
|
||||
# Raw accelerometer graphing
|
||||
######################################################################
|
||||
|
||||
def plot_accel(data, logname):
|
||||
first_time = data[0, 0]
|
||||
times = data[:,0] - first_time
|
||||
def plot_accel(datas, lognames):
|
||||
fig, axes = matplotlib.pyplot.subplots(nrows=3, sharex=True)
|
||||
axes[0].set_title("\n".join(wrap("Accelerometer data (%s)" % (logname,),
|
||||
MAX_TITLE_LENGTH)))
|
||||
axes[0].set_title("\n".join(wrap(
|
||||
"Accelerometer data (%s)" % (', '.join(lognames)), MAX_TITLE_LENGTH)))
|
||||
axis_names = ['x', 'y', 'z']
|
||||
for data, logname in zip(datas, lognames):
|
||||
if isinstance(data, shaper_calibrate.CalibrationData):
|
||||
raise error("Cannot plot raw accelerometer data using the processed"
|
||||
" resonances, raw_data input is required")
|
||||
first_time = data[0, 0]
|
||||
times = data[:,0] - first_time
|
||||
for i in range(len(axis_names)):
|
||||
avg = data[:,i+1].mean()
|
||||
adata = data[:,i+1] - data[:,i+1].mean()
|
||||
ax = axes[i]
|
||||
label = '\n'.join(wrap(logname, 60)) + ' (%+.3f mm/s^2)' % (-avg,)
|
||||
ax.plot(times, adata, alpha=0.8, label=label)
|
||||
axes[-1].set_xlabel('Time (s)')
|
||||
fontP = matplotlib.font_manager.FontProperties()
|
||||
fontP.set_size('x-small')
|
||||
for i in range(len(axis_names)):
|
||||
avg = data[:,i+1].mean()
|
||||
adata = data[:,i+1] - data[:,i+1].mean()
|
||||
ax = axes[i]
|
||||
ax.plot(times, adata, alpha=0.8)
|
||||
ax.grid(True)
|
||||
ax.set_ylabel('%s accel (%+.3f)\n(mm/s^2)' % (axis_names[i], -avg))
|
||||
axes[-1].set_xlabel('Time (%+.3f)\n(s)' % (-first_time,))
|
||||
ax.legend(loc='best', prop=fontP)
|
||||
ax.set_ylabel('%s accel' % (axis_names[i],))
|
||||
fig.tight_layout()
|
||||
return fig
|
||||
|
||||
@@ -56,10 +71,15 @@ def plot_accel(data, logname):
|
||||
|
||||
# Calculate estimated "power spectral density"
|
||||
def calc_freq_response(data, max_freq):
|
||||
if isinstance(data, shaper_calibrate.CalibrationData):
|
||||
return data
|
||||
helper = shaper_calibrate.ShaperCalibrate(printer=None)
|
||||
return helper.process_accelerometer_data(data)
|
||||
|
||||
def calc_specgram(data, axis):
|
||||
if isinstance(data, shaper_calibrate.CalibrationData):
|
||||
raise error("Cannot calculate the spectrogram using the processed"
|
||||
" resonances, raw_data input is required")
|
||||
N = data.shape[0]
|
||||
Fs = N / (data[-1,0] - data[0,0])
|
||||
# Round up to a power of 2 for faster FFT
|
||||
@@ -235,9 +255,7 @@ def main():
|
||||
|
||||
# Draw graph
|
||||
if options.raw:
|
||||
if len(args) > 1:
|
||||
opts.error("Only 1 input is supported in raw mode")
|
||||
fig = plot_accel(datas[0], args[0])
|
||||
fig = plot_accel(datas, args)
|
||||
elif options.specgram:
|
||||
if len(args) > 1:
|
||||
opts.error("Only 1 input is supported in specgram mode")
|
||||
|
||||
Reference in New Issue
Block a user