-
-
Notifications
You must be signed in to change notification settings - Fork 138
/
macros.cfg
1323 lines (1153 loc) · 53.8 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
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# WARNING: DO NOT EDIT THIS FILE
# To override settings from this file, you can copy and paste the relevant
# sections into your printer.cfg and change it there.
#####
# INCLUDE MACRO FILES
#####
[include macros/*.cfg]
#####
# GENERAL MACROS
#####
[gcode_macro PAUSE]
description: Pauses the print
rename_existing: PAUSE_BASE
variable_extrude: 1.5 # extrusion in mm when resuming the print
variable_retract: 1.5 # retraction in mm when print is paused
variable_fan_speed: 0 # internal use only. Do not touch!
variable_idex_mode: "" # internal use only. Do not touch!
variable_idex_toolhead: 0 # internal use only. Do not touch!
variable_idex_toolhead_x: 0.0 # internal use only. Do not touch!
variable_idex_toolhead_y: 0.0 # internal use only. Do not touch!
variable_idex_toolhead_z: 0.0 # internal use only. Do not touch!
gcode:
# parameter
{% set runout_detected = true if params.RUNOUT|default(false)|lower == 'true' else false %}
# visual feedback
_LED_PAUSE
# IDEX mode
{% set idex_mode = '' %}
{% if printer["dual_carriage"] is defined %}
{% set idex_mode = printer["dual_carriage"].carriage_1|lower %}
{% set idex_toolhead = 1 if idex_mode == 'primary' else 0 %}
{% endif %}
# Save gcode state
{% if printer["dual_carriage"] is not defined %}
SAVE_GCODE_STATE NAME=PAUSE_state
{% else %}
SET_GCODE_VARIABLE MACRO=PAUSE VARIABLE=idex_mode VALUE='"{idex_mode}"'
SET_GCODE_VARIABLE MACRO=PAUSE VARIABLE=idex_toolhead VALUE={idex_toolhead}
SET_GCODE_VARIABLE MACRO=PAUSE VARIABLE=idex_toolhead_x VALUE={printer.gcode_move.gcode_position.x|float}
SET_GCODE_VARIABLE MACRO=PAUSE VARIABLE=idex_toolhead_y VALUE={printer.gcode_move.gcode_position.y|float}
SET_GCODE_VARIABLE MACRO=PAUSE VARIABLE=idex_toolhead_z VALUE={printer.gcode_move.gcode_position.z|float}
DEBUG_ECHO PREFIX="PAUSE" MSG="idex_mode: {idex_mode}, idex_toolhead: {idex_toolhead}, idex_toolhead_x: {idex_toolhead_x}, idex_toolhead_y: {idex_toolhead_y}, idex_toolhead_z: {idex_toolhead_z}"
{% endif %}
# set is_printing_gcode state
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=is_printing_gcode VALUE=False
# Handle toolhead settings
CACHE_TOOLHEAD_SETTINGS KEY="pause"
SET_MACRO_TRAVEL_SETTINGS
# Calculate safe Z position
{% set max_z = printer.toolhead.axis_maximum.z|float %}
{% set current_z = printer.toolhead.position.z|float %}
{% if current_z < (max_z - 20.0) %}
{% set z_safe = 20.0 %}
{% else %}
{% set z_safe = max_z - current_z %}
{% endif %}
# Call internal PAUSE command
PAUSE_BASE
# Cache part cooling fan speed
{% if printer["dual_carriage"] is not defined %}
SET_GCODE_VARIABLE MACRO=PAUSE VARIABLE=fan_speed VALUE={printer["fan"].speed|float}
{% else %}
{% if idex_mode == 'copy' or idex_mode == 'mirror' %}
SET_GCODE_VARIABLE MACRO=PAUSE VARIABLE=fan_speed VALUE={printer["fan_generic part_fan_t0"].speed|float}
{% else %}
{% if idex_toolhead == 0 %}
SET_GCODE_VARIABLE MACRO=PAUSE VARIABLE=fan_speed VALUE={printer["fan_generic part_fan_t0"].speed|float}
{% else %}
SET_GCODE_VARIABLE MACRO=PAUSE VARIABLE=fan_speed VALUE={printer["fan_generic part_fan_t1"].speed|float}
{% endif %}
{% endif %}
{% endif %}
# Turn part cooling fan off
M106 S0
# Can extruder extrude
{% set can_extrude = true if printer['extruder'].can_extrude|lower == 'true' else false %}
{% if idex_mode != '' %}
{% if idex_mode == 'copy' or idex_mode == 'mirror' %}
{% set can_extrude = true if printer['extruder'].can_extrude|lower == 'true' and printer['extruder1'].can_extrude|lower == 'true' else false %}
{% else %}
{% if printer.toolhead.extruder == 'extruder1' %}
{% set can_extrude = true if printer['extruder1'].can_extrude|lower == 'true' else false %}
{% endif %}
{% endif %}
{% endif %}
# Retract
{% set R = printer["gcode_macro PAUSE"].retract|float %}
{% if can_extrude %}
G91 # Relative positioning
G1 E-{R} F2100
G90 # Absolute positioning
{% else %}
{action_respond_info("Extruder not hot enough")}
{% endif %}
# Move to park position
{% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %}
{% set pause_print_park_x = printer["gcode_macro RatOS"].pause_print_park_x %}
{% set pause_print_park_in = printer["gcode_macro RatOS"].pause_print_park_in %}
{% if runout_detected %}
{% set pause_print_park_x = printer["gcode_macro RatOS"].runout_park_x %}
{% set pause_print_park_in = printer["gcode_macro RatOS"].runout_park_in %}
{% endif %}
{% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %}
DEBUG_ECHO PREFIX="PAUSE" MSG="z_speed: {z_speed}, pause_print_park_x: {pause_print_park_x}, pause_print_park_in: {pause_print_park_in}, default_toolhead: {default_toolhead}"
{% if "xyz" in printer.toolhead.homed_axes %}
G91 # Relative positioning
G1 Z{z_safe} F{z_speed}
G90 # Absolute positioning
{% if printer["dual_carriage"] is not defined %}
# DEFAULT
_PARK LOCATION={pause_print_park_in} X={pause_print_park_x}
{% else %}
# IDEX
{% set parking_position = printer["gcode_macro T%s" % default_toolhead].parking_position|float %}
{% if idex_mode == 'copy' or idex_mode == 'mirror' %}
_IDEX_SINGLE X={parking_position}
{% else %}
PARK_TOOLHEAD
{% endif %}
_PARK LOCATION={pause_print_park_in} X={pause_print_park_x}
{% endif %}
{% else %}
{action_respond_info("Printer not homed")}
{% endif %}
# Handle toolhead settings
RESTORE_TOOLHEAD_SETTINGS KEY="pause"
[gcode_macro RESUME]
description: Resumes the print if the printer is paused.
rename_existing: RESUME_BASE
gcode:
# (the TOOLHEAD parameter is getting passed by the _JOIN_SPOOL macro)
# Config
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
# Target IDEX mode
{% set target_idex_mode = '' %}
{% if printer["dual_carriage"] is defined %}
{% set target_idex_mode = printer["gcode_macro PAUSE"].idex_mode|lower %}
{% endif %}
# Can extruder extrude
{% set can_extrude = true if printer['extruder'].can_extrude|lower == 'true' else false %}
{% if target_idex_mode != '' %}
{% if target_idex_mode == 'copy' or target_idex_mode == 'mirror' %}
{% set can_extrude = true if printer['extruder'].can_extrude|lower == 'true' and printer['extruder1'].can_extrude|lower == 'true' else false %}
{% else %}
{% if printer.toolhead.extruder == 'extruder1' %}
{% set can_extrude = true if printer['extruder1'].can_extrude|lower == 'true' else false %}
{% endif %}
{% endif %}
{% endif %}
# Turn part cooling back fan on
{% set fan_speed = printer["gcode_macro PAUSE"].fan_speed|float %}
{% if printer["dual_carriage"] is not defined %}
M106 S{(fan_speed * 255)}
{% else %}
{% if idex_mode == 'copy' or idex_mode == 'mirror' %}
SET_FAN_SPEED FAN=part_fan_t0 SPEED={fan_speed}
SET_FAN_SPEED FAN=part_fan_t1 SPEED={fan_speed}
{% else %}
{% if params.TOOLHEAD is defined %}
# toolhead override for spool join feature
{% if params.TOOLHEAD == 0 %}
SET_FAN_SPEED FAN=part_fan_t0 SPEED={fan_speed}
{% else %}
SET_FAN_SPEED FAN=part_fan_t1 SPEED={fan_speed}
{% endif %}
{% else %}
{% if printer["gcode_macro PAUSE"].idex_toolhead == 0 %}
SET_FAN_SPEED FAN=part_fan_t0 SPEED={fan_speed}
{% else %}
SET_FAN_SPEED FAN=part_fan_t1 SPEED={fan_speed}
{% endif %}
{% endif %}
{% endif %}
# Update core Klipper's fan speed to the fan speed of the active toolhead
# Only do this if you have a sacrificial [fan] section
M106.1 S{fan_speed}
{% endif %}
# Restore IDEX state
{% if printer["dual_carriage"] is defined %}
{% if target_idex_mode == "copy" %}
_IDEX_COPY DANCE=0
{% elif target_idex_mode == "mirror" %}
_IDEX_MIRROR DANCE=0
{% else %}
{% if params.TOOLHEAD is defined %}
_SELECT_TOOL T={params.TOOLHEAD} X=-1 Y=-1 TOOLSHIFT=false
{% else %}
_SELECT_TOOL T={printer["gcode_macro PAUSE"].idex_toolhead} X=-1 Y=-1 TOOLSHIFT=false
{% endif %}
{% endif %}
# restore IDEX toolhead position
{% set x = printer["gcode_macro PAUSE"].idex_toolhead_x|float %}
{% set y = printer["gcode_macro PAUSE"].idex_toolhead_y|float %}
{% set z = printer["gcode_macro PAUSE"].idex_toolhead_z|float %}
G1 X{x} Y{y} Z{z} F{speed}
{% if params.TOOLHEAD is defined %}
# overwrite internal gcode state to make sure new toolheads offsets are getting applied
SAVE_GCODE_STATE NAME=PAUSE_STATE
{% endif %}
{% endif %}
# Prime
{% if params.TOOLHEAD is not defined %}
{% set E = printer["gcode_macro PAUSE"].extrude|float %}
{% if can_extrude %}
G91 # Relative positioning
G1 E{E} F2100
G90 # Absolute positioning
{% else %}
{action_respond_info("Extruder not hot enough")}
{% endif %}
{% endif %}
# Restore gcode state
{% if printer["dual_carriage"] is not defined %}
RESTORE_GCODE_STATE NAME=PAUSE_state MOVE=1 MOVE_SPEED={speed}
{% endif %}
# set is_printing_gcode state
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=is_printing_gcode VALUE=True
# Call internal RESUME command
RESUME_BASE
# visual feedback
_LED_PRINTING
[gcode_macro CANCEL_PRINT]
description: Cancels the printer
rename_existing: CANCEL_PRINT_BASE
gcode:
END_PRINT
TURN_OFF_HEATERS
CLEAR_PAUSE
#SDCARD_RESET_FILE
CANCEL_PRINT_BASE
#####
# START PRINT MACROS
# Call this from your slicer (custom g-code).
# Read more here: https://rat-rig.github.io/V-CoreOS/#/slicers
#####
[gcode_macro START_PRINT]
description: Start print procedure, use this in your Slicer.
variable_post_processor_version: 2 # internal use only. Do not touch!
variable_is_printing_gcode: False # internal use only. Do not touch!
variable_both_toolheads: True # internal use only. Do not touch!
variable_object_xoffset: 0 # internal use only. Do not touch!
variable_first_x: -1 # internal use only. Do not touch!
variable_first_y: -1 # internal use only. Do not touch!
variable_total_toolshifts: 0 # internal use only. Do not touch!
variable_initial_tool: 0 # internal use only. Do not touch!
variable_extruder_first_layer_temp: "" # internal use only. Do not touch!
variable_extruder_other_layer_temp: "" # internal use only. Do not touch!
gcode:
# in case VAOC calibration is still active end it
{% if "xyz" in printer.toolhead.homed_axes and printer["dual_carriage"] is defined and printer["gcode_macro _VAOC"] is defined %}
{% if printer["gcode_macro _VAOC"].is_started|default(true)|lower == 'true' %}
_VAOC_END
{% endif %}
{% endif %}
# visual feedback
_LED_START_PRINTING
# cache toolhead settings
CACHE_TOOLHEAD_SETTINGS KEY="start_print"
# user START_PRINT hook
_USER_START_PRINT { rawparams }
# get ratos settings
{% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %}
{% set bed_heat_soak_time = printer["gcode_macro RatOS"].bed_heat_soak_time|default(0)|int %}
{% set hotend_heat_soak_time = printer["gcode_macro RatOS"].hotend_heat_soak_time|default(0)|int %}
{% set z_probe_stowable = printer["gcode_macro RatOS"].z_probe|lower == 'stowable' %}
{% if printer["dual_carriage"] is defined %}
{% set toolchange_standby_temp = printer["gcode_macro RatOS"].toolchange_standby_temp|default(-1)|float %}
{% endif %}
# beacon contact config
{% set beacon_contact_start_print_true_zero = true if printer["gcode_macro RatOS"].beacon_contact_start_print_true_zero|default(false)|lower == 'true' else false %}
# get macro parameters
{% set X0 = params.X0|default(-1)|float %}
{% set X1 = params.X1|default(-1)|float %}
{% set Y0 = params.Y0|default(-1)|float %}
{% set Y1 = params.Y1|default(-1)|float %}
{% if first_x == -1 or first_y == -1 %}
{% set first_x = params.FIRST_X|default(-1)|float %}
{% set first_y = params.FIRST_Y|default(-1)|float %}
{% endif %}
{% set total_toolshifts = params.TOTAL_TOOLSHIFTS|default(0)|int %}
{% set initial_tool = params.INITIAL_TOOL|default(default_toolhead)|int %}
{% set start_chamber_temp = params.START_CHAMBER_TEMP|default(0)|int %}
# -----------------------------------------------------------------------
# IMPORTANT!!! TODO!!!
# make sure IDEX chamber temps from the initial filament is getting used
# slicer variable needs to be a array
# make sure old slicer profiles are not affected
{% set chamber_temp = params.CHAMBER_TEMP|default(0)|int %}
{% set bed_temp = params.BED_TEMP|default(printer.heater_bed.target, true)|float %}
# -----------------------------------------------------------------------
{% set total_layer_count = params.TOTAL_LAYER_COUNT|default(0)|int %}
{% set extruder_first_layer_temp = (params.EXTRUDER_TEMP|default("")).split(",") %}
{% set client_post_processor_version = params.POST_PROCESSOR_VERSION|default(0)|int %}
# echo first print coordinates
RATOS_ECHO MSG="First print coordinates X:{first_x} Y:{first_y}"
# check for TOTAL_LAYER_COUNT parameter, important for beacon probe
{% if params.TOTAL_LAYER_COUNT is not defined %}
{% set link_url = "https://github.com/HelgeKeck/RatOS/tree/documentation_v2.1/site/docs/slicers.md" %}
{% set link_text = "RatOS Slicer Configuration" %}
{% set line_1 = '"Your slicer gcode settings are not up to date._N_Learn more about the <a href="%s" target="_blank" >%s</a>"' % (link_url, link_text) %}
CONSOLE_ECHO TITLE="Incomplete Slicer Configuration detected" TYPE="warning" MSG={line_1}
{% endif %}
# check client post processor version if needed
{% if client_post_processor_version > 0 %}
{% if client_post_processor_version < post_processor_version %}
{ action_raise_error("Client post processor outdated. Please download the new version from the scripts folder.")}
{% endif %}
{% endif %}
# update printer stats
SET_PRINT_STATS_INFO CURRENT_LAYER=1
SET_GCODE_VARIABLE MACRO=_ON_LAYER_CHANGE VARIABLE=layer_number VALUE=1
{% if total_layer_count > 0 %}
SET_PRINT_STATS_INFO TOTAL_LAYER={total_layer_count}
{% endif %}
# swap toolheads if needed
{% if printer["dual_carriage"] is defined %}
{% set swap_toolheads = true if printer["gcode_macro _IDEX_REMAP_TOOLHEADS"].enabled|default(false)|lower == 'true' else false %}
{% if swap_toolheads %}
{% set initial_tool = 0 if initial_tool == 1 else 1 %}
{% endif %}
{% endif %}
# reset is_printing_gcode state
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=is_printing_gcode VALUE=False
# update Frontend
SET_GCODE_VARIABLE MACRO=T0 VARIABLE=active VALUE=True
{% if printer["dual_carriage"] is defined %}
SET_GCODE_VARIABLE MACRO=T1 VARIABLE=active VALUE=True
{% endif %}
# set both_toolheads variable based on toolshift count. we first assume both toolheads will be needed
{% set both_toolheads = true %}
{% if total_toolshifts == 0 %}
{% set both_toolheads = false %}
{% endif %}
# IDEX mode
{% set idex_mode = '' %}
{% if printer["dual_carriage"] is defined %}
{% set idex_mode = printer["dual_carriage"].carriage_1|lower %}
{% set parking_position = printer["gcode_macro T%s" % default_toolhead].parking_position|float %}
_IDEX_SINGLE X={parking_position}
{% endif %}
{% if both_toolheads and (idex_mode == "copy" or idex_mode == "mirror") %}
_LED_START_PRINTING_ERROR
{ action_raise_error("Gcode tool changes found. Copy and mirror mode do not support toolchanges.")}
{% endif %}
{% if idex_mode == "copy" or idex_mode == "mirror" %}
{% set both_toolheads = true %}
{% endif %}
# cache print variables
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=initial_tool VALUE={initial_tool}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=first_x VALUE={first_x}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=first_y VALUE={first_y}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=total_toolshifts VALUE={total_toolshifts}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=both_toolheads VALUE={both_toolheads}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=extruder_first_layer_temp VALUE="'{params.EXTRUDER_TEMP}'"
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=extruder_other_layer_temp VALUE="'{params.EXTRUDER_OTHER_LAYER_TEMP}'"
# reset toolshift counter
{% if printer["dual_carriage"] is defined %}
SET_GCODE_VARIABLE MACRO=_TOOLCHANGE VARIABLE=toolshift_count VALUE=0
{% endif %}
# load IDEX variable file
{% if printer["dual_carriage"] is defined %}
{% set svv = printer.save_variables.variables %}
{% endif %}
# IDEX toolhead x-offset sanity check
{% if printer["dual_carriage"] is defined %}
{% set parking_position_t0 = printer["gcode_macro T0"].parking_position|float %}
{% set parking_position_t1 = printer["gcode_macro T1"].parking_position|float %}
{% set stepper_x_position_min = printer.configfile.settings.stepper_x.position_min|float %}
{% set stepper_x_position_endstop = printer.configfile.settings.stepper_x.position_endstop|float %}
{% set dual_carriage_position_max = printer.configfile.settings.dual_carriage.position_max|float %}
{% set dual_carriage_position_endstop = printer.configfile.settings.dual_carriage.position_endstop|float %}
{% set x_parking_space = parking_position_t0 - (stepper_x_position_endstop , stepper_x_position_min)|max %}
{% set dc_parking_space = (dual_carriage_position_endstop , dual_carriage_position_max)|min - parking_position_t1 %}
{% if svv.idex_xoffset|abs >= (x_parking_space - 0.5) or svv.idex_xoffset|abs >= (dc_parking_space - 0.5) %}
_LED_START_PRINTING_ERROR
{ action_raise_error("Toolhead x-offset is too high for the available parking space. Calibrate your X and DC endstop positions and make sure you stay below 1mm." % (copy_mode_max_width)) }
{% endif %}
{% endif %}
# IDEX post processor sanity check
{% if printer["dual_carriage"] is defined %}
{% if params.MIN_X is not defined or params.MAX_X is not defined or params.FIRST_X is not defined or params.FIRST_Y is not defined %}
_LED_START_PRINTING_ERROR
{ action_raise_error("Something went wrong! Missing important post processor start print parameter!") }
{% endif %}
{% endif %}
# IDEX copy and mirror mode sanity check
{% if idex_mode == "copy" or idex_mode == "mirror" %}
# reset object xoffset
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=object_xoffset VALUE=0
{% set printable_x_max = printer["gcode_macro RatOS"].printable_x_max|float %}
# ToDo!
# get boundary box from slicer if already available on PS and SS
{% set boundary_box_min_x = params.MIN_X|default(0)|float %} # params.MIN_X | bounding box value | post processor
{% set boundary_box_max_x = params.MAX_X|default(printable_x_max)|float %} # params.MAX_X | bounding box value | post processor
# Take toolhead x offset into account
{% set svv = printer.save_variables.variables %}
{% if default_toolhead == 0 %}
# T1 x-offset must be negative, its part of the sanity checks in the init macro
{% set boundary_box_max_x = boundary_box_max_x + svv.idex_xoffset %}
{% else %}
# T0 x-offset must be positive, its part of the sanity checks in the init macro
{% set boundary_box_min_x = boundary_box_min_x - svv.idex_xoffset %}
{% endif %}
{% set center_x = printable_x_max / 2.0 %}
{% set safe_distance = printer.configfile.settings.dual_carriage.safe_distance|float %}
{% set object_width = boundary_box_max_x - boundary_box_min_x %}
{% set copy_mode_max_width = center_x %}
{% set mirror_mode_max_width = center_x - safe_distance / 2.0 %}
DEBUG_ECHO PREFIX="START_PRINT" MSG="OBJECT_WIDTH: {object_width} BOUNDARY_BOX_MIN_X: {boundary_box_min_x} BOUNDARY_BOX_MAX_X: {boundary_box_max_x} CENTER_X: {center_x} SAFE_DISTANCE: {safe_distance}"
# object size sanity check
{% if idex_mode == "copy" and object_width > copy_mode_max_width %}
_LED_START_PRINTING_ERROR
{ action_raise_error("Object is too big for copy mode! Max supported width is %s mm" % (copy_mode_max_width)) }
{% endif %}
{% if idex_mode == "mirror" and object_width > mirror_mode_max_width %}
_LED_START_PRINTING_ERROR
{ action_raise_error("Object is too big for mirror mode! Max supported width is %s mm" % (mirror_mode_max_width)) }
{% endif %}
# get object x-offset to center the object on the build plate
{% if printer["gcode_macro RatOS"].auto_center_subject|default(false)|lower == 'true' %}
{% set object_xoffset = (printable_x_max - boundary_box_max_x - boundary_box_min_x) / 2 %}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=object_xoffset VALUE={object_xoffset}
{% endif %}
{% endif %}
# filament detection in case user has filament sensors configured
{% set has_initial_toolhead_filament_sensor = true if printer["filament_switch_sensor toolhead_filament_sensor_t%s" % initial_tool] is defined else false %}
{% if has_initial_toolhead_filament_sensor %}
# Initial toolhead filament sensor check
{% if printer["filament_switch_sensor toolhead_filament_sensor_t%s" % initial_tool].enabled|lower == "true" %}
{% if printer["filament_switch_sensor toolhead_filament_sensor_t%s" % initial_tool].filament_detected|lower != "true" %}
_LED_START_PRINTING_ERROR
{ action_raise_error("Filament not detected! Toolhead T%s filament sensor is empty." % (initial_tool)) }
{% endif %}
{% endif %}
{% endif %}
{% set has_initial_bowden_filament_sensor = true if printer["filament_switch_sensor bowden_filament_sensor_t%s" % initial_tool] is defined else false %}
{% if has_initial_bowden_filament_sensor %}
# Initial toolhead bowden filament sensor check
{% if printer["filament_switch_sensor bowden_filament_sensor_t%s" % initial_tool].enabled|lower == "true" %}
{% if printer["filament_switch_sensor bowden_filament_sensor_t%s" % initial_tool].filament_detected|lower != "true" %}
_LED_START_PRINTING_ERROR
{ action_raise_error("Filament not detected! Toolhead T%s bowden sensor is empty." % (initial_tool)) }
{% endif %}
{% endif %}
{% endif %}
{% if printer["dual_carriage"] is defined and both_toolheads %}
# Secondary toolhead filament sensor check
{% set has_secondary_toolhead_filament_sensor = true if printer["filament_switch_sensor toolhead_filament_sensor_t%s" % (1 if initial_tool == 0 else 0)] is defined else false %}
{% if has_secondary_toolhead_filament_sensor %}
{% if printer["filament_switch_sensor toolhead_filament_sensor_t%s" % (1 if initial_tool == 0 else 0)].enabled|lower == "true" %}
{% if printer["filament_switch_sensor toolhead_filament_sensor_t%s" % (1 if initial_tool == 0 else 0)].filament_detected|lower != "true" %}
_LED_START_PRINTING_ERROR
{ action_raise_error("Filament not detected! Toolhead T%s filament sensor is empty." % (1 if initial_tool == 0 else 0)) }
{% endif %}
{% endif %}
{% endif %}
# Secondary toolhead bowden filament sensor check
{% set has_secondary_bowden_filament_sensor = true if printer["filament_switch_sensor bowden_filament_sensor_t%s" % (1 if initial_tool == 0 else 0)] is defined else false %}
{% if has_secondary_bowden_filament_sensor %}
{% if printer["filament_switch_sensor bowden_filament_sensor_t%s" % (1 if initial_tool == 0 else 0)].enabled|lower == "true" %}
{% if printer["filament_switch_sensor bowden_filament_sensor_t%s" % (1 if initial_tool == 0 else 0)].filament_detected|lower != "true" %}
_LED_START_PRINTING_ERROR
{ action_raise_error("Filament not detected! Toolhead T%s bowden sensor is empty." % (1 if initial_tool == 0 else 0)) }
{% endif %}
{% endif %}
{% endif %}
{% endif %}
# chamber filter control
_CHAMBER_FILTER_ON AT="before_print_start"
# spool join
{% if printer["dual_carriage"] is defined %}
{% if printer["gcode_macro _IDEX_JOIN_SPOOLS"].enabled|default(false)|lower == 'true' %}
{% if both_toolheads %}
RATOS_ECHO MSG="Spool join is not possible if both toolheads are in use!"
SET_GCODE_VARIABLE MACRO=_IDEX_JOIN_SPOOLS VARIABLE=enabled VALUE=False
{% endif %}
{% endif %}
{% endif %}
# reset toolhead offset
{% if printer["dual_carriage"] is defined %}
{% if idex_mode == '' %}
_SET_TOOLHEAD_OFFSET T={default_toolhead} MOVE={1 if "xyz" in printer.toolhead.homed_axes else 0}
{% endif %}
{% endif %}
# start
CLEAR_PAUSE # clear pause state
{% if printer["gcode_macro RatOS"].force_absolute_position|lower == 'true' %}
G90
{% endif %}
SAVE_GCODE_STATE NAME=start_print_state # save gcode state
# Metric values
G21
# Absolute positioning
G90
# Set extruder to absolute mode
M82
_USER_START_PRINT_BEFORE_HOMING { rawparams }
# handle stowable probe
{% if z_probe_stowable == true %}
STOWABLE_PROBE_BEGIN_BATCH
{% endif %}
# Home if needed
MAYBE_HOME
# Make sure we're clear of the bed
_Z_HOP
# move toolhead to the oozeguard if needed
{% if idex_mode != '' and not (printer.configfile.settings.beacon is defined and beacon_contact_start_print_true_zero) %}
PARK_TOOLHEAD
{% endif %}
# heat chamber
{% if chamber_temp > 0 %}
{% if printer["fan_generic filter"] is defined %}
{% if printer["gcode_macro RatOS"].chamber_heater_filter_fan_speed|default(0)|float > 0 %}
SET_FAN_SPEED FAN=filter SPEED={printer["gcode_macro RatOS"].chamber_heater_filter_fan_speed|default(0)|float}
{% endif %}
{% endif %}
_CHAMBER_HEATER_ON START_CHAMBER_TEMP={start_chamber_temp} CHAMBER_TEMP={chamber_temp}
_USER_START_PRINT_HEAT_CHAMBER { rawparams } CHAMBER_TEMP={chamber_temp}
{% endif %}
# Run the customizable "BEFORE_HEATING_BED" macro.
_START_PRINT_BEFORE_HEATING_BED T={initial_tool} BOTH_TOOLHEADS={both_toolheads} IDEX_MODE={idex_mode}
RATOS_ECHO MSG="Heating bed..."
# Wait for bed to heat up
M190 S{bed_temp}
# Wait for bed thermal expansion
{% if bed_heat_soak_time > 0 %}
RATOS_ECHO MSG="Heat soaking bed for {bed_heat_soak_time} seconds..."
G4 P{(bed_heat_soak_time * 1000)}
{% endif %}
# Run the user created "AFTER_HEATING_BED" macro
_USER_START_PRINT_AFTER_HEATING_BED { rawparams }
# Run the customizable "AFTER_HEATING_BED" macro.
_START_PRINT_AFTER_HEATING_BED T={initial_tool} BOTH_TOOLHEADS={both_toolheads} IDEX_MODE={idex_mode}
# Run the user created "START_PRINT_BED_MESH" macro
_USER_START_PRINT_BED_MESH { rawparams } X0={X0} X1={X1} Y0={Y0} Y1={Y1}
# Run the customizable "BED_MESH" macro
_START_PRINT_BED_MESH X0={X0} X1={X1} Y0={Y0} Y1={Y1} T={initial_tool} BOTH_TOOLHEADS={both_toolheads} IDEX_MODE={idex_mode}
# handle stowable probe
{% if z_probe_stowable == true %}
STOWABLE_PROBE_END_BATCH
{% endif %}
# Start heating extruder
{% if idex_mode == '' %}
SET_HEATER_TEMPERATURE HEATER="extruder" TARGET={extruder_first_layer_temp[0]|float}
{% else %}
{% if initial_tool == 0 or both_toolheads or (default_toolhead == 0 and printer.configfile.settings.beacon is defined and beacon_contact_start_print_true_zero) %}
SET_HEATER_TEMPERATURE HEATER="extruder" TARGET={extruder_first_layer_temp[0]|float}
{% endif %}
{% if initial_tool == 1 or both_toolheads or (default_toolhead == 1 and printer.configfile.settings.beacon is defined and beacon_contact_start_print_true_zero) %}
SET_HEATER_TEMPERATURE HEATER="extruder1" TARGET={extruder_first_layer_temp[1]|float}
{% endif %}
{% endif %}
# Run the users "PARK" macro
_USER_START_PRINT_PARK { rawparams }
# Run the customizable "PARK" macro
_START_PRINT_PARK
# Wait for extruder to heat up
RATOS_ECHO MSG="Heating Extruder..."
{% if idex_mode == '' %}
TEMPERATURE_WAIT SENSOR="extruder" MINIMUM={extruder_first_layer_temp[0]|float} MAXIMUM={extruder_first_layer_temp[0]|float + 5}
{% else %}
{% if initial_tool == 0 or both_toolheads or (default_toolhead == 0 and printer.configfile.settings.beacon is defined and beacon_contact_start_print_true_zero) %}
TEMPERATURE_WAIT SENSOR="extruder" MINIMUM={extruder_first_layer_temp[0]|float} MAXIMUM={extruder_first_layer_temp[0]|float + 5}
{% endif %}
{% if initial_tool == 1 or both_toolheads or (default_toolhead == 1 and printer.configfile.settings.beacon is defined and beacon_contact_start_print_true_zero) %}
TEMPERATURE_WAIT SENSOR="extruder1" MINIMUM={extruder_first_layer_temp[1]|float} MAXIMUM={extruder_first_layer_temp[1]|float + 5}
{% endif %}
{% endif %}
# Wait for extruder thermal expansion
{% if hotend_heat_soak_time > 0 %}
RATOS_ECHO MSG="Heat soaking hotend for {hotend_heat_soak_time} seconds..."
G4 P{(hotend_heat_soak_time * 1000)}
{% endif %}
# visual feedback
{% if idex_mode == '' %}
_LED_PRINTING
{% else %}
{% if idex_mode == "copy" or idex_mode == "mirror" %}
_LED_PRINTING
{% else %}
{% if both_toolheads %}
_LED_PRINTING TOOLHEAD={initial_tool}
{% if toolchange_standby_temp > -1 %}
_LED_TOOLHEAD_STANDBY TOOLHEAD={0 if initial_tool == 1 else 1}
{% else %}
_LED_PRINTING TOOLHEAD={0 if initial_tool == 1 else 1}
{% endif %}
{% else %}
_LED_PRINTING TOOLHEAD={initial_tool}
_LED_DEACTIVATE_TOOLHEAD TOOLHEAD={0 if initial_tool == 1 else 1}
{% endif %}
{% endif %}
{% endif %}
# Run the user created "AFTER_HEATING_EXTRUDER" macro.
_USER_START_PRINT_AFTER_HEATING_EXTRUDER { rawparams } X0={X0} X1={X1} Y0={Y0} Y1={Y1}
# Run the customizable "AFTER_HEATING_EXTRUDER" macro.
_START_PRINT_AFTER_HEATING_EXTRUDER X0={X0} X1={X1} Y0={Y0} Y1={Y1} INITIAL_TOOLHEAD={initial_tool} BOTH_TOOLHEADS={both_toolheads} IDEX_MODE={idex_mode}
# cool down the preheated probing toolhead if not needed for printing
{% if idex_mode != '' %}
{% if not both_toolheads %}
{% if initial_tool != default_toolhead %}
SET_HEATER_TEMPERATURE HEATER={'extruder' if default_toolhead == 0 else 'extruder1'} TARGET=0
{% endif %}
{% endif %}
{% endif %}
# put toolhead into standby mode if configured
{% if idex_mode != '' %}
{% if idex_mode != "copy" and idex_mode != "mirror" %}
{% if toolchange_standby_temp > -1 %}
SET_HEATER_TEMPERATURE HEATER={'extruder' if initial_tool == 1 else 'extruder1'} TARGET={toolchange_standby_temp}
{% endif %}
{% endif %}
{% endif %}
# cache x offset
{% if idex_mode != '' %}
{% set x_offset = printer.toolhead.position.x|float - printer.gcode_move.gcode_position.x|float %}
{% endif %}
# restore gcode state
RESTORE_GCODE_STATE NAME=start_print_state
{% if idex_mode != '' %}
# restore x offset
{% set act_idex_mode = printer["dual_carriage"].carriage_1|default('')|lower %}
{% if act_idex_mode == "copy" or act_idex_mode == "mirror" %}
SET_GCODE_OFFSET X={x_offset} MOVE=0
{% endif %}
{% endif %}
# restore IDEX mode
{% if idex_mode != '' %}
{% if idex_mode == "copy" or idex_mode == "mirror" %}
{% if idex_mode == "copy" and idex_mode != act_idex_mode %}
_IDEX_COPY DANCE=0
{% elif idex_mode == "mirror" and idex_mode != act_idex_mode %}
_IDEX_MIRROR DANCE=0
{% endif %}
# adjust object x-offset
{% if printer["gcode_macro RatOS"].auto_center_subject|default(false)|lower == 'true' %}
RATOS_ECHO MSG="Adjusting object x-offset by {(object_xoffset)} mm"
SET_GCODE_OFFSET X_ADJUST={object_xoffset} MOVE=0
{% endif %}
{% else %}
_SELECT_TOOL T={initial_tool} TOOLSHIFT=false
{% if initial_tool != default_toolhead %}
#################################################################
# hacking stupid restore gcode bs
# test if this is only needed bc of the new beacon homing routine
{% set svv = printer.save_variables.variables %}
SAVE_VARIABLE VARIABLE=idex_applied_offset VALUE={default_toolhead}
#################################################################
_SET_TOOLHEAD_OFFSET T={initial_tool} MOVE=0
{% endif %}
{% endif %}
{% endif %}
# set nozzle thermal expansion offset
{% if printer.configfile.settings.beacon is defined %}
# the previously called restore gcode state removed the temp offset
# we need first to reset the applied offset value in the variables file
_BEACON_SET_NOZZLE_TEMP_OFFSET RESET=True
_BEACON_SET_NOZZLE_TEMP_OFFSET TOOLHEAD={initial_tool}
{% endif %}
# Set extrusion mode based on user configuration
_SET_EXTRUSION_MODE
# set is_printing_gcode state
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=is_printing_gcode VALUE=True
# set initial toolchange timestamp
{% if printer["gcode_macro _SELECT_TOOL"] is defined %}
SET_GCODE_VARIABLE MACRO=_SELECT_TOOL VARIABLE=last_timestamp VALUE={printer["print_stats"].print_duration}
{% endif %}
# user END_START_PRINT hook
_USER_END_START_PRINT { rawparams }
G92 E0 # reset extrusion distance
# chamber filter control
_CHAMBER_FILTER_ON AT="after_print_start"
RATOS_ECHO MSG="Printing..."
#####
# START PRINT MACRO HOOKS
# You can copy these to printer.cfg and modify them to your liking, or just use them as is.
####
[gcode_macro _START_PRINT_BEFORE_HEATING_BED]
gcode:
# parameter
{% set target_idex_mode = params.IDEX_MODE|default("")|lower %}
{% set initial_toolhead = params.T|default(default_toolhead)|int %}
{% set both_toolheads = true if params.BOTH_TOOLHEADS|default(true)|lower=='true' else false %}
# config
{% set min_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float %}
{% set max_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float + 5 %}
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
{% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %}
{% set printable_x_max = printer["gcode_macro RatOS"].printable_x_max|float %}
{% set printable_y_max = printer["gcode_macro RatOS"].printable_y_max|float %}
{% set safe_home_x = printer["gcode_macro RatOS"].safe_home_x %}
{% if safe_home_x is not defined or safe_home_x|lower == 'middle' %}
{% set safe_home_x = printable_x_max / 2 %}
{% endif %}
{% set safe_home_y = printer["gcode_macro RatOS"].safe_home_y %}
{% if safe_home_y is not defined or safe_home_y|lower == 'middle' %}
{% set safe_home_y = printable_y_max / 2 %}
{% endif %}
{% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %}
{% set idex_mode = '' %}
{% if printer["dual_carriage"] is defined %}
{% set idex_mode = printer["dual_carriage"].carriage_1|lower %}
{% endif %}
{% set act_t = 1 if idex_mode == 'primary' else 0 %}
# automated toolhead z-offset calibration config
{% set auto_z_offset_calibration = False %}
{% if printer["dual_carriage"] is defined and printer["gcode_macro _VAOC"] is defined %}
{% set is_fixed = true if printer["gcode_macro _VAOC"].is_fixed|default(true)|lower == 'true' else false %}
{% if printer["gcode_macro _VAOC"].auto_z_offset_calibration|default("false")|lower == 'true' and is_fixed %}
{% if target_idex_mode != "copy" and target_idex_mode != "mirror" %}
{% if both_toolheads or initial_toolhead != default_toolhead %}
{% set auto_z_offset_calibration = True %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
# z probe config
{% set beacon_contact_start_print_true_zero = true if printer["gcode_macro RatOS"].beacon_contact_start_print_true_zero|default(false)|lower == 'true' else false %}
{% set is_stowable_probe = true if printer["gcode_macro RatOS"].z_probe|lower == 'stowable' else false %}
# preheat extruder
{% if printer["gcode_macro RatOS"].preheat_extruder|lower == 'true' %}
RATOS_ECHO MSG="Pre-heating extruder..."
# Wait for extruder to reach a predefined preheat temp so an inductive probe (if present) is at a predictable temp.
# Also allows the bed heat to spread a little, and softens any plastic that might be stuck to the nozzle.
{% if printer["dual_carriage"] is defined %}
{% if auto_z_offset_calibration %}
SET_HEATER_TEMPERATURE HEATER="extruder" TARGET={min_temp}
SET_HEATER_TEMPERATURE HEATER="extruder1" TARGET={min_temp}
{% else %}
SET_HEATER_TEMPERATURE HEATER={'extruder' if default_toolhead == 0 else 'extruder1'} TARGET={min_temp}
{% endif %}
{% else %}
SET_HEATER_TEMPERATURE HEATER="extruder" TARGET={min_temp}
{% endif %}
{% endif %}
# park toolhead in the center at Z=2 for heat soaking
{% if not is_stowable_probe %}
{% if printer["dual_carriage"] is defined and act_t != default_toolhead %}
_SELECT_TOOL T={default_toolhead} X={safe_home_x} Y={safe_home_y} TOOLSHIFT=True
{% endif %}
RATOS_ECHO MSG="Heat soaking z probe..."
{% if auto_z_offset_calibration %}
{% set safe_distance = printer.configfile.settings.dual_carriage.safe_distance|float %}
{% if default_toolhead == 0 %}
_SELECT_TOOL T=0 TOOLSHIFT=false
G1 X{safe_home_x - safe_distance / 2} F{speed}
SET_DUAL_CARRIAGE CARRIAGE=1 MODE=PRIMARY
G1 X{safe_home_x + safe_distance / 2} F{speed}
SET_DUAL_CARRIAGE CARRIAGE=0 MODE=PRIMARY
{% elif default_toolhead == 1 %}
_SELECT_TOOL T=1 TOOLSHIFT=false
G1 X{safe_home_x + safe_distance / 2} F{speed}
SET_DUAL_CARRIAGE CARRIAGE=0 MODE=PRIMARY
G1 X{safe_home_x - safe_distance / 2} F{speed}
SET_DUAL_CARRIAGE CARRIAGE=1 MODE=PRIMARY
{% endif %}
{% else %}
_MOVE_TO_SAFE_Z_HOME
{% endif %}
# Always soak close to first layer height.
G0 Z2 F{z_speed}
{% endif %}
[gcode_macro _START_PRINT_AFTER_HEATING_BED]
gcode:
# parameter
{% set target_idex_mode = params.IDEX_MODE|default("")|lower %}
{% set initial_toolhead = params.T|default(default_toolhead)|int %}
{% set both_toolheads = true if params.BOTH_TOOLHEADS|default(true)|lower=='true' else false %}
# config
{% set min_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float %}
{% set max_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float + 5 %}
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
{% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %}
{% set printable_x_max = printer["gcode_macro RatOS"].printable_x_max|float %}
{% set printable_y_max = printer["gcode_macro RatOS"].printable_y_max|float %}
{% set safe_home_x = printer["gcode_macro RatOS"].safe_home_x %}
{% if safe_home_x is not defined or safe_home_x|lower == 'middle' %}
{% set safe_home_x = printable_x_max / 2 %}
{% endif %}
{% set safe_home_y = printer["gcode_macro RatOS"].safe_home_y %}
{% if safe_home_y is not defined or safe_home_y|lower == 'middle' %}
{% set safe_home_y = printable_y_max / 2 %}
{% endif %}
# automated toolhead z-offset calibration config
{% set auto_z_offset_calibration = False %}
{% if printer["dual_carriage"] is defined and printer["gcode_macro _VAOC"] is defined %}
{% set is_fixed = true if printer["gcode_macro _VAOC"].is_fixed|default(true)|lower == 'true' else false %}
{% if printer["gcode_macro _VAOC"].auto_z_offset_calibration|default("false")|lower == 'true' and is_fixed %}
{% if target_idex_mode != "copy" and target_idex_mode != "mirror" %}
{% if both_toolheads or initial_toolhead != default_toolhead %}
{% set auto_z_offset_calibration = True %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
# beacon contact config
{% set beacon_contact_start_print_true_zero = true if printer["gcode_macro RatOS"].beacon_contact_start_print_true_zero|default(false)|lower == 'true' else false %}
{% set beacon_contact_wipe_before_true_zero = true if printer["gcode_macro RatOS"].beacon_contact_wipe_before_true_zero|default(false)|lower == 'true' else false %}
# wait for extruder to be preheated
{% if printer["gcode_macro RatOS"].preheat_extruder|lower == 'true' %}
RATOS_ECHO MSG="Waiting for extruder to be preheated..."
# Wait for extruder to reach a predefined preheat temp so an inductive probe (if present) is at a predictable temp.
# Also allows the bed heat to spread a little, and softens any plastic that might be stuck to the nozzle.
{% if printer["dual_carriage"] is defined %}
{% if auto_z_offset_calibration %}
TEMPERATURE_WAIT SENSOR=extruder MINIMUM={min_temp} MAXIMUM={max_temp}
TEMPERATURE_WAIT SENSOR=extruder1 MINIMUM={min_temp} MAXIMUM={max_temp}
{% else %}
{% if default_toolhead == 0 %}
TEMPERATURE_WAIT SENSOR=extruder MINIMUM={min_temp} MAXIMUM={max_temp}
{% else %}
TEMPERATURE_WAIT SENSOR=extruder1 MINIMUM={min_temp} MAXIMUM={max_temp}
{% endif %}
{% endif %}
{% else %}
TEMPERATURE_WAIT SENSOR=extruder MINIMUM={min_temp} MAXIMUM={max_temp}
{% endif %}
{% endif %}
# raise z after heat soaking the beacon
{% if printer.configfile.settings.beacon is defined %}
_Z_HOP
{% endif %}
# automated toolhead z-offset calibration
{% if auto_z_offset_calibration %}
{% set parking_position_t0 = printer["gcode_macro T0"].parking_position|float %}
{% set parking_position_t1 = printer["gcode_macro T1"].parking_position|float %}
_SELECT_TOOL T={default_toolhead} X={safe_home_x} Y={safe_home_y} TOOLSHIFT=True
PARK_TOOLHEAD
_CLEANING_MOVE TOOLHEAD={default_toolhead}
_SELECT_TOOL T={0 if default_toolhead == 1 else 1} X={parking_position_t0 if default_toolhead == 1 else parking_position_t0} Y=0 TOOLSHIFT=false
_CLEANING_MOVE TOOLHEAD={0 if default_toolhead == 1 else 1}
_VAOC_CALIBRATE_Z_OFFSET AUTO_Z_OFFSET=True
_SELECT_TOOL T={default_toolhead} X={safe_home_x} Y={safe_home_y} TOOLSHIFT=false
{% endif %}
# automatic bed leveling
{% set needs_rehoming = False %}
{% if printer.z_tilt is defined and not printer.z_tilt.applied %}
RATOS_ECHO MSG="Adjusting Z tilt..."
Z_TILT_ADJUST
RATOS_ECHO MSG="Rehoming Z after Z tilt adjustment..."
{% set needs_rehoming = True %}
{% endif %}
{% if printer.quad_gantry_level is defined and not printer.quad_gantry_level.applied %}
RATOS_ECHO MSG="Running quad gantry leveling..."
QUAD_GANTRY_LEVEL
RATOS_ECHO MSG="Rehoming Z after quad gantry leveling..."
{% set needs_rehoming = True %}
{% endif %}
# Home again as Z will have changed after automatic bed leveling and bed heating.
{% if needs_rehoming %}
G28 Z
{% endif %}
# beacon contact homing with optional wipe
{% if printer.configfile.settings.beacon is defined and beacon_contact_start_print_true_zero %}
{% if beacon_contact_wipe_before_true_zero %}
_START_PRINT_AFTER_HEATING_BED_PROBE_FOR_WIPE
{% endif %}
_START_PRINT_AFTER_HEATING_CONTACT_WITH_OPTIONAL_WIPE
{% endif %}
[gcode_macro _START_PRINT_AFTER_HEATING_BED_PROBE_FOR_WIPE]
gcode:
# config
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
{% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %}
# move to wipe position
G0 Z5 F{z_speed}
G0 X50 Y10 F{speed}
# probe at wipe position
PROBE PROBE_METHOD=contact SAMPLES=1
BEACON_QUERY