forked from zellneralex/klipper_config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
magprobe.cfg
286 lines (271 loc) · 13.5 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
#####################################################################
# 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
gcode:
{% if not params.STATE or params.STATE|lower is not in ['unknown','attached','docked'] %}
{action_raise_error("Invalid probe state: %s. Valid probe states are [UNKNOWN, ATTACHED, DOCKED]" % params.STATE|default('none')|upper)}
{% endif %}
SET_GCODE_VARIABLE MACRO=_PROBE_ACTION VARIABLE=man_state VALUE='"{params.STATE|lower}"'
SET_GCODE_VARIABLE MACRO=_MAG_PROBE VARIABLE=state VALUE='"{params.STATE|lower}"'
#####################################################################
# 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:
{% set id = 1 if id == 0 else id + 1 %} ; generate an id not equal to 0
QUERY_PROBE ID={id}
_PROBE_ACTION ACTION={params.ACTION} ID={id} {"RESPOND=" + params.RESPOND if params.RESPOND is defined else ""}
SET_GCODE_VARIABLE MACRO=_MAG_PROBE VARIABLE=id VALUE={id}
[gcode_macro _PROBE_ACTION]
description: Helper: Perform MagProbe action
variable_man_state: 'unknown'
gcode:
{% set action = params.ACTION|default('undefined')|lower %}
{% set id = params.ID|default(0)|int %}
{% set probe_id = printer['gcode_macro QUERY_PROBE'].id|default(0)|int %}
{% set probe = 'attached' if printer.probe.last_query|int == 0
else 'docked' if printer.probe.last_query|int == 1 %}
{% set error_id = 1 if printer.probe.last_query|lower == 'false'
else 2 if id == 0 or id != probe_id
else 3 if action is not in ['attach','dock','check_attach','check_dock','get_status']
else 4 if action == 'check_dock' and probe != 'docked'
else 5 if action == 'check_attach' and probe != 'attached'
else 0 %}
{% set state = 'error' if error_id != 0
else man_state if man_state != 'unknown'
else probe %}
{% if params.RESPOND|default(printer['gcode_macro _USER_VARIABLE'].respond.probe_action)|int == 1 %}
{% set txt = [] %}
{% if man_state != 'unknown' %}{% set _dummy = txt.append("State was set to %s by SET_PROBE_STATUS" % man_state)%}{% endif %}
{% if action == 'attach' and state == 'docked' %}{% set _dummy = txt.append("Attach Probe")%}{% endif %}
{% if action == 'attach' and state == 'attached' %}{% set _dummy = txt.append("Already attached")%}{% endif %}
{% if action == 'dock' and state == 'attached' %}{% set _dummy = txt.append("Dock Probe")%}{% endif %}
{% if action == 'dock' and state == 'docked' %}{% set _dummy = txt.append("Already docked")%}{% endif %}
{% if action == 'get_status' %}{% set _dummy = txt.append("Status: %s" % state)%}{% endif %}
{% if txt|length > 0 %} {action_respond_info("MagProbe: %s" % txt|join("\n"))} {% endif %}
{% endif %}
{% if action == 'attach' and state == 'docked' %} _ATTACH_PROBE {% endif %}
{% if action == 'dock' and state == 'attached' %} _DOCK_PROBE {% endif %}
SET_GCODE_VARIABLE MACRO=_PROBE_ACTION VARIABLE=man_state VALUE='"unknown"'
SET_GCODE_VARIABLE MACRO=_MAG_PROBE VARIABLE=state VALUE='"{state}"'
SET_GCODE_VARIABLE MACRO=_CHECK_STATE VARIABLE=error_id VALUE={error_id}
_CHECK_STATE
[gcode_macro _CHECK_STATE]
description: Helper: Perform MagProbe error check
variable_error_id: 0
gcode:
{% set txt = "Please execute QUERY_PROBE first" if error_id == 1
else "Call ID invalid or does not match QUERY_PROBE call ID" if error_id == 2
else "action not defined" if error_id == 3
else "docking failed" if error_id == 4
else "attaching failed" if error_id == 5 %}
{% if error_id != 0 %} {action_raise_error("MagProbe: ERROR, %s" % 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:
{% set user = printer['gcode_macro _USER_VARIABLE'] %}
{% set move_z = [user.z_hop, printer.toolhead.position.z]|max %} ; calc movement high
G90 ; absolute positioning
G0 Z{move_z} F{user.speed.z_hop} ; move head up
G0 X{user.probe.store.x} Y{user.probe.store.y} F{user.speed.travel} ; step 1
G0 X{user.probe.dock.x} F{user.speed.dock} ; step 2
G0 Y{user.probe.dock.y} F{user.speed.dock} ; step 3
{% if not printer.gcode_move.absolute_coordinates %} G91 {% endif %} ; set back to relative
[gcode_macro _DOCK_PROBE]
description: Helper: Dock MagProbe
gcode:
{% set user = printer['gcode_macro _USER_VARIABLE'] %}
{% set move_z = [user.z_hop, printer.toolhead.position.z]|max %} ; calc movement high
G90 ; absolute positioning
G0 Z{move_z} F{user.speed.z_hop} ; move head up
G0 X{user.probe.dock.x} Y{user.probe.dock.y} F{user.speed.travel} ; step 1
G0 Y{user.probe.store.y} F{user.speed.dock} ; step 2
G0 X{user.probe.store.x} F{user.speed.dock} ; step 3
{% if not printer.gcode_move.absolute_coordinates %} G91 {% endif %} ; set back to relative
#####################################################################
# 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:
{% if params.FORCE is defined or printer['gcode_macro _MAG_PROBE'].state == 'docked' %}
G0.1 {rawparams}
{% else %}
{% set param = [] %}
{% for key in params %} ; get gcode input parameters
{% set _dummy = param.append(key + "=" + params[key]) if key is not in ['G', 'FORCE'] %}
{% endfor %}
_Z_MOVE_CHECK CALLER=G0 {param|join(" ")}
{% endif %}
[gcode_macro G1]
description: Move gcode that prevents moves lower than the limit when probe attached
rename_existing: G1.1
gcode:
{% if params.FORCE is defined or printer['gcode_macro _MAG_PROBE'].state == 'docked' %}
G1.1 {rawparams}
{% else %}
{% set param = [] %}
{% for key in params %} ; get gcode input parameters
{% set _dummy = param.append(key + "=" + params[key]) if key is not in ['G', 'FORCE'] %}
{% endfor %}
_Z_MOVE_CHECK CALLER=G1 {param|join(" ")}
{% endif %}
[gcode_macro _Z_MOVE_CHECK]
description: Helper: Check limit and perform move
gcode:
{% set param = [] %}
{% for key in params %} ; generate base macro call
{% if key == 'Z' %}
{% set z_target = params.Z|float if printer.gcode_move.absolute_coordinates
else params.Z|float + printer.gcode_move.gcode_position.z %}
{% set z_move_ok = True if z_target >= printer['gcode_macro _USER_VARIABLE'].z_hop or
z_target >= printer.gcode_move.gcode_position.z
else False %}
{% if z_move_ok %}
{% set _dummy = param.append(key + params[key]) %}
{% else %}
{action_respond_info("%s: Z Move (%.3f mm -> %.3f mm) not allowed" %
(params.CALLER, printer.gcode_move.gcode_position.z, z_target))}
{% endif %}
{% elif key != 'CALLER' %}
{% set _dummy = param.append(key + params[key]) %}
{% endif %}
{% endfor %}
{params.CALLER}.1 {param|join(" ")} ; call G0 or G1 base macro with all parameters
[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 means invalid
[gcode_macro PROBE_ACCURACY]
description: Probe Z-height accuracy at current XY position and dock/undock MagProbe
rename_existing: PROBE_ACCURACY_BASE
gcode:
{% set user = printer['gcode_macro _USER_VARIABLE'] %}
# as we need to return to the position with the probe we need to be at least at z_hop
{% if user.hw.mag_probe.ena and printer.gcode_move.gcode_position.z < user.z_hop %}
{action_respond_info("PROBE_ACCURACY: High must be above %.2f" % user.z_hop)}
G90 ; absolute positioning
G0 Z{user.z_hop} F{user.speed.z_hop} ; move head up
{% if not printer.gcode_move.absolute_coordinates %} G91 {% endif %} ; set back to relative
{% endif %}
{% if user.hw.mag_probe.ena == 'true' %}
SAVE_GCODE_STATE NAME=STATE_PROBE_ACCURACY
ATTACH_PROBE
RESTORE_GCODE_STATE NAME=STATE_PROBE_ACCURACY MOVE=1 MOVE_SPEED={(user.speed.travel|float / 60)}
{% endif %}
PROBE_ACCURACY_BASE {rawparams}
{% if user.hw.mag_probe.ena == 'true' and params.DOCK|default(1)|int == 1 %} ; use DOCK=0 to omit the probe docking
DETACH_PROBE
RESTORE_GCODE_STATE NAME=STATE_PROBE_ACCURACY MOVE=1 MOVE_SPEED={(user.speed.travel|float / 60)}
{% endif %}
[gcode_macro PROBE]
description: Probe Z-height at current XY position and dock/undock MagProbe
rename_existing: PROBE_BASE
gcode:
{% set user = printer['gcode_macro _USER_VARIABLE'] %}
# as we need to return to the position with the probe we need to be at least at z_hop
{% if user.hw.mag_probe.ena == 'true' and printer.gcode_move.gcode_position.z < user.z_hop %}
{action_respond_info("PROBE_ACCURACY: High must be above %.2f" % user.z_hop)}
G90 ; absolute positioning
G0 Z{user.z_hop} F{user.speed.z_hop} ; move head up
{% if not printer.gcode_move.absolute_coordinates %} G91 {% endif %} ; set back to relative
{% endif %}
{% if user.hw.mag_probe.ena == 'true' %}
SAVE_GCODE_STATE NAME=STATE_PROBE
ATTACH_PROBE
RESTORE_GCODE_STATE NAME=STATE_PROBE MOVE=1 MOVE_SPEED={(user.speed.travel|float / 60)}
{% endif %}
PROBE_BASE {rawparams}
G1 Z{user.z_hop} F{user.speed.z_hop} ; move head up to remove trigger
{% if user.hw.mag_probe.ena == 'true' and params.DOCK|default(1)|int == 1 %} ; use DOCK=0 to omit the probe docking
DETACH_PROBE
RESTORE_GCODE_STATE NAME=STATE_PROBE MOVE=1 MOVE_SPEED={(user.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:
{% set user = printer['gcode_macro _USER_VARIABLE'] %}
# as we need to return to the position with the probe we need to be at least at z_hop
{% if user.hw.mag_probe.ena == 'true' and printer.gcode_move.gcode_position.z < user.z_hop %}
{action_respond_info("PROBE_ACCURACY: High must be above %.2f" % user.z_hop)}
G90 ; absolute positioning
G0 Z{user.z_hop} F{user.speed.z_hop} ; move head up
{% if not printer.gcode_move.absolute_coordinates %} G91 {% endif %} ; set back to relative
{% endif %}
{% if user.hw.mag_probe.ena == 'true' %}
SAVE_GCODE_STATE NAME=STATE_PROBE_CALIBRATE_ATTACH
ATTACH_PROBE
RESTORE_GCODE_STATE NAME=STATE_PROBE_CALIBRATE_ATTACH MOVE=1 MOVE_SPEED={(user.speed.travel|float / 60)}
{% endif %}
PROBE_CALIBRATE_BASE {rawparams}
{% if user.hw.mag_probe.ena == 'true' %}
SAVE_GCODE_STATE NAME=STATE_PROBE_CALIBRATE_DETACH
DETACH_PROBE
RESTORE_GCODE_STATE NAME=STATE_PROBE_CALIBRATE_DETACH MOVE=1 MOVE_SPEED={(user.speed.travel|float / 60)}
{% endif %}