-
Notifications
You must be signed in to change notification settings - Fork 5
/
macros.cfg
456 lines (385 loc) · 13.9 KB
/
macros.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
######################################################################
# Start Print and End Print
######################################################################
# Replace the slicer's custom start and end g-code scripts with
# START_PRINT and END_PRINT.
[gcode_macro WIPE_LINE]
gcode:
{% set z = params.Z|default(0.30)|float %}
{% set n = params.N|default(0.6)|float %}
{% if printer.toolhead.homed_axes != "xyz" %}
{action_respond_info("Please home XYZ first")}
{% elif printer.extruder.temperature < 170 %}
{action_respond_info("Extruder temperature too low")}
{% else %}
SAVE_GCODE_STATE NAME=WIPE_LINE_state
M82
G90
G92 E0
G1 X10 Y20 Z5 F3000
G1 Z{z} F3000
G1 X10 Y150 F1500 E10.83
G1 X{ n + 10.0 } F5000
G1 Y22 F1500 E21.5
G1 Y20 F5000
RESTORE_GCODE_STATE NAME=WIPE_LINE_state MOVE=0
{% endif %}
[delayed_gcode delayed_printer_off]
initial_duration: 600
gcode:
{% if printer.idle_timeout.state == "Idle" %}
M117 Shutdown
WLED_OFF
POWEROFF
{% endif %}
[gcode_macro POWEROFF]
variable_value: 1
gcode:
M117 Shutdown
SET_DISPLAY_GROUP GROUP=_blank
WLED_OFF
{action_call_remote_method("set_device_power",
device="Lighting",
state="off")}
{action_call_remote_method("set_device_power",
device="Filter",
state="off")}
UPDATE_DELAYED_GCODE ID=turn_off DURATION=5
[delayed_gcode turn_off]
gcode:
{action_call_remote_method("set_device_power",
device="Printer",
state="off")}
[save_variables]
filename: ~/klipper_config/variables.cfg
[gcode_macro SAVE_AT_END]
variable_save: 0
gcode:
SET_GCODE_VARIABLE MACRO=SAVE_AT_END VARIABLE=save VALUE=1
[gcode_macro SAVE_IF_SET]
gcode:
{% if printer["gcode_macro SAVE_AT_END"].save == 1 %}
SAVE_CONFIG
{% endif %}
[gcode_macro INITIALIZE_VARIABLE]
gcode:
{% if 'VARIABLE' not in params %}
{action_respond_info("Missing VARIABLE parameter")}
{% elif 'VALUE' not in params %}
{action_respond_info("Missing VALUE parameter")}
{% else %}
{% set svv = printer.save_variables.variables %}
{% if params.VARIABLE not in svv %}
{% set escaped = params.VALUE|replace("\"", "\\\"") %}
SAVE_VARIABLE VARIABLE={params.VARIABLE} VALUE="{escaped}"
{% endif %}
{% endif %}
[gcode_macro BEGIN_LAYER]
description: Start a new layer and notify system
gcode:
#Get layer details from Slicer GCode
{% set CUR_LAYER = params.NUM|default(0)|float + 1 %}
{% set NUM_LAYERS = params.COUNT|default(0)|float %}
{% set LAYER_Z = params.ZLAY|default(0)|float %}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=cur_layer VALUE={CUR_LAYER}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=num_layers VALUE={NUM_LAYERS}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=layer_z VALUE={LAYER_Z}
[gcode_macro M73]
rename_existing: M73.1
gcode:
{% set NUM_LAYERS = printer["gcode_macro PREP_PRINT"].num_layers %}
{% set CUR_LAYER = printer["gcode_macro PREP_PRINT"].cur_layer %}
M117 { "%02d:%02d" % (params.R|int // 60, (params.R|int) % 60) } remaining Layer {CUR_LAYER|int} of {NUM_LAYERS|int}
[gcode_macro PREP_PRINT]
description: Loads and starts the print
variable_x_max: 0
variable_y_max: 0
variable_z_max: 0
variable_nozzle: 0
variable_fila_dia: 0
variable_bed_temp: 0
variable_extruder_temp: 0
variable_chamber_temp: 0
variable_layer_count: 0
variable_tool_changes: 0
variable_cur_layer: 0
variable_num_layers: 0
variable_layer_z: 0
gcode:
M117 Print intializing...
#Get Printer built volume dimensions
{% set X_MAX = printer.toolhead.axis_maximum.x|default(400)|float %}
{% set Y_MAX = printer.toolhead.axis_maximum.y|default(400)|float %}
{% set Z_MAX = printer.toolhead.axis_maximum.z|default(450)|float %}
#Get Nozzle diameter and filament width for conditioning
{% set NOZZLE = printer.extruder.nozzle_diameter|default(0.6)|float %}
{% set FILADIA = printer.extruder.filament_diameter|default(1.75)|float %}
#Set Start coordinates of priming lines
{% set X_START = 10.0|default(10.0)|float %}
{% set Y_START = 20.0|default(20.0)|float %}
#Calculate Primer line extrusion volume and filament length
{% set PRIMER_WIDTH = 0.75 * NOZZLE %}
{% set PRIMER_HEIGHT = 0.70 * NOZZLE %}
{% set PRIMER_SECT = PRIMER_WIDTH * PRIMER_HEIGHT %}
{% set PRIMER_VOL = PRIMER_SECT * (X_MAX - 3 * X_START) %}
{% set FILA_SECT = 3.1415 * ( FILADIA / 2.0)**2 %}
{% set FILA_LENGTH = 1.55 * PRIMER_VOL / FILA_SECT %}
{% set FILAMENT_TYPE = params.FILAMENT|default(PLA)|string %}
#Get Bed, Extruder, and Chamber temperatures from Slicer GCode
{% set BED_TEMP = params.BED|default(0)|float %}
{% set EXTRUDER_TEMP = params.EXTRUDER|default(190)|float %}
{% set CHAMBER_TEMP = params.CHAMBER|default(0)|float %}
# Get Number of Layers
{% set NUM_LAYERS = params.COUNT|default(0)|float %}
{% set CUR_LAYER = params.NUM|default(0)|float + 1 %}
# Get Number of Tool Changes Required
{% set TOOL_CHANGES = params.TOOLS|default(0)|float %}
# Save print configuration specs for later use
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=x_max VALUE={X_MAX}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=y_max VALUE={Y_MAX}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=z_max VALUE={Z_MAX}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=nozzle VALUE={NOZZLE}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=fila_dia VALUE={FILADIA}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=bed_temp VALUE={BED_TEMP}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=extruder_temp VALUE={EXTRUDER_TEMP}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=chamber_temp VALUE={CHAMBER_TEMP}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=cur_layer VALUE={CUR_LAYER}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=num_layers VALUE={NUM_LAYERS}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=tool_changes VALUE={TOOL_CHANGES}
# Turn on the lights!
; WLED_ON PRESET=1
# Begin preheating and prepping for print
G90 ; use absolute coordinates
SET_GCODE_OFFSET Z=0.0
;M83 ; extruder relative mode
M117 Preheating bed for homing...
M104 S180 ; set temporary nozzle temp to prevent oozing during homing and auto bed leveling
G4 S10 ; allow partial nozzle warmup
M140 S{BED_TEMP} ; set final bed temp
M117 Homing all axis...
G28 ; home all axis
; BED_MESH_PROFILE LOAD="default"
G1 Z20 F240
G1 X2 Y10 F3000
M117 Waiting for temperatures to stabilize... B: {BED} H: {EXTRUDER_TEMP}
M104 S{EXTRUDER_TEMP} ; set final nozzle temp
M190 S{BED_TEMP} ; wait for bed temp to stabilize
M109 S{EXTRUDER_TEMP} ; wait for nozzle temp to stabilize
WIPE_LINE
M117 Print Started
[gcode_macro START_PRINT]
gcode:
{% set BED_TEMP = params.BED_TEMP|default(60)|float %}
{% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(190)|float %}
# Start bed heating
M140 S{BED_TEMP}
M104 S{EXTRUDER_TEMP - 20}
# Use absolute coordinates
G90
# Reset the G-Code Z offset (adjust Z offset if needed)
SET_GCODE_OFFSET Z=0.0
# Home the printer
G28
# Move the nozzle near the bed
G1 Z5 F3000
# Move the nozzle very close to the bed
G1 Z0.15 F300
# Wait for bed to reach temperature
M190 S{BED_TEMP}
# Set and wait for nozzle to reach temperature
M109 S{EXTRUDER_TEMP}
[gcode_macro END_PRINT]
gcode:
# Turn off bed, extruder, and fan
M140 S0
M104 S0
M106 S0
# Move nozzle away from print while retracting
G91
G1 X-20 Y-20 Z20 E-1 F300
# Raise nozzle by 20mm
#G1 Z20 F3000
G90
G1 X360 Y360 F3000
# 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
G91
G1 E-50 F1000
RESTORE_GCODE_STATE NAME=M600_state
######################################################################
# Override M117 command with rawparams
######################################################################
# The macro below will override the default M117 command to echo the message.
#
# It uses the rawparams pseudo-variable that contains the full unparsed
# parameters that was passed to the M117 command.
#
# As this can include comments, we are trimming the text when a `;` or `#` is
# found, and escaping any existing `"`
#[gcode_macro M117]
#rename_existing: M117.1
#gcode:
# {% if rawparams %}
# {% set escaped_msg = rawparams.split(';', 1)[0].split('\x23', 1)[0]|replace('"', '\\"') %}
# SET_DISPLAY_TEXT MSG="{escaped_msg}"
# RESPOND TYPE=command MSG="{escaped_msg}"
# {% else %}
# SET_DISPLAY_TEXT
# {% endif %}
# SDCard 'looping' (aka Marlin M808 commands) support
#
# Support SDCard looping
[sdcard_loop]
# 'Marlin' style M808 compatibility macro for SDCard looping
#[gcode_macro M808]
#gcode:
# {% if params.K is not defined and params.L is defined %}SDCARD_LOOP_BEGIN COUNT={params.L|int}{% endif %}
# {% if params.K is not defined and params.L is not defined %}SDCARD_LOOP_END{% endif %}
# {% if params.K is defined and params.L is not defined %}SDCARD_LOOP_DESIST{% endif %}
# Cancel object (aka Marlin/RRF M486 commands) support
#
# Enable object exclusion
[exclude_object]
[gcode_macro M486]
gcode:
# Parameters known to M486 are as follows:
# [C<flag>] Cancel the current object
# [P<index>] Cancel the object with the given index
# [S<index>] Set the index of the current object.
# If the object with the given index has been canceled, this will cause
# the firmware to skip to the next object. The value -1 is used to
# indicate something that isn’t an object and shouldn’t be skipped.
# [T<count>] Reset the state and set the number of objects
# [U<index>] Un-cancel the object with the given index. This command will be
# ignored if the object has already been skipped
{% if 'exclude_object' not in printer %}
{action_raise_error("[exclude_object] is not enabled")}
{% endif %}
{% if 'T' in params %}
EXCLUDE_OBJECT RESET=1
{% for i in range(params.T | int) %}
EXCLUDE_OBJECT_DEFINE NAME={i}
{% endfor %}
{% endif %}
{% if 'C' in params %}
EXCLUDE_OBJECT CURRENT=1
{% endif %}
{% if 'P' in params %}
EXCLUDE_OBJECT NAME={params.P}
{% endif %}
{% if 'S' in params %}
{% if params.S == '-1' %}
{% if printer.exclude_object.current_object %}
EXCLUDE_OBJECT_END NAME={printer.exclude_object.current_object}
{% endif %}
{% else %}
EXCLUDE_OBJECT_START NAME={params.S}
{% endif %}
{% endif %}
{% if 'U' in params %}
EXCLUDE_OBJECT RESET=1 NAME={params.U}
{% endif %}
#[gcode_macro G29]
#gcode: BED_MESH_CALIBRATE
[gcode_macro m205]
gcode:
[gcode_macro SHUTDOWN]
gcode:
{action_call_remote_method("shutdown_machine")}
[gcode_macro REBOOT]
gcode:
{action_call_remote_method("reboot_machine")}
[gcode_macro CANCEL_PRINT]
description: Cancel the actual running print
rename_existing: CANCEL_PRINT_BASE
variable_park: True
gcode:
## Move head and retract only if not already in the pause state and park set to true
{% if printer.pause_resume.is_paused|lower == 'false' and park|lower == 'true'%}
_TOOLHEAD_PARK_PAUSE_CANCEL
{% endif %}
TURN_OFF_HEATERS
M106 S0
CANCEL_PRINT_BASE
[gcode_macro PAUSE]
description: Pause the actual running print
rename_existing: PAUSE_BASE
gcode:
PAUSE_BASE
_TOOLHEAD_PARK_PAUSE_CANCEL
[gcode_macro RESUME]
description: Resume the actual running print
rename_existing: RESUME_BASE
gcode:
##### read extrude from _TOOLHEAD_PARK_PAUSE_CANCEL macro #####
{% set extrude = printer['gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL'].extrude %}
#### get VELOCITY parameter if specified ####
{% if 'VELOCITY' in params|upper %}
{% set get_params = ('VELOCITY=' + params.VELOCITY) %}
{%else %}
{% set get_params = "" %}
{% endif %}
##### end of definitions #####
{% if printer.extruder.can_extrude|lower == 'true' %}
M83
G1 E{extrude} F2100
{% if printer.gcode_move.absolute_extrude |lower == 'true' %} M82 {% endif %}
{% else %}
{action_respond_info("Extruder not hot enough")}
{% endif %}
RESUME_BASE {get_params}
[gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
description: Helper: park toolhead used in PAUSE and CANCEL_PRINT
variable_extrude: 1.0
gcode:
##### set park positon for x and y #####
# default is your max posion from your printer.cfg
{% set x_park = printer.toolhead.axis_maximum.x|float - 5.0 %}
{% set y_park = printer.toolhead.axis_maximum.y|float - 5.0 %}
{% set z_park_delta = 2.0 %}
##### calculate save lift position #####
{% set max_z = printer.toolhead.axis_maximum.z|float %}
{% set act_z = printer.toolhead.position.z|float %}
{% if act_z < (max_z - z_park_delta) %}
{% set z_safe = z_park_delta %}
{% else %}
{% set z_safe = max_z - act_z %}
{% endif %}
##### end of definitions #####
{% if printer.extruder.can_extrude|lower == 'true' %}
M83
G1 E-{extrude} F2100
{% if printer.gcode_move.absolute_extrude |lower == 'true' %} M82 {% endif %}
{% else %}
{action_respond_info("Extruder not hot enough")}
{% endif %}
{% if "xyz" in printer.toolhead.homed_axes %}
G91
G1 Z{z_safe} F900
G90
G1 X{x_park} Y{y_park} F6000
{% if printer.gcode_move.absolute_coordinates|lower == 'false' %} G91 {% endif %}
{% else %}
{action_respond_info("Printer not homed")}
{% endif %}