forked from viesturz/klipper-toolchanger
-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
toolchanger-homing.cfg
208 lines (180 loc) · 7.75 KB
/
toolchanger-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
# Original written by Viesturs Zarins
# Modified by Justin F. Hallett
[homing_override]
axes: xyz
gcode:
{% if printer.toolchanger.homing_usetap and printer.probe.last_query %}
RESPOND TYPE=error MSG='Z Probe triggered, cannot home.'
{% else %}
{% if printer["gcode_macro _TOOLCHANGER_HOMING_START"] is defined %}
_TOOLCHANGER_HOMING_START
{% endif %}
SET_GCODE_OFFSET X=0.0 Y=0.0 Z=0.0
{% set max_y = printer.configfile.config["stepper_y"]["position_max"]|float %}
{% set max_x = printer.configfile.config["stepper_x"]["position_max"]|float %}
{% set home_all = 'X' not in params and 'Y' not in params and 'Z' not in params %}
G90 ; absolute mode
{% if 'z' not in printer.toolhead.homed_axes %}
SET_KINEMATIC_POSITION Z=0
G0 Z10 F1000
{% elif printer.toolhead.position[2]|float < 10 %}
G0 Z10 F1000
{% endif %}
{% if home_all or 'Y' in params or 'X' in params %}
{% if printer.toolchanger.sensorless_y %}
_SENSORLESS_HOME AXIS=Y
{% else %}
G28 Y
{% endif %}
G0 Y{ max_y - printer.toolchanger.homing_rebound_y } F6000
{% endif %}
{% if home_all or 'X' in params %}
{% if printer.toolchanger.sensorless_x %}
_SENSORLESS_HOME AXIS=X
{% else %}
G28 X
{% endif %}
G0 X{ max_x - 10} F6000
{% endif %}
{% if home_all or 'Z' in params %}
{% if printer["gcode_macro _TOOLCHANGER_ZSWITCH"] is defined %}
; Make sure we don't collide with the docks when homing Z
; can be done cold as it doesn't matter it's just to make sure we
; aren't too high up Z
{% if 'z' not in printer.toolhead.homed_axes and printer.probe.active_tool_probe %}
_MOVE_TO_CENTER
SET_KINEMATIC_POSITION Z={printer.configfile.config["stepper_z"]["position_max"]|float}
PROBE
SET_KINEMATIC_POSITION Z=0
G0 Z10 F1000
{% endif %}
G0 X{printer["gcode_macro _TOOLCHANGER_ZSWITCH"].x} Y{printer["gcode_macro _TOOLCHANGER_ZSWITCH"].y} F12000
G28 Z
{% endif %}
G0 Z10 F1000
INITIALIZE_TOOLCHANGER
STOP_TOOL_PROBE_CRASH_DETECTION
{% set tool = printer.toolchanger.tool_names[printer.tool_probe_endstop.active_tool_number] %}
{% if params.CLEAN is defined %}
{% if printer["gcode_macro _TOOLCHANGER_CLEAN_NOZZLE"] is defined %}
_TOOLCHANGER_CLEAN_NOZZLE
{% endif %}
{% endif %}
_MOVE_TO_CENTER
{% if printer.toolchanger.homing_usetap %}
{% if printer["gcode_macro _TOOLCHANGER_ZSWITCH"] is defined %}
PROBE
{% else %}
G28 Z
{% endif %}
{% endif %}
SET_GCODE_VARIABLE MACRO=_APPLY_Z_HOME_FOR_TOOL_OFFSET VARIABLE=applied VALUE=0
SET_GCODE_VARIABLE MACRO=_APPLY_Z_HOME_FOR_TOOL_OFFSET VARIABLE=probe_z_offset VALUE={printer.tool_probe_endstop.active_tool_probe_z_offset|default(0)|float}
{% if tool %}
SET_GCODE_VARIABLE MACRO=_APPLY_Z_HOME_FOR_TOOL_OFFSET VARIABLE=tool VALUE="'{tool}'"
SET_GCODE_VARIABLE MACRO=_APPLY_Z_HOME_FOR_TOOL_OFFSET VARIABLE=tool_z_offset VALUE={printer[tool].gcode_z_offset|default(0)|float}
{% endif %}
_APPLY_Z_HOME_FOR_TOOL_OFFSET
{% endif %}
_APPLY_ACTIVE_TOOL_GCODE_OFFSETS
_MOVE_TO_CENTER
M400
{% if printer["gcode_macro _TOOLCHANGER_HOMING_END"] is defined %}
_TOOLCHANGER_HOMING_END
{% endif %}
{% endif %}
[gcode_macro _SENSORLESS_HOME]
gcode:
{% set axis = params.AXIS|default('X')|string %}
# Always use consistent run_current on A/B steppers during sensorless homing
{% set RUN_CURRENT_X = printer.configfile.settings[printer.toolchanger.stepper_driver ~ ' stepper_x'].run_current|float %}
{% set RUN_CURRENT_Y = printer.configfile.settings[printer.toolchanger.stepper_driver ~ ' stepper_y'].run_current|float %}
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={printer.toolchanger.homing_current}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={printer.toolchanger.homing_current}
{% if printer.toolchanger.stepper_driver ~ 'stepper_x1' in printer.configfile.settings %}
{% set RUN_CURRENT_X1 = printer.configfile.settings[printer.toolchanger.stepper_driver ~ ' stepper_x1'].run_current|float %}
SET_TMC_CURRENT STEPPER=stepper_x1 CURRENT=0.1
{% endif %}
{% if printer.toolchanger.stepper_driver ~ 'stepper_y1' in printer.configfile.settings %}
{% set RUN_CURRENT_Y1 = printer.configfile.settings[printer.toolchanger.stepper_driver ~ ' stepper_y1'].run_current|float %}
SET_TMC_CURRENT STEPPER=stepper_y1 CURRENT=0.1
{% endif %}
# Home
G28 {axis|upper}
# Wait just a second… (give StallGuard registers time to clear)
G4 P1000
# Set current during print
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={RUN_CURRENT_X}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={RUN_CURRENT_Y}
{% if printer.toolchanger.stepper_driver ~ 'stepper_x1' in printer.configfile.settings %}
SET_TMC_CURRENT STEPPER=stepper_x1 CURRENT={RUN_CURRENT_X1}
{% endif %}
{% if printer.toolchanger.stepper_driver ~ 'stepper_y1' in printer.configfile.settings %}
SET_TMC_CURRENT STEPPER=stepper_y1 CURRENT={RUN_CURRENT_Y1}
{% endif %}
; Depending on the selected tool at the time of homing, the physical Z endstop position is offset.
; This corrects for that using current tool offset.
[gcode_macro _APPLY_Z_HOME_FOR_TOOL_OFFSET]
variable_default_raise: 10.0
variable_tool: ''
variable_tool_z_offset: 0
variable_probe_z_offset: 0
variable_probe_compensate: 1
variable_applied: 0
variable_debug_output: 0
gcode:
{% set raise = params.RAISE|default(default_raise)|float %}
{% if probe_compensate %}
{% set probe_compensation = probe_z_offset %}
{% endif %}
G90 ; absolute mode
G0 Z{raise} F1000
{% if tool in printer %}
{% if debug_output %}
RESPOND TYPE=echo MSG='Current Adjustment: {applied}'
RESPOND TYPE=echo MSG='Tool: {tool}'
RESPOND TYPE=echo MSG='Probe Offset: {probe_z_offset}'
RESPOND TYPE=echo MSG='Probe Compensation: {probe_compensation}'
RESPOND TYPE=echo MSG='Tool Offset: {tool_z_offset}'
{% endif %}
{% if params.MESH is defined %}
_REMOVE_Z_HOME_FOR_TOOL_OFFSET
{% set applied = probe_compensation %}
{% if debug_output %}
RESPOND TYPE=echo MSG='Bed Adjustment: {raise} = {raise + applied}'
{% endif %}
SET_KINEMATIC_POSITION Z={raise + applied}
{% else %}
_REMOVE_Z_HOME_FOR_TOOL_OFFSET
{% set applied = probe_compensation + tool_z_offset %}
{% if debug_output %}
RESPOND TYPE=echo MSG='Bed Adjustment: {raise} = {raise + applied}'
{% endif %}
SET_KINEMATIC_POSITION Z={raise + applied}
{% endif %}
{% endif %}
[gcode_macro _REMOVE_Z_HOME_FOR_TOOL_OFFSET]
gcode:
{% set raise = printer["gcode_macro _APPLY_Z_HOME_FOR_TOOL_OFFSET"].raise|default(10)|float %}
{% set applied = printer["gcode_macro _APPLY_Z_HOME_FOR_TOOL_OFFSET"].applied|default(0)|float %}
{% if applied != 0 %}
RESPOND TYPE=echo MSG='Bed Adjustment: {raise} = {raise - applied}'
SET_KINEMATIC_POSITION Z={raise - applied}
SET_GCODE_VARIABLE MACRO=_APPLY_Z_HOME_FOR_TOOL_OFFSET VARIABLE=applied VALUE=0
{% endif %}
[gcode_macro _APPLY_ACTIVE_TOOL_GCODE_OFFSETS]
gcode:
; Apply gcode offsets
{% set tool = printer.toolchanger.tool %}
{% if tool %}
{% set tool_x_offset = printer[tool].gcode_x_offset|default(0)|float %}
{% set tool_y_offset = printer[tool].gcode_y_offset|default(0)|float %}
{% set tool_z_offset = printer[tool].gcode_z_offset|default(0)|float %}
SET_GCODE_OFFSET X={tool_x_offset} Y={tool_y_offset} Z={tool_z_offset}
{% endif %}
[gcode_macro BED_MESH_CALIBRATE]
rename_existing: TOOL_BED_MESH_CALIBRATE
gcode:
_APPLY_Z_HOME_FOR_TOOL_OFFSET MESH=1
TOOL_BED_MESH_CALIBRATE {rawparams}
_APPLY_Z_HOME_FOR_TOOL_OFFSET