Skip to content

Commit

Permalink
feat: Reset velocity limits in END_PRINT macro
Browse files Browse the repository at this point in the history
  • Loading branch information
mjonuschat committed Dec 21, 2024
1 parent d25823b commit 6d040c1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
37 changes: 36 additions & 1 deletion macros/base/end_print.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Available actions: "retract_filament", "turn_off_heaters", "turn_off_fans", "turn_off_motors"
##
[gcode_macro _USER_VARIABLES]
variable_endprint_actions: "retract_filament", "turn_off_heaters", "turn_off_fans", "turn_off_motors"
variable_endprint_actions: "retract_filament", "turn_off_heaters", "turn_off_fans", "turn_off_motors", "reset_limits"
gcode: # do not remove this line

[gcode_macro END_PRINT]
Expand Down Expand Up @@ -44,6 +44,8 @@ gcode:
_MODULE_TURN_OFF_FANS
{% elif action == "turn_off_motors" %}
_MODULE_TURN_OFF_MOTORS
{% elif action == "reset_limits" %}
_MODULE_RESET_LIMITS
{% else %}
{% if "_END_PRINT_ACTION_%s" % (action|upper) in printer.gcode.commands %}
_END_PRINT_ACTION_{action|upper} {rawparams}
Expand Down Expand Up @@ -136,3 +138,36 @@ gcode:
{% if disable_motors_in_end_print %}
M84
{% endif %}


[gcode_macro _MODULE_RESET_LIMITS]
gcode:
# ----- RESET LIMITS ---------------------------------
# Reset velocity limits, extrusion and speed factor (if configured)
{% set reset_velocity_limits = printer["gcode_macro _USER_VARIABLES"].reset_velocity_limits_in_end_print %}
{% set reset_extrude_factor = printer["gcode_macro _USER_VARIABLES"].reset_extrude_factor_in_end_print %}
{% set reset_speed_factor = printer["gcode_macro _USER_VARIABLES"].reset_speed_factor_in_end_print %}

{% if reset_speed_factor %}
M220 S100
{% endif %}

{% if reset_extrude_factor %}
M221 S100
{% endif %}

{% if reset_velocity_limits %}
SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity}
SET_VELOCITY_LIMIT ACCEL={printer.configfile.settings.printer.max_accel}
SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY={printer.configfile.settings.printer.square_corner_velocity}

# Legacy Klipper versions
{% if printer.configfile.settings.printer.max_accel_to_decel is defined %}
SET_VELOCITY_LIMIT ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel_to_decel}
{% endif %}

# Modern Klipper versions
{% if printer.configfile.settings.printer.minimum_cruise_ratio is defined %}
SET_VELOCITY_LIMIT MINIMUM_CRUISE_RATIO={printer.configfile.settings.printer.minimum_cruise_ratio}
{% endif %}
{% endif %}
9 changes: 9 additions & 0 deletions user_templates/variables.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ variable_disable_motors_in_end_print: False
## Automatically turn-off heaters in the END_PRINT macro
variable_turn_off_heaters_in_end_print: True

## Automatically reset velocity limits to configured values in the END_PRINT macro
variable_reset_velocity_limits_in_end_print: True

## Automatically reset extrude factor to 100% in the END_PRINT macro
variable_reset_extrude_factor_in_end_print: True

## Automatically reset speed factor to 100% in the END_PRINT macro
variable_reset_speed_factor_in_end_print: True


#########################################################
# Dockable probe variables (if available in the machine)
Expand Down

0 comments on commit 6d040c1

Please sign in to comment.