Skip to content

Commit

Permalink
Line purge will pick X or Y, cross_section warning
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleisah committed Apr 20, 2023
1 parent ce72499 commit e218dd9
Showing 1 changed file with 66 additions and 24 deletions.
90 changes: 66 additions & 24 deletions Configuration/Line_Purge_New.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 +23,91 @@ gcode:
{% set flow_rate = printer["gcode_macro _KAMP_Settings"].flow_rate | float %}


# Calculate purge origin from objects
# Calculate purge origins and centers from objects
{% set all_points = printer.exclude_object.objects | map(attribute='polygon') | sum(start=[]) %} # Get all object points
{% set purge_x_min = (all_points | map(attribute=0) | min | default(0)) %} # Object x min
{% set purge_x_max = (all_points | map(attribute=0) | max | default(0)) %} # Object x max
{% set purge_y_min = (all_points | map(attribute=1) | min | default(0)) %} # Object y min
{% set purge_y_max = (all_points | map(attribute=1) | max | default(0)) %} # Object y max

{% set purge_x_origin = ([((purge_x_max + purge_x_min) / 2) - (purge_amount / 2), 0] | max) %} # Center purge line relative to print
{% set purge_x_center = ([((purge_x_max + purge_x_min) / 2) - (purge_amount / 2), 0] | max) %} # Create center point of purge line relative to print on X axis
{% set purge_y_center = ([((purge_y_max + purge_y_min) / 2) - (purge_amount / 2), 0] | max) %} # Create center point of purge line relative to print on Y axis

{% set purge_y_origin = (all_points | map(attribute=1) | min | default(0)) %} # Object y min
{% set purge_y_origin = ([purge_y_origin - purge_margin, 0] | max) %} # Add margin to y min, compare to 0, and choose the larger
{% set purge_x_origin = ([purge_x_min - purge_margin, 0] | max) %} # Add margin to x min, compare to 0, and choose the larger
{% set purge_y_origin = ([purge_y_min - purge_margin, 0] | max) %} # Add margin to y min, compare to 0, and choose the larger

# Calculate purge speed
{% set purge_move_speed = (flow_rate / cross_section) * 60 | float %}

{% if verbose_enable == True %}
{% if cross_section != 5 %}

{action_respond_info("[Extruder] max_extrude_cross_section is not configured correctly, please set it to 5. Purge skipped.")}

{% else %}

{% if verbose_enable == True %}

{action_respond_info("Moving filament tip {}mms".format(
(tip_distance),
)) }
{% endif %}

{% if printer.firmware_retraction is defined %}
{action_respond_info("KAMP purge is using firmware retraction.")}
{% else %}
{action_respond_info("KAMP purge is not using firmware retraction, it is recommended to configure it.")}
{% endif %}

{action_respond_info("KAMP purge starting at {}, {} and purging {}mm of filament, requested flow rate is {}mm/s3.".format(
(purge_x_origin),
(purge_y_origin),
(purge_amount),
(flow_rate),
)) }
{% if purge_y_origin > 0 %}

{action_respond_info("KAMP purge starting at {}, {} and purging {}mm of filament, requested flow rate is {}mm/s3.".format(
(purge_x_center),
(purge_y_origin),
(purge_amount),
(flow_rate),
)) }

{% else %}

{action_respond_info("KAMP purge starting at {}, {} and purging {}mm of filament, requested flow rate is {}mm/s3.".format(
(purge_x_origin),
(purge_y_center),
(purge_amount),
(flow_rate),
)) }

{% endif %}
{% endif %}

{% if purge_y_origin > 0 %} # If there's room on Y, purge along X axis in front of print area

G92 E0 # Reset extruder
G0 F{travel_speed} # Set travel speed
G90 # Absolute positioning
G0 X{purge_x_origin} Y{purge_y_origin} # Move to purge position
G0 Z{purge_height} # Move to purge Z height
M83 # Relative extrusion mode
G1 E{tip_distance} F{purge_move_speed} # Move filament tip
G1 X{purge_x_origin + purge_amount} E{purge_amount} F{purge_move_speed} # Purge line
{RETRACT} # Retract
G92 E0 # Reset extruder distance
M82 # Absolute extrusion mode
G0 Z{purge_height * 2} F{travel_speed} # Z hop
G92 E0 # Reset extruder
G0 F{travel_speed} # Set travel speed
G90 # Absolute positioning
G0 X{purge_x_center} Y{purge_y_origin} # Move to purge position
G0 Z{purge_height} # Move to purge Z height
M83 # Relative extrusion mode
G1 E{tip_distance} F{purge_move_speed} # Move filament tip
G1 X{purge_x_center + purge_amount} E{purge_amount} F{purge_move_speed} # Purge line
{RETRACT} # Retract
G92 E0 # Reset extruder distance
M82 # Absolute extrusion mode
G0 Z{purge_height * 2} F{travel_speed} # Z hop

{% else %} # If there's room on X, purge along Y axis to the left of print area

G92 E0 # Reset extruder
G0 F{travel_speed} # Set travel speed
G90 # Absolute positioning
G0 X{purge_x_origin} Y{purge_y_center} # Move to purge position
G0 Z{purge_height} # Move to purge Z height
M83 # Relative extrusion mode
G1 E{tip_distance} F{purge_move_speed} # Move filament tip
G1 Y{purge_y_center + purge_amount} E{purge_amount} F{purge_move_speed} # Purge line
{RETRACT} # Retract
G92 E0 # Reset extruder distance
M82 # Absolute extrusion mode
G0 Z{purge_height * 2} F{travel_speed} # Z hop

{% endif %}

{% endif %}

0 comments on commit e218dd9

Please sign in to comment.