added filesystem sync and file handler checks to avoid going too fast with corrupted CSVs
This commit is contained in:
@@ -2,9 +2,10 @@
|
|||||||
###### STANDARD INPUT_SHAPER CALIBRATIONS ######
|
###### STANDARD INPUT_SHAPER CALIBRATIONS ######
|
||||||
################################################
|
################################################
|
||||||
# Written by Frix_x#0161 #
|
# Written by Frix_x#0161 #
|
||||||
# @version: 1.4
|
# @version: 1.5
|
||||||
|
|
||||||
# CHANGELOG:
|
# CHANGELOG:
|
||||||
|
# v1.5: modified EXCITATE_AXIS_AT_FREQ to allow A or B belt testing
|
||||||
# v1.4: added possibility to only run one axis at a time for the axes shaper calibration
|
# v1.4: added possibility to only run one axis at a time for the axes shaper calibration
|
||||||
# v1.3: added possibility to override the default parameters
|
# v1.3: added possibility to override the default parameters
|
||||||
# v1.2: added EXCITATE_AXIS_AT_FREQ to hold a specific excitating frequency on an axis and diagnose mechanical problems
|
# v1.2: added EXCITATE_AXIS_AT_FREQ to hold a specific excitating frequency on an axis and diagnose mechanical problems
|
||||||
@@ -26,7 +27,7 @@
|
|||||||
|
|
||||||
|
|
||||||
[gcode_macro AXES_SHAPER_CALIBRATION]
|
[gcode_macro AXES_SHAPER_CALIBRATION]
|
||||||
description: Run standard input shaper test for all axes
|
description: Perform standard axis input shaper tests on one or both XY axes to select the best input shaper filter
|
||||||
gcode:
|
gcode:
|
||||||
{% set verbose = params.VERBOSE|default(true) %}
|
{% set verbose = params.VERBOSE|default(true) %}
|
||||||
{% set min_freq = params.FREQ_START|default(5)|float %}
|
{% set min_freq = params.FREQ_START|default(5)|float %}
|
||||||
@@ -51,7 +52,8 @@ gcode:
|
|||||||
M400
|
M400
|
||||||
|
|
||||||
{% if verbose %}
|
{% if verbose %}
|
||||||
RESPOND MSG="X axis shaper graphs generation..."
|
RESPOND MSG="X axis frequency profile generation..."
|
||||||
|
RESPOND MSG="This may take some time (1-3min)"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
RUN_SHELL_COMMAND CMD=plot_graph PARAMS=SHAPER
|
RUN_SHELL_COMMAND CMD=plot_graph PARAMS=SHAPER
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -61,14 +63,15 @@ gcode:
|
|||||||
M400
|
M400
|
||||||
|
|
||||||
{% if verbose %}
|
{% if verbose %}
|
||||||
RESPOND MSG="Y axis shaper graphs generation..."
|
RESPOND MSG="Y axis frequency profile generation..."
|
||||||
|
RESPOND MSG="This may take some time (1-3min)"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
RUN_SHELL_COMMAND CMD=plot_graph PARAMS=SHAPER
|
RUN_SHELL_COMMAND CMD=plot_graph PARAMS=SHAPER
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
[gcode_macro BELTS_SHAPER_CALIBRATION]
|
[gcode_macro BELTS_SHAPER_CALIBRATION]
|
||||||
description: Run custom demi-axe test to analyze belts on CoreXY printers
|
description: Perform a custom half-axis test to analyze and compare the frequency profiles of individual belts on CoreXY printers
|
||||||
gcode:
|
gcode:
|
||||||
{% set verbose = params.VERBOSE|default(true) %}
|
{% set verbose = params.VERBOSE|default(true) %}
|
||||||
{% set min_freq = params.FREQ_START|default(5)|float %}
|
{% set min_freq = params.FREQ_START|default(5)|float %}
|
||||||
@@ -77,21 +80,33 @@ gcode:
|
|||||||
|
|
||||||
TEST_RESONANCES AXIS=1,1 OUTPUT=raw_data NAME=b FREQ_START={min_freq} FREQ_END={max_freq} HZ_PER_SEC={hz_per_sec}
|
TEST_RESONANCES AXIS=1,1 OUTPUT=raw_data NAME=b FREQ_START={min_freq} FREQ_END={max_freq} HZ_PER_SEC={hz_per_sec}
|
||||||
M400
|
M400
|
||||||
|
|
||||||
TEST_RESONANCES AXIS=1,-1 OUTPUT=raw_data NAME=a FREQ_START={min_freq} FREQ_END={max_freq} HZ_PER_SEC={hz_per_sec}
|
TEST_RESONANCES AXIS=1,-1 OUTPUT=raw_data NAME=a FREQ_START={min_freq} FREQ_END={max_freq} HZ_PER_SEC={hz_per_sec}
|
||||||
M400
|
M400
|
||||||
|
|
||||||
{% if verbose %}
|
{% if verbose %}
|
||||||
RESPOND MSG="Belts graphs generation..."
|
RESPOND MSG="Belts comparative frequency profile generation..."
|
||||||
|
RESPOND MSG="This may take some time (3-5min)"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
RUN_SHELL_COMMAND CMD=plot_graph PARAMS=BELTS
|
RUN_SHELL_COMMAND CMD=plot_graph PARAMS=BELTS
|
||||||
|
|
||||||
|
|
||||||
[gcode_macro EXCITATE_AXIS_AT_FREQ]
|
[gcode_macro EXCITATE_AXIS_AT_FREQ]
|
||||||
description: Maintain a specified input shaper excitating frequency for some time to diagnose vibrations
|
description: Maintain a specified input shaper excitation frequency for a period of time to diagnose and locate a source of vibration
|
||||||
gcode:
|
gcode:
|
||||||
{% set FREQUENCY = params.FREQUENCY|default(25)|int %}
|
{% set FREQUENCY = params.FREQUENCY|default(25)|int %}
|
||||||
{% set TIME = params.TIME|default(10)|int %}
|
{% set TIME = params.TIME|default(10)|int %}
|
||||||
{% set AXIS = params.AXIS|default("x")|string|lower %}
|
{% set AXIS = params.AXIS|default("x")|string|lower %}
|
||||||
|
|
||||||
|
{% if AXIS not in ["x", "y", "a", "b"] %}
|
||||||
|
{ action_raise_error("AXIS selection invalid. Should be either x, y, a or b!") }
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if axis == "a" %}
|
||||||
|
{% set AXIS = "1,-1" %}
|
||||||
|
{% elif axis == "b" %}
|
||||||
|
{% set AXIS = "1,1" %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
TEST_RESONANCES OUTPUT=raw_data AXIS={AXIS} FREQ_START={FREQUENCY-1} FREQ_END={FREQUENCY+1} HZ_PER_SEC={1/(TIME/3)}
|
TEST_RESONANCES OUTPUT=raw_data AXIS={AXIS} FREQ_START={FREQUENCY-1} FREQ_END={FREQUENCY+1} HZ_PER_SEC={1/(TIME/3)}
|
||||||
M400
|
M400
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
###### INPUT SHAPER KLIPPAIN WORKFLOW ######
|
###### INPUT SHAPER KLIPPAIN WORKFLOW ######
|
||||||
############################################
|
############################################
|
||||||
# Written by Frix_x#0161 #
|
# Written by Frix_x#0161 #
|
||||||
# @version: 2.0
|
# @version: 2.1
|
||||||
|
|
||||||
# CHANGELOG:
|
# CHANGELOG:
|
||||||
|
# v2.1: added more filesystem sync and file handler checks to avoid using corrupted CSV files by going to fast
|
||||||
# v2.0: new version of this as a Python script (to replace the old bash script) and implement the newer and improved shaper plotting scripts
|
# v2.0: new version of this as a Python script (to replace the old bash script) and implement the newer and improved shaper plotting scripts
|
||||||
# v1.7: updated the handling of shaper files to account for the new analysis scripts as we are now using raw data directly
|
# v1.7: updated the handling of shaper files to account for the new analysis scripts as we are now using raw data directly
|
||||||
# v1.6: - updated the handling of shaper graph files to be able to optionnaly account for added positions in the filenames and remove them
|
# v1.6: - updated the handling of shaper graph files to be able to optionnaly account for added positions in the filenames and remove them
|
||||||
@@ -25,14 +26,12 @@
|
|||||||
# VIBRATIONS - To generate vibration diagram after calling the custom (Frix_x#0161) VIBRATIONS_CALIBRATION macro
|
# VIBRATIONS - To generate vibration diagram after calling the custom (Frix_x#0161) VIBRATIONS_CALIBRATION macro
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import glob
|
import glob
|
||||||
import sys
|
import sys
|
||||||
import shutil
|
import shutil
|
||||||
import tarfile
|
import tarfile
|
||||||
import fcntl
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
#################################################################################################################
|
#################################################################################################################
|
||||||
@@ -80,16 +79,21 @@ def get_belts_graph():
|
|||||||
for filename in sorted_files[:2]:
|
for filename in sorted_files[:2]:
|
||||||
# Wait for the file handler to be released by Klipper
|
# Wait for the file handler to be released by Klipper
|
||||||
while is_file_open(filename):
|
while is_file_open(filename):
|
||||||
time.sleep(3)
|
time.sleep(2)
|
||||||
|
|
||||||
# Extract the tested belt from the filename and rename/move the CSV file to the result folder
|
# Extract the tested belt from the filename and rename/move the CSV file to the result folder
|
||||||
belt = os.path.basename(filename).split('_')[3].split('.')[0].upper()
|
belt = os.path.basename(filename).split('_')[3].split('.')[0].upper()
|
||||||
new_file = os.path.join(RESULTS_FOLDER, RESULTS_SUBFOLDERS[0], f'belt_{current_date}_{belt}.csv')
|
new_file = os.path.join(RESULTS_FOLDER, RESULTS_SUBFOLDERS[0], f'belt_{current_date}_{belt}.csv')
|
||||||
shutil.move(filename, new_file)
|
shutil.move(filename, new_file)
|
||||||
|
os.sync() # Sync filesystem to avoid problems
|
||||||
|
|
||||||
# Save the file path for later
|
# Save the file path for later
|
||||||
lognames.append(new_file)
|
lognames.append(new_file)
|
||||||
|
|
||||||
|
# Wait for the file handler to be released by the move command
|
||||||
|
while is_file_open(new_file):
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
# Generate the belts graph and its name
|
# Generate the belts graph and its name
|
||||||
fig = belts_calibration(lognames, KLIPPER_FOLDER)
|
fig = belts_calibration(lognames, KLIPPER_FOLDER)
|
||||||
png_filename = os.path.join(RESULTS_FOLDER, RESULTS_SUBFOLDERS[0], f'belts_{current_date}.png')
|
png_filename = os.path.join(RESULTS_FOLDER, RESULTS_SUBFOLDERS[0], f'belts_{current_date}.png')
|
||||||
@@ -110,12 +114,17 @@ def get_shaper_graph():
|
|||||||
|
|
||||||
# Wait for the file handler to be released by Klipper
|
# Wait for the file handler to be released by Klipper
|
||||||
while is_file_open(filename):
|
while is_file_open(filename):
|
||||||
time.sleep(3)
|
time.sleep(2)
|
||||||
|
|
||||||
# Extract the tested axis from the filename and rename/move the CSV file to the result folder
|
# Extract the tested axis from the filename and rename/move the CSV file to the result folder
|
||||||
axis = os.path.basename(filename).split('_')[3].split('.')[0].upper()
|
axis = os.path.basename(filename).split('_')[3].split('.')[0].upper()
|
||||||
new_file = os.path.join(RESULTS_FOLDER, RESULTS_SUBFOLDERS[1], f'resonances_{current_date}_{axis}.csv')
|
new_file = os.path.join(RESULTS_FOLDER, RESULTS_SUBFOLDERS[1], f'resonances_{current_date}_{axis}.csv')
|
||||||
shutil.move(filename, new_file)
|
shutil.move(filename, new_file)
|
||||||
|
os.sync() # Sync filesystem to avoid problems
|
||||||
|
|
||||||
|
# Wait for the file handler to be released by the move command
|
||||||
|
while is_file_open(new_file):
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
# Generate the shaper graph and its name
|
# Generate the shaper graph and its name
|
||||||
fig = shaper_calibration([new_file], KLIPPER_FOLDER)
|
fig = shaper_calibration([new_file], KLIPPER_FOLDER)
|
||||||
@@ -139,7 +148,7 @@ def get_vibrations_graph(axis_name):
|
|||||||
for filename in globbed_files:
|
for filename in globbed_files:
|
||||||
# Wait for the file handler to be released by Klipper
|
# Wait for the file handler to be released by Klipper
|
||||||
while is_file_open(filename):
|
while is_file_open(filename):
|
||||||
time.sleep(3)
|
time.sleep(2)
|
||||||
|
|
||||||
# Cleanup of the filename and moving it in the result folder
|
# Cleanup of the filename and moving it in the result folder
|
||||||
cleanfilename = os.path.basename(filename).replace('adxl345', f'vibr_{current_date}')
|
cleanfilename = os.path.basename(filename).replace('adxl345', f'vibr_{current_date}')
|
||||||
@@ -151,6 +160,7 @@ def get_vibrations_graph(axis_name):
|
|||||||
|
|
||||||
# Sync filesystem to avoid problems as there is a lot of file copied
|
# Sync filesystem to avoid problems as there is a lot of file copied
|
||||||
os.sync()
|
os.sync()
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
# Generate the vibration graph and its name
|
# Generate the vibration graph and its name
|
||||||
fig = vibrations_calibration(lognames, KLIPPER_FOLDER, axis_name)
|
fig = vibrations_calibration(lognames, KLIPPER_FOLDER, axis_name)
|
||||||
|
|||||||
Reference in New Issue
Block a user