-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsensorless_homing.cfg
299 lines (242 loc) · 13.1 KB
/
sensorless_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
# This configuration file contains variables and macros specific for homing using stallguard rather than
# physical switches. You will likely need to have DIAG jumpers installed on your mainboard and Klipper configured
# correctly for this to work.
#
# More information can be found here: https://www.klipper3d.org/TMC_Drivers.html?sensorless-homing
#
# Be sure to [include] this .cfg file in printer.cfg **BEFORE** you have working SGTHRS/SGT values for
# [tmcXXXX stepper_AXIS] as that will simplify this process. If you already have SGTHRS/SGT
# values in your config, they will likely need adjusting after enabling this configuration.
#
### Default motor current and homing speed are configured per axis in printer.cfg ###
#
##################################
## Sensorless Homing Variables:
[gcode_macro _Sensorless_Homing_Variables]
description: Variables for sensorless homing
variable_homing_current: 0.85 # The desired motor current for homing the X and Y axes. Leave as '0.0' to use run_current values instead.
variable_clear_time: 1 # Time in seconds to wait for StallGuard registers to clear, default is 1 second.
variable_x_backoff_distance: 11 # Distance in mm to back off from the X axis after homing.
variable_y_backoff_distance: 24 # Distance in mm to back off from the Y axis after homing.
variable_z_hop_distance: 10 # Distance to move the Z axis prior to homing (unless homing Z first).
variable_first_homed_axis: 'X' # First axis to home when 'G28' is called.
## The following variable is only used if first_homed_axis is 'Z':
variable_second_homed_axis: 'X' # If the Z axis is homed first, this is the next axis that will be homed when 'G28' is called.
## The following variables are used for moving the printhead to a certain part of the bed before homing the Z axis, unless Z is homed first.
variable_safe_z_enable:True # Enables/disables moving the printhead to a safe XY position before homing the Z axis.
variable_safe_x: 165 # Safe X position to home the Z axis, leave at -165 to home to the center of the X axis.
variable_safe_y: 165 # Safe Y position to home the Z axis, leave at -165 to home to the center of the Y axis.
# Do not modify below
gcode:
[gcode_macro _SET_HOMING_CURRENT]
description: This macro is used to change driver current when homing
gcode:
{% set kinematics = printer.configfile.config.printer.kinematics | string %}
{% set sensorless_variables = printer["gcode_macro _Sensorless_Homing_Variables"] %}
{% set homing_current = sensorless_variables.homing_current | float %}
{% if kinematics == 'corexy' %}
{% for stepper in printer.configfile.settings if (stepper.startswith('stepper_x') or stepper.startswith('stepper_y')) %}
SET_TMC_CURRENT STEPPER={stepper} CURRENT={homing_current}
{% endfor %}
{% else %}
{% for stepper in printer.configfile.settings if (stepper.startswith('stepper_x') or stepper.startswith('stepper_y') or stepper.startswith('stepper_z')) %}
SET_TMC_CURRENT STEPPER={stepper} CURRENT={homing_current}
{% endfor %}
{% endif %}
[gcode_macro _SET_RUN_CURRENT]
description: This macro is used to revert driver current back to normal
gcode:
{% set kinematics = printer.configfile.config.printer.kinematics | string %}
{% if kinematics == 'corexy' %}
{% for stepper in printer.configfile.settings if (stepper.startswith('stepper_x') or stepper.startswith('stepper_y')) %}
{% for driver in printer.configfile.settings if (driver.startswith('tmc') and driver.endswith(stepper)) %}
{% set default_current = printer.configfile.settings[driver].run_current %}
SET_TMC_CURRENT STEPPER={stepper} CURRENT={default_current}
{% endfor %}
{% endfor %}
{% else %}
{% for stepper in printer.configfile.settings if (stepper.startswith('stepper_x') or stepper.startswith('stepper_y') or stepper.startswith('stepper_z')) %}
{% for driver in printer.configfile.settings if (driver.startswith('tmc') and driver.endswith(stepper)) %}
{% set default_current = printer.configfile.settings[driver].run_current %}
SET_TMC_CURRENT STEPPER={stepper} CURRENT={default_current}
{% endfor %}
{% endfor %}
{% endif %}
[gcode_macro _HOME_X]
gcode:
{% set sensorless_variables = printer["gcode_macro _Sensorless_Homing_Variables"] %}
{% set homing_current = sensorless_variables.homing_current | float %}
{% set backoff_distance = sensorless_variables.x_backoff_distance | float %}
{% set clear_time = (sensorless_variables.clear_time * 1000) | float %}
{% set probe_x_offset = printer.configfile.config.scanner.x_offset | float %} # Taking probe X offset from cartographer.cfg
{% set positive_dir = printer.configfile.settings.stepper_x.homing_positive_dir | abs %}
{% set homing_speed = (printer.configfile.settings['stepper_x'].homing_speed * 60) | float %}
{% if homing_current != 0.0 %}
_SET_HOMING_CURRENT
{% endif %}
G4 P{clear_time}
G28 X
{% if backoff_distance > 0 %}
{% if positive_dir == True %}
G91
G0 X-{backoff_distance} F{homing_speed}
G90
{% else %}
G91
G0 X{backoff_distance} F{homing_speed}
G90
{% endif %}
{% endif %}
{% if positive_dir == True %}
G0 X{printer.configfile.settings.stepper_x.position_endstop - backoff_distance}
{% else %}
G0 X{printer.configfile.settings.stepper_x.position_endstop + backoff_distance}
{% endif %}
{% if homing_current != 0.0 %}
_SET_RUN_CURRENT
{% endif %}
G4 P{clear_time}
[gcode_macro _HOME_Y]
gcode:
{% set sensorless_variables = printer["gcode_macro _Sensorless_Homing_Variables"] %}
{% set homing_current = sensorless_variables.homing_current | float %}
{% set backoff_distance = sensorless_variables.y_backoff_distance | float %}
{% set clear_time = (sensorless_variables.clear_time * 1000) | float %}
{% set probe_y_offset = printer.configfile.config.scanner.y_offset | float %} # Taking probe Y offset from cartographer.cfg
{% set positive_dir = printer.configfile.settings.stepper_y.homing_positive_dir | abs %}
{% set homing_speed = (printer.configfile.settings['stepper_y'].homing_speed * 60) | float %}
{% if homing_current != 0.0 %}
_SET_HOMING_CURRENT
{% endif %}
G4 P{clear_time}
G28 Y
{% if backoff_distance > 0 %}
{% if positive_dir == True %}
G91
G0 Y-{backoff_distance} F{homing_speed}
G90
{% else %}
G91
G0 Y{backoff_distance} F{homing_speed}
G90
{% endif %}
{% endif %}
{% if positive_dir == True %}
G0 Y{printer.configfile.settings.stepper_y.position_endstop - backoff_distance}
{% else %}
G0 Y{printer.configfile.settings.stepper_y.position_endstop + backoff_distance}
{% endif %}
{% if homing_current != 0.0 %}
_SET_RUN_CURRENT
{% endif %}
G4 P{clear_time}
[gcode_macro _HOME_Z]
gcode:
{% set sensorless_variables = printer["gcode_macro _Sensorless_Homing_Variables"] %}
{% set first_homed_axis = sensorless_variables.first_homed_axis | string %}
{% set positive_dir = printer.configfile.settings.stepper_z.homing_positive_dir | abs %}
{% set z_retract_distance = printer.configfile.settings.stepper_z.homing_retract_dist | float %}
{% set homing_speed = (printer.configfile.settings['stepper_z'].homing_speed * 60) | float %}
G28 Z
{% if positive_dir == True %}
G91
G0 Z{-z_retract_distance} F{homing_speed}
G90
{% else %}
G91
G0 Z{z_retract_distance} F{homing_speed}
G90
{% endif %}
[homing_override]
axes: xyz
set_position_z: 0
gcode:
{% set home_all = 'X' not in params and 'Y' not in params and 'Z' not in params %}
{% set z_hop_speed = (printer.configfile.settings['stepper_z'].homing_speed * 30) | float %}
{% set travel_speed = (printer.toolhead.max_velocity * 30) | float %}
{% set sensorless_variables = printer["gcode_macro _Sensorless_Homing_Variables"] %}
{% set z_hop_distance = sensorless_variables.z_hop_distance | float %}
{% set first_homed_axis = sensorless_variables.first_homed_axis | string %}
{% set second_homed_axis = sensorless_variables.second_homed_axis | string %}
{% set probe_y_offset = printer.configfile.config.scanner.y_offset | float %}
{% set probe_x_offset = printer.configfile.config.scanner.x_offset | float %}
{% set safe_x = sensorless_variables.safe_x | float %}
{% set safe_y = sensorless_variables.safe_y | float %}
{% set safe_z = sensorless_variables.safe_z_enable | abs %}
{% if safe_x == -165 %}
{% set safe_x = (printer.configfile.settings.stepper_x.position_max) /2 %}
{% endif %}
{% if safe_y == -165 %}
{% set safe_y = (printer.configfile.settings.stepper_y.position_max) /2 %}
{% endif %}
{% if z_hop_distance > 0 %}
{% if 'x' not in printer.toolhead.homed_axes and 'y' not in printer.toolhead.homed_axes %}
{% if first_homed_axis != 'Z' %}
G0 Z{z_hop_distance} F{z_hop_speed}
{% endif %}
{% endif %}
{% endif %}
{% if z_hop_distance > 0 %}
{% if 'x' not in printer.toolhead.homed_axes and 'y' not in printer.toolhead.homed_axes %}
{% if first_homed_axis != 'Z' %}
G0 Z{z_hop_distance} F{z_hop_speed}
{% endif %}
{% endif %}
{% endif %}
{% if first_homed_axis == 'X' %}
{% if home_all or 'X' in params %}
_HOME_X
{% endif %}
{% if home_all or 'Y' in params %}
_HOME_Y
{% endif %}
{% endif %}
{% if first_homed_axis == 'Y' %}
{% if home_all or 'Y' in params %}
_HOME_Y
{% endif %}
{% if home_all or 'X' in params %}
_HOME_X
{% endif %}
{% endif %}
{% if first_homed_axis == 'Z' %}
{% if home_all or 'Z' in params %}
_HOME_Z
{% endif %}
{% if second_homed_axis == 'X' %}
{% if home_all or 'X' in params %}
_HOME_X
{% endif %}
{% if home_all or 'Y' in params %}
_HOME_Y
{% endif %}
{% endif %}
{% if second_homed_axis == 'Y' %}
{% if home_all or 'Y' in params %}
_HOME_Y
{% endif %}
{% if home_all or 'X' in params %}
_HOME_X
{% endif %}
{% endif %}
{% endif %}
{% if safe_z == True and (home_all or 'Z' in params) and first_homed_axis != 'Z' %} # If safe_z is true and home_all or 'Z' is in params,
G0 X{safe_x} Y{safe_y} F{travel_speed} # Move to the defined safe XY location
{% endif %} #
{% if home_all or 'Z' in params %} #
{% if first_homed_axis != 'Z'%}
_HOME_Z
{% endif %}
{% endif %}
##{% if home_all or 'X' in params %}
##_HOME_X
##{% endif %}
##{% if home_all or 'Y' in params %}
##_HOME_Y
##{% endif %}
#{% if home_all or 'Z' in params %}
##_HOME_Z
##{% endif %}
##{% if safe_z == True and (home_all or 'Z' in params) and first_homed_axis != 'Z' %}
##G0 X{safe_x} Y{safe_y} F{travel_speed}
##{% endif %}