Skip to content

Commit

Permalink
switched to stdata objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Frix-x committed Aug 17, 2024
1 parent 3c586f7 commit cc46ff6
Show file tree
Hide file tree
Showing 19 changed files with 454 additions and 412 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ Follow these steps to install Shake&Tune on your printer:
# result_folder: ~/printer_data/config/ShakeTune_results
# The folder where the results will be stored. It will be created if it doesn't exist.
# number_of_results_to_keep: 3
# The number of results to keep in the result_folder. The oldest results will
# The number of results to keep in the result folder. The oldest results will
# be automatically deleted after each runs.
# keep_raw_csv: False
# If True, the raw CSV files will be kept in the result_folder alongside the
# PNG graphs. If False, they will be deleted and only the graphs will be kept.
# keep_raw_data: False
# If True, the raw data files will be kept in the result folder alongside the
# PNG graphs for archive and debbuging purposes. Please attach them on GitHub when
# reporting any issue to help understand and solve them.
# show_macros_in_webui: True
# Mainsail and Fluidd doesn't create buttons for "system" macros that are not in the
# printer.cfg file. If you want to see the macros in the webui, set this to True.
# timeout: 600
# The maximum time in seconds to let Shake&Tune process the CSV files and generate the graphs.
# The maximum time in seconds to let Shake&Tune process the data and generate the graphs.
```

Don't forget to check out **[Shake&Tune documentation here](./docs/README.md)**.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ matplotlib==3.8.2
numpy==1.26.2
scipy==1.11.4
PyWavelets==1.6.0
zstandard==0.23.0
108 changes: 0 additions & 108 deletions shaketune/commands/accelerometer.py

This file was deleted.

25 changes: 12 additions & 13 deletions shaketune/commands/axes_map_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
# and performs post-processing to analyze the collected data.


from ..helpers.accelerometer import Accelerometer, MeasurementsManager
from ..helpers.console_output import ConsoleOutput
from ..shaketune_process import ShakeTuneProcess
from .accelerometer import Accelerometer

SEGMENT_LENGTH = 30 # mm

Expand All @@ -35,9 +35,9 @@ def axes_map_calibration(gcmd, config, st_process: ShakeTuneProcess) -> None:
current_axes_map = pconfig.status_raw_config[accel_chip].get('axes_map', None)
if current_axes_map is not None and current_axes_map.strip().replace(' ', '') != 'x,y,z':
raise gcmd.error(
f'The parameter axes_map is already set in your {accel_chip} configuration! Please remove it (or set it to "x,y,z")!'
f'The parameter axes_map is already set in your {accel_chip} configuration! Please remove it (or set it to "x,y,z") to be able to use this macro!'
)
accelerometer = Accelerometer(printer.get_reactor(), k_accelerometer)
accelerometer = Accelerometer(k_accelerometer)

toolhead_info = toolhead.get_status(systime)
old_accel = toolhead_info['max_accel']
Expand Down Expand Up @@ -69,28 +69,27 @@ def axes_map_calibration(gcmd, config, st_process: ShakeTuneProcess) -> None:
toolhead.move([mid_x - SEGMENT_LENGTH / 2, mid_y - SEGMENT_LENGTH / 2, z_height, E], feedrate_travel)
toolhead.dwell(0.5)

measurements_manager = MeasurementsManager()

# Start the measurements and do the movements (+X, +Y and then +Z)
accelerometer.start_measurement()
accelerometer.start_recording(measurements_manager, name='axesmap_X', append_time=True)
toolhead.dwell(0.5)
toolhead.move([mid_x + SEGMENT_LENGTH / 2, mid_y - SEGMENT_LENGTH / 2, z_height, E], speed)
toolhead.dwell(0.5)
accelerometer.stop_measurement('axesmap_X', append_time=True)
accelerometer.stop_recording()
toolhead.dwell(0.5)
accelerometer.wait_for_file_writes()
accelerometer.start_measurement()
accelerometer.start_recording(measurements_manager, name='axesmap_Y', append_time=True)
toolhead.dwell(0.5)
toolhead.move([mid_x + SEGMENT_LENGTH / 2, mid_y + SEGMENT_LENGTH / 2, z_height, E], speed)
toolhead.dwell(0.5)
accelerometer.stop_measurement('axesmap_Y', append_time=True)
accelerometer.stop_recording()
toolhead.dwell(0.5)
accelerometer.wait_for_file_writes()
accelerometer.start_measurement()
accelerometer.start_recording(measurements_manager, name='axesmap_Z', append_time=True)
toolhead.dwell(0.5)
toolhead.move([mid_x + SEGMENT_LENGTH / 2, mid_y + SEGMENT_LENGTH / 2, z_height + SEGMENT_LENGTH, E], speed)
toolhead.dwell(0.5)
accelerometer.stop_measurement('axesmap_Z', append_time=True)
accelerometer.stop_recording()
toolhead.dwell(0.5)
accelerometer.wait_for_file_writes()

# Re-enable the input shaper if it was active
if input_shaper is not None:
Expand All @@ -111,5 +110,5 @@ def axes_map_calibration(gcmd, config, st_process: ShakeTuneProcess) -> None:
ConsoleOutput.print('This may take some time (1-3min)')
creator = st_process.get_graph_creator()
creator.configure(accel, SEGMENT_LENGTH)
st_process.run()
st_process.run(measurements_manager)
st_process.wait_for_completion()
15 changes: 9 additions & 6 deletions shaketune/commands/axes_shaper_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
# and generates graphs for each axis to analyze the collected data.


from ..helpers.accelerometer import Accelerometer, MeasurementsManager
from ..helpers.common_func import AXIS_CONFIG
from ..helpers.console_output import ConsoleOutput
from ..helpers.resonance_test import vibrate_axis
from ..shaketune_process import ShakeTuneProcess
from .accelerometer import Accelerometer


def axes_shaper_calibration(gcmd, config, st_process: ShakeTuneProcess) -> None:
Expand Down Expand Up @@ -90,29 +90,32 @@ def axes_shaper_calibration(gcmd, config, st_process: ShakeTuneProcess) -> None:
else:
input_shaper = None

measurements_manager = MeasurementsManager()

# Filter axis configurations based on user input, assuming 'axis_input' can be 'x', 'y', 'all' (that means 'x' and 'y')
filtered_config = [
a for a in AXIS_CONFIG if a['axis'] == axis_input or (axis_input == 'all' and a['axis'] in ('x', 'y'))
]
for config in filtered_config:
measurements_manager.clear_measurements() # Clear the measurements in each iteration of the loop

# First we need to find the accelerometer chip suited for the axis
accel_chip = Accelerometer.find_axis_accelerometer(printer, config['axis'])
if accel_chip is None:
raise gcmd.error('No suitable accelerometer found for measurement!')
accelerometer = Accelerometer(printer.get_reactor(), printer.lookup_object(accel_chip))
accelerometer = Accelerometer(printer.lookup_object(accel_chip))

# Then do the actual measurements
accelerometer.start_measurement()
accelerometer.start_recording(measurements_manager, name=config['label'], append_time=True)
vibrate_axis(toolhead, gcode, config['direction'], min_freq, max_freq, hz_per_sec, accel_per_hz)
accelerometer.stop_measurement(config['label'], append_time=True)
accelerometer.stop_recording()
toolhead.dwell(0.5)
toolhead.wait_moves()
accelerometer.wait_for_file_writes()

# And finally generate the graph for each measured axis
ConsoleOutput.print(f'{config["axis"].upper()} axis frequency profile generation...')
ConsoleOutput.print('This may take some time (1-3min)')
st_process.run()
st_process.run(measurements_manager)
st_process.wait_for_completion()
toolhead.dwell(1)

Expand Down
13 changes: 7 additions & 6 deletions shaketune/commands/compare_belts_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
# for each axis to analyze the collected data.


from ..helpers.accelerometer import Accelerometer, MeasurementsManager
from ..helpers.common_func import AXIS_CONFIG
from ..helpers.console_output import ConsoleOutput
from ..helpers.motors_config_parser import MotorsConfigParser
from ..helpers.resonance_test import vibrate_axis
from ..shaketune_process import ShakeTuneProcess
from .accelerometer import Accelerometer


def compare_belts_responses(gcmd, config, st_process: ShakeTuneProcess) -> None:
Expand Down Expand Up @@ -60,7 +60,7 @@ def compare_belts_responses(gcmd, config, st_process: ShakeTuneProcess) -> None:
raise gcmd.error(
'No suitable accelerometer found for measurement! Multi-accelerometer configurations are not supported for this macro.'
)
accelerometer = Accelerometer(printer.get_reactor(), printer.lookup_object(accel_chip))
accelerometer = Accelerometer(printer.lookup_object(accel_chip))

# Move to the starting point
test_points = res_tester.test.get_start_test_points()
Expand Down Expand Up @@ -103,14 +103,15 @@ def compare_belts_responses(gcmd, config, st_process: ShakeTuneProcess) -> None:
else:
input_shaper = None

measurements_manager = MeasurementsManager()

# Run the test for each axis
for config in filtered_config:
accelerometer.start_measurement()
accelerometer.start_recording(measurements_manager, name=config['label'], append_time=True)
vibrate_axis(toolhead, gcode, config['direction'], min_freq, max_freq, hz_per_sec, accel_per_hz)
accelerometer.stop_measurement(config['label'], append_time=True)
accelerometer.stop_recording()
toolhead.dwell(0.5)
toolhead.wait_moves()
accelerometer.wait_for_file_writes()

# Re-enable the input shaper if it was active
if input_shaper is not None:
Expand All @@ -125,5 +126,5 @@ def compare_belts_responses(gcmd, config, st_process: ShakeTuneProcess) -> None:
# Run post-processing
ConsoleOutput.print('Belts comparative frequency profile generation...')
ConsoleOutput.print('This may take some time (1-3min)')
st_process.run()
st_process.run(measurements_manager)
st_process.wait_for_completion()
13 changes: 7 additions & 6 deletions shaketune/commands/create_vibrations_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

import math

from ..helpers.accelerometer import Accelerometer, MeasurementsManager
from ..helpers.console_output import ConsoleOutput
from ..helpers.motors_config_parser import MotorsConfigParser
from ..shaketune_process import ShakeTuneProcess
from .accelerometer import Accelerometer

MIN_SPEED = 2 # mm/s

Expand Down Expand Up @@ -81,6 +81,8 @@ def create_vibrations_profile(gcmd, config, st_process: ShakeTuneProcess) -> Non
toolhead.move([mid_x - 15, mid_y - 15, z_height, E], feedrate_travel)
toolhead.dwell(0.5)

measurements_manager = MeasurementsManager()

nb_speed_samples = int((max_speed - MIN_SPEED) / speed_increment + 1)
for curr_angle in main_angles:
ConsoleOutput.print(f'-> Measuring angle: {curr_angle} degrees...')
Expand Down Expand Up @@ -127,16 +129,15 @@ def create_vibrations_profile(gcmd, config, st_process: ShakeTuneProcess) -> Non
movements = 2

# Back and forth movements to record the vibrations at constant speed in both direction
accelerometer.start_measurement()
name = f'vib_an{curr_angle:.2f}sp{curr_speed:.2f}'.replace('.', '_')
accelerometer.start_recording(measurements_manager, name=name, append_time=True)
for _ in range(movements):
toolhead.move([mid_x + dX, mid_y + dY, z_height, E], curr_speed)
toolhead.move([mid_x - dX, mid_y - dY, z_height, E], curr_speed)
name = f'vib_an{curr_angle:.2f}sp{curr_speed:.2f}'.replace('.', '_')
accelerometer.stop_measurement(name)
accelerometer.stop_recording()

toolhead.dwell(0.3)
toolhead.wait_moves()
accelerometer.wait_for_file_writes()

# Restore the previous acceleration values
if old_mcr is not None: # minimum_cruise_ratio found: Klipper >= v0.12.0-239
Expand All @@ -152,5 +153,5 @@ def create_vibrations_profile(gcmd, config, st_process: ShakeTuneProcess) -> Non
ConsoleOutput.print('This may take some time (5-8min)')
creator = st_process.get_graph_creator()
creator.configure(motors_config_parser.kinematics, accel, motors_config_parser)
st_process.run()
st_process.run(measurements_manager)
st_process.wait_for_completion()
12 changes: 6 additions & 6 deletions shaketune/commands/excitate_axis_at_freq.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
# and optionally creates a graph of the vibration data collected by the accelerometer.


from ..helpers.accelerometer import Accelerometer, MeasurementsManager
from ..helpers.common_func import AXIS_CONFIG
from ..helpers.console_output import ConsoleOutput
from ..helpers.resonance_test import vibrate_axis_at_static_freq
from ..shaketune_process import ShakeTuneProcess
from .accelerometer import Accelerometer


def excitate_axis_at_freq(gcmd, config, st_process: ShakeTuneProcess) -> None:
Expand Down Expand Up @@ -41,7 +41,8 @@ def excitate_axis_at_freq(gcmd, config, st_process: ShakeTuneProcess) -> None:
k_accelerometer = printer.lookup_object(accel_chip, None)
if k_accelerometer is None:
raise gcmd.error(f'Accelerometer chip [{accel_chip}] was not found!')
accelerometer = Accelerometer(printer.get_reactor(), k_accelerometer)
accelerometer = Accelerometer(k_accelerometer)
measurements_manager = MeasurementsManager()

ConsoleOutput.print(f'Excitating {axis.upper()} axis at {freq}Hz for {duration} seconds')

Expand Down Expand Up @@ -87,7 +88,7 @@ def excitate_axis_at_freq(gcmd, config, st_process: ShakeTuneProcess) -> None:

# If the user want to create a graph, we start accelerometer recording
if create_graph:
accelerometer.start_measurement()
accelerometer.start_recording(measurements_manager, name=f'staticfreq_{axis.upper()}', append_time=True)

toolhead.dwell(0.5)
vibrate_axis_at_static_freq(toolhead, gcode, axis_config['direction'], freq, duration, accel_per_hz)
Expand All @@ -99,11 +100,10 @@ def excitate_axis_at_freq(gcmd, config, st_process: ShakeTuneProcess) -> None:

# If the user wanted to create a graph, we stop the recording and generate it
if create_graph:
accelerometer.stop_measurement(f'staticfreq_{axis.upper()}', append_time=True)
accelerometer.stop_recording()
toolhead.dwell(0.5)
accelerometer.wait_for_file_writes()

creator = st_process.get_graph_creator()
creator.configure(freq, duration, accel_per_hz)
st_process.run()
st_process.run(measurements_manager)
st_process.wait_for_completion()
Loading

0 comments on commit cc46ff6

Please sign in to comment.