Skip to content

Commit

Permalink
fix: make prime line height a variable parameter
Browse files Browse the repository at this point in the history
* Fix #465
  • Loading branch information
arcadien committed Feb 10, 2024
1 parent a1e7214 commit 623b96e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
21 changes: 13 additions & 8 deletions macros/helpers/prime_line.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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 %}
{% set prime_line_height = params.LINE_HEIGHT|default(printer["gcode_macro _USER_VARIABLES"].prime_line_height)|float %}

# Set internal macro vars
{% set prime_line_x, prime_line_y = printer["gcode_macro _USER_VARIABLES"].prime_line_xy|map('float') %}
Expand All @@ -19,40 +20,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 %}
Expand All @@ -78,7 +83,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
Expand Down
1 change: 1 addition & 0 deletions user_templates/variables.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 623b96e

Please sign in to comment.