cribbageSTARSHIP

AI-macros.cfg

Jul 13th, 2025
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.09 KB | None | 0 0
  1. # Klipper Custom G-Code Macros - Updated & Complete
  2. #
  3. # In your slicer, set your start G-code to:
  4. # START_PRINT BED_TEMP=[first_layer_bed_temperature] EXTRUDER_TEMP=[first_layer_temperature]
  5. #
  6. # And your end G-code to:
  7. # END_PRINT
  8. #
  9.  
  10. # --- 1. Slicer Entry Point Macros ---
  11. # These are the simple macros you call from your slicer.
  12.  
  13. [gcode_macro START_PRINT]
  14. description: The primary macro called by your slicer to start a print
  15. gcode:
  16. # Pass all slicer parameters to the main start logic
  17. _PRINT_START_LOGIC BED_TEMP={params.BED_TEMP} EXTRUDER_TEMP={params.EXTRUDER_TEMP}
  18.  
  19. [gcode_macro END_PRINT]
  20. description: The primary macro called by your slicer to end a print
  21. gcode:
  22. _PRINT_END_LOGIC
  23.  
  24. # --- 2. Core Print Workflows ---
  25. # These macros contain the detailed logic for starting and ending a print.
  26.  
  27. [gcode_macro _PRINT_START_LOGIC]
  28. gcode:
  29. # Parameters passed from START_PRINT
  30. {% set BED_TEMP = params.BED_TEMP|default(60)|float %}
  31. {% set EXTRUDER_TEMP = params.EXTRUDER|default(210)|float %}
  32. {% set x_wait = printer.toolhead.axis_maximum.x|float / 2 %}
  33. {% set y_wait = printer.toolhead.axis_maximum.y|float / 2 %}
  34.  
  35. M117 Homing...
  36. _CG28 ; Conditional home
  37.  
  38. M117 Heating Bed to {BED_TEMP}C...
  39. M190 S{BED_TEMP}
  40.  
  41. M117 Heating Hotend to 150C for probing...
  42. M109 S150
  43.  
  44. M117 Creating Bed Mesh...
  45. BED_MESH_CALIBRATE ADAPTIVE=1
  46.  
  47. M117 Heating Hotend to {EXTRUDER_TEMP}C...
  48. G1 X{x_wait} Y{y_wait} Z15 F9000
  49. M109 S{EXTRUDER_TEMP}
  50.  
  51. M117 Purging...
  52. LINE_PURGE ; This is a generic purge line macro defined below
  53.  
  54. M117 Print Starting!
  55.  
  56. [gcode_macro _PRINT_END_LOGIC]
  57. gcode:
  58. # Get printer boundaries
  59. {% set max_x = printer.configfile.config["stepper_x"]["position_max"]|float %}
  60. {% set max_y = printer.configfile.config["stepper_y"]["position_max"]|float %}
  61.  
  62. M400 ; Wait for buffer to clear
  63. G92 E0 ; Zero the extruder
  64. G1 E-4.0 F3600 ; Retract filament
  65.  
  66. # Move nozzle up and away
  67. G90 ; Absolute positioning
  68. G0 X{max_x / 2} Y{max_y - 10} F3600 ; Move to back-center
  69.  
  70. TURN_OFF_HEATERS
  71. M107 ; Turn off part cooling fan
  72.  
  73. M84 ; Disable motors
  74.  
  75. M117 Print Finished!
  76.  
  77. # --- 3. Pause / Resume / Cancel ---
  78. # These are essential for interacting with the print from Mainsail.
  79.  
  80. [gcode_macro PAUSE]
  81. description: Pause the active print
  82. rename_existing: PAUSE_BASE
  83. gcode:
  84. PAUSE_BASE
  85. _TOOLHEAD_PARK_PAUSE_CANCEL
  86.  
  87. [gcode_macro RESUME]
  88. description: Resume the active print
  89. rename_existing: RESUME_BASE
  90. gcode:
  91. M109 S{printer.motion_queue.extruder_temp} ; Restore extruder temperature
  92. RESUME_BASE
  93.  
  94. [gcode_macro CANCEL_PRINT]
  95. description: Cancel the active print
  96. rename_existing: CANCEL_PRINT_BASE
  97. gcode:
  98. TURN_OFF_HEATERS
  99. _TOOLHEAD_PARK_PAUSE_CANCEL
  100. CLEAR_PAUSE
  101. SDCARD_RESET_FILE
  102. BASE_CANCEL
  103.  
  104. [gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
  105. description: Helper macro to park the toolhead during a pause or cancel
  106. gcode:
  107. SAVE_GCODE_STATE NAME=PAUSE_PARK
  108. G90
  109. G1 Z{printer.toolhead.position.z + 5} F19000
  110. G1 X{printer.toolhead.axis_maximum.x / 2} Y{printer.toolhead.axis_minimum.y + 5} F19000
  111. RESTORE_GCODE_STATE NAME=PAUSE_PARK
  112.  
  113. # --- 4. Filament Handling ---
  114. # Macros for loading, unloading, and changing filament mid-print.
  115.  
  116. [gcode_macro M600]
  117. description: Filament change command
  118. gcode:
  119. PAUSE
  120. M117 Filament Change
  121. M118 Unload filament, then insert new filament.
  122. M118 Once ready, click RESUME.
  123.  
  124. [gcode_macro LOAD_FILAMENT]
  125. description: Load filament into the extruder
  126. gcode:
  127. {% set TEMP = params.TEMP|default(210)|int %}
  128. M109 S{TEMP}
  129. M117 Loading Filament...
  130. G91
  131. G1 E50 F300
  132. G1 E40 F100
  133. G90
  134. M117 Filament Loaded
  135.  
  136. [gcode_macro UNLOAD_FILAMENT]
  137. description: Unload filament from the extruder
  138. gcode:
  139. {% set TEMP = params.TEMP|default(210)|int %}
  140. M109 S{TEMP}
  141. M117 Unloading Filament...
  142. G91
  143. G1 E5 F300
  144. G1 E-10 F2000
  145. G1 E-70 F1500
  146. G90
  147. M117 Filament Unloaded
  148.  
  149. # --- 5. Utility & Compatibility Macros ---
  150. # These are helper macros and G-code overrides.
  151.  
  152. [gcode_macro _CG28]
  153. description: Conditional G28 (home only if needed)
  154. gcode:
  155. {% if "xyz" not in printer.toolhead.homed_axes %}
  156. G28
  157. {% endif %}
  158.  
  159. [gcode_macro G29]
  160. description: Override G29 to run a full adaptive bed mesh
  161. gcode:
  162. BED_MESH_CLEAR
  163. BED_MESH_CALIBRATE ADAPTIVE=1
  164.  
  165. [gcode_macro LINE_PURGE]
  166. description: A generic purge line macro
  167. gcode:
  168. G92 E0 ; Reset Extruder
  169. G1 Z1.0 F3000 ; Move Z up
  170. G1 X5 Y5 F5000 ; Move to start position
  171. G1 Z0.3 F5000 ; Move Z down
  172. G1 F2000
  173. G1 X100 E20 ; Draw the first line
  174. G1 X100 Y5.3 ; Move to side
  175. G1 X5 E20 ; Draw the second line
  176. G92 E0 ; Reset Extruder
  177. G1 Z1.0 F3000 ; Move Z up
  178.  
  179. # --- 6. Diagnostic Macros ---
  180. # Macros used for tuning and testing.
  181.  
  182. [gcode_macro TEST_SPEED]
  183. description: Test for max speed and acceleration parameters.
  184. gcode:
  185. # Parameters
  186. {% set speed = params.SPEED|default(printer.configfile.settings.printer.max_velocity)|int %}
  187. {% set iterations = params.ITERATIONS|default(5)|int %}
  188. {% set accel = params.ACCEL|default(printer.configfile.settings.printer.max_accel)|int %}
  189. {% set bound = params.BOUND|default(20)|int %}
  190. # Axis Boundaries
  191. {% set x_min = printer.toolhead.axis_minimum.x + bound %}
  192. {% set x_max = printer.toolhead.axis_maximum.x - bound %}
  193. {% set y_min = printer.toolhead.axis_minimum.y + bound %}
  194. {% set y_max = printer.toolhead.axis_maximum.y - bound %}
  195.  
  196. SAVE_GCODE_STATE NAME=TEST_SPEED
  197. { action_respond_info("TEST_SPEED: starting %d iterations at speed %d, accel %d" % (iterations, speed, accel)) }
  198. G28
  199. G0 X{x_min} Y{y_min} Z{bound + 10} F{speed*60}
  200. SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel}
  201. {% for i in range(iterations) %}
  202. G0 X{x_min} Y{y_min} F{speed*60}
  203. G0 X{x_max} Y{y_max} F{speed*60}
  204. G0 X{x_max} Y{y_min} F{speed*60}
  205. G0 X{x_min} Y{y_max} F{speed*60}
  206. {% endfor %}
  207. SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel}
  208. G28
  209. RESTORE_GCODE_STATE NAME=TEST_SPEED
  210.  
  211. # --- Custom Utility Macros ---
  212.  
  213. [gcode_macro HEAT_BED_FOR_TIME]
  214. gcode:
  215. # Announce the start of the process
  216. M117 Homing...
  217.  
  218. # Home all three axes
  219. G28
  220.  
  221. # Announce the next step
  222. M117 Lifting gantry...
  223.  
  224. # Set to absolute positioning and lift gantry to 200mm
  225. G90
  226. G1 Z200 F3000
  227.  
  228. # Get parameters or use defaults
  229. {% set T = params.TEMP|default(60)|int %}
  230. {% set M = params.TIME|default(30)|int %}
  231.  
  232. # Announce heating cycle and set bed temperature
  233. M117 Heating bed to {T}C for {M} mins.
  234. SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={T}
  235.  
  236. # Wait for the specified time in minutes
  237. G4 P{M * 60000}
  238.  
  239. # Turn off bed heater and announce completion
  240. SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET=0
  241. M117 Bed heating complete.
  242.  
Advertisement
Add Comment
Please, Sign In to add comment