From 7669ad0a12b883e8bf77f0e8b2267020bf63c3c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Labrosse?= Date: Sat, 10 Feb 2024 09:51:26 +0100 Subject: [PATCH] fix: make prime line height a variable parameter * Fix #465 --- macros/helpers/prime_line.cfg | 25 +++++++++++++++++-------- user_templates/variables.cfg | 1 + 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/macros/helpers/prime_line.cfg b/macros/helpers/prime_line.cfg index fef104b69..3d1d36a84 100644 --- a/macros/helpers/prime_line.cfg +++ b/macros/helpers/prime_line.cfg @@ -4,6 +4,11 @@ gcode: {% set prime_line_length = params.LINE_LENGTH|default(printer["gcode_macro _USER_VARIABLES"].prime_line_length)|float %} {% set prime_line_purge_distance = params.PURGE_LENGTH|default(printer["gcode_macro _USER_VARIABLES"].prime_line_purge_distance)|float %} {% set prime_line_flowrate = params.FLOWRATE|default(printer["gcode_macro _USER_VARIABLES"].prime_line_flowrate)|float %} + {% if printer["gcode_macro _USER_VARIABLES"].prime_line_height %} + {% set prime_line_height = params.LINE_HEIGHT|default(printer["gcode_macro _USER_VARIABLES"].prime_line_height)|float %} + {% else %} + {% set prime_line_height = params.LINE_HEIGHT|default(0.6)|float %} + {% endif %} # Set internal macro vars {% set prime_line_x, prime_line_y = printer["gcode_macro _USER_VARIABLES"].prime_line_xy|map('float') %} @@ -19,40 +24,44 @@ gcode: {% set max_extrude_cross_section = printer["configfile"].config["extruder"]["max_extrude_cross_section"]|float %} {% set filament_diameter = printer["configfile"].config["extruder"]["filament_diameter"]|float %} - {% set line_height = 0.6 %} - # some more Macro parameters after retrieving defaults {% set prime_line_x = params.START_X|default(prime_line_x)|float %} {% set prime_line_y = params.START_Y|default(prime_line_y)|float %} {% set prime_line_direction = params.LINE_DIRECTION|default(printer["gcode_macro _USER_VARIABLES"].prime_line_direction)|string|upper %} + {% if verbose %} + {action_respond_info("Prime line length: %.4f" % prime_line_length)} + {action_respond_info("Prime line eight: %.4f" % prime_line_height)} + {action_respond_info("prime line extrusion length: %4.f" % prime_line_purge_distance)} + {% endif %} + # We first compute the width of the prime line {% set purge_volume = prime_line_purge_distance * 3.14159 * (filament_diameter / 2)**2 %} - {% set line_width = purge_volume / (line_height * prime_line_length) %} + {% set line_width = purge_volume / (prime_line_height * prime_line_length) %} # Then we check that the prime line cross section will not be problematic (exceeding Klipper max_extrude_cross_section) # or, if it's the case, we warn the user and add a correction to the length of filament to be purged - {% if (line_height * line_width) > max_extrude_cross_section %} + {% if (prime_line_height * line_width) > max_extrude_cross_section %} {% if verbose %} {action_respond_info("The prime_line_purge_distance of %.4f mm is too high and will exceed the max_extrude_cross_section!" % prime_line_purge_distance)} {% endif %} {% set prime_line_purge_distance = 0.98 * (max_extrude_cross_section * prime_line_length) / (3.14159 * (filament_diameter / 2)**2) %} {% set purge_volume = prime_line_purge_distance * 3.14159 * (filament_diameter / 2)**2 %} - {% set line_width = purge_volume / (line_height * prime_line_length) %} + {% set line_width = purge_volume / (prime_line_height * prime_line_length) %} {% if verbose %} {action_respond_info("Klippain corrected the prime_line_purge_distance to %.4f mm" % prime_line_purge_distance)} {% endif %} {% endif %} # We then compute the height to width ratio and validate that the prime line will not be too thin - {% if (line_height / line_width) >= 0.5 %} # TODO: validate this 1/2 ratio is good for all + {% if (prime_line_height / line_width) >= 0.5 %} # TODO: validate this 1/2 ratio is good for all {% if verbose %} {action_raise_error("The prime line will be too thin and will probably not stick properly to the bed. Increase its purge distance or decrease its length! Aborting...")} {% endif %} {% endif %} # Finally we compute the speed to get the correct flowrate for the prime line - {% set speed = (prime_line_flowrate / (line_height * line_width)) * 60 |float %} + {% set speed = (prime_line_flowrate / (prime_line_height * line_width)) * 60 |float %} {% if klippain_ercf_enabled %} {% if printer.ercf.enabled %} @@ -78,7 +87,7 @@ gcode: # Starting position G90 G0 X{prime_line_x} Y{prime_line_y} F{St} - G1 Z{line_height} F{Sz|int / 2} + G1 Z{prime_line_height} F{Sz|int / 2} # Add pressure in the nozzle G92 E0 diff --git a/user_templates/variables.cfg b/user_templates/variables.cfg index c6f0468ed..76115fb78 100644 --- a/user_templates/variables.cfg +++ b/user_templates/variables.cfg @@ -60,6 +60,7 @@ variable_prime_line_direction: "X" # can also be set to "Y" variable_prime_line_length: 40 # length of the prime line on the bed (in mm) variable_prime_line_purge_distance: 30 # length of filament to purge (in mm) variable_prime_line_flowrate: 10 # mm3/s used for the prime line +variable_prime_line_height: 0.6 # mm, used for actual cross section computation ## Park position used when pause, end_print, etc... variable_park_position_xy: -1, -1