improved automatic accelerometer choice and removed filemanager.py
This commit is contained in:
@@ -89,7 +89,6 @@ Here are the parameters available when calling this macro:
|
||||
|SPEED|80|speed of the toolhead in mm/s for the movements|
|
||||
|ACCEL|1500 (or max printer accel)|accel in mm/s^2 used for all the moves|
|
||||
|TRAVEL_SPEED|120|speed in mm/s used for all the travels moves|
|
||||
|ACCEL_CHIP|None|accelerometer to use for the test. If unset, it will automatically select the proper accelerometer based on what is configured in your `[resonance_tester]` config section|
|
||||
|
||||
The machine will move slightly in +X, +Y, and +Z, and output in the console: `Detected axes_map: -z,y,x`.
|
||||
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Common file management functions for the Shake&Tune package
|
||||
# Written by Frix_x#0161 #
|
||||
|
||||
import os
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def wait_file_ready(filepath: Path, timeout: int = 60) -> None:
|
||||
file_busy = True
|
||||
loop_count = 0
|
||||
|
||||
while file_busy:
|
||||
if loop_count >= timeout:
|
||||
raise TimeoutError(f'Klipper is taking too long to release the CSV file ({filepath})!')
|
||||
|
||||
# Try to open the file in write-only mode to check if it is in use
|
||||
# If we successfully open and close the file, it is not in use
|
||||
try:
|
||||
fd = os.open(filepath, os.O_WRONLY)
|
||||
os.close(fd)
|
||||
file_busy = False
|
||||
except OSError:
|
||||
# If OSError is caught, it indicates the file is still being used
|
||||
pass
|
||||
except Exception:
|
||||
# If another exception is raised, it's not a problem, we just loop again
|
||||
pass
|
||||
|
||||
loop_count += 1
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
def ensure_folders_exist(folders: list[Path]) -> None:
|
||||
for folder in folders:
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
@@ -11,20 +11,17 @@ def axes_map_calibration(gcmd, config, st_thread: ShakeTuneThread) -> None:
|
||||
speed = gcmd.get_float('SPEED', default=80.0, minval=20.0)
|
||||
accel = gcmd.get_int('ACCEL', default=1500, minval=100)
|
||||
feedrate_travel = gcmd.get_float('TRAVEL_SPEED', default=120.0, minval=20.0)
|
||||
accel_chip = gcmd.get('ACCEL_CHIP', default=None)
|
||||
|
||||
printer = config.get_printer()
|
||||
gcode = printer.lookup_object('gcode')
|
||||
toolhead = printer.lookup_object('toolhead')
|
||||
systime = printer.get_reactor().monotonic()
|
||||
|
||||
if accel_chip is None:
|
||||
accel_chip = Accelerometer.find_axis_accelerometer(printer, 'xy')
|
||||
if accel_chip is None:
|
||||
gcmd.error(
|
||||
'No accelerometer specified for measurement! Multi-accelerometer configurations are not supported for this macro.'
|
||||
)
|
||||
accelerometer = Accelerometer(printer.lookup_object(accel_chip))
|
||||
k_accelerometer = printer.lookup_object(accel_chip, None)
|
||||
if k_accelerometer is None:
|
||||
gcmd.error('Error: multi-accelerometer configurations are not supported for this macro!')
|
||||
accelerometer = Accelerometer(k_accelerometer)
|
||||
|
||||
toolhead_info = toolhead.get_status(systime)
|
||||
old_accel = toolhead_info['max_accel']
|
||||
|
||||
@@ -70,20 +70,17 @@ def create_vibrations_profile(gcmd, config, st_thread: ShakeTuneThread) -> None:
|
||||
ConsoleOutput.print(f'-> Measuring angle: {curr_angle} degrees...')
|
||||
radian_angle = math.radians(curr_angle)
|
||||
|
||||
# Find the best accelerometer chip for the current angle if not specified
|
||||
if curr_angle == 0:
|
||||
accel_axis = 'x'
|
||||
elif curr_angle == 90:
|
||||
accel_axis = 'y'
|
||||
else:
|
||||
accel_axis = 'xy'
|
||||
# Map angles to accelerometer axes and default to 'xy' if angle is not 0 or 90 degrees
|
||||
# and then find the best accelerometer chip for the current angle if not manually specified
|
||||
angle_to_axis = {0: 'x', 90: 'y'}
|
||||
accel_axis = angle_to_axis.get(curr_angle, 'xy')
|
||||
if accel_chip is None:
|
||||
accel_chip = Accelerometer.find_axis_accelerometer(printer, accel_axis)
|
||||
if accel_chip is None:
|
||||
gcmd.error(
|
||||
'No accelerometer specified for measurement! Multi-accelerometer configurations are not supported for this macro.'
|
||||
)
|
||||
accelerometer = Accelerometer(printer.lookup_object(accel_chip))
|
||||
k_accelerometer = printer.lookup_object(accel_chip, None)
|
||||
if k_accelerometer is None:
|
||||
gcmd.error(f'Error: accelerometer "{accel_chip}" not found!')
|
||||
accelerometer = Accelerometer(k_accelerometer)
|
||||
ConsoleOutput.print(f'Accelerometer chip for {curr_angle} degree angle: {accel_chip}')
|
||||
|
||||
# Sweep the speed range to record the vibrations at different speeds
|
||||
for curr_speed_sample in range(nb_speed_samples):
|
||||
|
||||
@@ -10,7 +10,6 @@ from typing import Callable, Optional
|
||||
|
||||
from matplotlib.figure import Figure
|
||||
|
||||
from ..helpers import filemanager as fm
|
||||
from ..helpers.console_output import ConsoleOutput
|
||||
from ..measurement.motorsconfigparser import MotorsConfigParser
|
||||
from ..shaketune_config import ShakeTuneConfig
|
||||
@@ -53,7 +52,6 @@ class GraphCreator(abc.ABC):
|
||||
|
||||
lognames = []
|
||||
for filename in sorted(globbed_files, key=lambda f: f.stat().st_mtime, reverse=True)[:min_files_required]:
|
||||
fm.wait_file_ready(filename)
|
||||
custom_name = custom_name_func(filename) if custom_name_func else filename.name
|
||||
new_file = self._folder / f'{self._type}_{self._graph_date}_{custom_name}.csv'
|
||||
# shutil.move() is needed to move the file across filesystems (mainly for BTT CB1 Pi default OS image)
|
||||
|
||||
@@ -6,7 +6,6 @@ import threading
|
||||
import traceback
|
||||
from typing import Optional
|
||||
|
||||
from .helpers import filemanager as fm
|
||||
from .helpers.console_output import ConsoleOutput
|
||||
from .shaketune_config import ShakeTuneConfig
|
||||
|
||||
@@ -52,7 +51,9 @@ class ShakeTuneThread(threading.Thread):
|
||||
except Exception:
|
||||
ConsoleOutput.print('Warning: failed reducing Shake&Tune thread priority, continuing...')
|
||||
|
||||
fm.ensure_folders_exist(self._config.get_results_subfolders())
|
||||
# Ensure the output folders exist
|
||||
for folder in self._config.get_results_subfolders():
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
try:
|
||||
graph_creator.create_graph()
|
||||
|
||||
Reference in New Issue
Block a user