Skip to content

Commit

Permalink
Merge pull request #16 from Frix-x/accel-patch
Browse files Browse the repository at this point in the history
Allow user input for ACCEL on vibration measurements
and use a low accel by default (with automated restore of the previous values at the end of the test) to get proper measurements
  • Loading branch information
Frix-x authored Nov 27, 2023
2 parents 8e304a7 + f95c552 commit a1e9269
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
43 changes: 14 additions & 29 deletions K-ShakeTune/IS_vibrations_measurements.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,17 @@
###### VIBRATIONS AND SPEED OPTIMIZATIONS ######
################################################
# Written by Frix_x#0161 #
# @version: 2.1
# @version: 2.2

# CHANGELOG:
# v2.2: allow custom accel values and set sane defaults (3k) to avoid using very high accels that produce bad results
# v2.1: allow decimal entries for speed and increment and added the E axis as an option to be neasured
# v2.0: added the possibility to measure mutliple axis
# v1.0: first speed and vibrations optimization macro


### What is it ? ###
# This macro helps you to identify the speed settings that exacerbate the vibrations of the machine (ie. where the frame resonate badly).
# It also helps to find the clean speed ranges where the machine is silent.
# I had some strong vibrations at very specific speeds on my machine (52mm/s for example) and I wanted to find all these problematic speeds
# to avoid them in my slicer profile and finally get the silent machine I was dreaming!

# It works by moving the toolhead at different speed settings while recording the vibrations using the ADXL chip. Then the macro call a custom script
# to compute and find the best speed settings. The results can be found in your config folder using Fluidd/Mainsail file manager.

# The goal is to make it easy to set, share and use it.

# This macro is parametric and most of the values can be adjusted with their respective input parameters.
# It can be called without any parameters - in which case the default values would be used - or with any combination of parameters as desired.

# Usage:
# 1. DO YOUR INPUT SHAPER CALIBRATION FIRST !!! This macro should not be used before as it would be useless and the results invalid.
# 2. Call the VIBRATIONS_CALIBRATION macro with the speed range you want to measure (default 20 to 200mm/s with 2mm/s increment).
# Be carefull about the Z_HEIGHT variable that default to 20mm -> if your ADXL is under the nozzle, increase it to avoid a crash of the ADXL on the bed of the machine.
# 3. Wait for it to finish all the measurement and compute the graph. Then look at it in the results folder.


[gcode_macro VIBRATIONS_CALIBRATION]
gcode:
#
# PARAMETERS
#
{% set size = params.SIZE|default(60)|int %} # size of the area where the movements are done
{% set direction = params.DIRECTION|default('XY') %} # can be set to either XY, AB, ABXY, A, B, X, Y, Z
{% set z_height = params.Z_HEIGHT|default(20)|int %} # z height to put the toolhead before starting the movements
Expand All @@ -45,16 +22,18 @@ gcode:
{% set max_speed = params.MAX_SPEED|default(200)|float * 60 %} # maximum feedrate for the movements
{% set speed_increment = params.SPEED_INCREMENT|default(2)|float * 60 %} # feedrate increment between each move
{% set feedrate_travel = params.TRAVEL_SPEED|default(200)|int * 60 %} # travel feedrate between moves

{% set accel = params.ACCEL|default(3000)|int %} # accel value used to move on the pattern
{% set accel_chip = params.ACCEL_CHIP|default("adxl345") %} # ADXL chip name in the config

#
# COMPUTED VALUES
#
{% set mid_x = printer.toolhead.axis_maximum.x|float / 2 %}
{% set mid_y = printer.toolhead.axis_maximum.y|float / 2 %}
{% set nb_samples = ((max_speed - min_speed) / speed_increment + 1) | int %}

{% set accel = [accel, printer.configfile.settings.printer.max_accel]|min %}
{% set old_accel = printer.toolhead.max_accel %}
{% set old_accel_to_decel = printer.toolhead.max_accel_to_decel %}
{% set old_sqv = printer.toolhead.square_corner_velocity %}

{% set direction_factor = {
'XY' : {
'start' : {'x': -0.5, 'y': -0.5 },
Expand Down Expand Up @@ -158,6 +137,9 @@ gcode:
M83
G90

# Set the wanted acceleration values (not too high to avoid oscillation, not too low to be able to reach constant speed on each segments)
SET_VELOCITY_LIMIT ACCEL={accel} ACCEL_TO_DECEL={accel} SQUARE_CORNER_VELOCITY={[(accel / 1000), 5.0]|max}

# Going to the start position
G1 Z{z_height}
G1 X{mid_x + (size * direction_factor[direction].start.x) } Y{mid_y + (size * direction_factor[direction].start.y)} F{feedrate_travel}
Expand Down Expand Up @@ -188,4 +170,7 @@ gcode:
{% endif %}
RUN_SHELL_COMMAND CMD=plot_graph PARAMS="VIBRATIONS {direction}"

# Restore the previous acceleration values
SET_VELOCITY_LIMIT ACCEL={old_accel} ACCEL_TO_DECEL={old_accel_to_decel} SQUARE_CORNER_VELOCITY={old_sqv}

RESTORE_GCODE_STATE NAME=STATE_VIBRATIONS_CALIBRATION
1 change: 1 addition & 0 deletions docs/macros/vibrations_tuning.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Call the `VIBRATIONS_CALIBRATION` macro with the direction and speed range you w
|DIRECTION|"XY"|direction vector where you want to do the measurements. Can be set to either "XY", "AB", "ABXY", "A", "B", "X", "Y", "Z", "E"|
|Z_HEIGHT|20|z height to put the toolhead before starting the movements. Be careful, if your ADXL is under the nozzle, increase it to avoid a crash of the ADXL on the bed of the machine|
|VERBOSE|1|Wether to log the current speed in the console|
|ACCEL|3000 (or max printer accel)|accel in mm/s^2 used for all the moves. Try to keep it relatively low to avoid bad oscillations that affect the measurements, but but high enough to reach constant speed for >~70% of the segments|
|MIN_SPEED|20|minimum speed of the toolhead in mm/s for the movements|
|MAX_SPEED|200|maximum speed of the toolhead in mm/s for the movements|
|SPEED_INCREMENT|2|speed increments of the toolhead in mm/s between every movements|
Expand Down

0 comments on commit a1e9269

Please sign in to comment.