Skip to content

Commit

Permalink
fixed case where prime line could belong outside the bed
Browse files Browse the repository at this point in the history
  • Loading branch information
Frix-x authored Feb 27, 2024
1 parent 4a1d799 commit 6dc72d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion macros/base/start_print.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ gcode:
{% set TOOLS_USED = params.TOOLS_USED|default("")|string %} # Check if MMU gates (used in gcode file) are availables
{% set SYNC_MMU_EXTRUDER = params.SYNC_MMU_EXTRUDER|default(0)|int %} # set MMU gear motor and extruder synchronization during print TODO
{% set BED_MESH_PROFILE = params.MESH|default("")|string %} # Bed mesh profile to load
{% set ADAPTIVE_PRIMELINE = params.ADAPTIVE_PRIMELINE|default(True) %} # Weither to do or not an adaptive prime line near the real print zone
{% set ADAPTIVE_PRIMELINE = params.ADAPTIVE_PRIMELINE|default(1)|int %} # Weither to do or not an adaptive prime line near the real print zone

# Set the variables to be used in all the modules based on the slicer parameters
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=bed_temp VALUE={BED_TEMP}
Expand Down
23 changes: 14 additions & 9 deletions macros/helpers/prime_line.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ gcode:
{% 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)|default(0.6)|float %}
{% set prime_line_adaptive = params.ADAPTIVE_MODE|default(True) %}
{% set prime_line_adaptive = params.ADAPTIVE_MODE|default(1)|int %}
{% set prime_line_margin = params.LINE_MARGIN|default(printer["gcode_macro _USER_VARIABLES"].prime_line_margin)|default(5.0)|float %} # Used only in adaptive mode

# If the SIZE parameter is defined and not a dummy placeholder, we use it to do the adaptive bed mesh logic
{% set coordinatesFound = false %}
Expand All @@ -31,16 +32,22 @@ gcode:
{% 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 first layer is retrieved and adaptive mode is enabled, then we replace the coordinates to do an adaptive purge
{% if coordinatesFound and prime_line_adaptive %}
{% set prime_line_margin = params.LINE_MARGIN|default(printer["gcode_macro _USER_VARIABLES"].prime_line_margin)|default(5.0)|float %}
{% set center_x, center_y = [printer.toolhead.axis_maximum.x / 2, printer.toolhead.axis_maximum.y / 2]|map("float") %}

# If first layer coordinates are retrieved and adaptive mode is enabled, then we replace the coordinates to
# do an adaptive purge while being careful to have the line stay on the bed when the first layer
# is in an opposite bed quadrant than the prime line initial coordinates (due to mirrored coordinates from center axes)...
{% if coordinatesFound and prime_line_adaptive == 1 %}
{% set prime_line_x = 2*center_x - prime_line_x if (prime_line_x > center_x and xMaxSpec < center_x) or (prime_line_x < center_x and xMinSpec > center_x)
else prime_line_x %}
{% set prime_line_y = 2*center_y - prime_line_y if (prime_line_y > center_y and yMaxSpec < center_y) or (prime_line_y < center_y and yMinSpec > center_y)
else prime_line_y %}
{% set prime_line_x = [[prime_line_x, xMinSpec - prime_line_margin]|max, xMaxSpec + prime_line_margin]|min %}
{% set prime_line_y = [[prime_line_y, yMinSpec - prime_line_margin]|max, yMaxSpec + prime_line_margin]|min %}
{% endif %}

# Choose the way of printing the primeline (in + or -) alongside the direction to avoid going outside the bed boundaries
{% set axes_max = printer.toolhead.axis_maximum %}
{% set prime_line_way = -1 if (prime_line_direction == "X" and prime_line_x > axes_max.x/2) or (prime_line_direction == "Y" and prime_line_y > axes_max.y/2) else 1 %}
{% set prime_line_way = -1 if (prime_line_direction == "X" and prime_line_x > center_x) or (prime_line_direction == "Y" and prime_line_y > center_y) else 1 %}

{% set St = printer["gcode_macro _USER_VARIABLES"].travel_speed * 60 %}
{% set Sz = printer["gcode_macro _USER_VARIABLES"].z_drop_speed * 60 %}
Expand Down Expand Up @@ -73,9 +80,7 @@ gcode:

# We then compute the height to width ratio and validate that the prime line will not be too thin
{% 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!")}
{% endif %}
{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!")}
{% endif %}

# Finally we compute the speed to get the correct flowrate for the prime line
Expand Down

0 comments on commit 6dc72d2

Please sign in to comment.