-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacros.cfg
780 lines (670 loc) · 29.3 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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
# Macros
#####################################################################
[force_move]
enable_force_move: True
[gcode_macro CG28]
gcode:
{% if "xyz" not in printer.toolhead.homed_axes %}
G28
{% endif %}
[gcode_macro G32]
gcode:
SAVE_GCODE_STATE NAME=STATE_G32
STOP_LED_EFFECTS
SET_LED_EFFECT EFFECT=leveling_comet
G90
G28
QUAD_GANTRY_LEVEL
G28
STOP_LED_EFFECTS
## Uncomment for for your size printer:
#--------------------------------------------------------------------
## Uncomment for 250mm build
#G0 X125 Y125 Z30 F3600
# Uncomment for 300 build
G0 X150 Y150 Z30 F3600
## Uncomment for 350mm build
#G0 X175 Y175 Z30 F3600
#--------------------------------------------------------------------
RESTORE_GCODE_STATE NAME=STATE_G32
[gcode_macro MR_NOTIFY]
description: Allows you to send a custom notification via Mobileraker without using the M117 command
gcode:
{% set msg = "MR_NOTIFY:" ~ (params.TITLE ~ "|" if 'TITLE' in params|upper else "") ~ params.MESSAGE %}
{% if 'MESSAGE' in params|upper %}
{ action_respond_info(msg) }
{% else %}
{ action_raise_error('Must provide MESSAGE parameter') }
{% endif %}
#.................................................................................................................
[homing_override]
axes: xyz
gcode:
STATUS_HOMING
{% set X_MID = printer.configfile.config["stepper_x"]["position_max"]|float / 2.0 %}
{% set Y_MID = printer.configfile.config["stepper_y"]["position_max"]|float / 2.0 %}
{% set home_all = 'X' not in params and 'Y' not in params and 'Z' not in params %}
{% set Z_POS = printer.toolhead.position.z %}
#......Conditional Z-Hop
# ! If the Z axis is not already homed, a full homed sequence will be run. If this is not desired, comment out the below line with !!!!!
# The 'Safety On' line below crudely gets around the issue of a false homed state when either 'set_position_z: 0.0' or 'SET_KINEMATIC_POSITION Z=0'
# The problem is that if either of these commands are issued, and the Z axis is not currently homed, it will now register as homed and potentially cause
# issues with that false homed state later. Conditional flags could be set on the onset, saving which axes were already homed before using
# 'SET_KINEMATIC_POSITION Z=0' to then be followed by logic to execute M18 [AXIS that wasn't homed] to reflect the true state of things, but klipper
# M18/M84 does not take axis flag - it's all or nothing.
{% if "z" not in printer.toolhead.homed_axes %} ; Check if Z not already homed
{% set home_all = 'Safety On' %} ; !!!!! THIS WILL HOME ALL AXIS IF Z IS NOT HOMED, COMMENT OUT IF THIS IS NOT DESIRED !!!!!
SET_KINEMATIC_POSITION Z=0
G0 Z10 F3600 ; Raise toolhead 10mm since unknown/not homed
{% else %}
{% if Z_POS < 10 %}
G90
G0 Z10 ; Make sure Z height is at least 10mm
{% else %}
G91
G0 Z1 F3600 ; If Z was above 10mm, raise by 1mm for safety
G90
{% endif %}
{% endif %}
#......Sort Y
{% if home_all or 'Y' in params %}
_HOME_Y
{% endif %}
#......Sort X
{% if home_all or 'X' in params %}
_HOME_X
{% endif %}
#......Sort Z
{% if home_all or 'Z' in params %}
G90
G0 X{X_MID} Y{Y_MID} F4000
G28 Z
G1 Z10
{% endif %}
STATUS_OFF
[gcode_macro _CQGL]
gcode:
{% if printer.quad_gantry_level.applied == False %}
{% if "xyz" not in printer.toolhead.homed_axes %}
G28 ; home if not already homed
{% endif %}
QUAD_GANTRY_LEVEL
G28 Z
{% endif %}
#####################################################################
# LIGHTS
#####################################################################
[gcode_macro lights_off]
gcode:
SET_PIN PIN=caselight VALUE=0
[gcode_macro lights_on]
gcode:
SET_PIN PIN=caselight VALUE=.5
[gcode_macro lights]
gcode:
{% if printer["output_pin caselight"].value > 0 %}
lights_off
{% else %}
lights_on
{% endif %}
[gcode_macro lights_out]
gcode:
LIGHTS_OFF
STOP_LED_EFFECTS
SET_LOGO_LEDS_OFF
SET_NOZZLE_LEDS_OFF
SET_SKIRT_LEDS_OFF
[gcode_macro exhaust]
gcode:
{% if printer["fan_generic Exhaust"].speed > 0 %}
SET_FAN_SPEED FAN=Exhaust SPEED=0
{% else %}
SET_FAN_SPEED FAN=Exhaust SPEED=1
{% endif %}
###############################################################################
# CANCEL
###############################################################################
[gcode_macro CANCEL_PRINT]
rename_existing: BASE_CANCEL_PRINT
gcode:
G92 E0 ; zero the extruder
G1 E-5.0 F1800 ; retract filament
CLEAR_PAUSE
SDCARD_RESET_FILE
BASE_CANCEL_PRINT
TURN_OFF_HEATERS
STOP_LED_EFFECTS
SET_LOGO_LEDS_OFF
SET_NOZZLE_LEDS_OFF
SET_SKIRT_LEDS_OFF
M106 S0
SET_FAN_SPEED FAN=Exhaust SPEED=0
SET_FAN_SPEED FAN=Nevermore SPEED=0
# safe anti-stringing move coords
{% set th = printer.toolhead %}
{% set x_safe = th.position.x + 20 * (1 if th.axis_maximum.x - th.position.x > 20 else -1) %}
{% set y_safe = th.position.y + 20 * (1 if th.axis_maximum.y - th.position.y > 20 else -1) %}
{% set z_safe = [th.position.z + 2, th.axis_maximum.z]|min %}
G90 ; absolute positioning
G0 X{x_safe} Y{y_safe} Z{z_safe} F20000 ; move nozzle to remove stringing
G0 X{th.axis_maximum.x//2} Y{th.axis_maximum.y - 2} F3600 ; park nozzle at rear
###############################################################################
# PAUSE
###############################################################################
[gcode_macro PAUSE]
rename_existing: BASE_PAUSE
gcode:
# Parameters
{% set z = params.Z|default(10)|int %} ; z hop amount
{% if printer['pause_resume'].is_paused|int == 0 %}
SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=zhop VALUE={z} ; set z hop variable for reference in resume macro
SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=etemp VALUE={printer['extruder'].target} ; set hotend temp variable for reference in resume macro
SAVE_GCODE_STATE NAME=PAUSE ; save current print position for resume
BASE_PAUSE ; pause print
{% if (printer.gcode_move.position.z + z) < printer.toolhead.axis_maximum.z %} ; check that zhop doesn't exceed z max
G91 ; relative positioning
G1 Z{z} F900 ; raise Z up by z hop amount
{% else %}
{ action_respond_info("Pause zhop exceeds maximum Z height.") } ; if z max is exceeded, show message and set zhop value for resume to 0
SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=zhop VALUE=0
{% endif %}
G90 ; absolute positioning
G1 X{printer.toolhead.axis_maximum.x/2} Y{printer.toolhead.axis_minimum.y+5} F19500 ; park toolhead at front center
SAVE_GCODE_STATE NAME=PAUSEPARK ; save parked position in case toolhead is moved during the pause (otherwise the return zhop can error)
M104 S0 ; turn off hotend
SET_IDLE_TIMEOUT TIMEOUT=43200 ; set timeout to 12 hours
{% endif %}
###############################################################################
# RESUME
###############################################################################
[gcode_macro RESUME]
rename_existing: BASE_RESUME
variable_zhop: 0
variable_etemp: 0
gcode:
# Parameters
{% set e = params.E|default(2.5)|int %}
{% if printer['pause_resume'].is_paused|int == 1 %}
SET_IDLE_TIMEOUT TIMEOUT={printer.configfile.settings.idle_timeout.timeout} ; set timeout back to configured value
{% if etemp > 0 %}
M109 S{etemp|int} ; wait for hotend to heat back up
{% endif %}
RESTORE_GCODE_STATE NAME=PAUSEPARK MOVE=1 MOVE_SPEED=100 ; go back to parked position in case toolhead was moved during pause (otherwise the return zhop can error)
G91 ; relative positioning
M83 ; relative extruder positioning
{% if printer[printer.toolhead.extruder].temperature >= printer.configfile.settings.extruder.min_extrude_temp %}
G1 Z{zhop * -1} E{e} F900 ; prime nozzle by E, lower Z back down
{% else %}
G1 Z{zhop * -1} F900 ; lower Z back down without priming (just in case we are testing the macro with cold hotend)
{% endif %}
RESTORE_GCODE_STATE NAME=PAUSE MOVE=1 MOVE_SPEED=100 ; restore position
BASE_RESUME ; resume print
{% endif %}
# Filament runout / change alias
[gcode_macro M600]
gcode:
M117 $MR$:$printer_name requires a filament swap
PAUSE
###############################################################################
# FILAMENT
###############################################################################
[gcode_macro UNLOAD_FILAMENT]
gcode:
PARKFRONT
{% if printer['extruder'].temperature < 220 %}
{% set t = params.T|default(220)|int %}
M104 S{t}
M109 S{t}
{% endif %}
SAVE_GCODE_STATE NAME=UNLOADFILAMENT
#M83 ; set extruder to relative
#G1 E10 F600 ; extrude a little to soften tip
#G1 E-25 F1800 ; retract filament completely
#G1 E-25 F1800 ; retract filament completely
#G1 E-25 F1800 ; retract filament completely
#G1 E-25 F1800 ; retract filament completely
#G1 E-25 F1800 ; retract filament completely
G0 E10 F500 # extruder 20mm of filament before extracting
G0 E-5 F3600 #extract filament to cold end
G4 P2000 # wait for two seconds
G0 E6 F3600 # push the filament back
G0 E-10 F9600 #extract filament to cold end
G0 E-100 F300
RESTORE_GCODE_STATE NAME=UNLOADFILAMENT
M83
[gcode_macro LOAD_FILAMENT]
gcode:
{% if printer['extruder'].temperature < 240 %}
{% set t = params.T|default(240)|int %}
M104 S{t}
M82 #set extruder to absolute mode
G92 E0
FORCE_MOVE STEPPER=extruder DISTANCE=15 VELOCITY=10 ACCEL=1000
PARKFRONT
M109 S{t}
{% endif %}
# {% else %}
SAVE_GCODE_STATE NAME=LOADFILAMENT
M83 ; set extruder to relative
#G1 E25 F300
#G1 E25 F300
#G1 E100 F550
G1 E2600 F3600
RESTORE_GCODE_STATE NAME=LOADFILAMENT
M109 S{t}
M83
# {% endif %}
#[gcode_macro HOT_UNLOAD]
#gcode:
# # Parameters
# {% set t = params.T|default(220)|int %}
#
# M104 S{t}
# PARKFRONT
# M109 S{t}
# UNLOAD_FILAMENT
#
#[gcode_macro HOT_LOAD]
#gcode:
# # Parameters
# {% set t = params.T|default(220)|int %}
#
# M104 S{t}
# PARKFRONT
# M109 S{t}
# LOAD_FILAMENT
###############################################################################
# CONDITIONAL HOMING
###############################################################################
# Conditional G28 (home if not already homed)
[gcode_macro CG28]
gcode:
{% if "xyz" not in printer.toolhead.homed_axes %}
G28
{% endif %}
# Conditional G28 (home if not already homed)
[gcode_macro XYCG28]
gcode:
{% if "xy" not in printer.toolhead.homed_axes %}
G28 X Y
{% endif %}
[gcode_macro ZCG28]
gcode:
{% if "z" not in printer.toolhead.homed_axes %}
G28 Z
{% endif %}
[gcode_macro QUAD_GANTRY_LEVEL]
rename_existing: _QUAD_GANTRY_LEVEL
gcode:
SET_LED_EFFECT EFFECT=leveling_comet
# If QGL is not applied, first run a course calibration
{% if printer.quad_gantry_level.applied == False %}
_QUAD_GANTRY_LEVEL RETRY_TOLERANCE=1.0
{% endif %}
# then perform fine QGL down to desired spec
# this has to be a separate macro call so the results of the above call will be visible!
_FINE_QUAD_GANTRY_LEVEL
[gcode_macro _FINE_QUAD_GANTRY_LEVEL]
gcode:
{% if printer.quad_gantry_level.applied == True %}
# go for full quality at reduced probing height
_QUAD_GANTRY_LEVEL HORIZONTAL_MOVE_Z=1.0 # <- set your preferred probing height here!
{% else %}
# This should never happen, just perform the full calibration using the defaults
{action_respond_info("Fine QGL called without calling course QGL first!")}
_QUAD_GANTRY_LEVEL # default behavior, no speedup
{% endif %}
G1 Y50 F20000
STOP_LED_EFFECTS
###############################################################################
# PARKING
###############################################################################
# Park front center
[gcode_macro PARKFRONT]
gcode:
CG28
SAVE_GCODE_STATE NAME=PARKFRONT
G90
G0 X{printer.toolhead.axis_maximum.x/2} Y{printer.toolhead.axis_minimum.y+5} Z{printer.toolhead.axis_maximum.z/2} F19500
RESTORE_GCODE_STATE NAME=PARKFRONT
# Park front center, but low down
[gcode_macro PARKFRONTLOW]
gcode:
CG28
SAVE_GCODE_STATE NAME=PARKFRONT
G90
G0 X{printer.toolhead.axis_maximum.x/2} Y{printer.toolhead.axis_minimum.y+5} Z20 F19500
RESTORE_GCODE_STATE NAME=PARKFRONT
# Park top rear left
[gcode_macro PARKREAR]
gcode:
CG28
SAVE_GCODE_STATE NAME=PARKREAR
G90
G0 X{printer.toolhead.axis_minimum.x+10} Y{printer.toolhead.axis_maximum.y-10} Z{printer.toolhead.axis_maximum.z-50} F19500
RESTORE_GCODE_STATE NAME=PARKREAR
# Park center of build volume
[gcode_macro PARKCENTER]
gcode:
CG28
SAVE_GCODE_STATE NAME=PARKCENTER
G90
G0 X{printer.toolhead.axis_maximum.x/2} Y{printer.toolhead.axis_maximum.y/2} Z{printer.toolhead.axis_maximum.z/2} F19500
RESTORE_GCODE_STATE NAME=PARKCENTER
# Park 15mm above center of bed
[gcode_macro PARKBED]
gcode:
CG28
SAVE_GCODE_STATE NAME=PARKBED
G90
G0 X{printer.toolhead.axis_maximum.x/2} Y{printer.toolhead.axis_maximum.y/2} Z15 F19500
RESTORE_GCODE_STATE NAME=PARKBED
###############################################################################
# TEMPERATURE
###############################################################################
[gcode_macro M109]
rename_existing: M99109
gcode:
#Parameters
{% set s = params.S|float %}
M104 {% for p in params %}{'%s%s' % (p, params[p])}{% endfor %} ; Set hotend temp
{% if s != 0 %}
TEMPERATURE_WAIT SENSOR=extruder MINIMUM={s} MAXIMUM={s+1} ; Wait for hotend temp (within 1 degree)
{% endif %}
[gcode_macro M190]
rename_existing: M99190
gcode:
#Parameters
{% set s = params.S|float %}
M140 {% for p in params %}{'%s%s' % (p, params[p])}{% endfor %} ; Set bed temp
{% if s != 0 %}
TEMPERATURE_WAIT SENSOR=heater_bed MINIMUM={s} MAXIMUM={s+1} ; Wait for bed temp (within 1 degree)
{% endif %}
###############################################################################
# TIMED HEAT SOAK
###############################################################################
[gcode_macro HEAT_SOAK]
description: heats the bed for a while
variable_target_temp: 0
variable_stage: None ## heating -> soaking -> done -> None
## in seconds
variable_check_interval: 10
variable_soak_time_remaining: 0
variable_total_time_elapsed: 0
gcode:
{% set TARGET = params.TARGET | default(110) | float %}
{% set DURATION = (params.DURATION | default(30) | int) * 60 %} ## minutes to seconds
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=target_temp VALUE={ TARGET }
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=stage VALUE="'heating'"
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_time_remaining VALUE={ DURATION }
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=total_time_elapsed VALUE=0
;; fire up the heater
SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={ TARGET }
;; run the fan to circulate air
SET_FAN_SPEED FAN=Nevermore SPEED=1.0
;; put the bed and nozzle where they're a safe distance apart
CG28
PARKCENTER
STATUS_BED_HEATING
M84 ;; turn off steppers
UPDATE_DELAYED_GCODE ID=heat_soaker DURATION={ check_interval }
[gcode_macro CANCEL_HEAT_SOAK]
description: cancels an in-progress HEAT_SOAK cycle
gcode:
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=stage VALUE="'cancel'"
UPDATE_DELAYED_GCODE ID=heat_soaker DURATION=1
SET_FAN_SPEED FAN=Nevermore SPEED=0
STATUS_OFF
[delayed_gcode heat_soaker]
; ## debug
; { action_respond_info( printer['gcode_macro HEAT_SOAK'] | tojson )}
gcode:
{% set heat_soak = printer['gcode_macro HEAT_SOAK'] %}
## update total time elapsed
{% set total_time_elapsed = heat_soak.total_time_elapsed + heat_soak.check_interval %}
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=total_time_elapsed VALUE={ total_time_elapsed }
{% set stage = heat_soak.stage %}
{% if stage == "heating" and printer.heater_bed.temperature >= heat_soak.target_temp %}
{% set stage = "soaking" %}
{% endif %}
{% if stage == "soaking" %}
## update soak countdown
{% set soak_time_remaining = [heat_soak.soak_time_remaining - heat_soak.check_interval, 0] | max %}
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_time_remaining VALUE={ soak_time_remaining }
SET_FAN_SPEED FAN=Nevermore SPEED=1
{% if soak_time_remaining == 0 %}
{% set stage = "done" %}
{% endif %}
{% endif %}
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=stage VALUE="'{ stage }'"
{% if stage in ("done", "cancel") %}
{% if stage == "cancel" %}
{% set stage = "done" %}
TURN_OFF_HEATERS
SET_FAN_SPEED FAN=Nevermore SPEED=0
#M107 ; turn off fan
RESPOND TYPE=echo MSG="{ "soak cancelled after ~%.1fm" | format(total_time_elapsed / 60.0) }"
{% else %}
RESPOND TYPE=echo MSG="{ "soak complete after %.1fm" | format(total_time_elapsed / 60.0) }"
{% endif %}
## reset all state vars, except stage, which may be queried via the api
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=target_temp VALUE=0
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_time_remaining VALUE=0
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=total_time_elapsed VALUE=0
BASE_PAUSE
{% else %}
{% if total_time_elapsed % 90 == 0 %}
## output status periodically
{% if stage == "heating" %}
RESPOND TYPE=echo MSG="{ "heating -- %.1fm elapsed" | format(total_time_elapsed / 60.0)}"
RESPOND TYPE=echo MSG="{ printer['heater_bed'].temperature }"
{% elif stage == "soaking" %}
RESPOND TYPE=echo MSG="{ "soaking -- %.1fm remaining" | format(soak_time_remaining / 60.0)}"
RESPOND TYPE=echo MSG="{ printer['heater_bed'].temperature }"
{% endif %}
{% endif %}
## trigger ourselves again
UPDATE_DELAYED_GCODE ID=heat_soaker DURATION={ heat_soak.check_interval }
## dwell for 1ms to prevent from going idle
G4 P1
{% endif %}
###############################################################################
# CANCEL 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 %}
###############################################################################
# Dump Parameters
###############################################################################
[gcode_macro DUMP_PARAMETERS]
description: Dump all Klipper parameters to terminal, helps find names and values of variables for use in macros
gcode:
{% set parameters = namespace(output = '') %}
{% for name1 in printer %}
{% for name2 in printer[name1] %}
{% set donotwant = ['bed_mesh','configfile'] %}
{% if name1 is not in donotwant %}
{% set param = "printer['%s'].%s = %s" % (name1, name2, printer[name1][name2]) %}
{% set parameters.output = parameters.output + param + "\n" %}
{% endif %}
{% else %}
{% set param = "printer['%s'] = %s" % (name1, printer[name1]) %}
{% set parameters.output = parameters.output + param + "\n" %}
{% endfor %}
{% endfor %}
{action_respond_info(parameters.output)}
###############################################################################
# Utilities
###############################################################################
[gcode_macro Belt_Tension]
description: A macro that assists with repeatable belt tensioning.
variable_y_tensioning_position: 115 #Position the printhead needs to be to have 150mm of belt length exposed for belt tensioning.
gcode:
{% set x_max = printer.configfile.settings.stepper_x.position_max %}
{% set travel_speed = printer.configfile.settings.printer.max_velocity %}
G0 X{x_max/2} Y{y_tensioning_position} F{travel_speed*60}
{ action_respond_info( "Tension A/B belts to 110hz @ X: {}, Y: {}".format(x_max/2, y_tensioning_position) ) }
[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
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 %}
# 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:
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}
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
SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel} ACCEL_TO_DECEL={accel / 2}
{% 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}
# 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
# Small 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 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
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}
# Re-home and get position again for comparison:
G28
# 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
[gcode_macro FANTEST]
gcode:
RESPOND MSG="10%"
M106 S25.5
G4 P2000
RESPOND MSG="20%"
M106 S51
G4 P2000
RESPOND MSG="30%"
M106 S76.5
G4 P2000
RESPOND MSG="40%"
M106 S102
G4 P2000
RESPOND MSG="50%"
M106 S127.5
G4 P2000
RESPOND MSG="60%"
M106 S153
G4 P2000
RESPOND MSG="70%"
M106 S178.5
G4 P2000
RESPOND MSG="80%"
M106 S204
G4 P2000
RESPOND MSG="90%"
M106 S229.5
G4 P2000
RESPOND MSG="100%"
M106 S255
G4 P3000
M107