Skip to content

Instantly share code, notes, and snippets.

@djsplice
Created January 6, 2023 14:06
Show Gist options
  • Save djsplice/eb310ca8bc3c5a6c087517d9d83ad281 to your computer and use it in GitHub Desktop.
Save djsplice/eb310ca8bc3c5a6c087517d9d83ad281 to your computer and use it in GitHub Desktop.
# # # Klipper Adaptive Purging - ZeroG Logo # # #
# Based on the original found here: https://github.com/kyleisah/Klipper-Adaptive-Meshing-Purging/tree/main/Configuration
# This macro will parse information from objects in your gcode to define a min and max area, creating a nearby purge with Voron flair!
# For successful purging, you may need to configure:
#
# [extruder]
# max_extrude_cross_section: 5
[gcode_macro ADAPTIVE_PURGE]
description: A purge macro that adapts to be near your actual printed objects
variable_adaptive_enable: True # Change to False if you'd like the purge to be in the same spot every print
variable_z_height: 0.4 # Height above the bed to purge
variable_tip_distance: 15 # Distance between filament tip and nozzle before purge (this will require some tuning)
variable_purge_amount: 15 # Amount of filament to purge
variable_flow_rate: 10 # Desired flow rate in mm3/s
variable_x_default: 10 # X location to purge, overwritten if adaptive is True
variable_y_default: 10 # Y location to purge, overwritten if adaptive is True
variable_size: 20 # Size of the logo
variable_distance_to_object_x: 15 # Distance in x to the print area
variable_distance_to_object_y: 0 # Distance in y to the print area
variable_travel_speed: 300 # Travel speed
gcode:
{% if adaptive_enable == True %}
{% set all_points = printer.exclude_object.objects | map(attribute='polygon') | sum(start=[]) %}
{% set x_origin = (all_points | map(attribute=0) | min | default(x_default + distance_to_object_x + size)) - distance_to_object_x - size %}
{% set y_origin = (all_points | map(attribute=1) | min | default(y_default + distance_to_object_y + size)) - distance_to_object_y - size %}
{% set x_origin = ([x_origin, 0] | max) %}
{% set y_origin = ([y_origin, 0] | max) %}
{% else %}
{% set x_origin = x_default | float %}
{% set y_origin = y_default | float %}
{% endif %}
{% set purge_move_speed = 2.31 * size * flow_rate / (purge_amount * 2.405) %}
{% set prepurge_speed = flow_rate / 2.405 %}
{ action_respond_info( "x: " + x_origin|string + " y: " + y_origin|string + " purge_move_speed: " + purge_move_speed|string + " prepurge_speed: " + prepurge_speed|string ) }
G92 E0
G0 F{travel_speed*60} # Set travel speed
G90 # Absolute positioning
G0 X{x_origin} Y{y_origin+size/2} # Move to purge position
G0 Z{z_height} # Move to purge Z height
M83 # Relative extrusion mode
G1 E{tip_distance} F{prepurge_speed*60} # Move tip of filament to nozzle
G1 X{x_origin+size*0.285} Y{y_origin+size} E{purge_amount/4} F{purge_move_speed*60} # Purge first line of logo
G1 X{x_origin+size*0.789} Y{y_origin+size} E{purge_amount/4} F{purge_move_speed*60} # Purge second line of logo
G1 X{x_origin+size*0.250} Y{y_origin} E{purge_amount/4} F{purge_move_speed*60} # Purge third line of logo
G1 X{x_origin+size*0.711} Y{y_origin} E{purge_amount/4} F{purge_move_speed*60} # Purge fourth line of log
G1 X{x_origin+size} Y{y_origin+size/2} E{purge_amount/4} F{purge_move_speed*60} # Purge fifth line of logo
G1 X{x_origin+size*0.80} Y{y_origin+size/2} E{purge_amount/4} F{purge_move_speed*60} # Purge sixth line of logo
G1 E-0.5 F2100 # Retract
G92 E0 # Reset extruder distance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment