Skip to content

Commit

Permalink
Port MIN_CRUISE_RATIO fix to TEST_SPEED_DELTA macro, match formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewEllis93 committed Jul 12, 2024
1 parent baeccd6 commit 309fbf1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
18 changes: 12 additions & 6 deletions macros/TEST_SPEED.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ gcode:
# Acceleration
{% set accel = params.ACCEL|default(printer.configfile.settings.printer.max_accel)|int %}
# Minimum Cruise Ratio
{% set min_cruise_ratio = params.MIN_CRUISE_RATIO|default(0)|float %} # Possible location in printer object stack: printer.configfile.settings.printer.minimum_cruise_ratio
{% set min_cruise_ratio = params.MIN_CRUISE_RATIO|default(0.5)|float %}
# Bounding inset for large pattern (helps prevent slamming the toolhead into the sides after small skips, and helps to account for machines with imperfectly set dimensions)
{% set bound = params.BOUND|default(20)|int %}
# Size for small pattern box
Expand Down Expand Up @@ -67,8 +67,11 @@ gcode:
G0 X{x_min} Y{y_min} Z{bound + 10} F{speed*60}

# Set new limits
# SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel} ACCEL_TO_DECEL={accel / 2} # DEPRECATED | Due to deprecation of accel_to_decel parameter in Klipper
SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel} MIN_CRUISE_RATIO={minCruiseRatio}
{% if printer.configfile.settings.printer.minimum_cruise_ratio is defined %}
SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel} MINIMUM_CRUISE_RATIO={min_cruise_ratio}
{% else %}
SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel} ACCEL_TO_DECEL={accel / 2}
{% endif %}

{% for i in range(iterations) %}
# Large pattern diagonals
Expand All @@ -93,16 +96,19 @@ gcode:
G0 X{x_center_min} Y{y_center_max} F{speed*60}
G0 X{x_center_max} Y{y_center_min} F{speed*60}

# Small patternbox
# Small pattern box
G0 X{x_center_min} Y{y_center_min} F{speed*60}
G0 X{x_center_min} Y{y_center_max} F{speed*60}
G0 X{x_center_max} Y{y_center_max} F{speed*60}
G0 X{x_center_max} Y{y_center_min} F{speed*60}
{% endfor %}

# Restore max speed/accel/accel_to_decel to their configured values
#SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel} ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel_to_decel} # DEPRECATED | Depercating of accel_to_decel param in klipper
SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel} MIN_CRUISE_RATIO={printer.configfile.settings.printer.minimum_cruise_ratio}
{% if printer.configfile.settings.printer.minimum_cruise_ratio is defined %}
SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel} MINIMUM_CRUISE_RATIO={printer.configfile.settings.printer.minimum_cruise_ratio}
{% else %}
SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel} ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel_to_decel}
{% endif %}

# Re-home and get position again for comparison:
M400 # Finish moves - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/66
Expand Down
24 changes: 17 additions & 7 deletions macros/TEST_SPEED_DELTA.cfg
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# This variant is for delta printers.

[gcode_macro TEST_SPEED_DELTA]
# Home, get position, throw around toolhead, home again.
# If MCU stepper positions (first line in GET_POSITION) are greater than a full step different (your number of microsteps), then skipping occured.
# We only measure to a full step to accomodate for endstop variance.
# Example: TEST_SPEED_DELTA SPEED=300 ACCEL=5000 ITERATIONS=10

[gcode_macro TEST_SPEED_DELTA]
description: Test for max speed and acceleration parameters for the printer. Procedure: Home -> ReadPositionFromMCU -> MovesToolhead@Vel&Accel -> Home -> ReadPositionfromMCU

gcode:
# Speed
{% set speed = params.SPEED|default(printer.configfile.settings.printer.max_velocity)|int %}
# Iterations
{% set iterations = params.ITERATIONS|default(5)|int %}
# Acceleration
{% set accel = params.ACCEL|default(printer.configfile.settings.printer.max_accel)|int %}
# Minimum Cruise Ratio
{% set min_cruise_ratio = params.MIN_CRUISE_RATIO|default(0.5)|float %}
# Bounding inset for large pattern (helps prevent slamming the toolhead into the sides after small skips, and helps to account for machines with imperfectly set dimensions)
{% set bound = params.BOUND|default(20)|int %}
# Size for small pattern box
Expand Down Expand Up @@ -51,7 +53,11 @@ gcode:
G0 X{x_min} Y{y_min} Z{printer.toolhead.axis_maximum.z/2} F{speed*60}

# Set new limits
SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel} ACCEL_TO_DECEL={accel / 2}
{% if printer.configfile.settings.printer.minimum_cruise_ratio is defined %}
SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel} MINIMUM_CRUISE_RATIO={min_cruise_ratio}
{% else %}
SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel} ACCEL_TO_DECEL={accel / 2}
{% endif %}

{% for i in range(iterations) %}
# Large pattern diagonals
Expand Down Expand Up @@ -84,13 +90,17 @@ gcode:
{% endfor %}

# Restore max speed/accel/accel_to_decel to their configured values
SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel} ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel_to_decel}

{% if printer.configfile.settings.printer.minimum_cruise_ratio is defined %}
SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel} MINIMUM_CRUISE_RATIO={printer.configfile.settings.printer.minimum_cruise_ratio}
{% else %}
SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel} ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel_to_decel}
{% endif %}
# Re-home and get position again for comparison:
M400 # Finish moves - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/66
G28 # This is a full G28 to fix an issue with CoreXZ - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/12
G4 P1000
GET_POSITION

# Restore previous gcode state (absolute/relative, etc)
RESTORE_GCODE_STATE NAME=TEST_SPEED_DELTA
RESTORE_GCODE_STATE NAME=TEST_SPEED_DELTA

0 comments on commit 309fbf1

Please sign in to comment.