forked from zellneralex/klipper_config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagprobe.cfg
369 lines (354 loc) · 16.6 KB
/
magprobe.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
#####################################################################
# User Macros
#####################################################################
## Used the same names as in <https://github.com/KevinOConnor/klipper/pull/4328>
## to make the switch easier after the PR is merged
[gcode_macro ATTACH_PROBE]
description: Attaching the MagProbe if not already attached
gcode:
_MAG_PROBE ACTION=ATTACH
_MAG_PROBE ACTION=CHECK_ATTACH
[gcode_macro DETACH_PROBE]
description: Dock the MagProbe if not already docked
gcode:
_MAG_PROBE ACTION=DOCK
_MAG_PROBE ACTION=CHECK_DOCK
[gcode_macro GET_PROBE_STATUS]
description: Prints the current MagProbe state, valid probe states are UNKNOWN, ATTACHED and DOCKED
gcode:
_MAG_PROBE ACTION=GET_STATUS RESPOND=1
[gcode_macro SET_PROBE_STATUS]
description: Manually specify MagProbe status, valid probe states are UNKNOWN, ATTACHED and DOCKED
variable_state: 'unknown'
gcode:
{% if 'STATE' in params|upper and
(params.STATE|lower == 'unknown' or params.STATE|lower == 'attached' or params.STATE|lower == 'docked') %}
SET_GCODE_VARIABLE MACRO=SET_PROBE_STATUS VARIABLE=state VALUE='"{params.STATE|lower}"'
SET_GCODE_VARIABLE MACRO=_MAG_PROBE VARIABLE=state VALUE='"{params.STATE|lower}"'
{% else %}
{action_raise_error("Invalid probe state: %s. Valid probe states are [UNKNOWN, ATTACHED, DOCKED]" % params.STATE|default('none')|upper)}
{% endif %}
#####################################################################
# Helper Macros
#####################################################################
# QUERY_PROBE must run direct before _PROBE_ACTION
# that relation is insured by the caller id
[gcode_macro _MAG_PROBE]
description: Helper: Query MagProbe state and request action
variable_state: 'unknown'
variable_dock_state: 'unknown'
variable_id: 0
gcode:
##### add RESPOND if specified #####
{% set respond = "RESPOND=" + params.RESPOND if 'RESPOND' in params|upper else "" %}
##### generate an id not equal to 0 #####
{% set id = 1 if id == 0 else id + 1 %}
##### end of definition #####
QUERY_PROBE ID={id}
_PROBE_ACTION ACTION={params.ACTION} ID={id} {respond}
SET_GCODE_VARIABLE MACRO=_MAG_PROBE VARIABLE=id VALUE={id}
M400
[gcode_macro _PROBE_ACTION]
description: Helper: Perform MagProbe action
variable_error_txt: ''
gcode:
##### get params and defaults #####
{% set respond = params.RESPOND|default(printer['gcode_macro _USER_VARIABLE'].respond.probe_action)|int %}
{% set action = params.ACTION|lower %}
##### generate state #####
{% if printer['gcode_macro SET_PROBE_STATUS'].state|lower != 'unknown' %}
SET_GCODE_VARIABLE MACRO=SET_PROBE_STATUS VARIABLE=state VALUE='"unknown"'
{% set state = printer['gcode_macro SET_PROBE_STATUS'].state|lower %}
{% if respond == 1 %} {action_respond_info("MagProbe: State was set to %s by SET_PROBE_STATUS"%
printer['gcode_macro SET_PROBE_STATUS'].state|lower|upper)} {% endif %}
{% elif params.ID|default(0)|int == 0 or
params.ID|default(0)|int != printer['gcode_macro QUERY_PROBE'].id|default(0)|int %}
{action_raise_error("MagProbe: Call ID invalid or does not match QUERY_PROBE call ID")}
{% elif printer.probe.last_query|lower == 'false' %}
{action_raise_error("MagProbe: Please execute QUERY_PROBE first")}
{% else %}
{% set state = 'attached' if printer.probe.last_query|int == 0 else 'docked'%}
{% endif %}
##### end of defines #####
{% if action == 'attach' %}
{% if state == 'docked' %}
{% if respond == 1 %} {action_respond_info("MagProbe: Attach Probe")} {% endif %}
_ATTACH_PROBE
{% else %}
{% if respond == 1 %} {action_respond_info("MagProbe: already attached")} {% endif %}
{% endif %}
{% elif action == 'dock' %}
{% if state == 'attached' %}
{% if respond == 1 %} {action_respond_info("MagProbe: Dock Probe")} {% endif %}
_DOCK_PROBE
{% else %}
{% if respond == 1 %} {action_respond_info("MagProbe: already docked")} {% endif %}
{% endif %}
{% elif action == 'check_dock' %}
{% set state = 'error' if state != 'docked' else state %}
{% set error_txt = "MagProbe: dock failed!" if state != 'docked'%}
{% elif action == 'check_attach' %}
{% set state = 'error' if state != 'attached' else state %}
{% set error_txt = "MagProbe: attach failed!" if state != 'attached' %}
{% elif action == 'get_status' %}
{% if respond == 1 %} {action_respond_info("MagProbe Status: %s" % state)} {% endif %}
{% else %}
{action_raise_error("MagProbe: action not defined")}
{% endif %}
SET_GCODE_VARIABLE MACRO=_MAG_PROBE VARIABLE=state VALUE='"{state}"'
SET_GCODE_VARIABLE MACRO=_PROBE_ACTION VARIABLE=error_txt VALUE='"{error_txt}"'
_CHECK_STATE
[gcode_macro _CHECK_STATE]
description: Helper: Perform MagProbe error check
gcode:
{% if printer['gcode_macro _MAG_PROBE'].state|default('error')|lower == 'error' %}
{action_raise_error("%s" % printer['gcode_macro _PROBE_ACTION'].error_txt)}
{% endif %}
## used probe: klicky probe
## the probe is fixed to the Gantry
##
## Gantry
## =======
## | dock| x position: probe.store
## | arm|
##
## x position: probe.dock
##
## Attach:
## 1) Prepare : move toolhead next to of dock arm (left or right depending on mouting position)
##
## 2) Dock Probe : move toolhead in X direction on the dock
##
## 3) Finisch : slide toolhead from holder (Y direction)
##
## Detach:
## 1) Prepare : move toolhead infront of the dock arm
##
## 2) UnDock Probe : slide toolhead on holder (Y direction)
##
## 3) Finisch Dock : move toolhead from dock arm (left or right depending on mouting position)
##
[gcode_macro _ATTACH_PROBE]
description: Helper: Attach MagProbe
gcode:
##### Get user defines #####
{% set pos = printer['gcode_macro _USER_VARIABLE'].probe %}
{% set z_hop = printer['gcode_macro _USER_VARIABLE'].z_hop|float %}
{% set speed = printer['gcode_macro _USER_VARIABLE'].speed %}
##### get toolhead position #####
{% set act_z = printer.toolhead.position.z|float %}
##### end of definitions #####
SAVE_GCODE_STATE NAME=STATE_ATTACH_PROBE
SET_GCODE_OFFSET Z=0.0 ; reset offset - will be restored
G90 ; absolute positioning
{% if act_z < z_hop %}
G1 Z{z_hop} F{speed.z_hop} ; move head up
{% endif %}
G0 X{pos.store.x} Y{pos.store.y} F{speed.travel} ; move next to mag-probe
G0 X{pos.dock.x} F{speed.dock} ; move sidewards to attach probe
G0 Y{pos.dock.y} F{speed.dock} ; move out of holder
RESTORE_GCODE_STATE NAME=STATE_ATTACH_PROBE
[gcode_macro _DOCK_PROBE]
description: Helper: Dock MagProbe
gcode:
##### Get user defines #####
{% set pos = printer['gcode_macro _USER_VARIABLE'].probe %}
{% set z_hop = printer['gcode_macro _USER_VARIABLE'].z_hop|float %}
{% set speed = printer['gcode_macro _USER_VARIABLE'].speed %}
##### get toolhead position #####
{% set act_z = printer.toolhead.position.z|float %}
##### end of definitions #####
SAVE_GCODE_STATE NAME=STATE_DOCK_PROBE
SET_GCODE_OFFSET Z=0.0 ; reset offset - will be restored
G90 ; absolute positioning
{% if act_z < z_hop %}
G1 Z{z_hop} F{speed.z_hop} ; move head up
{% endif %}
G0 X{pos.dock.x} Y{pos.dock.y} F{speed.travel} ; move infront of mag-probe
G0 Y{pos.store.y} F{speed.dock} ; move into the holder
G0 X{pos.store.x} F{speed.dock} ; move sidewards to remove probe
RESTORE_GCODE_STATE NAME=STATE_DOCK_PROBE
#####################################################################
# Customized standard macros
#####################################################################
# QUAD_GANTRY_LEVEL can be found in probe_qgl.cfg
# BED_MESH_CALIBRATE can be found in bed_mesh.cfg
#####################################################################
#
# !!! Caution !!!
#
# PROBE_CALIBRATE will attach the probe run the probe sequence and
# than detach the probe. After that use the normal paper test to find
# the right height. Use ACCEPT or ABOURT as usual.
#
#####################################################################
#
# If your probe needs a Z move for attach/detach use either
# G0 .... FORCE
# G1 .... FORCE
#
#####################################################################
[gcode_macro G0]
description: Move gcode that prevents moves lower than the limit when probe attached
rename_existing: G0.1
gcode:
##### set manual override #####
{% set force = 1 if 'FORCE' in params|upper or printer['gcode_macro _USER_VARIABLE'].hw_ena.mag_probe == 'false' else 0 %}
##### get params #####
{% set get_params = ["CALLER=G0", "FORCE=" + force|string] %}
{% for key in params %}
{% set get_params = get_params.append(key + "=" + params[key]) if key is not in ['G', 'FORCE'] %}
{% endfor %}
##### end of definition #####
{% if printer['gcode_macro _MAG_PROBE'].state|default('unknown')|lower == 'unknown'
and force == 0 %} _MAG_PROBE ACTION=GET_STATUS RESPOND=0 {% endif %}
_Z_MOVE_CHECK {get_params|join(" ")}
[gcode_macro G1]
description: Move gcode that prevents moves lower than the limit when probe attached
rename_existing: G1.1
gcode:
##### set manual override #####
{% set force = 1 if 'FORCE' in params|upper or printer['gcode_macro _USER_VARIABLE'].hw_ena.mag_probe == 'false' else 0 %}
##### get params #####
{% set get_params = ["CALLER=G1", "FORCE=" + force|string] %}
{% for key in params %}
{% set get_params = get_params.append(key + "=" + params[key]) if key is not in ['G', 'FORCE'] %}
{% endfor %}
##### end of definition #####
{% if printer['gcode_macro _MAG_PROBE'].state|default('unknown')|lower == 'unknown'
and force == 0 %} _MAG_PROBE ACTION=GET_STATUS RESPOND=0 {% endif %}
_Z_MOVE_CHECK {get_params|join(" ")}
[gcode_macro _Z_MOVE_CHECK]
description: Helper: Check limit and performe move
gcode:
##### z values #####
{% set z_min = printer['gcode_macro _USER_VARIABLE'].z_hop|float %}
{% set z_act = printer.toolhead.position.z|float %}
##### MagProbe state #####
{% set probe_state = printer['gcode_macro _MAG_PROBE'].state|default('unknown')|lower %}
##### calc z_target depending one movemnent
{% set z_target = params.Z|default(0.0)|float if printer.gcode_move.absolute_coordinates
else z_act + params.Z|default(0.0)|float %}
##### get params and prepare to send them to the base macro #####
{% set get_params = [] %}
{% for key in params %}
{% set get_params = get_params.append(key + params[key]) if key is not in ['Z', 'CALLER', 'FORCE']
else get_params.append(key + params[key]) if key is in ['Z'] and (params.FORCE|int == 1 or
probe_state == 'docked' or
((probe_state == 'attached' or probe_state == 'error') and
(z_target >= z_min or z_act < z_target))) %}
{% if key is in ['Z'] and params.FORCE|int == 0 %}
{% if probe_state == 'unknown' %}
{action_raise_error("%s: MagProbe state %s run \"_MAG_PROBE ACTION=GET_STATUS\"" % (caller, probe_state|upper))}
{% elif (probe_state == 'attached' or probe_state == 'error') and (z_target < z_act and z_target < z_min) %}
{action_respond_info("%s: Z Moves (%.3f mm -> %.3f mm) lower than %.3f mm not allowed with installed probe" %
(params.CALLER|upper,z_act,z_target,z_min))}
{action_respond_info("Probe %s" % probe_state)}
{% elif probe_state != 'docked' and probe_state != 'attached' and probe_state != 'error' %}
{action_raise_error("%s: MagProbe state %s not valid" % (params.CALLER|upper, probe_state|upper))}
{% endif %}
{% endif %}
{% endfor %}
##### end of definitions #####
{params.CALLER|upper}.1 {get_params|join(" ")}
[gcode_macro QUERY_PROBE]
description: Return the status of the z-probe and store ID
rename_existing: QUERY_PROBE_BASE
variable_id: 0
gcode:
QUERY_PROBE_BASE
SET_GCODE_VARIABLE MACRO=QUERY_PROBE VARIABLE=id VALUE={params.ID|default(0)} ; call id 0 menas invalid
[gcode_macro PROBE_ACCURACY]
description: Probe Z-height accuracy at current XY position and dock/undock MagProbe
rename_existing: PROBE_ACCURACY_BASE
gcode:
##### get new parameter. #####
{% set dock = params.DOCK|default(1)|int %} ; use DOCK=0 to omit the probe docking
##### Get hardware enables #####
{% set hw_ena = printer['gcode_macro _USER_VARIABLE'].hw_ena %}
##### get user defines #####
{% set speed = printer['gcode_macro _USER_VARIABLE'].speed %}
{% set z_hop = printer['gcode_macro _USER_VARIABLE'].z_hop|float %}
##### get toolhead parameters #####
{% set act_z = printer.gcode_move.gcode_position.z|float %}
# as we need to return to the position with the probe we need to be at least at z_hop
G90 ; absolute positioning
{% if hw_ena.mag_probe == 'true' and act_z < z_hop %}
{action_respond_info("PROBE_ACCURACY: High must be above %.2f" % z_hop)}
G1 Z{z_hop} F{speed.z_hop} ; move head up
{% endif %}
M400 ; get the buffer cleard first
SAVE_GCODE_STATE NAME=STATE_PROBE_ACCURACY
{% if hw_ena.mag_probe == 'true' %}
ATTACH_PROBE
RESTORE_GCODE_STATE NAME=STATE_PROBE_ACCURACY MOVE=1 MOVE_SPEED={(speed.travel|float / 60)}
{% endif %}
PROBE_ACCURACY_BASE {rawparams}
{% if hw_ena.mag_probe == 'true' and dock == 1 %}
DETACH_PROBE
RESTORE_GCODE_STATE NAME=STATE_PROBE_ACCURACY MOVE=1 MOVE_SPEED={(speed.travel|float / 60)}
{% endif %}
{% if not printer.gcode_move.absolute_coordinates %} G91 {% endif %} ; set back to relative
[gcode_macro PROBE]
description: Probe Z-height at current XY position and dock/undock MagProbe
rename_existing: PROBE_BASE
gcode:
##### get new parameter. #####
{% set dock = params.DOCK|default(1)|int %} ; use DOCK=0 to omit the probe docking
##### Get hardware enables #####
{% set hw_ena = printer['gcode_macro _USER_VARIABLE'].hw_ena %}
##### get user defines #####
{% set speed = printer['gcode_macro _USER_VARIABLE'].speed %}
{% set z_hop = printer['gcode_macro _USER_VARIABLE'].z_hop|float %}
##### get toolhead parameters #####
{% set act_z = printer.gcode_move.gcode_position.z|float %}
# as we need to return to the position with the probe we need to be at least at z_hop
G90 ; absolute positioning
{% if hw_ena.mag_probe == 'true' and act_z < z_hop %}
{action_respond_info("PROBE: High must be above %.2f" % z_hop)}
G1 Z{z_hop} F{speed.z_hop} ; move head up
{% endif %}
M400 ; get the buffer cleard first
SAVE_GCODE_STATE NAME=STATE_PROBE
{% if hw_ena.mag_probe == 'true' %}
ATTACH_PROBE
RESTORE_GCODE_STATE NAME=STATE_PROBE MOVE=1 MOVE_SPEED={(speed.travel|float / 60)}
{% endif %}
PROBE_BASE {rawparams}
G1 Z{z_hop} F{speed.z_hop} ; move head up to remove trigger
{% if hw_ena.mag_probe == 'true' and dock == 1 %}
DETACH_PROBE
RESTORE_GCODE_STATE NAME=STATE_PROBE MOVE=1 MOVE_SPEED={(speed.travel|float / 60)}
{% endif %}
{% if not printer.gcode_move.absolute_coordinates %} G91 {% endif %} ; set back to relative
[gcode_macro PROBE_CALIBRATE]
description: Calibrate the probe's z_offset and undock MagProbe
rename_existing: PROBE_CALIBRATE_BASE
gcode:
##### Get hardware enables #####
{% set hw_ena = printer['gcode_macro _USER_VARIABLE'].hw_ena %}
##### get user defines #####
{% set speed = printer['gcode_macro _USER_VARIABLE'].speed %}
{% set z_hop = printer['gcode_macro _USER_VARIABLE'].z_hop|float %}
##### get toolhead parameters #####
{% set act_z = printer.gcode_move.gcode_position.z|float %}
# as we need to return to the position with the probe we need to be at least at z_hop
G90 ; absolute positioning
{% if hw_ena.mag_probe == 'true' and act_z < z_hop %}
{action_respond_info("PROBE_CALIBRATE: High must be above %.2f" % z_hop)}
G1 Z{z_hop} F{speed.z_hop} ; move head up
{% endif %}
M400 ; get the buffer cleard first
# set back movement if needed
{% if not printer.gcode_move.absolute_coordinates %} G91 {% endif %} ; set back to relative
{% if hw_ena.mag_probe == 'true' %}
SAVE_GCODE_STATE NAME=STATE_PROBE_CALIBRATE_ATTACH
ATTACH_PROBE
RESTORE_GCODE_STATE NAME=STATE_PROBE_CALIBRATE_ATTACH MOVE=1 MOVE_SPEED={(speed.travel|float / 60)}
{% endif %}
PROBE_CALIBRATE_BASE {rawparams}
{% if hw_ena.mag_probe == 'true' %}
SAVE_GCODE_STATE NAME=STATE_PROBE_CALIBRATE_DETACH
DETACH_PROBE
RESTORE_GCODE_STATE NAME=STATE_PROBE_CALIBRATE_DETACH MOVE=1 MOVE_SPEED={(speed.travel|float / 60)}
{% endif %}