|
| 1 | +[gcode_macro VORON_PURGE] |
| 2 | +description: A purge macro that adapts to be near your actual printed objects |
| 3 | +gcode: |
| 4 | + # Get relevant printer params |
| 5 | + {% set travel_speed = (printer.toolhead.max_velocity) * 60 | float %} |
| 6 | + {% set cross_section = printer.configfile.settings.extruder.max_extrude_cross_section | float %} |
| 7 | + |
| 8 | + # Use firmware retraction if it is defined |
| 9 | + {% if printer.firmware_retraction is defined %} |
| 10 | + {% set RETRACT = G10 | string %} |
| 11 | + {% set UNRETRACT = G11 | string %} |
| 12 | + {% else %} |
| 13 | + {% set RETRACT = 'G1 E-.5 F2100' | string %} |
| 14 | + {% set UNRETRACT = 'G1 E.5 F2100' | string %} |
| 15 | + {% endif %} |
| 16 | + |
| 17 | + # Get purge settings from _Kamp_Settings |
| 18 | + {% set verbose_enable = printer["gcode_macro _KAMP_Settings"].verbose_enable | abs %} |
| 19 | + {% set purge_height = printer["gcode_macro _KAMP_Settings"].purge_height | float %} |
| 20 | + {% set tip_distance = printer["gcode_macro _KAMP_Settings"].tip_distance | float %} |
| 21 | + {% set purge_margin = printer["gcode_macro _KAMP_Settings"].purge_margin | float %} |
| 22 | + {% set purge_amount = printer["gcode_macro _KAMP_Settings"].purge_amount | float %} |
| 23 | + {% set flow_rate = printer["gcode_macro _KAMP_Settings"].flow_rate | float %} |
| 24 | + {% set size = 10 | float %} |
| 25 | + |
| 26 | + # Calculate purge origins and centers from objects |
| 27 | + {% set all_points = printer.exclude_object.objects | map(attribute='polygon') | sum(start=[]) %} # Get all object points |
| 28 | + {% set purge_x_min = (all_points | map(attribute=0) | min | default(0)) %} # Object x min |
| 29 | + {% set purge_x_max = (all_points | map(attribute=0) | max | default(0)) %} # Object x max |
| 30 | + {% set purge_y_min = (all_points | map(attribute=1) | min | default(0)) %} # Object y min |
| 31 | + {% set purge_y_max = (all_points | map(attribute=1) | max | default(0)) %} # Object y max |
| 32 | + |
| 33 | + {% 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 |
| 34 | + {% 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 |
| 35 | + |
| 36 | + {% set purge_x_origin = ([purge_x_min - purge_margin, 0] | max) %} # Add margin to x min, compare to 0, and choose the larger |
| 37 | + {% set purge_y_origin = ([purge_y_min - purge_margin, 0] | max) %} # Add margin to y min, compare to 0, and choose the larger |
| 38 | + |
| 39 | + # Calculate purge speed |
| 40 | + {% set purge_move_speed = (flow_rate / 5.0) * 60 | float %} |
| 41 | + |
| 42 | + {% if cross_section < 5 %} |
| 43 | + |
| 44 | + {action_respond_info("[Extruder] max_extrude_cross_section is insufficient for purge, please set it to 5 or greater. Purge skipped.")} |
| 45 | + |
| 46 | + {% else %} |
| 47 | + |
| 48 | + {% if verbose_enable == True %} |
| 49 | + |
| 50 | + {action_respond_info("Moving filament tip {}mms".format( |
| 51 | + (tip_distance), |
| 52 | + )) } |
| 53 | + {% endif %} |
| 54 | + |
| 55 | + {% if printer.firmware_retraction is defined %} |
| 56 | + {action_respond_info("KAMP purge is using firmware retraction.")} |
| 57 | + {% else %} |
| 58 | + {action_respond_info("KAMP purge is not using firmware retraction, it is recommended to configure it.")} |
| 59 | + {% endif %} |
| 60 | + |
| 61 | + G92 E0 # Reset extruder |
| 62 | + G0 F{travel_speed} # Set travel speed |
| 63 | + G90 # Absolute positioning |
| 64 | + G0 X{purge_x_origin} Y{purge_y_origin+size/2} # Move to purge position |
| 65 | + G0 Z{purge_height} # Move to purge Z height |
| 66 | + M83 # Relative extrusion mode |
| 67 | + G1 E{tip_distance} F{purge_move_speed} # Move tip of filament to nozzle |
| 68 | + G1 X{purge_x_origin+size*0.289} Y{purge_y_origin+size} E{purge_amount/4} F{purge_move_speed}# Purge first line of logo |
| 69 | + G1 E-.5 F2100 # Retract |
| 70 | + G0 Z{purge_height*2} # Z hop |
| 71 | + G0 X{purge_x_origin+size*0.789} Y{purge_y_origin+size} # Move to second purge line origin |
| 72 | + G0 Z{purge_height} # Move to purge Z height |
| 73 | + G1 E.5 F2100 # Recover |
| 74 | + G1 X{purge_x_origin+size*0.211} Y{purge_y_origin} E{purge_amount/2} F{purge_move_speed} # Purge second line of logo |
| 75 | + G1 E-.5 F2100 # Retract |
| 76 | + G0 Z{purge_height*2} # Z hop |
| 77 | + G0 X{purge_x_origin+size*0.711} Y{purge_y_origin} # Move to third purge line origin |
| 78 | + G0 Z{purge_height} # Move to purge Z height |
| 79 | + G1 E.5 F2100 # Recover |
| 80 | + G1 X{purge_x_origin+size} Y{purge_y_origin+size/2} E{purge_amount/4} F{purge_move_speed} # Purge third line of logo |
| 81 | + G1 E-.5 F2100 # Retract |
| 82 | + G92 E0 # Reset extruder distance |
| 83 | + M82 # Absolute extrusion mode |
| 84 | + G0 Z{purge_height*2} F{travel_speed} |
| 85 | + |
| 86 | + {% endif %} |
0 commit comments