# This file provides Klipper G-Code macros. # See docs/Config_Reference.md for a description of parameters. ###################################################################### # Start Print and End Print ###################################################################### # Replace the slicer's custom start and end g-code scripts with # START_PRINT and END_PRINT. See docs/Slicers.md for more information on using these macros. [gcode_macro PRINT_START] gcode: # This part fetches data from your slicer. Such as bed temp, extruder temp and size of your printer. {% set target_bed = params.BED|int %} {% set target_extruder = params.EXTRUDER|int %} # Apply our z-offset SET_GCODE_OFFSET Z=0 _SET_PLATE_OFFSET # Homes the printer, sets absolute positioning, update the Stealthburner leds and clear old bed mesh. STATUS_PRINTING # Sets SB-leds to printing-mode SET_NOZZLE_LEDS_OFF # Disable SB nozzle leds G28 # Full home (XYZ) G90 # Absolute position BED_MESH_CLEAR # Clears old saved bed mesh (if any) # Heat up the bed with 5 minute soak. RESPOND TYPE=echo_no_space MSG="Bed: {target_bed}c" # Displays info M190 S{target_bed} # Sets the target temp for the bed RESPOND TYPE=echo_no_space MSG="Soak for 5min" # Displays info G4 P300000 # Waits 5 min for the bedtemp to stabilize # Heating nozzle to 150 degrees. This helps with getting a correct Z-home RESPOND TYPE=echo_no_space MSG="Hotend: 150c" # Displays info M109 S150 # Heats the nozzle to 150c # Adjust for gantry tilt. RESPOND TYPE=echo_no_space MSG="Z-tilt adjust" # Displays info Z_TILT_ADJUST # Levels the x gantry via z_tilt_adjust G28 Z # Homes Z again after z_tilt_adjust # Take a mesh of the bed. RESPOND TYPE=echo_no_space MSG="Bed mesh" # Displays info BED_MESH_CALIBRATE # Starts bed mesh # Parks the printhead, update the SB-leds and heat the nozzle. RESPOND TYPE=echo_no_space MSG="Hotend: {target_extruder}c" # Displays info SMART_PARK # Move the printhead near the print area M109 S{target_extruder} # Heats the nozzle to printing temp # Gets ready to print by doing a purge line and updating the SB-leds RESPOND TYPE=echo_no_space MSG="Printer goes brr" # Displays info SET_NOZZLE_LEDS_ON # Enable SB nozzle leds LINE_PURGE # Purge line G90 # Absolute position [gcode_macro PRINT_END] gcode: # Fetch position for axis {% set x_min = printer.toolhead.axis_minimum.x %} {% set y_max = printer.toolhead.axis_maximum.y %} # Turn off bed, extruder, and fan M140 S0 M104 S0 M106 S0 # Move nozzle away from print while retracting G91 G1 X-2 Y-2 E-3 F300 # Raise nozzle by 10mm G1 Z10 F3000 G90 # Present print G1 X{x_min} Y{y_max} # Disable steppers M84 ###################################################################### # Filament Change ###################################################################### # M600: Filament Change. This macro will pause the printer, move the # tool to the change position, and retract the filament 50mm. Adjust # the retraction settings for your own extruder. After filament has # been changed, the print can be resumed from its previous position # with the "RESUME" gcode. [pause_resume] [gcode_macro M600] gcode: {% set X = params.X|default(50)|float %} {% set Y = params.Y|default(0)|float %} {% set Z = params.Z|default(10)|float %} SAVE_GCODE_STATE NAME=M600_state PAUSE G91 G1 E-.8 F2700 G1 Z{Z} G90 G1 X{X} Y{Y} F3000 FILAMENT_UNLOAD # Use orbiter sensor unload macro RESTORE_GCODE_STATE NAME=M600_state # Enable the "M118" and "RESPOND" extended commands. [respond] # Enable object exclusion [exclude_object] ###################################################################### # Maximum Speed and Acceleration ###################################################################### [gcode_macro TEST_SPEED] # Home, get position, throw around toolhead, home again. # If MCU stepper positions (first line in GET_POSITION) are greater than a full step different (your number of microsteps), then skipping occured. # We only measure to a full step to accomodate for endstop variance. # Example: TEST_SPEED SPEED=300 ACCEL=5000 ITERATIONS=10 description: Test for max speed and acceleration parameters for the printer. Procedure: Home -> ReadPositionFromMCU -> MovesToolhead@Vel&Accel -> Home -> ReadPositionfromMCU gcode: # Speed {% set speed = params.SPEED|default(printer.configfile.settings.printer.max_velocity)|int %} # Iterations {% set iterations = params.ITERATIONS|default(5)|int %} # Acceleration {% set accel = params.ACCEL|default(printer.configfile.settings.printer.max_accel)|int %} # Minimum Cruise Ratio {% set min_cruise_ratio = params.MIN_CRUISE_RATIO|default(0.5)|float %} # Bounding inset for large pattern (helps prevent slamming the toolhead into the sides after small skips, and helps to account for machines with imperfectly set dimensions) {% set bound = params.BOUND|default(20)|int %} # Size for small pattern box {% set smallpatternsize = SMALLPATTERNSIZE|default(20)|int %} # Large pattern # Max positions, inset by BOUND {% set x_min = printer.toolhead.axis_minimum.x + bound %} {% set x_max = printer.toolhead.axis_maximum.x - bound %} {% set y_min = printer.toolhead.axis_minimum.y + bound %} {% set y_max = printer.toolhead.axis_maximum.y - bound %} # Small pattern at center # Find X/Y center point {% set x_center = (printer.toolhead.axis_minimum.x|float + printer.toolhead.axis_maximum.x|float ) / 2 %} {% set y_center = (printer.toolhead.axis_minimum.y|float + printer.toolhead.axis_maximum.y|float ) / 2 %} # Set small pattern box around center point {% set x_center_min = x_center - (smallpatternsize/2) %} {% set x_center_max = x_center + (smallpatternsize/2) %} {% set y_center_min = y_center - (smallpatternsize/2) %} {% set y_center_max = y_center + (smallpatternsize/2) %} # Save current gcode state (absolute/relative, etc) SAVE_GCODE_STATE NAME=TEST_SPEED # Output parameters to g-code terminal { action_respond_info("TEST_SPEED: starting %d iterations at speed %d, accel %d" % (iterations, speed, accel)) } # Home and get position for comparison later: M400 # Finish moves - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/66 G28 # QGL if not already QGLd (only if QGL section exists in config) {% if printer.configfile.settings.quad_gantry_level %} {% if printer.quad_gantry_level.applied == False %} QUAD_GANTRY_LEVEL G28 Z {% endif %} {% endif %} # Move 50mm away from max position and home again (to help with hall effect endstop accuracy - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/24) G90 G1 X{printer.toolhead.axis_maximum.x-50} Y{printer.toolhead.axis_maximum.y-50} F{30*60} M400 # Finish moves - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/66 G28 X Y G0 X{printer.toolhead.axis_maximum.x-1} Y{printer.toolhead.axis_maximum.y-1} F{30*60} G4 P1000 GET_POSITION # Go to starting position G0 X{x_min} Y{y_min} Z{bound + 10} F{speed*60} # Set new limits {% if printer.configfile.settings.printer.minimum_cruise_ratio is defined %} SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel} MINIMUM_CRUISE_RATIO={min_cruise_ratio} {% else %} SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel} ACCEL_TO_DECEL={accel / 2} {% endif %} {% for i in range(iterations) %} # Large pattern diagonals G0 X{x_min} Y{y_min} F{speed*60} G0 X{x_max} Y{y_max} F{speed*60} G0 X{x_min} Y{y_min} F{speed*60} G0 X{x_max} Y{y_min} F{speed*60} G0 X{x_min} Y{y_max} F{speed*60} G0 X{x_max} Y{y_min} F{speed*60} # Large pattern box G0 X{x_min} Y{y_min} F{speed*60} G0 X{x_min} Y{y_max} F{speed*60} G0 X{x_max} Y{y_max} F{speed*60} G0 X{x_max} Y{y_min} F{speed*60} # Small pattern diagonals G0 X{x_center_min} Y{y_center_min} F{speed*60} G0 X{x_center_max} Y{y_center_max} F{speed*60} G0 X{x_center_min} Y{y_center_min} F{speed*60} G0 X{x_center_max} Y{y_center_min} F{speed*60} G0 X{x_center_min} Y{y_center_max} F{speed*60} G0 X{x_center_max} Y{y_center_min} F{speed*60} # Small pattern box G0 X{x_center_min} Y{y_center_min} F{speed*60} G0 X{x_center_min} Y{y_center_max} F{speed*60} G0 X{x_center_max} Y{y_center_max} F{speed*60} G0 X{x_center_max} Y{y_center_min} F{speed*60} {% endfor %} # Restore max speed/accel/accel_to_decel to their configured values {% if printer.configfile.settings.printer.minimum_cruise_ratio is defined %} SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel} MINIMUM_CRUISE_RATIO={printer.configfile.settings.printer.minimum_cruise_ratio} {% else %} SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel} ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel_to_decel} {% endif %} # Re-home and get position again for comparison: M400 # Finish moves - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/66 G28 # This is a full G28 to fix an issue with CoreXZ - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/12 # Go to XY home positions (in case your homing override leaves it elsewhere) G90 G0 X{printer.toolhead.axis_maximum.x-1} Y{printer.toolhead.axis_maximum.y-1} F{30*60} G4 P1000 GET_POSITION # Restore previous gcode state (absolute/relative, etc) RESTORE_GCODE_STATE NAME=TEST_SPEED