forked from jlas1/Klicky-Probe
-
Notifications
You must be signed in to change notification settings - Fork 4
/
klack-macros.cfg
executable file
·698 lines (601 loc) · 27.9 KB
/
klack-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
[respond]
[gcode_macro _Probe_Variables]
variable_probe_attached: False
variable_probe_state: False
variable_probe_lock: False
variable_z_endstop_x: 0
variable_z_endstop_y: 0
gcode:
#checks if the variable definitions are up to date
[gcode_macro _Klack_check_variables_version]
gcode:
{% set version = printer["gcode_macro _User_Variables"].version|default(0) %}
{% if version != 1 %}
{ action_raise_error("Please update your Klack variables, there are some functionality changes") }
{% endif %}
[gcode_macro _KlackDebug]
gcode:
{% set message = params.MSG %}
{% set debug = printer["gcode_macro _User_Variables"].debug|default(False) %}
{% if debug %}
{ action_respond_info(message) }
{% endif %}
[gcode_macro _Homing_Variables]
gcode:
{% set reset = params.RESET|default(0) %}
{% if reset %}
SET_GCODE_VARIABLE MACRO=_Probe_Variables VARIABLE=probe_lock VALUE={ False }
{% endif %}
##########################
# Attach probe and lock it
[gcode_macro Attach_Probe_Lock]
description: Attaches Klack Probe, can only be docked after unlocking
gcode:
Attach_Probe
_Probe_Lock
########################
# Dock probe and lock it
[gcode_macro Dock_Probe_Unlock]
description: Docks Klack Probe even if it was locked
gcode:
_Probe_Unlock
Dock_Probe
##############
# Unlock Probe
[gcode_macro _Probe_Unlock]
description: Unlocks Klack Probe state
gcode:
_KlackDebug msg="_Probe_Lock setting probe_lock variable to False"
SET_GCODE_VARIABLE MACRO=_Probe_Variables VARIABLE=probe_lock VALUE={ False }
############
# Lock Probe
[gcode_macro _Probe_Lock]
description: Locks Klack Probe state
gcode:
_KlackDebug msg="_Probe_Lock setting probe_lock variable to True"
SET_GCODE_VARIABLE MACRO=_Probe_Variables VARIABLE=probe_lock VALUE={ True }
######################
# Attach Probe Routine
[gcode_macro Attach_Probe]
description: Attaches Klack Probe
gcode:
# See if the position should be restored after the attach
{% set goback = params.BACK|default(0) %}
# Get probe attach status
{% set probe_attached = printer["gcode_macro _Probe_Variables"].probe_attached %}
{% set probe_lock = printer["gcode_macro _Probe_Variables"].probe_lock %}
{% set verbose = printer["gcode_macro _User_Variables"].verbose %}
# Get Docking location
{% set docklocation_x = printer["gcode_macro _User_Variables"].docklocation_x %}
{% set attachmove_x = printer["gcode_macro _User_Variables"].attachmove_x|default(0) %}
# Safe Z for travel
{% set safe_z = printer["gcode_macro _User_Variables"].safe_z %}
{% set enable_z_hop = printer["gcode_macro _User_Variables"].enable_z_hop %}
# Set feedrates
{% set travel_feedrate = printer["gcode_macro _User_Variables"].travel_speed * 60 %}
{% set dock_feedrate = printer["gcode_macro _User_Variables"].dock_speed * 60 %}
{% set release_feedrate = printer["gcode_macro _User_Variables"].release_speed * 60 %}
{% set z_drop_feedrate = printer["gcode_macro _User_Variables"].z_drop_speed * 60 %}
# If x and y are not homed
{% if not 'xy' in printer.toolhead.homed_axes %}
{ action_raise_error("Must Home X and Y Axis First!") }
_KlackDebug msg="Attach_Probe Axis homed"
# If probe not attached and locked
{% elif not probe_attached and not probe_lock %}
_KlackDebug msg="Attach_Probe going to attach probe"
{% if verbose %}
{ action_respond_info("Attaching Probe") }
{% endif %}
{% if not 'z' in printer.toolhead.homed_axes %}
{% if verbose %}
{ action_respond_info("Resetting Z position to zero") }
{% endif %}
_KlackDebug msg="Attach_Probe Z not homed, setting position as X=Y=Z=0"
SET_KINEMATIC_POSITION Z=0
{% if not enable_z_hop %} # Disables safe_z
_KlackDebug msg="Attach_Probe z_hop disabled"
{% set safe_z = 0 %}
{% endif %}
{% endif %}
# Prior to saving actual position, check if its necessary to move to a safe Z
# that has enought overhead for the attached probe
{% if printer.toolhead.position.z < safe_z %}
_KlackDebug msg="Attach_Probe toolhead too low, raising it by {safe_z}mm"
{% if verbose %}
{ action_respond_info("moving to a safe Z distance") }
{% endif %}
G0 Z{safe_z} F{z_drop_feedrate}
{% endif %}
{% if not 'z' in printer.toolhead.homed_axes %} #duplicate??
{% if verbose %}
{ action_respond_info("Resetting Z position to zero, duplicate?") }
{% endif %}
_KlackDebug msg="Attach_Probe Z not homed, setting position as X=Y=Z=0"
SET_KINEMATIC_POSITION Z=0
{% endif %}
{% if printer.toolhead.position.z < safe_z %} #duplicate??
_KlackDebug msg="Attach_Probe toolhead too low, raising it by {safe_z}mm, duplicate?"
G0 Z{safe_z} F{z_drop_feedrate}
{% endif %}
G0 X{docklocation_x|int - attachmove_x|int} F{travel_feedrate}
G0 X{docklocation_x} F{dock_feedrate}
G4 P300
G0 X{docklocation_x|int - attachmove_x|int} F{release_feedrate}
## Go to Z safe distance
{% if (printer.toolhead.position.z < safe_z)%}
_KlackDebug msg="Attach_Probe moving to a safe Z position: G0 Z{safe_z} F{z_drop_feedrate} from {printer.toolhead.position.z}"
G0 Z{safe_z} F{z_drop_feedrate}
{% endif %}
_Park_Toolhead
_CheckProbe action=attach
{% elif probe_lock %}
{% if verbose %}
{ action_respond_info("Probe locked!") }
{% endif %}
# Probe attached, do nothing
_KlackDebug msg="Attach_Probe probe locked not attaching probe"
_CheckProbe action=query
{% else %}
{% if verbose %}
{ action_respond_info("Probe already attached!") }
{% endif %}
# Probe attached, do nothing
_KlackDebug msg="Attach_Probe probe already attached, doing nothing"
_CheckProbe action=query
{% endif %}
####################
# Dock Probe Routine
[gcode_macro Dock_Probe]
description: Docks Klack Probe
gcode:
# See if the position should be restored after the dock
{% set goback = params.BACK|default(0) %}
# Get probe attach status
{% set probe_attached = printer["gcode_macro _Probe_Variables"].probe_attached %}
{% set probe_lock = printer["gcode_macro _Probe_Variables"].probe_lock %}
{% set verbose = printer["gcode_macro _User_Variables"].verbose %}
# Get Docking location
{% set dockmove_x = printer["gcode_macro _User_Variables"].dockmove_x|default(0) %}
{% set dockmove_z = printer["gcode_macro _User_Variables"].dockmove_z|default(0) %}
{% set docklocation_x = printer["gcode_macro _User_Variables"].docklocation_x %}
{% set attachmove_x = printer["gcode_macro _User_Variables"].attachmove_x|default(0) %}
# Safe Z for travel
{% set safe_z = printer["gcode_macro _User_Variables"].safe_z|float %}
# Set feedrates
{% set travel_feedrate = printer["gcode_macro _User_Variables"].travel_speed * 60 %}
{% set dock_feedrate = printer["gcode_macro _User_Variables"].dock_speed * 60 %}
{% set release_feedrate = printer["gcode_macro _User_Variables"].release_speed * 60 %}
{% set z_drop_feedrate = printer["gcode_macro _User_Variables"].z_drop_speed * 60 %}
# If axis aren't homed, fail
{% if not 'xyz' in printer.toolhead.homed_axes %}
{ action_raise_error("Must Home X, Y and Z Axis First!") }
{% endif %}
_KlackDebug msg="Dock_Probe Axis homed"
# If probe not attached and not locked
{% if probe_attached and not probe_lock %}
_KlackDebug msg="Dock_Probe going to dock probe"
{% if verbose %}
{ action_respond_info("Docking Probe") }
{% endif %}
{% if printer.toolhead.position.z < safe_z %}
_KlackDebug msg="Dock_Probe toolhead too low, raising it to {safe_z}mm"
G0 Z{safe_z} F{z_drop_feedrate}
{% endif %}
# Drop Probe to Probe location
G0 X{docklocation_x|int - attachmove_x|int} F{travel_feedrate}
G0 X{docklocation_x} F{dock_feedrate}
G0 Z{dockmove_z} F{dock_feedrate}
G0 X{docklocation_x|int + dockmove_x|int} F{release_feedrate}
## Go to Z safe distance
{% if (printer.toolhead.position.z < safe_z)%}
_KlackDebug msg="Dock_Probe moving to a safe Z position: G0 Z{safe_z} F{z_drop_feedrate} from {printer.toolhead.position.z}"
G0 Z{safe_z} F{z_drop_feedrate}
{% endif %}
_Park_Toolhead
G4 P1000
_CheckProbe action=dock
{% elif probe_lock %}
{% if verbose %}
{ action_respond_info("Probe locked") }
{% endif %}
# Probe docked, do nothing
_KlackDebug msg="Dock_Probe probe locked not docking probe"
_CheckProbe action=query
{% else %}
{% if verbose %}
{ action_respond_info("Probe already docked") }
{% endif %}
# Probe docked, do nothing
_KlackDebug msg="Dock_Probe probe already docked, doing nothing"
_CheckProbe action=query
{% endif %}
#################
# Probe Calibrate
[gcode_macro PROBE_CALIBRATE]
rename_existing: _PROBE_CALIBRATE
description:Calibrate the probes z_offset with Klack automount
gcode:
{% set safe_z = printer["gcode_macro _User_Variables"].safe_z|float %}
{% set z_drop_feedrate = printer["gcode_macro _User_Variables"].z_drop_speed * 60 %}
{% set probe_offset_x = printer['configfile'].config["probe"]["x_offset"]|float %}
{% set probe_offset_y = printer['configfile'].config["probe"]["y_offset"]|float %}
{% if not 'xyz' in printer.toolhead.homed_axes %}
{ action_raise_error("Must Home X, Y and Z Axis First!") }
{% endif %}
_KlackDebug msg="probe_calibrate Axis homed"
_CheckProbe action=query
G90
Attach_Probe back=1
_KlackDebug msg="probe_calibrate calling klipper probe_calibrate"
_Center_Probe
_PROBE_CALIBRATE {% for p in params
%}{'%s=%s ' % (p, params[p])}{%
endfor %}
M118 moving the toolhead 20 mm from the bed
_Center_Nozzle
_KlackDebug msg="probe_calibrate Moving Z up by 20mm"
TESTZ Z=20
M118 remove manually the probe and continue calibration
################
# Probe Accuracy
[gcode_macro PROBE_ACCURACY]
rename_existing: _PROBE_ACCURACY
description:Probe Z-height accuracy at current XY position with Klack automount
gcode:
{% set safe_z = printer["gcode_macro _User_Variables"].safe_z|float %}
{% set z_drop_feedrate = printer["gcode_macro _User_Variables"].z_drop_speed * 60 %}
{% set probe_offset_x = printer['configfile'].config["probe"]["x_offset"]|float %}
{% set probe_offset_y = printer['configfile'].config["probe"]["y_offset"]|float %}
{% if not 'xyz' in printer.toolhead.homed_axes %}
{ action_raise_error("Must Home X, Y and Z Axis First!") }
{% endif %}
_KlackDebug msg="probe_accuracy Axis homed"
_CheckProbe action=query
Attach_Probe back=1
_Center_Probe
_KlackDebug msg="probe_accuracy calling klipper probe accuracy"
_PROBE_ACCURACY {% for p in params
%}{'%s=%s ' % (p, params[p])}{%
endfor %}
Dock_Probe back=1
#############################################
# Enable to SET_KINEMATIC_POSITION for Z hop
[force_move]
enable_force_move: True
#################
# Homing Override
[homing_override]
axes: xyz
gcode:
# collect user state variables
_User_Variables
{% set verbose = printer["gcode_macro _User_Variables"].verbose %}
{% set safe_z = printer["gcode_macro _User_Variables"].safe_z|float %}
# Safe Z for travel
{% set safe_z = printer["gcode_macro _User_Variables"].safe_z %}
{% set enable_z_hop = printer["gcode_macro _User_Variables"].enable_z_hop %}
{% set kinematic_z = 0 %}
{% set dock_on_zhome = printer["gcode_macro _User_Variables"].dock_on_zhome|default(True) %}
{% set attachmove_x = printer["gcode_macro _User_Variables"].attachmove_x|default(0) %}
{% set attachmove_y = printer["gcode_macro _User_Variables"].attachmove_y|default(0) %}
{% set z_drop_feedrate = printer["gcode_macro _User_Variables"].z_drop_speed * 60 %}
{% set travel_feedrate = printer["gcode_macro _User_Variables"].travel_speed * 60 %}
{% set home_backoff_x = printer["gcode_macro _User_Variables"].home_backoff_x|default(0) %}
{% set home_backoff_y = printer["gcode_macro _User_Variables"].home_backoff_y|default(0) %}
{% set override_homing = printer["gcode_macro _User_Variables"].override_homing|default('') %}
#checks if the variable definitions are up to date
_Klack_check_variables_version
_CheckProbe action=query
# reset parameters
{% set home_x, home_y, home_z, leave_probe_attached = False, False, False, False %}
{% if 'PROBE_LOCK' in params%}
{% if verbose %}
{ action_respond_info("PROBE_LOCK = True") }
{% endif %}
{% set leave_probe_attached = True %}
{% endif %}
# which axes have been requested for homing
{% if not 'X' in params
and not 'Y' in params
and not 'Z' in params %}
{% set home_x, home_y, home_z = True, True, True %}
_KlackDebug msg="homing_override going to home all axes"
{% else %}
{% if 'X' in params %}
{% set home_x = True %}
_KlackDebug msg="homing_override going to home X"
{% endif %}
{% if 'Y' in params %}
{% set home_y = True %}
_KlackDebug msg="homing_override going to home Y"
{% endif %}
{% if 'Z' in params %}
{% set home_z = True %}
_KlackDebug msg="homing_override going to home Z"
{% endif %}
{% if 'X' in params
and 'Y' in params
and 'Z' in params %}
# reset homing state variables
# if homing all axes
_Homing_Variables reset=1
_KlackDebug msg="homing_override going to home all axes"
{% endif %}
{% endif %}
# if Z is not homed, do not move the bed if it goes down
{% if 'z' not in printer.toolhead.homed_axes %}
{% if not enable_z_hop %} # Disables safe_z
_KlackDebug msg="homing_override z_hop disabled"
#preserve safe_z to use as the SET KINEMATIC Z position, so that the toolhead does not move to pick up the probe
{% set kinematic_z = safe_z %}
{% set safe_z = 0 %}
{% endif %}
{% endif %}
{% if home_z %}
{% if 'z' in printer.toolhead.homed_axes %}
{% if printer.toolhead.position.z < safe_z %}
_KlackDebug msg="homing_override toolhead too low, with homed axes, raising it to {safe_z}mm"
{% if verbose %}
{ action_respond_info("moving to a safe Z distance") }
{% endif %}
G0 Z{safe_z} F{z_drop_feedrate}
{% endif %}
{% else %}
{% if verbose %}
{ action_respond_info("Z not homed, forcing full G28") }
{% endif %}
_KlackDebug msg="homing_override Z not homed, setting position as X=Y=0 Z={kinematic_z}"
SET_KINEMATIC_POSITION X=0 Y=0 Z={kinematic_z}
{% if printer.toolhead.position.z < safe_z %}
_KlackDebug msg="homing_override toolhead too low, raising it to {safe_z}mm"
{% if verbose %}
{ action_respond_info("moving to a safe Z distance") }
{% endif %}
G0 Z{safe_z} F{z_drop_feedrate}
{% endif %}
{% set home_x, home_y, home_z = True, True, True %}
{% endif %}
{% endif %}
# if the dock is oriented on the Y, first do Y endstop
{% if (override_homing == '' or (override_homing == 'Y'))%}
# Home y
{% if home_y %}
{% if override_homing == 'Y' %}
_KlackDebug msg="homing_override Y homing first override, due to override_homing = Y"
{% else %}
_KlackDebug msg="homing_override Y homing first override"
{% endif %}
{% if verbose %}
{ action_respond_info("Homing Y") }
{% endif %}
{% if printer["gcode_macro _HOME_Y"] is defined %}
_KlackDebug msg="homing_override calling _HOME_Y external script to handle the Y homing"
_HOME_Y
{% else %}
_KlackDebug msg="homing_override Homing Y G28 Y0"
G28 Y0
# does it need to back away from the home position
{% if home_backoff_y != 0 %}
{% if (printer.configfile.settings.stepper_y.position_endstop > (printer.configfile.settings.stepper_y.position_min|default(0) + printer.configfile.settings.stepper_y.position_max)/2) %}
_KlackDebug msg="homing_override backing off Y endstop, G0 Y{printer.configfile.settings.stepper_y.position_endstop-home_backoff_y|int} F{travel_feedrate}"
G0 Y{printer.configfile.settings.stepper_y.position_endstop - home_backoff_y|int} F{travel_feedrate}
{% else %}
_KlackDebug msg="homing_override backing off Y endstop, G0 Y{printer.configfile.settings.stepper_y.position_endstop + home_backoff_y|int} F{travel_feedrate}"
G0 Y{printer.configfile.settings.stepper_y.position_endstop + home_backoff_y|int} F{travel_feedrate}
{%endif %}
{%endif %}
{% endif %}
{% endif %}
{% set home_y = False %}
{% endif %}
# Home x
{% if home_x %}
{% if verbose %}
{ action_respond_info("Homing X") }
{% endif %}
{% if printer["gcode_macro _HOME_X"] is defined %}
_KlackDebug msg="homing_override calling _HOME_X external script to handle the X homing"
_HOME_X
{% else %}
_KlackDebug msg="homing_override Homing X, G28 X0"
G28 X0
# does it need to back away from the home position
{% if home_backoff_x != 0 %}
{% if (printer.configfile.settings.stepper_x.position_endstop > (printer.configfile.settings.stepper_x.position_min|default(0) + printer.configfile.settings.stepper_x.position_max)/2) %}
_KlackDebug msg="homing_override backing off X endstop, G0 X{printer.configfile.settings.stepper_x.position_endstop - home_backoff_x|int} F{travel_feedrate}"
G0 X{printer.configfile.settings.stepper_x.position_endstop - home_backoff_x|int} F{travel_feedrate}
{% else %}
_KlackDebug msg="homing_override backing off X endstop, G0 X{printer.configfile.settings.stepper_x.position_endstop + home_backoff_x|int} F{travel_feedrate}"
G0 X{printer.configfile.settings.stepper_x.position_endstop + home_backoff_x|int} F{travel_feedrate}
{%endif %}
{%endif %}
{% endif %}
{% endif %}
# Home y
{% if home_y %}
{% if verbose %}
{ action_respond_info("Homing Y") }
{% endif %}
{% if printer["gcode_macro _HOME_Y"] is defined %}
_KlackDebug msg="homing_override calling _HOME_Y external script to handle the Y homing"
_HOME_Y
{% else %}
_KlackDebug msg="homing_override Homing Y, G28 Y0"
G28 Y0
{% if home_backoff_y != 0 %}
{% if (printer.configfile.settings.stepper_y.position_endstop > (printer.configfile.settings.stepper_y.position_min|default(0) + printer.configfile.settings.stepper_y.position_max)/2) %}
_KlackDebug msg="homing_override backing off Y endstop, G0 Y{printer.configfile.settings.stepper_y.position_endstop - home_backoff_y|int} F{travel_feedrate}"
G0 Y{printer.configfile.settings.stepper_y.position_endstop - home_backoff_y|int} F{travel_feedrate}
{% else %}
_KlackDebug msg="homing_override backing off Y endstop, G0 Y{printer.configfile.settings.stepper_y.position_endstop + home_backoff_y|int} F{travel_feedrate}"
G0 Y{printer.configfile.settings.stepper_y.position_endstop + home_backoff_y|int} F{travel_feedrate}
{%endif %}
{%endif %}
{% endif %}
{% endif %}
# Home z
{% if home_z %}
{% if verbose %}
{ action_respond_info("Homing Z") }
{% endif %}
# if probe is configured as endstop, attach it, else check if the probe needs to be docked if attached
{% if printer['configfile'].config["stepper_z"]["endstop_pin"] == 'probe:z_virtual_endstop' %}
_KlackDebug msg="homing_override probe configured as a virtual Z endstop attaching probe"
Attach_Probe
# if PROBE_LOCK parameter is given, Attach Probe and lock until it´s unlocked
{% if leave_probe_attached %}
_Probe_Lock
{% endif %}
{% elif dock_on_zhome == True %}
Dock_Probe
{% endif %}
_Home_Z
# if probe is configured as endstop, dock it
{% if printer['configfile'].config["stepper_z"]["endstop_pin"] == 'probe:z_virtual_endstop' %}
_KlackDebug msg="homing_override probe no longer required, docking probe"
Dock_Probe
{% elif dock_on_zhome == False %}
Dock_Probe
{% endif %}
{% endif %}
_CheckProbe action=query
# park the toolhead
_Park_Toolhead
[gcode_macro Home_Lock]
gcode:
# collect user state variables
_User_Variables
{% set safe_z = printer["gcode_macro _User_Variables"].safe_z|float %}
{% set z_drop_feedrate = printer["gcode_macro _User_Variables"].z_drop_speed * 60 %}
SET_KINEMATIC_POSITION X=0 Y=0 Z=0
G0 Z{safe_z} F{z_drop_feedrate}
G28 X
G28 Y
Attach_Probe_Lock
_Center_Probe
G28 Z
# Home Z Routine
[gcode_macro _Home_Z]
gcode:
{% set z_endstop_x = printer["gcode_macro _Probe_Variables"].z_endstop_x %}
{% set z_endstop_y = printer["gcode_macro _Probe_Variables"].z_endstop_y %}
{% set safe_z = printer["gcode_macro _User_Variables"].safe_z|float %}
{% set travel_feedrate = printer["gcode_macro _User_Variables"].travel_speed * 60 %}
{% set z_drop_feedrate = printer["gcode_macro _User_Variables"].z_drop_speed * 60 %}
{% set verbose = printer["gcode_macro _User_Variables"].verbose %}
# if x and y are not homed yet, raise error
{% if not 'xy' in printer.toolhead.homed_axes %}
{ action_raise_error("Must Home X and Y Axis First!") }
{% else %}
_KlackDebug msg="_Home_Z XY Axis homed"
{% if not 'z' in printer.toolhead.homed_axes %}
{% if verbose %}
{ action_respond_info("Resetting Z position to zero") }
{% endif %}
_KlackDebug msg="_Home_Z Z not homed, setting position as X=Y=Z=0"
SET_KINEMATIC_POSITION Z=0
{% endif %}
# Move tool to safe homing position and home Z axis
# location of z endstop
_KlackDebug msg="_Home_Z moving to Z endstop position G0 X{z_endstop_x} Y{z_endstop_y} F{travel_feedrate}"
#G0 X{z_endstop_x} Y{z_endstop_y} F{travel_feedrate}
_Center_Probe
_KlackDebug msg="_Home_Z Homing Z G28 Z"
G28 Z0
_KlackDebug msg="_Home_Z toolhead too low, raising it to {safe_z}mm"
G0 Z{safe_z} F{z_drop_feedrate}
{% endif %}
# Check to see if probe is where it is supposed to be after
# attaching/docking maneuver and set homing error or shutdown
[gcode_macro _CheckProbe]
variable_probe_state: 0
gcode:
Query_Probe
_SetProbeState action={ params.ACTION }
# Due to how templates are evaluated, we have query endstops in one
# macro and call another macro to make decisions based on the result
[gcode_macro _SetProbeState]
gcode:
{% set query_probe_triggered = printer.probe.last_query %}
{% set action = params.ACTION|default('') %}
# If triggered (true), probe not attached
{% if query_probe_triggered %}
SET_GCODE_VARIABLE MACRO=_Probe_Variables VARIABLE=probe_attached VALUE={ False }
{% else %}
# If not triggered (false), probe attached
SET_GCODE_VARIABLE MACRO=_Probe_Variables VARIABLE=probe_attached VALUE={ True }
{% endif %}
{% if action == 'query' %}
SET_GCODE_VARIABLE MACRO=_Probe_Variables VARIABLE=probe_state VALUE={ query_probe_triggered }
{% endif %}
# If probe fails to attach/detach
# If not docked
{% if not query_probe_triggered and action == 'dock' %}
{ action_raise_error("Probe dock failed!") }
{% endif %}
# If not attached
{% if query_probe_triggered and action == 'attach' %}
{ action_raise_error("Probe attach failed!") }
{% endif %}
# Park Toolhead Routine
[gcode_macro _Park_Toolhead]
gcode:
{% set park_toolhead = printer["gcode_macro _User_Variables"].park_toolhead %}
{% set parkposition_x = printer["gcode_macro _User_Variables"].parkposition_x %}
{% set parkposition_y = printer["gcode_macro _User_Variables"].parkposition_y %}
{% set parkposition_z = printer["gcode_macro _User_Variables"].parkposition_z %}
{% set travel_feedrate = printer["gcode_macro _User_Variables"].travel_speed * 60 %}
{% set verbose = printer["gcode_macro _User_Variables"].verbose %}
{% if park_toolhead and 'xyz' in printer.toolhead.homed_axes %}
{% if verbose %}
{ action_respond_info("Parking Toolhead") }
{% endif %}
{% if parkposition_z == -128 %}
_KlackDebug msg="_Park_Toolhead moving to G0 X{parkposition_x} Y{parkposition_y} F{travel_feedrate}"
G0 X{parkposition_x} Y{parkposition_y} F{travel_feedrate}
{% else %}
_KlackDebug msg="_Park_Toolhead moving to G0 X{parkposition_x} Y{parkposition_y} Z{parkposition_z} F{travel_feedrate}"
G0 X{parkposition_x} Y{parkposition_y} Z{parkposition_z} F{travel_feedrate}
{% endif %}
{% endif %}
#################
# Centering utils
[gcode_macro _Center_Probe]
gcode:
{% set travel_feedrate = printer["gcode_macro _User_Variables"].travel_speed * 60 %}
{% set max_x = printer["gcode_macro _User_Variables"].bed_size_x|float %}
{% set max_y = printer["gcode_macro _User_Variables"].bed_size_y|float %}
{% set probe_offset_x = printer['configfile'].config["probe"]["x_offset"]|float %}
{% set probe_offset_y = printer['configfile'].config["probe"]["y_offset"]|float %}
{% set probe_x = max_x / 2 - probe_offset_x %}
{% set probe_y = max_y / 2 - probe_offset_y %}
_KlackDebug msg="probe to center of the bed"
_Move_to_Safe_z
G0 X{probe_x} Y{probe_y} F{travel_feedrate}
[gcode_macro _Center_Nozzle]
gcode:
{% set travel_feedrate = printer["gcode_macro _User_Variables"].travel_speed * 60 %}
{% set max_x = printer["gcode_macro _User_Variables"].bed_size_x|float %}
{% set max_y = printer["gcode_macro _User_Variables"].bed_size_y|float %}
_Move_to_Safe_z
G0 X{max_x/2} Y{max_y/2} F{travel_feedrate}
[gcode_macro _Move_to_Safe_z]
gcode:
# Safe Z for travel
{% set safe_z = printer["gcode_macro _User_Variables"].safe_z %}
{% set enable_z_hop = printer["gcode_macro _User_Variables"].enable_z_hop %}
# Set feedrates
{% set z_drop_feedrate = printer["gcode_macro _User_Variables"].z_drop_speed * 60 %}
{% if not enable_z_hop %} # Disables safe_z
_KlackDebug msg="Attach_Probe z_hop disabled"
{% set safe_z = 0 %}
{% endif %}
# Prior to saving actual position, check if its necessary to move to a safe Z
# that has enought overhead for the attached probe
{% if printer.toolhead.position.z < safe_z %}
_KlackDebug msg="Attach_Probe toolhead too low, raising it by {safe_z}mm"
{% if verbose %}
{ action_respond_info("moving to a safe Z distance") }
{% endif %}
G0 Z{safe_z} F{z_drop_feedrate}
{% endif %}