forked from Rat-OS/RatOS-configuration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
macros.cfg
826 lines (758 loc) · 31.2 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
# 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.
#####
# CONFIGURATION VARIABLES
#####
[gcode_macro ECHO_RATOS_VARS]
description: Echo RatOS variables to the console.
gcode:
{% for var, value in printer["gcode_macro RatOS"].items() %}
{action_respond_info(var ~ ": " ~ value)}
{% endfor %}
[gcode_macro RatOS]
description: RatOS variable storage macro, will echo variables to the console when run.
# Configuration Defaults
# This is only here to make the config backwards compatible.
# Configuration should exclusively happen in printer.cfg.
variable_relative_extrusion: False
variable_force_absolute_position: False
variable_preheat_extruder: True
variable_preheat_extruder_temp: 150
variable_calibrate_bed_mesh: True
variable_nozzle_priming: "primeblob"
variable_nozzle_prime_start_x: "max" # min, max or number
variable_nozzle_prime_start_y: "min" # min, max or number
variable_nozzle_prime_direction: "auto" # auto, forwards, backwards
variable_nozzle_prime_bridge_fan: 102
variable_filament_unload_length: 130
variable_filament_unload_speed: 5
variable_filament_load_length: 100
variable_filament_load_speed: 10
variable_start_print_park_in: "back"
variable_start_print_park_z_height: 50
variable_start_print_heat_chamber_bed_temp: 115
variable_end_print_park_in: "back"
variable_pause_print_park_in: "back"
variable_macro_travel_speed: 150
variable_macro_z_speed: 15
variable_end_print_park_z_hop: 20
# Possible values: 'sensorless' or 'endstops'.
variable_homing: "endstops"
variable_sensorless_x_current: 0.6
variable_sensorless_y_current: 0.9
# Possible values: 'static' or 'stowable'
variable_z_probe: "static"
# Possible Values: 'middle' or an absolute x coordinate
variable_safe_home_x: "middle"
# Possible Values: 'middle' or an absolute y coordinate
variable_safe_home_y: "middle"
variable_stowable_probe_stop_on_error: False
variable_driver_type_x: "tmc2209"
variable_driver_type_y: "tmc2209"
variable_adaptive_mesh: False
variable_probe_for_priming_result: None
variable_adaptive_prime_offset_threshold: -1.0
gcode:
ECHO_RATOS_VARS
#####
# GENERAL MACROS
#####
[gcode_macro PAUSE]
description: Pauses the printer
rename_existing: PAUSE_BASE
variable_extrude: 1.5
gcode:
SAVE_GCODE_STATE NAME=PAUSE_state
# Define park positions
{% set E = printer["gcode_macro PAUSE"].extrude|float %}
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
{% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %}
# Calculate safe Z position
{% set max_z = printer.toolhead.axis_maximum.z|float %}
{% set act_z = printer.toolhead.position.z|float %}
{% if act_z < (max_z - 20.0) %}
{% set z_safe = 20.0 %}
{% else %}
{% set z_safe = max_z - act_z %}
{% endif %}
PAUSE_BASE
G91
# Retract
{% if printer.extruder.can_extrude|lower == 'true' %}
G1 E-{E} F2100
{% else %}
{action_respond_info("Extruder not hot enough")}
{% endif %}
# Move to park position
{% if "xyz" in printer.toolhead.homed_axes %}
G1 Z{z_safe} F{z_speed}
_PARK LOCATION={printer["gcode_macro RatOS"].pause_print_park_in} X={printer["gcode_macro RatOS"].pause_print_park_x}
{% else %}
{action_respond_info("Printer not homed")}
{% endif %}
[gcode_macro RESUME]
description: Resumes the print if the printer is paused.
rename_existing: RESUME_BASE
gcode:
{% set E = printer["gcode_macro PAUSE"].extrude|float %}
# Prime
{% if printer.extruder.can_extrude|lower == 'true' %}
G91
G1 E{E} F2100
G90
{% else %}
{action_respond_info("Extruder not hot enough")}
{% endif %}
RESTORE_GCODE_STATE NAME=PAUSE_state MOVE=1 MOVE_SPEED={printer["gcode_macro RatOS"].macro_travel_speed|float}
RESUME_BASE
[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
[gcode_macro PRIME_LINE]
description: Prints a primeline, used internally, if configured, as part of the START_PRINT macro.
gcode:
SAVE_GCODE_STATE NAME=prime_line_state
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
{% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %}
{% if printer["gcode_macro RatOS"].nozzle_prime_start_x|lower == 'min' %}
{% set x_start = 5 %}
{% elif printer["gcode_macro RatOS"].nozzle_prime_start_x|lower == 'max' %}
{% set x_start = printer.toolhead.axis_maximum.x - 5 %}
{% else %}
{% set x_start = printer["gcode_macro RatOS"].nozzle_prime_start_x|float %}
{% endif %}
{% if printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == 'min' %}
{% set y_start = 5 %}
{% set y_factor = 1 %}
{% elif printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == 'max' %}
{% set y_start = printer.toolhead.axis_maximum.y - 5 %}
{% set y_factor = -1 %}
{% else %}
{% set y_start = printer["gcode_macro RatOS"].nozzle_prime_start_y|float %}
{% if printer["gcode_macro RatOS"].nozzle_prime_start_y|float < printer.toolhead.axis_maximum.y / 2 %}
{% set y_factor = 1 %}
{% else %}
{% set y_factor = -1 %}
{% endif %}
{% endif %}
{% if printer["gcode_macro RatOS"].nozzle_prime_direction|lower == 'forwards' %}
{% set y_factor = 1 %}
{% elif printer["gcode_macro RatOS"].nozzle_prime_direction|lower == 'backwards' %}
{% set y_factor = -1 %}
{% endif %}
{% set z = printer["gcode_macro RatOS"].start_print_park_z_height|float %}
# Absolute positioning
G90
# Absolute extrusion
M82
M117 Priming nozzle with prime line..
RESPOND MSG="Priming nozzle with prime line.."
# Lift to start print Z height
G0 Z{z} F{z_speed}
# move to blob position along the edge of the bed
G1 X{x_start} F{speed}
G1 Y{y_start} F{speed}
# Get ready to prime
G1 Z0.3 F{z_speed}
# Reset extrusion distance
G92 E0
# Prime nozzle
G1 Y{y_start + (70 * y_factor)} E16 F1200
# Wipe
G1 Y{y_start + (90 * y_factor)} F{speed}
RESTORE_GCODE_STATE NAME=prime_line_state
[gcode_macro PRIME_BLOB]
description: Prints a primeblob, used internally, if configured, as part of the START_PRINT macro. Slower than PRIME_LINE but much more effective.
gcode:
SAVE_GCODE_STATE NAME=prime_blob_state
M117 Priming nozzle with prime blob..
RESPOND MSG="Priming nozzle with prime blob.."
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
{% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %}
{% set fan_speed = printer["gcode_macro RatOS"].nozzle_prime_bridge_fan|float %}
{% if printer["gcode_macro RatOS"].nozzle_prime_start_x|lower == 'min' %}
{% set x_start = 5 %}
{% elif printer["gcode_macro RatOS"].nozzle_prime_start_x|lower == 'max' %}
{% set x_start = printer.toolhead.axis_maximum.x - 5 %}
{% else %}
{% set x_start = printer["gcode_macro RatOS"].nozzle_prime_start_x|float %}
{% endif %}
{% if printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == 'min' %}
{% set y_start = 5 %}
{% set y_factor = 1 %}
{% elif printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == 'max' %}
{% set y_start = printer.toolhead.axis_maximum.y - 5 %}
{% set y_factor = -1 %}
{% else %}
{% set y_start = printer["gcode_macro RatOS"].nozzle_prime_start_y|float %}
{% if printer["gcode_macro RatOS"].nozzle_prime_start_y|float < printer.toolhead.axis_maximum.y / 2 %}
{% set y_factor = 1 %}
{% else %}
{% set y_factor = -1 %}
{% endif %}
{% endif %}
{% if printer["gcode_macro RatOS"].nozzle_prime_direction|lower == 'forwards' %}
{% set y_factor = 1 %}
{% elif printer["gcode_macro RatOS"].nozzle_prime_direction|lower == 'backwards' %}
{% set y_factor = -1 %}
{% endif %}
{% set z = printer["gcode_macro RatOS"].start_print_park_z_height|float %}
# Absolute positioning
G90
# Relative extrusion
M83
# Lift to start print Z height
G0 Z{z} F{z_speed}
# move close to blob position along the edge of the bed
G1 X{x_start} F{speed}
G1 Y{y_start + (15 * y_factor)} F{speed}
# Lower to blob extrusion height
G1 Z0.5 F{z_speed}
# Move to final position horizontally
G1 Y{y_start} F{speed}
# Extrude a blob
G1 F60 E20
# 40% fan
M106 S{fan_speed}
# Move the extruder up by 5mm while extruding, breaks away from blob
G1 Z5 F100 E5
# Move to wipe position, but keep extruding so the wipe is attached to blob
G1 F200 Y{y_start + (25 * y_factor)} E1
# Go down diagonally while extruding
# Broken down in z moves under 2mm as a workaround for a tuning tower test.
# The tuning tower command thinks a new print has been started when z moves over 2mm and aborts.
G1 F200 Y{y_start + (30 * y_factor)} Z3.8 E0.5
G1 F200 Y{y_start + (35 * y_factor)} Z2.6 E0.5
G1 F200 Y{y_start + (40 * y_factor)} Z1.4 E0.5
G1 F200 Y{y_start + (45 * y_factor)} Z0.2 E0.5
# 0% fan
M106 S0
# small wipe line
G1 F200 Y{y_start + (50 * y_factor)} Z0.2 E0.6
# Break away wipe
G1 F{speed} Y{y_start + (100 * y_factor)}
RESTORE_GCODE_STATE NAME=prime_blob_state
[gcode_macro _PARK]
gcode:
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
# Get X position
{% if params.X != '' %}
{% if params.X|float >= printer.toolhead.axis_minimum.x + 5 and params.X|float <= printer.toolhead.axis_maximum.x - 5 %}
{% set safe_x = params.X|float %}
{% else %}
{action_respond_info('The requested X co-ordinate is outside the defined axis bounds - using defaults')}
{% set safe_x = printer.toolhead.axis_maximum.x / 2 %}
{% endif %}
{% else %}
{% set safe_x = printer.toolhead.axis_maximum.x / 2 %}
{% endif %}
# Get Y position
{% if params.LOCATION|default('back')|lower == 'back' %}
{% set y = printer.toolhead.axis_maximum.y - 5 %}
{% elif params.LOCATION|lower == 'front' %}
{% set y = printer.toolhead.axis_minimum.y + 5 %}
{% elif params.LOCATION|lower == 'center' %}
{% set y = printer.toolhead.axis_maximum.y / 2 %}
{% endif %}
# Absolute positioning
G90
# Park
G0 X{safe_x} Y{y} F{speed}
#####
# COLOR CHANGE
#####
[gcode_macro M600]
description: Executes a color change by pausing the printer an unloading the filament.
gcode:
PAUSE
UNLOAD_FILAMENT
M117 Please load new filament and resume
RESPOND MSG="Please load new filament and resume"
#####
# FILAMENT MANAGEMENT
#####
[gcode_macro UNLOAD_FILAMENT]
description: Unloads the filament. Note: be careful with PETG, make sure you inspect the tip of your filament before reloading to avoid jams.
gcode:
SAVE_GCODE_STATE NAME=unload_state
G91
{% if params.TEMP is defined or printer.extruder.can_extrude|lower == 'false' %}
M117 Heating...
# Heat up hotend to provided temp or 220 as default as that should work OK with most filaments.
M104 S{params.TEMP|default(220, true)}
TEMPERATURE_WAIT SENSOR=extruder MINIMUM={params.TEMP|default(220, true)}
{% endif %}
{% set unload_speed = printer["gcode_macro RatOS"].filament_unload_speed|float * 60 %}
{% set unload_length = printer["gcode_macro RatOS"].filament_unload_length|float %}
M117 Unloading filament...
# Extrude a bit
G0 E10 F300
# Extract filament to cold end area
G0 E-5 F3600
# Wait for three seconds
G4 P3000
# Push back the filament to smash any stringing
G0 E5 F3600
# Extract back fast in to the cold zone
G0 E-15 F3600
# Continue extraction slowly, allow the filament time to cool solid before it reaches the gears
G0 E-{unload_length} F{unload_speed}
M117 Filament unloaded!
RESPOND MSG="Filament unloaded! Please inspect the tip of the filament before reloading."
RESTORE_GCODE_STATE NAME=unload_state
[gcode_macro LOAD_FILAMENT]
description: Loads new filament. Note: be careful with PETG, make sure you inspect the tip of your filament before loading to avoid jams.
gcode:
SAVE_GCODE_STATE NAME=load_state
G91
# Heat up hotend to provided temp or 220 as default as that should work OK with most filaments.
{% if params.TEMP is defined or printer.extruder.can_extrude|lower == 'false' %}
M117 Heating...
M104 S{params.TEMP|default(220, true)}
TEMPERATURE_WAIT SENSOR=extruder MINIMUM={params.TEMP|default(220, true)}
{% endif %}
{% set load_speed = printer["gcode_macro RatOS"].filament_load_speed|float * 60 %}
{% set load_length = printer["gcode_macro RatOS"].filament_load_length|float %}
M117 Loading filament...
# Load the filament into the hotend area.
G0 E{load_length} F{load_speed}
# Wait a secod
G4 P1000
# Purge
G0 E40 F100
# Wait for purge to complete
M400
M117 Filament loaded!
RESPOND MSG="Filament loaded!"
RESTORE_GCODE_STATE NAME=load_state
[gcode_macro SET_CENTER_KINEMATIC_POSITION]
description: FOR DEBUGGING PURPOSES ONLY. Sets the internal printer kinematic state to the center of all axes regardless of actual physical position.
gcode:
RESPOND MSG="WARNING: ONLY USE SET_CENTER_KINEMATIC_POSITION FOR DEBUGGING PURPOSES. YOU'RE OVERRIDING THE INTERNAL POSITIONING STATE OF THE PRINTER. PROCEED WITH CAUTION AND DO A PROPER G28 WHEN DONE."
SET_GCODE_VARIABLE MACRO=MAYBE_HOME VARIABLE=is_kinematic_position_overriden VALUE=True
SET_KINEMATIC_POSITION X={printer.toolhead.axis_maximum.x / 2} Y={printer.toolhead.axis_maximum.y / 2} Z={printer.toolhead.axis_maximum.z / 2}
#####
# 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.
gcode:
CLEAR_PAUSE
{% if printer["gcode_macro RatOS"].force_absolute_position|lower == 'true' %}
G90
{% endif %}
SAVE_GCODE_STATE NAME=start_print_state
# Metric values
G21
# Absolute positioning
G90
# Set extruder to absolute mode
M82
_USER_START_PRINT_BEFORE_HOMING
{% if printer["gcode_macro RatOS"].z_probe|lower == 'stowable' %}
STOWABLE_PROBE_BEGIN_BATCH
{% endif %}
# Home if needed
MAYBE_HOME
{% if params.CHAMBER_TEMP is defined %}
_START_PRINT_HEAT_CHAMBER CHAMBER_TEMP={params.CHAMBER_TEMP} BED_TEMP={printer["gcode_macro RatOS"].start_print_heat_chamber_bed_temp}
_USER_START_PRINT_HEAT_CHAMBER CHAMBER_TEMP={params.CHAMBER_TEMP} BED_TEMP={printer["gcode_macro RatOS"].start_print_heat_chamber_bed_temp}
{% endif %}
M117 Heating bed...
RESPOND MSG="Heating bed..."
# Wait for bed to heat up
M190 S{params.BED_TEMP|default(printer.heater_bed.target, true) }
# Run the user created "AFTER_HEATING_BED" macro
_USER_START_PRINT_AFTER_HEATING_BED
# Run the customizable "AFTER_HEATING_BED" macro.
_START_PRINT_AFTER_HEATING_BED
# Run the user created "START_PRINT_BED_MESH" macro
_USER_START_PRINT_BED_MESH
# Run the customizable "BED_MESH" macro
_START_PRINT_BED_MESH X0={params.X0} X1={params.X1} Y0={params.Y0} Y1={params.Y1}
{% if printer["gcode_macro RatOS"].z_probe|lower == 'stowable' %}
STOWABLE_PROBE_END_BATCH
{% endif %}
# Start heating extruder
M104 S{params.EXTRUDER_TEMP|default(printer.extruder.target, true) }
# Run the users "PARK" macro
_USER_START_PRINT_PARK
# Run the customizable "PARK" macro
_START_PRINT_PARK
# Wait for extruder to heat up
M117 Heating Extruder...
RESPOND MSG="Heating Extruder..."
M109 S{params.EXTRUDER_TEMP|default(printer.extruder.target, true) }
# Run the user created "AFTER_HEATING_EXTRUDER" macro.
_USER_START_PRINT_AFTER_HEATING_EXTRUDER
# Run the customizable "AFTER_HEATING_EXTRUDER" macro.
_START_PRINT_AFTER_HEATING_EXTRUDER
M117 Printing...
RESPOND MSG="Printing..."
RESTORE_GCODE_STATE NAME=start_print_state
# Set extrusion mode based on user configuration
{% if printer["gcode_macro RatOS"].relative_extrusion|lower == 'true' %}
M83
{% else %}
M82
{% endif %}
G92 E0
#####
# 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 _USER_START_PRINT_BEFORE_HOMING]
gcode:
[gcode_macro _START_PRINT_AFTER_HEATING_BED]
gcode:
{% if printer["gcode_macro RatOS"].preheat_extruder|lower == 'true' %}
{% set min_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float %}
{% set max_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float + 5 %}
M117 Pre-heating extruder...
RESPOND 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.
M104 S{min_temp}
TEMPERATURE_WAIT SENSOR=extruder MINIMUM={min_temp} MAXIMUM={max_temp}
{% endif %}
[gcode_macro _USER_START_PRINT_AFTER_HEATING_BED]
gcode:
[gcode_macro _START_PRINT_BED_MESH]
gcode:
{% set default_profile = printer["gcode_macro RatOS"].bed_mesh_profile|default('ratos') %}
{% if printer["gcode_macro RatOS"].calibrate_bed_mesh|lower == 'true' %}
BED_MESH_CLEAR
{% if printer["gcode_macro RatOS"].adaptive_mesh|lower == 'true' %}
CALIBRATE_ADAPTIVE_MESH PROFILE={default_profile} X0={params.X0} X1={params.X1} Y0={params.Y0} Y1={params.Y1}
{% else %}
BED_MESH_CALIBRATE PROFILE={default_profile}
{% endif %}
BED_MESH_PROFILE LOAD={default_profile}
{% elif printer["gcode_macro RatOS"].bed_mesh_profile is defined %}
BED_MESH_CLEAR
BED_MESH_PROFILE LOAD={printer["gcode_macro RatOS"].bed_mesh_profile}
{% endif %}
[gcode_macro _USER_START_PRINT_BED_MESH]
gcode:
[gcode_macro _START_PRINT_PARK]
gcode:
{% set z = printer["gcode_macro RatOS"].start_print_park_z_height|float %}
{% set zSpeed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %}
_PARK LOCATION={printer["gcode_macro RatOS"].start_print_park_in} X={printer["gcode_macro RatOS"].start_print_park_x}
G0 Z{z} F{zSpeed}
[gcode_macro _USER_START_PRINT_PARK]
gcode:
[gcode_macro _START_PRINT_AFTER_HEATING_EXTRUDER]
gcode:
{% set has_offset = printer["gcode_macro RatOS"].probe_for_priming_result|float(9999.9) != 9999.9 %}
{% if has_offset %}
ADD_PRIME_PROBE_TO_OFFSET
{% endif %}
{% if printer["gcode_macro RatOS"].nozzle_priming|lower == 'primeline' %}
PRIME_LINE
{% endif %}
{% if printer["gcode_macro RatOS"].nozzle_priming|lower == 'primeblob' %}
PRIME_BLOB
{% endif %}
{% if has_offset %}
SUBTRACT_PRIME_PROBE_FROM_OFFSET
{% endif %}
{% if printer["gcode_macro RatOS"].skew_profile is defined %}
SKEW_PROFILE LOAD={printer["gcode_macro RatOS"].skew_profile}
{% endif %}
[gcode_macro _USER_START_PRINT_AFTER_HEATING_EXTRUDER]
gcode:
[gcode_macro _START_PRINT_HEAT_CHAMBER]
description: Uses the extruder sensor to wait for chamber temp. Override the _START_PRINT_HEAT_CHAMBER macro to implement heated chamber handling.
gcode:
{% if params.CHAMBER_TEMP is defined and params.BED_TEMP is defined and params.CHAMBER_TEMP|int > 0 %}
{% set z = printer["gcode_macro RatOS"].start_print_park_z_height|float %}
{% set zSpeed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %}
G0 Z{z} F{zSpeed}
M84
M117 Heating chamber...
RESPOND MSG="Heating chamber..."
M140 S{params.BED_TEMP}
TEMPERATURE_WAIT SENSOR=extruder MINIMUM={params.CHAMBER_TEMP}
MAYBE_HOME
{% endif %}
[gcode_macro _USER_START_PRINT_HEAT_CHAMBER]
description: Uses the extruder sensor to wait for chamber temp. Override the _START_PRINT_HEAT_CHAMBER macro to implement heated chamber handling.
gcode:
#####
# END PRINT MACROS
# Call this from your slicer (custom g-code).
# Read more here: https://rat-rig.github.io/V-CoreOS/#/slicers
#####
# The end_print macro is also called from CANCEL_PRINT.
[gcode_macro END_PRINT]
description: End print procedure, use this in your Slicer.
gcode:
SAVE_GCODE_STATE NAME=end_print_state
_USER_END_PRINT_BEFORE_HEATERS_OFF
_END_PRINT_BEFORE_HEATERS_OFF
TURN_OFF_HEATERS
_USER_END_PRINT_AFTER_HEATERS_OFF
_END_PRINT_AFTER_HEATERS_OFF
_USER_END_PRINT_PARK
_END_PRINT_PARK
# Clear skew profile if any was loaded.
{% if printer["gcode_macro RatOS"].skew_profile is defined %}
SET_SKEW CLEAR=1
{% endif %}
# Steppers off
M84
# Part cooling fan off
M107
# Clear bed mesh so that G28 doesn't fail.
BED_MESH_CLEAR
M117 Done :)
RESPOND MSG="Done :)"
RESTORE_GCODE_STATE NAME=end_print_state
#####
# END PRINT MACRO HOOKS
# You can copy these to printer.cfg and modify them to your liking, or just use them as is.
####
[gcode_macro _END_PRINT_BEFORE_HEATERS_OFF]
gcode:
RESPOND MSG="Cleaning up..."
[gcode_macro _USER_END_PRINT_BEFORE_HEATERS_OFF]
gcode:
[gcode_macro _END_PRINT_AFTER_HEATERS_OFF]
gcode:
# Calculate safe Z position
{% set max_z = printer.toolhead.axis_maximum.z|float %}
{% set act_z = printer.toolhead.position.z|float %}
{% set z_hop = printer["gcode_macro RatOS"].end_print_park_z_hop|float %}
{% if act_z < (max_z - z_hop) %}
{% set z_safe = z_hop %}
{% else %}
{% set z_safe = max_z - act_z %}
{% endif %}
# Relative positioning
G91
# Retract the filament a bit before lifting the nozzle.
G1 E-2 F3600
# Move to safe Z position
G0 Z{z_safe} F3600
# Retract filament even more
G1 E-2 F3600
# Back to absolute positioning
G90
[gcode_macro _USER_END_PRINT_AFTER_HEATERS_OFF]
gcode:
[gcode_macro _END_PRINT_PARK]
gcode:
_PARK LOCATION={printer["gcode_macro RatOS"].end_print_park_in} X={printer["gcode_macro RatOS"].end_print_park_x}
[gcode_macro _USER_END_PRINT_PARK]
gcode:
#####
# MESH MACROS
####
[gcode_macro SAVE_PROBE_RESULT]
gcode:
{% set last_z = printer.probe.last_z_result %}
SET_GCODE_VARIABLE MACRO=RatOS VARIABLE={params.VARIABLE|default('last_z')} VALUE={last_z}
[gcode_macro PROBE_FOR_PRIMING]
gcode:
{% if printer["gcode_macro RatOS"].nozzle_priming|lower != 'false' %}
SAVE_GCODE_STATE NAME=probe_for_priming_state
RESPOND MSG="Probing the prime location.."
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
{% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %}
{% if printer["gcode_macro RatOS"].nozzle_prime_start_x|lower == 'min' %}
{% set x_start = 5 %}
{% elif printer["gcode_macro RatOS"].nozzle_prime_start_x|lower == 'max' %}
{% set x_start = printer.toolhead.axis_maximum.x - 5 %}
{% else %}
{% set x_start = printer["gcode_macro RatOS"].nozzle_prime_start_x|float %}
{% endif %}
{% if printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == 'min' %}
{% set y_start = 5 %}
{% elif printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == 'max' %}
{% set y_start = printer.toolhead.axis_maximum.y - 5 %}
{% else %}
{% set y_start = printer["gcode_macro RatOS"].nozzle_prime_start_y|float %}
{% endif %}
{% set z = printer.configfile.settings.bed_mesh.horizontal_move_z|float %}
# get bed mesh config object
{% set mesh_config = printer.configfile.config.bed_mesh %}
# Get probe offsets
{% if printer.configfile.settings.bltouch is defined %}
{% set x_offset = printer.configfile.settings.bltouch.x_offset|float %}
{% set y_offset = printer.configfile.settings.bltouch.y_offset|float %}
{% elif printer.configfile.settings.probe is defined %}
{% set x_offset = printer.configfile.settings.probe.x_offset|float %}
{% set y_offset = printer.configfile.settings.probe.y_offset|float %}
{% elif printer.configfile.settings.beacon is defined %}
{% set x_offset = printer.configfile.settings.beacon.x_offset|float %}
{% set y_offset = printer.configfile.settings.beacon.y_offset|float %}
{% else %}
{ action_raise_error("No probe or bltouch section found. Adaptive priming only works with [probe] or [bltouch].") }
{% endif %}
# get configured bed mesh area
{% set min_x = mesh_config.mesh_min.split(",")[0]|float - x_offset %}
{% set min_y = mesh_config.mesh_min.split(",")[1]|float - y_offset %}
{% set max_x = mesh_config.mesh_max.split(",")[0]|float - x_offset %}
{% set max_y = mesh_config.mesh_max.split(",")[1]|float - y_offset %}
# make sure probe coordinates lie within the configured mesh area
{% set x_start = [[x_start, max_x]|min, min_x]|max %}
{% set y_start = [[y_start, max_y]|min, min_y]|max %}
RESPOND MSG="PROBE_FOR_PRIMING: Probing the prime location at X: {x_start} Y: {y_start}"
# Absolute positioning
G90
# Relative extrusion
M83
# Lift to horizontal_move_z
G0 Z{z} F{z_speed}
# move close to blob position
G1 X{x_start} Y{y_start} F{speed}
PROBE_CURRENT_POSITION
SAVE_PROBE_RESULT VARIABLE=probe_for_priming_result
RESTORE_GCODE_STATE NAME=probe_for_priming_state
{% endif %}
[gcode_macro RESET_PRIME_PROBE_STATE]
gcode:
SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=probe_for_priming_result VALUE=None
[gcode_macro PROBE_CURRENT_POSITION]
gcode:
SAVE_GCODE_STATE NAME=probe_current_position_state
{% if printer["gcode_macro RatOS"].z_probe|lower == 'stowable' %}
ASSERT_PROBE_DEPLOYED
{% endif %}
PROBE
RESTORE_GCODE_STATE NAME=probe_current_position_state MOVE=1 MOVE_SPEED={printer["gcode_macro RatOS"].macro_z_speed|float}
[gcode_macro ADD_PRIME_PROBE_TO_OFFSET]
gcode:
{% set last_z = printer["gcode_macro RatOS"].probe_for_priming_result|float(9999.9) %}
{% if printer.configfile.settings.bltouch is defined %}
{% set z_offset = printer.configfile.settings.bltouch.z_offset|float %}
{% elif printer.configfile.settings.probe is defined %}
{% set z_offset = printer.configfile.settings.probe.z_offset|float %}
{% else %}
{ action_raise_error("No probe or bltouch section found. Adaptive priming only works with [probe] or [bltouch].") }
{% endif %}
{% if last_z == 9999.9 %}
{ action_raise_error("No probe result found for prime area. This is likely a bug.") }
{% endif %}
{% set adjustment = last_z - z_offset %}
{% set adjustment_threshold = printer["gcode_macro RatOS"].adaptive_prime_offset_threshold|float %}
{% if adjustment < adjustment_threshold %}
{ action_raise_error("Abnormal probe offset detected. Needed offset of {adjustment} is below the offset threshold of -1mm. Please verify the probe is over the bed when probing for priming. If it isn't, you should adjust you min/max bed_mesh settings so the probe is always over the print area.") }
{% endif %}
RESPOND MSG="ADD_PRIME_PROBE_TO_OFFSET: adjusting z offset by {adjustment}"
SET_GCODE_OFFSET Z_ADJUST={adjustment} MOVE=1
[gcode_macro SUBTRACT_PRIME_PROBE_FROM_OFFSET]
gcode:
{% set last_z = printer["gcode_macro RatOS"].probe_for_priming_result|float(9999.9) %}
{% if printer.configfile.settings.bltouch is defined %}
{% set z_offset = printer.configfile.settings.bltouch.z_offset|float %}
{% elif printer.configfile.settings.probe is defined %}
{% set z_offset = printer.configfile.settings.probe.z_offset|float %}
{% else %}
{ action_raise_error("No probe or bltouch section found. Adaptive priming only works with [probe] or [bltouch].") }
{% endif %}
{% if last_z == 9999.9 %}
{ action_raise_error("No probe result found for prime area. This is likely a bug.") }
{% endif %}
RESPOND MSG="SUBTRACT_PRIME_PROBE_FROM_OFFSET: adjusting z offset by {z_offset - last_z}"
SET_GCODE_OFFSET Z_ADJUST={z_offset - last_z} MOVE=1
[gcode_macro CALIBRATE_ADAPTIVE_MESH]
gcode:
# get default mesh profile
{% set default_profile = params.PROFILE %}
# coordinates from the slicer start gcode
{% set x0 = params.X0|default(-1)|float %}
{% set y0 = params.Y0|default(-1)|float %}
{% set x1 = params.X1|default(-1)|float %}
{% set y1 = params.Y1|default(-1)|float %}
RESPOND MSG="CALIBRATE_ADAPTIVE_MESH: Recieved coordinates X0={x0} Y0={y0} X1={x1} Y1={y1}"
{% if x0 >= x1 or y0 >= y1 %}
# coordinates are invalid, fall back to full bed mesh
RESPOND MSG="CALIBRATE_ADAPTIVE_MESH: Invalid coordinates received. Please check your slicer settings. Falling back to full bed mesh."
BED_MESH_CALIBRATE PROFILE={default_profile}
{% else %}
# get bed mesh config object
{% set mesh_config = printer.configfile.config.bed_mesh %}
# get configured bed mesh area
{% set min_x = mesh_config.mesh_min.split(",")[0]|float %}
{% set min_y = mesh_config.mesh_min.split(",")[1]|float %}
{% set max_x = mesh_config.mesh_max.split(",")[0]|float %}
{% set max_y = mesh_config.mesh_max.split(",")[1]|float %}
# make sure mesh coordinates lie within the configured mesh area
{% set mesh_x0 = [[x0, max_x]|min, min_x]|max %}
{% set mesh_y0 = [[y0, max_y]|min, min_y]|max %}
{% set mesh_x1 = [[x1, max_x]|min, min_x]|max %}
{% set mesh_y1 = [[y1, max_y]|min, min_y]|max %}
{% if mesh_x0 == min_x and mesh_y0 == min_y and mesh_x1 == max_x and mesh_y1 == max_y %}
# coordinates are invalid, fall back to full bed mesh
RESPOND MSG="CALIBRATE_ADAPTIVE_MESH: Print is using the full bed, falling back to full bed mesh."
BED_MESH_CALIBRATE PROFILE={default_profile}
{% else %}
{% if printer["gcode_macro RatOS"].z_probe|lower == 'stowable' %}
DEPLOY_PROBE
{% endif %}
# get configured probe count
{% set probe_count_x = mesh_config.probe_count.split(",")[0]|int %}
{% if mesh_config.probe_count.split(",")|length == 2 %}
{% set probe_count_y = mesh_config.probe_count.split(",")[1]|int %}
{% else %}
{% set probe_count_y = mesh_config.probe_count.split(",")[0]|int %}
{% endif %}
# calculate mesh point resolution
{% set probe_x_step = (max_x - min_x) / probe_count_x %}
{% set probe_y_step = (max_y - min_y) / probe_count_y %}
# calculate xy probe count
{% set mesh_count_x = ([(mesh_x1 - mesh_x0) / probe_x_step, 3]|max)|int %}
{% set mesh_count_y = ([(mesh_y1 - mesh_y0) / probe_y_step, 3]|max)|int %}
{% set min_mesh_count = [mesh_count_x, mesh_count_y]|min %}
{% set max_mesh_count = [mesh_count_x, mesh_count_y]|max %}
# check algorithms
{% set algorithm = mesh_config.algorithm %}
{% if algorithm|lower == 'lagrange' and max_mesh_count > 6 %}
RESPOND MSG="CALIBRATE_ADAPTIVE_MESH: cannot exceed a probe_count of 6 when using lagrange interpolation. Falling back to bicubic interpolation."
{% set algorithm = 'bicubic' %}
{% endif %}
{% if algorithm|lower == 'bicubic' and min_mesh_count < 4 %}
{% if max_mesh_count > 6 %}
RESPOND MSG="CALIBRATE_ADAPTIVE_MESH: invalid probe_count option when using bicubic interpolation. Combination of 3 points on one axis with more than 6 on another is not permitted. Forcing minimum mesh count to be 4."
{% set min_mesh_count = 4 %}
{% else %}
RESPOND MSG="CALIBRATE_ADAPTIVE_MESH: bicubic interpolation with a probe_count of less than 4 points detected. Forcing lagrange interpolation."
{% set algorithm = 'lagrange' %}
{% endif %}
{% endif %}
{% set mesh_count_x = ([min_mesh_count, mesh_count_x]|max)|int %}
{% set mesh_count_x = ([max_mesh_count, mesh_count_x]|min)|int %}
{% set mesh_count_y = ([min_mesh_count, mesh_count_y]|max)|int %}
{% set mesh_count_y = ([max_mesh_count, mesh_count_y]|min)|int %}
{% set should_prime = printer["gcode_macro RatOS"].nozzle_priming == 'primeline' or printer["gcode_macro RatOS"].nozzle_priming == 'primeblob' %}
{% if printer.configfile.settings.beacon is defined %}
RESPOND MSG="CALIBRATE_ADAPTIVE_MESH: adaptive priming is currently not supported for Beacon. Disabling priming.."
SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=nozzle_priming VALUE=False
{% set should_prime = False %}
{% endif %}
{% set prime_first = printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == "min" or printer["gcode_macro RatOS"].nozzle_prime_start_y|float(printer.toolhead.axis_maximum.y) < printer.toolhead.axis_maximum.y / 2 %}
{% if should_prime and prime_first %}
PROBE_FOR_PRIMING
{% endif %}
# mesh
RESPOND MSG="CALIBRATE_ADAPTIVE_MESH: mesh coordinates X0={mesh_x0} Y0={mesh_y0} X1={mesh_x1} Y1={mesh_y1}"
BED_MESH_CALIBRATE PROFILE={default_profile} algorithm={algorithm} mesh_min={mesh_x0},{mesh_y0} mesh_max={mesh_x1},{mesh_y1} probe_count={mesh_count_x},{mesh_count_y}
{% if should_prime and not prime_first %}
PROBE_FOR_PRIMING
{% endif %}
{% if printer["gcode_macro RatOS"].z_probe|lower == 'stowable' %}
STOW_PROBE
{% endif %}
{% endif %}
{% endif %}