-
-
Notifications
You must be signed in to change notification settings - Fork 138
/
homing.cfg
418 lines (367 loc) · 16.3 KB
/
homing.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
# 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 RatOS]
variable_homing: "endstops" # endstops|sensorless = axis homing method
variable_z_probe: "static" # static|stowable = z-probe type
variable_sensorless_x_current: 0.6 # float = stepper driver run current for sensorless x-homing
variable_sensorless_y_current: 0.9 # float = stepper driver run current for sensorless y-homing
variable_safe_home_x: "middle" # float|middle = z-homing x location
variable_safe_home_y: "middle" # float|middle = z-homing y location
variable_driver_type_x: "tmc2209" # tmc2209|tmc2130|tmc5160 = stepper driver type for sensorless homing
variable_driver_type_y: "tmc2209" # tmc2209|tmc2130|tmc5160 = stepper driver type for sensorless homing
variable_stowable_probe_stop_on_error: False # internal use only. Do not touch!
[ratos_homing]
axes: xyz
z_hop: 15 # homing z-hop distance
z_hop_speed: 15 # homing z-hop speed
gcode:
# visual feedback
_LED_ON
# config
{% set prev_stop_on_error = printer["gcode_macro RatOS"].stowable_probe_stop_on_error %}
# reset IDEX mode
{% if printer["dual_carriage"] is defined %}
{% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %}
{% set target_idex_mode = printer["dual_carriage"].carriage_1|lower %}
_IDEX_SINGLE
_SELECT_TOOL T={default_toolhead} TOOLSHIFT=false
{% endif %}
# Make stowable probe assertion failures cause an emergency stop
SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=stowable_probe_stop_on_error VALUE=True
# Wait for moves to finish
M400
# Absolute positioning
G90
# home printer
{% set X = true if params.X is defined else false %}
{% set Y = true if params.Y is defined else false %}
{% set Z = true if params.Z is defined else false %}
{% if printer["gcode_macro RatOS"].home_y_first|default(false)|lower == 'true' %}
HOME_Y X={X} Y={Y} Z={Z}
HOME_X X={X} Y={Y} Z={Z}
{% else %}
HOME_X X={X} Y={Y} Z={Z}
HOME_Y X={X} Y={Y} Z={Z}
{% endif %}
HOME_Z X={X} Y={Y} Z={Z}
# Reset stowable probe stop on error state
SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=stowable_probe_stop_on_error VALUE={prev_stop_on_error}
# restore IDEX mode
{% if printer["dual_carriage"] is defined %}
{% if target_idex_mode == "copy" %}
_IDEX_COPY
{% elif target_idex_mode == "mirror" %}
_IDEX_MIRROR
{% endif %}
{% endif %}
[gcode_macro HOME_X]
gcode:
# config
{% set x_homed = 'x' in printer.toolhead.homed_axes %}
{% set homing = printer["gcode_macro RatOS"].homing|lower %}
{% set homing_x = printer["gcode_macro RatOS"].homing_x|lower %}
{% set homing_x = homing_x if homing_x else homing %}
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
{% set printable_x_max = printer["gcode_macro RatOS"].printable_x_max|float %}
{% set safe_home_x = printer["gcode_macro RatOS"].safe_home_x %}
{% if safe_home_x is not defined or safe_home_x|lower == 'middle' %}
{% set safe_home_x = printable_x_max / 2 %}
{% endif %}
# parameter
{% set X = true if params.X|lower == 'true' else false %}
{% set Y = true if params.Y|lower == 'true' else false %}
{% set Z = true if params.Z|lower == 'true' else false %}
DEBUG_ECHO PREFIX="HOME_X" MSG="printable_x_max: {printable_x_max}, safe_home_x: {safe_home_x}, axis_maximum.x: {printer.toolhead.axis_maximum.x}, bed_margin_x: {printer['gcode_macro RatOS'].bed_margin_x}"
# home x
{% if X or not Y and not Z %}
{% if homing_x == 'endstop' %}
G28 X
{% elif homing_x == 'sensorless' %}
{% if printer["dual_carriage"] is defined %}
{ action_emergency_stop("sensorless homing not supported on IDEX!") }
{% endif %}
HOME_X_SENSORLESS
{% else %}
{ action_emergency_stop("expected RatOS variable_homing_x to be 'sensorless' 'endstop' or variable_homing to be 'sensorless' or 'endstops' but found {} and {}".format(homing_x, homing)) }
{% endif %}
{% if printer["dual_carriage"] is defined %}
# park secondary toolhead in its parking position instead of the endstop position
{% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %}
{% set parking_position = printer["gcode_macro T%s" % (0 if default_toolhead==1 else 1)].parking_position|float %}
SET_DUAL_CARRIAGE CARRIAGE={0 if default_toolhead==1 else 1} MODE=PRIMARY
G1 X{parking_position} F{speed}
SET_DUAL_CARRIAGE CARRIAGE={default_toolhead} MODE=PRIMARY
{% endif %}
{% set x_homed = True %}
G0 X{safe_home_x} F{speed}
M400 # Wait for moves to finish
{% endif %}
[gcode_macro HOME_Y]
gcode:
# config
{% set y_homed = 'y' in printer.toolhead.homed_axes %}
{% set homing = printer["gcode_macro RatOS"].homing|lower %}
{% set homing_y = printer["gcode_macro RatOS"].homing_y|lower %}
{% set homing_y = homing_y if homing_y else homing %}
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
{% set printable_y_max = printer["gcode_macro RatOS"].printable_y_max|float %}
{% set safe_home_y = printer["gcode_macro RatOS"].safe_home_y %}
{% if safe_home_y is not defined or safe_home_y|lower == 'middle' %}
{% set safe_home_y = printable_y_max / 2 %}
{% endif %}
# parameter
{% set X = true if params.X|lower == 'true' else false %}
{% set Y = true if params.Y|lower == 'true' else false %}
{% set Z = true if params.Z|lower == 'true' else false %}
DEBUG_ECHO PREFIX="HOME_Y" MSG="printable_y_max: {printable_y_max}, safe_home_y: {safe_home_y}, axis_maximum.y: {printer.toolhead.axis_maximum.y}, bed_margin_y: {printer['gcode_macro RatOS'].bed_margin_y}"
# home y
{% if Y or not X and not Z %}
{% if homing_y == 'endstop' %}
G28 Y
{% elif homing_y == 'sensorless' %}
HOME_Y_SENSORLESS
{% else %}
{ action_emergency_stop("expected RatOS variable_homing_y to be 'sensorless' 'endstop' or variable_homing to be 'sensorless' or 'endstops' but found {} and {}".format(homing_y, homing)) }
{% endif %}
{% set y_homed = True %}
G0 Y{safe_home_y} F{speed}
{% endif %}
[gcode_macro HOME_Z]
gcode:
# config
{% set x_homed = 'x' in printer.toolhead.homed_axes %}
{% set y_homed = 'y' in printer.toolhead.homed_axes %}
{% set z_probe = printer["gcode_macro RatOS"].z_probe %}
# beacon contact config
{% set beacon_contact_z_homing = true if printer["gcode_macro RatOS"].beacon_contact_z_homing|default(false)|lower == 'true' else false %}
# parameter
{% set X = true if params.X|lower == 'true' else false %}
{% set Y = true if params.Y|lower == 'true' else false %}
{% set Z = true if params.Z|lower == 'true' else false %}
DEBUG_ECHO PREFIX="HOME_Z" MSG="x_homed: {x_homed}, y_homed: {y_homed}, z_probe: {z_probe}, beacon_contact_z_homing: {beacon_contact_z_homing}"
# home z
{% if Z or not Y and not X %}
RATOS_ECHO MSG="Homing Z"
{% if x_homed == False or y_homed == False %}
{ action_emergency_stop("X and Y must be homed before homing Z") }
{% else %}
{% if z_probe == "stowable" %}
DEPLOY_PROBE
_MOVE_TO_SAFE_Z_HOME
{% if printer.configfile.settings.beacon is defined and beacon_contact_z_homing %}
BEACON_AUTO_CALIBRATE SKIP_MODEL_CREATION=1
_MOVE_TO_SAFE_Z_HOME Z_HOP=True
{% else %}
G28 Z
{% endif %}
_Z_HOP
STOW_PROBE
{% else %}
_MOVE_TO_SAFE_Z_HOME
{% if printer.configfile.settings.beacon is defined and beacon_contact_z_homing %}
BEACON_AUTO_CALIBRATE SKIP_MODEL_CREATION=1
_MOVE_TO_SAFE_Z_HOME Z_HOP=True
{% else %}
G28 Z
{% endif %}
_Z_HOP
{% endif %}
{% endif %}
{% endif %}
[gcode_macro HOME_X_SENSORLESS]
gcode:
# Handle toolhead settings
CACHE_TOOLHEAD_SETTINGS KEY="home_x_sensorless"
# config
{% set printable_x_max = printer["gcode_macro RatOS"].printable_x_max|float %}
# Set homing acceleration (important!)
M204 S1000
# set tmc stepper current
{% if printer["gcode_macro RatOS"].x_axes is defined %}
{% for axis in printer["gcode_macro RatOS"].x_axes %}
{% set stepper = "stepper_" ~ axis|lower %}
SET_TMC_CURRENT STEPPER={stepper} CURRENT={printer["gcode_macro RatOS"].sensorless_x_current}
{% endfor %}
{% else %}
{% set x_driver = printer["gcode_macro RatOS"].driver_type_x|lower ~ " stepper_x" %}
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={printer["gcode_macro RatOS"].sensorless_x_current}
{% endif %}
{% if printer["gcode_macro RatOS"].y_axes is defined %}
{% for axis in printer["gcode_macro RatOS"].y_axes %}
{% set stepper = "stepper_" ~ axis|lower %}
SET_TMC_CURRENT STEPPER={stepper} CURRENT={printer["gcode_macro RatOS"].sensorless_x_current}
{% endfor %}
{% else %}
{% set y_driver = printer["gcode_macro RatOS"].driver_type_y|lower ~ " stepper_y" %}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={printer["gcode_macro RatOS"].sensorless_x_current}
{% endif %}
# Wait for currents to settle
G4 P300
# Home X
G28 X
# restore tmc stepper current
{% if printer["gcode_macro RatOS"].x_axes is defined %}
{% for axis in printer["gcode_macro RatOS"].x_axes %}
{% set stepper = "stepper_" ~ axis|lower %}
{% set stepper_driver = printer["gcode_macro RatOS"].x_driver_types[loop.index0] ~ " " ~ stepper %}
SET_TMC_CURRENT STEPPER={stepper} CURRENT={printer.configfile.config[stepper_driver].run_current}
{% endfor %}
{% else %}
{% set x_driver = printer["gcode_macro RatOS"].driver_type_x|lower ~ " stepper_x" %}
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={printer.configfile.config[x_driver].run_current}
{% endif %}
{% if printer["gcode_macro RatOS"].y_axes is defined %}
{% for axis in printer["gcode_macro RatOS"].y_axes %}
{% set stepper = "stepper_" ~ axis|lower %}
{% set stepper_driver = printer["gcode_macro RatOS"].y_driver_types[loop.index0] ~ " " ~ stepper %}
SET_TMC_CURRENT STEPPER={stepper} CURRENT={printer.configfile.config[stepper_driver].run_current}
{% endfor %}
{% else %}
{% set y_driver = printer["gcode_macro RatOS"].driver_type_y|lower ~ " stepper_y" %}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={printer.configfile.config[y_driver].run_current}
{% endif %}
# Wait for currents to settle
G4 P300
# Handle toolhead settings
RESTORE_TOOLHEAD_SETTINGS KEY="home_x_sensorless"
[gcode_macro HOME_Y_SENSORLESS]
gcode:
# Handle toolhead settings
CACHE_TOOLHEAD_SETTINGS KEY="home_y_sensorless"
# config
{% set printable_y_max = printer["gcode_macro RatOS"].printable_y_max|float %}
# Set homing acceleration (important!)
M204 S1000
# set tmc stepper current
{% if printer["gcode_macro RatOS"].x_axes is defined %}
{% for axis in printer["gcode_macro RatOS"].x_axes %}
{% set stepper = "stepper_" ~ axis|lower %}
SET_TMC_CURRENT STEPPER={stepper} CURRENT={printer["gcode_macro RatOS"].sensorless_y_current}
{% endfor %}
{% else %}
{% set x_driver = printer["gcode_macro RatOS"].driver_type_x|lower ~ " stepper_x" %}
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={printer["gcode_macro RatOS"].sensorless_y_current}
{% endif %}
{% if printer["gcode_macro RatOS"].y_axes is defined %}
{% for axis in printer["gcode_macro RatOS"].y_axes %}
{% set stepper = "stepper_" ~ axis|lower %}
SET_TMC_CURRENT STEPPER={stepper} CURRENT={printer["gcode_macro RatOS"].sensorless_y_current}
{% endfor %}
{% else %}
{% set y_driver = printer["gcode_macro RatOS"].driver_type_y|lower ~ " stepper_y" %}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={printer["gcode_macro RatOS"].sensorless_y_current}
{% endif %}
# Wait for currents to settle
G4 P300
# Home Y
G28 Y
# restore tmc stepper current
{% if printer["gcode_macro RatOS"].x_axes is defined %}
{% for axis in printer["gcode_macro RatOS"].x_axes %}
{% set stepper = "stepper_" ~ axis|lower %}
{% set stepper_driver = printer["gcode_macro RatOS"].x_driver_types[loop.index0] ~ " " ~ stepper %}
SET_TMC_CURRENT STEPPER={stepper} CURRENT={printer.configfile.config[stepper_driver].run_current}
{% endfor %}
{% else %}
{% set x_driver = printer["gcode_macro RatOS"].driver_type_x|lower ~ " stepper_x" %}
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={printer.configfile.config[x_driver].run_current}
{% endif %}
{% if printer["gcode_macro RatOS"].y_axes is defined %}
{% for axis in printer["gcode_macro RatOS"].y_axes %}
{% set stepper = "stepper_" ~ axis|lower %}
{% set stepper_driver = printer["gcode_macro RatOS"].y_driver_types[loop.index0] ~ " " ~ stepper %}
SET_TMC_CURRENT STEPPER={stepper} CURRENT={printer.configfile.config[stepper_driver].run_current}
{% endfor %}
{% else %}
{% set y_driver = printer["gcode_macro RatOS"].driver_type_y|lower ~ " stepper_y" %}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={printer.configfile.config[y_driver].run_current}
{% endif %}
# Wait for currents to settle
G4 P300
# Handle toolhead settings
RESTORE_TOOLHEAD_SETTINGS KEY="home_y_sensorless"
[gcode_macro _Z_HOP]
description: Move Z axis up by Z_HOP distance at Z_HOP_SPEED. In relative mode it will move Z axis up by Z_HOP distance. In absolute mode it will move Z axis to Z_HOP distance.
gcode:
{% set z_hop = printer.configfile.config.ratos_homing.z_hop|float %}
{% set z_hop_speed = printer.configfile.config.ratos_homing.z_hop_speed|float * 60 %}
G0 Z{z_hop} F{z_hop_speed}
[gcode_macro _MOVE_TO_SAFE_Z_HOME]
description: Move to safe home position with optional Z_HOP (pass Z_HOP=True as parameter)
gcode:
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
{% set printable_x_max = printer["gcode_macro RatOS"].printable_x_max|float %}
{% set printable_y_max = printer["gcode_macro RatOS"].printable_y_max|float %}
{% set safe_home_x = printer["gcode_macro RatOS"].safe_home_x %}
{% if safe_home_x is not defined or safe_home_x|lower == 'middle' %}
{% set safe_home_x = printable_x_max / 2 %}
{% endif %}
{% set safe_home_y = printer["gcode_macro RatOS"].safe_home_y %}
{% if safe_home_y is not defined or safe_home_y|lower == 'middle' %}
{% set safe_home_y = printable_y_max / 2 %}
{% endif %}
{% if params.Z_HOP is defined %}
_Z_HOP
{% endif %}
DEBUG_ECHO PREFIX="_MOVE_TO_SAFE_Z_HOME" MSG="axis_maximum.x: {printer.toolhead.axis_maximum.x}, axis_maximum.y: {printer.toolhead.axis_maximum.y}, bed_margin_x: {printer['gcode_macro RatOS'].bed_margin_x}, bed_margin_y: {printer['gcode_macro RatOS'].bed_margin_y}, safe_home_x: {safe_home_x}, safe_home_y: {safe_home_y}, printable_x_max: {printable_x_max}, printable_y_max: {printable_y_max}"
# Go to safe home
G0 X{safe_home_x} Y{safe_home_y} F{speed}
[gcode_macro MAYBE_HOME]
description: Only home unhomed axis
variable_is_kinematic_position_overriden: False
gcode:
{% if printer["gcode_macro MAYBE_HOME"].is_kinematic_position_overriden|lower == 'true' %}
RATOS_ECHO MSG="SET_CENTER_KINEMATIC_POSITION has been abused. Homing all axes. Please refrain from using SET_CENTER_KINEMATIC_POSITION outside of debugging purposes."
G28
SET_GCODE_VARIABLE MACRO=MAYBE_HOME VARIABLE=is_kinematic_position_overriden VALUE=False
{% else %}
{% set axes = '' %}
{% set isHomed = true %}
{% set axesToHome = '' %}
{% if params.X is defined %}
{% set axes = axes ~ 'X ' %}
{% if 'x' not in printer.toolhead.homed_axes %}
{% set isHomed = false %}
{% set axesToHome = axesToHome ~ 'X ' %}
{% endif %}
{% endif %}
{% if params.Y is defined %}
{% set axes = axes ~ 'Y ' %}
{% if 'y' not in printer.toolhead.homed_axes %}
{% set isHomed = false %}
{% set axesToHome = axesToHome ~ 'Y ' %}
{% endif %}
{% endif %}
{% if params.Z is defined %}
{% set axes = axes ~ 'Z ' %}
{% if 'z' not in printer.toolhead.homed_axes %}
{% set isHomed = false %}
{% set axesToHome = axesToHome ~ 'Z ' %}
{% endif %}
{% endif %}
{% if params.X is not defined and params.Y is not defined and params.Z is not defined %}
{% set axes = '' %}
{% if 'x' not in printer.toolhead.homed_axes %}
{% set isHomed = false %}
{% set axesToHome = axesToHome ~ 'X ' %}
{% endif %}
{% if 'y' not in printer.toolhead.homed_axes %}
{% set isHomed = false %}
{% set axesToHome = axesToHome ~ 'Y ' %}
{% endif %}
{% if 'z' not in printer.toolhead.homed_axes %}
{% set isHomed = false %}
{% set axesToHome = axesToHome ~ 'Z ' %}
{% endif %}
{% endif %}
{% if isHomed is false %}
RATOS_ECHO MSG="Homing {axesToHome}"
G28 {axesToHome}
{% else %}
RATOS_ECHO MSG="All requested axes already homed, skipping.."
{% endif %}
{% endif %}