Skip to content

Instantly share code, notes, and snippets.

@alienboyxp
Last active July 27, 2024 12:31
Show Gist options
  • Save alienboyxp/fe225e1667da13557c270b7e5b73db10 to your computer and use it in GitHub Desktop.
Save alienboyxp/fe225e1667da13557c270b7e5b73db10 to your computer and use it in GitHub Desktop.
3Dwork.io - Klipper - Macro start_print
# Current Version v_20240319
# More detailed information and description - https://klipper.3dwork.io/klipper/empezamos/configuracion-klipper-en-laminadores
# Configure prime line - From Klipper-Adaptive-Meshing-Purging https://github.com/kyleisah/Klipper-Adaptive-Meshing-Purging
### START_PRINT ###
[gcode_macro START_PRINT]
##############################################################################
# BOOLEAN VARIABLES(True|False) ALWAYS UPPERCASE THE FIRST LETTER #
# LAS VARIABLES BOOLEANAS(True|False) SIEMPRE LA PRIMERA LETRA EN MAYUSCULAS #
##############################################################################
variable_buffer: 80
variable_adaptive_enable: False # Change to False if you'd like the purge to be in the same spot every print - Cambie a False si desea que la purga esté en el mismo lugar en cada impresión
variable_z_height: 0.3 # Height above the bed to purge - Altura sobre la cama para purgar
variable_z_speed: 300 # Default Z speed (in mm/min) for start print movements, set to 300 mm/min (5 mm/s)
variable_purge_amount: 35 # Amount of filament in millimeters to purge - Cantidad de filamento en milímetros a purgar
variable_line_length: 100 # (USE 80 as less) Overall desired length of purge line in millimeters, around 1/5th of X axis length is a good starting value - (USE 80 como poco) La longitud total deseada de la línea de purga en milímetros, alrededor de 1/5 de la longitud del eje X es un buen valor inicial
variable_flow_rate: 12 # Desired flow rate in mm3/s (Around 12 for standard flow hotends, around 24 for high flow hotends) - Caudal deseado en mm3/s (Alrededor de 12 para hotends de flujo estándar, alrededor de 24 para hotends de alto flujo)
variable_x_default: 5 # Default X location to purge. If adaptive_enable is True, this is overwritten - Ubicación X predeterminada para purgar. Si adaptive_enable es True, esto se sobrescribe
variable_y_default: 5 # Default Y location to purge. If adaptive_enable is True, this is overwritten - Ubicación Y predeterminada para purgar. Si adaptive_enable es True, esto se sobrescribe
variable_distance_to_object_y: 10 # Y distance in millimeters away from the print area for purging. Must be less than or equal to y_default if adaptive_enable is False - Distancia Y en milímetros desde el área de impresión para la purga. Debe ser menor o igual que y_default si adaptive_enable es False
#Configure Leveling
variable_calibrate_z_tilt: False # If True launch z-tilt calibration process - Si es True, realiza el proceso de calibración z-tilt - https://3dwork.qitec.net/klipper/empezamos/nivelacion-gantry-z-tilt
variable_calibrate_bed_mesh: True # If True create a new mesh False load default mesh - Si es True, crea una malla nueva. False, carga la malla predeterminada. - https://3dwork.qitec.net/klipper/empezamos/malla-nivelacion-de-cama-klipper
gcode:
#Get Printer built volume dimensions
#Obtener las dimensiones de impresion
{% set X_MAX = printer.toolhead.axis_maximum.x|default(100)|float %}
{ action_respond_info("x_max : %f" % (X_MAX)) }
{% set Y_MAX = printer.toolhead.axis_maximum.y|default(100)|float %}
{ action_respond_info("y_max : %f" % (Y_MAX)) }
{% set Z_MAX = printer.toolhead.axis_maximum.z|default(100)|float %}
{ action_respond_info("z_max : %f" % (Z_MAX)) }
#Get Printer config
#Obtener configuración de la impresora
{% set PROBECONFIG = printer['configfile'].config["probe"] is defined %}
{% set BLTOUCHCONFIG = printer['configfile'].config["bltouch"] is defined %}
{% set BEACONCONFIG = printer['configfile'].config["beacon"] is defined %}
{% set IDMCONFIG = printer['configfile'].config["idm"] is defined %}
{% set CARTOGRAPHERCONFIG = printer['configfile'].config["cartographer"] is defined %}
{% set Z_TILT = printer['configfile'].config["z_tilt"] is defined %}
{ action_respond_info("z-tilt : %d" % (Z_TILT)) }
#Get Nozzle diameter and filament width
#Obtener el diámetro de la boquilla y el ancho del filamento
{% set NOZZLE = printer.extruder.nozzle_diameter|default(0.4)|float %}
{ action_respond_info("nozzle_diameter : %f" % (NOZZLE)) }
{% set FILADIA = printer.extruder.filament_diameter|default(1.75)|float %}
{ action_respond_info("filament_diameter : %f" % (FILADIA)) }
#Set Start coordinates of priming lines
#Establecer las coordenadas de inicio de las líneas de purga
{% set X_START = 10.0|default(10.0)|float %}
{ action_respond_info("x_start : %f" % (X_START)) }
{% set Y_START = 20.0|default(20.0)|float %}
{ action_respond_info("y_start : %f" % (Y_START)) }
#Get Bed and Extruder temperature from Slicer GCode
#Obtener la temperatura de la cama y del extrusor del GCode del laminador
{% set BED_TEMP = params.BED_TEMP|default(60)|float %}
{ action_respond_info("bed_temperature : %f" % (BED_TEMP)) }
{% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(190)|float %}
{ action_respond_info("extruder_temperature : %f" % (EXTRUDER_TEMP)) }
#Get print boundaries from Slicer GCode
#Obtener límites de impresión del GCode del laminador
{% if adaptive_enable and not params.PRINT_MIN %}
{action_respond_info("PRINT_MIN is not provided")}
{% else %}
{action_respond_info("PRINT_MIN is provided")}
{% endif %}
#Pre-heat bed
#Precalentar la cama
M117 Pre-heating bed...
{ action_respond_info("Pre-heating bed : %d" % (BED_TEMP)) }
M140 S{BED_TEMP}
{% if PROBECONFIG %}
# Wait for extruder to reach 170 so an inductive probe (if present) is at a predictable temp - Espera a que la extrusora alcance 170 para que una sonda inductiva (si esta presente) este a una temperatura optima
# Also allows the bed heat to spread a little, and softens any plastic that might be stuck to the nozzle - También permite que el calor de la cama se propague un poco y ablanda cualquier plástico que pueda estar adherido a la boquilla
{action_respond_info("WAITING MINIMUM PROBE TEMPERATURE")}
{% set min_temp = printer.extruder.min_extrude_temp|default(170) %}
{ action_respond_info("Min Extrude Temp : %d" % (min_temp)) }
{ action_respond_info("Max Extrude Temp : %d" % (EXTRUDER_TEMP)) }
TEMPERATURE_WAIT SENSOR=extruder MINIMUM={min_temp} MAXIMUM={EXTRUDER_TEMP}
{% else %}
{action_respond_info("No PROBE detected bypass extruder MIN temp")}
{% endif %}
#Home
M117 Homing...
{action_respond_info("Homing...")}
G28
{action_respond_info("Homing Position...")}
GET_POSITION
#Z-tilt Leveling
{% if Z_TILT %}
{% if calibrate_z_tilt %}
M117 Z-tilt Leveling...
{action_respond_info("Z-TILT Leveling...")}
Z_TILT_ADJUST
{% endif %}
{% else %}
{action_respond_info("Z-TILT is not enabled")}
{% endif %}
#Bed Leveling
M117 Bed Leveling...
{action_respond_info("Bed Leveling...")}
{% if calibrate_bed_mesh and (BLTOUCHCONFIG or PROBECONFIG or BEACONCONFIG or IDMCONFIG or CARTOGRAPHERCONFIG) %}
BED_MESH_CLEAR
{ action_respond_info("Bed Leveling Mesh Cleared...")}
{ action_respond_info("print_min: %s" % params.PRINT_MIN) }
{ action_respond_info("print_max: %s" % params.PRINT_MAX) }
BED_MESH_CALIBRATE MESH_MIN={params.PRINT_MIN} MESH_MAX={params.PRINT_MAX} PROFILE=default # Create a new bed mesh if adaptative area is provided will use it
{action_respond_info("Bed Leveling Creating New Mesh...")}
BED_MESH_PROFILE LOAD=default # Load stored bed mesh
{action_respond_info("Bed Leveling Loading Default Mesh...")}
{% else %}
BED_MESH_PROFILE LOAD=default # Load stored bed mesh
{action_respond_info("Bed Leveling Loading Default Mesh...")}
{% endif %}
#Pre-heat nozzle
#Precalentar nozzle
M117 Pre-heating extruder...
{ action_respond_info("Pre-heating extruder : %d" % (EXTRUDER_TEMP)) }
M104 S{EXTRUDER_TEMP}
#Move up to clean bed
#Desplazamiento a zona de calentado
M117 Parking to Heat Position...
{action_respond_info("Parking to Heat Position...")}
G1 X{X_MAX / 2.0} Y{Y_MAX - 20} Z{Z_MAX / 4.0} F6000
{action_respond_info("Parking Position...")}
GET_POSITION
#Heat nozzle and bed
#Calentando nozzle y cama
M117 Heating bed...
{ action_respond_info("Heating Bed at : %d" % (BED_TEMP)) }
M190 S{BED_TEMP}
M117 Heating Extruder...
{ action_respond_info("Heating Extruder at : %d" % (EXTRUDER_TEMP)) }
M109 S{EXTRUDER_TEMP} T0
#Prime Line
#Linea de purgado
{% if adaptive_enable %}
{% if params.PRINT_MIN %}
{% set print_min_y = params.PRINT_MIN.split(",")[1]|float %}
{% set y_origin = (print_min_y - distance_to_object_y) | float %}
{% if y_origin < 5 %} # Check y_origin out of bounds
{ action_respond_info("Corrected y_origin dynamic prime line out of bounds : %f" % (y_origin)) }
{% set y_origin = y_default | float %}
{% endif %}
{% set x_origin = params.PRINT_MIN.split(",")[0]|float %}
{ action_respond_info("Prime Line x_origin : %f" % (x_origin)) }
{ action_respond_info("Prime Line y_origin : %f" % (y_origin)) }
{% endif %}
{% else %}
{% set x_origin = x_default | float %}
{% set y_origin = y_default | float %}
{ action_respond_info("Prime Line x_origin : %f" % (x_origin)) }
{ action_respond_info("Prime Line y_origin : %f" % (y_origin)) }
{% endif %}
{% set max_extrude_cross_section = printer.configfile.settings.extruder.max_extrude_cross_section | float %}
{ action_respond_info("max_extrude_cross_section : %f" % (max_extrude_cross_section)) }
{% set z_offset = 0 %}
{% if BLTOUCHCONFIG %}
M117 BlTouch zoffset used...
{action_respond_info("BlTouch zoffset used...")}
{% set z_offset = printer.configfile.settings.bltouch.z_offset %}
{% elif PROBECONFIG %}
M117 Probe zoffset used...
{action_respond_info("Probe zoffset used...")}
{% set z_offset = printer.configfile.config.probe.z_offset %}
{% elif BEACONCONFIG %}
M117 Beacon zoffset used...
{action_respond_info("Beacon zoffset used...")}
{% set z_offset = printer.configfile.config.beacon.z_offset %}
{% elif IDMCONFIG %}
M117 IDM zoffset used...
{action_respond_info("IDM zoffset used...")}
{% set z_offset = printer.configfile.config.idm.z_offset %}
{% elif CARTOGRAPHERCONFIG %}
M117 Cartographer zoffset used...
{action_respond_info("Cartographer zoffset used...")}
{% set z_offset = printer.configfile.config.cartographer.z_offset %}
{% endif %}
# Prime Line Volumetric Calculations
# Calculos volumetricos para la linea de purga
{% set nozzle_dia = printer.configfile.config.extruder.nozzle_diameter | float %}
{ action_respond_info("nozzle_dia : %f" % (nozzle_dia)) }
{% set cross_section = nozzle_dia * z_height | float %}
{ action_respond_info("cross_section : %f" % (cross_section)) }
{% set purge_move_speed = (cross_section * flow_rate) * 60 | float %}
{ action_respond_info("purge_move_speed : %f" % (purge_move_speed)) }
{% set travel_speed = (printer.toolhead.max_velocity) * 60 | float %}
{ action_respond_info("travel_speed : %f" % (travel_speed)) }
{ action_respond_info("z_speed : %f" % (z_speed)) }
M117 Prime Line...
{action_respond_info("Prime Line...")}
G92 E0 # Reset extruder
G0 F{travel_speed/1.5} # Set travel speed
G90 # Absolute positioning
G1 X{x_origin} Y{y_origin} # Move to purge position
G1 Z{nozzle_dia} F{z_speed} # Move to purge Z height
M83 # Relative extrusion mode
# Prime Line X check to adjust to PRINT_MAX_X coordinate
{% set x_prime_end = (x_origin + line_length) | float %}
{% set print_max_x = params.PRINT_MAX.split(",")[0]|float %}
{% if x_prime_end > print_max_x %}
{% set x_prime_end = print_max_x | float %}
{% endif %}
{ action_respond_info("x_prime_end : %f" % (x_prime_end)) }
{% if adaptive_enable == False %}
M117 Prime Blob...
{action_respond_info("Prime Blob...")}
# Extrude a blob
G1 F60 E20
# 40% fan
M106 S102
# Move the extruder up by 5mm while extruding, breaks away from blob
G1 Z5 F100 E5
# Move to wipe position, but keep extruding so the wipe is attached to blob
G1 F200 X{x_origin + 25} E1
# Go down diagonally while extruding
# Broken down in z moves under 2mm as a workaround for a tuning tower test.
# The tuning tower command thinks a new print has been started when z moves over 2mm and aborts.
G1 F200 X{x_origin + 30} Z3.8 E0.5
G1 F200 X{x_origin + 35} Z2.6 E0.5
G1 F200 X{x_origin + 40} Z1.4 E0.5
G1 F200 X{x_origin + 45} Z0.2 E0.5
# 0% fan
M106 S0
# Wipe line
M117 Wiping Prime Line...
{action_respond_info("Wiping Prime Line...")}
G1 X{x_prime_end - 10} Z{z_height} E{purge_amount/2} F{purge_move_speed} # Purge line
G1 X{x_prime_end} F{travel_speed}
{% else %}
M117 Wiping Prime Line...
{action_respond_info("Wiping Prime Line...")}
# Wipe line
G1 X{x_prime_end - 10} Z{z_height} E{purge_amount/2} F{purge_move_speed} # Purge line
G1 X{x_prime_end} F{travel_speed}
{% endif %}
M117 Getting Ready to Print...
{action_respond_info("Getting Ready to Print...")}
G1 E-{nozzle_dia} F2100 # Retract nozzle diameter
G92 E0 # Reset extruder distance
M82 # Absolute extrusion mode
G0 Z{z_height * 2} F{z_speed} # Z hop
M117 Ready to Print...
{action_respond_info("Ready to Print...")}
[gcode_macro SETUP_START_PRINT]
gcode:
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=calibrate_bed_mesh VALUE={params.CALIBRATE_BED_MESH|default(True)|int}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=adaptive_enable VALUE={params.ADAPTIVE_ENABLE|default(True)|int}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=z_height VALUE={params.Z_HEIGHT|default(0.4)|float}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=purge_amount VALUE={params.PURGE_AMOUNT|default(40)|float}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=line_length VALUE={params.LINE_LENGTH|default(50)|float}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=flow_rate VALUE={params.FLOW_RATE|default(12)|float}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=x_default VALUE={params.X_DEFAULT|default(10)|float}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=y_default VALUE={params.Y_DEFAULT|default(10)|float}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=distance_to_object_y VALUE={params.DISTANCE_TO_OBJECT_Y|default(10)|float}
[gcode_macro M109]
description: Transform M109 (wait for hotend temperature) gcode to Klipper native macro
rename_existing: M99109
gcode:
{% set s = params.S|float %} # Parameters
M104 {% for p in params %}{'%s%s' % (p, params[p])}{% endfor %} # Set hotend temp
{% if s != 0 %}
TEMPERATURE_WAIT SENSOR=extruder MINIMUM={s-1} MAXIMUM={s+1} # Wait for hotend temp (within 1 degree)
{% endif %}
[gcode_macro M190]
description: Transform M190 (wait for bed temperature) gcode to Klipper native macro
rename_existing: M99190
gcode:
{% set s = params.S|float %} # Parameters
M140 {% for p in params %}{'%s%s' % (p, params[p])}{% endfor %} # Set bed temp
{% if s != 0 %}
TEMPERATURE_WAIT SENSOR=heater_bed MINIMUM={s-1} MAXIMUM={s+1} # Wait for bed temp (within 1 degree)
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment