forked from viesturz/klipper-toolchanger
-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
toolchanger-macros.cfg
359 lines (307 loc) · 13.2 KB
/
toolchanger-macros.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
# Original written by Viesturs Zarins
# Modified by Justin F. Hallett
[gcode_macro _TOOLCHANGER_VARS]
variable_fan_speed: 0
gcode:
[gcode_macro _TOOLCHANGER_DISABLE_EXTRUDER_STEPPERS]
description: Disable all extruder steppers
gcode:
{% for toolname in printer.toolchanger.tool_names %}
SET_STEPPER_ENABLE STEPPER={printer[toolname].extruder} ENABLE=0
{% endfor %}
[gcode_macro _MOVE_TO_CENTER]
gcode:
{% set max_y = printer.configfile.config["stepper_y"]["position_max"]|float %}
{% set max_x = printer.configfile.config["stepper_x"]["position_max"]|float %}
{% if "xyz" not in printer.toolhead.homed_axes %}
G28
{% endif %}
G90 ; absolute mode
G0 X{max_x//2} Y{max_y//2} F12000
[gcode_macro _TAP_PROBE_ACTIVATE]
description: Ensure safe temp for bed probing
gcode:
{% set max_temp = params.TEMP|default(150)|int %}
{% set actual_temp = printer[params.HEATER].temperature %}
{% set target_temp = printer[params.HEATER].target %}
{% if target_temp > max_temp %}
{ action_respond_info('Extruder temperature target of %.1fC is too high, lowering to %.1fC' % (target_temp, max_temp)) }
SET_HEATER_TEMPERATURE HEATER={params.HEATER} TARGET={ max_temp }
{% endif %}
# Temperature target is already low enough, but nozzle may still be too hot.
{% if actual_temp > max_temp + 2 %}
{ action_respond_info('Extruder temperature %.1fC is still too high, waiting until below %.1fC' % (actual_temp, max_temp)) }
TEMPERATURE_WAIT SENSOR={params.HEATER} MAXIMUM={ max_temp }
{% endif %}
[gcode_macro M104]
rename_existing: M104.1
description: [T<index>] [S<temperature>]
Set tool temperature.
T= Tool number, optional. If this parameter is not provided, the current tool is used.
S= Target temperature
gcode:
{% if params.T is defined %}
{% set newparameters = "" %}
{% set newparameters = newparameters ~ " T="~params.T %}
{% if params.S is defined %}
{% set newparameters = newparameters ~ " TARGET="~params.S %}
{% endif %}
SET_TOOL_TEMPERATURE{newparameters}
{% else %}
M104.1 {rawparams}
{% endif %}
[gcode_macro M109]
rename_existing: M109.1
description: [T<index>] [S<temperature>]
Set tool temperature and wait.
T= Tool number, optional. If this parameter is not provided, the current tool is used.
S= Target temperature
gcode:
{% if params.T is defined %}
{% set newparameters = "" %}
{% set newparameters = newparameters ~ " T="~params.T %}
{% if params.S is defined %}
{% set newparameters = newparameters ~ " TARGET="~params.S %}
{% endif %}
SET_TOOL_TEMPERATURE WAIT=1 {newparameters}
{% else %}
M109.1 {rawparams}
{% endif %}
[gcode_macro _TOOL_BEFORE_CHANGE]
gcode:
{% set tn = params.TN|string %}
{% set tool = printer['tool ' + tn] %}
{% if printer["gcode_macro T" + tool.tool_number|string ] %}
SET_GCODE_VARIABLE MACRO=T{tool.tool_number} VARIABLE=color VALUE="''"
{% endif %}
[gcode_macro _TOOL_AFTER_CHANGE]
gcode:
{% set tn = params.TN|string %}
{% set tool = printer['tool ' + tn] %}
{% set max_z = printer.configfile.config["stepper_z"]["position_max"]|float %}
{% if printer["gcode_macro T" + tool.tool_number|string ] %}
SET_GCODE_VARIABLE MACRO=T{tool.tool_number} VARIABLE=color VALUE="'c44'"
{% endif %}
{% if 'input_shaper' in printer.configfile.config %}
{% set default_x_freq = printer.configfile.config['input_shaper']['shaper_freq_x']|default(0)|float %}
{% set default_x_type = printer.configfile.config['input_shaper']['shaper_type_x']|default('mzv')|string %}
{% set default_x_damping = printer.configfile.config['input_shaper']['damping_ratio_x']|default(0.1)|float %}
{% set default_y_freq = printer.configfile.config['input_shaper']['shaper_freq_y']|default(0)|float %}
{% set default_y_type = printer.configfile.config['input_shaper']['shaper_type_y']|default('mzv')|string %}
{% set default_y_damping = printer.configfile.config['input_shaper']['damping_ratio_y']|default(0.1)|float %}
SET_INPUT_SHAPER SHAPER_TYPE_X={tool.params_input_shaper_type_x if tool.params_input_shaper_type_x else default_x_type} SHAPER_FREQ_X={tool.params_input_shaper_freq_x if tool.params_input_shaper_freq_x else default_x_freq} SHAPER_TYPE_Y={tool.params_input_shaper_type_y if tool.params_input_shaper_type_y else default_y_type} SHAPER_FREQ_Y={tool.params_input_shaper_freq_y if tool.params_input_shaper_freq_y else default_y_freq} DAMPING_RATIO_X={tool.params_input_shaper_damping_ratio_x if tool.params_input_shaper_damping_ratio_x else default_x_damping} DAMPING_RATIO_Y={tool.params_input_shaper_damping_ratio_y if tool.params_input_shaper_damping_ratio_y else default_y_damping}
{% endif %}
[gcode_macro _TOOL_DROPOFF]
gcode:
{% set tn = params.TN|string %}
{% set tool = printer['tool ' + tn] %}
{% set x = tool.params_park_x|float %}
{% set y = tool.params_park_y|float %}
{% set z = tool.params_park_z|float %}
{% set safe_y = tool.params_safe_y|float %}
{% set fast = tool.params_fast_speed|float %}
{% set path = tool['params_dock_' + tool.params_dock_type + '_path'] + [{'f':0.5}] + tool['params_changer_' + tool.params_changer_type + '_path'] %}
{% set max_z = printer.configfile.config["stepper_z"]["position_max"]|float %}
{% set cur_z = printer.toolhead.position[2]|float %}
G90
; Move 1 mm up to avoid crashing into things
G0 Z{ [cur_z+1.0, max_z]|min } F{fast}
# ############## Move up to the dock ##############
ROUNDED_G0 Y={safe_y} D=20 F={fast}
ROUNDED_G0 X={x} D=150 F={fast}
ROUNDED_G0 Z={z + path[0].get('z', 0)|float} D=20 F={fast}
ROUNDED_G0 Y={y + path[0].get('y', 0)|float} X={x + path[0].get('x', 0)|float} D=0 F={fast}
STOP_TOOL_PROBE_CRASH_DETECTION
# ############## Run the path ##############
{% for pos in path %}
G0 Y{y + pos.get('y', 0)|float} X{x + pos.get('x', 0)|float} Z{z + pos.get('z', 0)|float} F{tool.params_path_speed|float * (pos.get('f', 1.0)|float) }
{% endfor %}
SET_GCODE_VARIABLE MACRO=_TOOLCHANGER_VARS VARIABLE=fan_speed VALUE={ printer[tool.fan].speed * 255|default(0)|int }
M106 S0 T{tn}
[gcode_macro _TOOL_PICKUP]
gcode:
{% set tn = params.TN|string %}
{% set tool = printer['tool ' + tn] %}
{% set x = tool.params_park_x|float %}
{% set y = tool.params_park_y|float %}
{% set z = tool.params_park_z|float %}
{% set close_y = tool.params_close_y|float %}
{% set fast = tool.params_fast_speed|float %}
{% set path = tool['params_dock_' + tool.params_dock_type + '_path'] + [{'f':0.5}] + tool['params_changer_' + tool.params_changer_type + '_path'] %}
G90
# ############## Fast to the last point ##############
ROUNDED_G0 Y={close_y} F={fast} D=5
ROUNDED_G0 X={x} Z={z + path[-1].get('z', 0)|float} F={fast} D=5
ROUNDED_G0 Y={y + path[-1].get('y', 0)|float} X={x + path[-1].get('x', 0)|float} F={fast} D=0
# Wait for temp before actually picking up the tool, while the nozzle is resting on it's pad.
{% if tool.extruder %}
M109 T{tool.tool_number} S{printer[tool.extruder].target|int}
{% endif %}
# Run the path in reverse
{% for pos in path|reverse %}
G0 Y{y + pos.get('y', 0)|float} X{x + pos.get('x', 0)|float} Z{z + pos.get('z', 0)|float} F{tool.params_path_speed|float * (pos.get('f', 1.0)|float) }
{% if 'f' in pos %} # Use the f presence as marker that we have made contact with the tool.
START_TOOL_PROBE_CRASH_DETECTION T={tool.tool_number}
{% endif %}
{% endfor %}
SET_STEPPER_ENABLE STEPPER={tool.extruder} ENABLE=1
# Restore the position with smooth rounded move.
ROUNDED_G0 Y={tool.params_safe_y} F={fast} D=20
{% if 'Z' in restore_position %}
ROUNDED_G0 Z={restore_position.Z} F={fast} D=150
{% endif %}
{% if 'X' in restore_position %}
ROUNDED_G0 X={restore_position.X} F={fast} D=1000
{% endif %}
{% if 'Y' in restore_position %}
ROUNDED_G0 Y={restore_position.Y} F={fast} D=0
{% endif %}
ROUNDED_G0 D=0
M106 S{printer["gcode_macro _TOOLCHANGER_VARS"].fan_speed} T{tn}
[gcode_macro _INITIALIZE_FROM_DETECTED_TOOL]
gcode:
{% if printer.tool_probe_endstop.active_tool_number|int == -1 %}
{% if (printer.toolchanger.homing_toolless and 'z' in printer.toolhead.homed_axes) %}
RESPOND TYPE=echo MSG='No tool found, picking up T{printer.toolchanger.tool_numbers[0]}'
SELECT_TOOL T={printer.toolchanger.tool_numbers[0]} FORCE_PICKUP=1 RESTORE_AXIS=Z
DETECT_ACTIVE_TOOL_PROBE
INITIALIZE_TOOLCHANGER T={printer.toolchanger.tool_numbers[0]}
{% else %}
RESPOND TYPE=error MSG='Failed to detect active tool'
PAUSE
{% endif %}
{% else %}
INITIALIZE_TOOLCHANGER T={printer.tool_probe_endstop.active_tool_number}
{% endif %}
[gcode_macro TOOL_ALIGN_START]
gcode:
INITIALIZE_TOOLCHANGER # Detect current tool
_TOOL_ALIGN_START
[gcode_macro _TOOL_ALIGN_START]
gcode:
STOP_TOOL_PROBE_CRASH_DETECTION
{% set tool = printer[printer.toolchanger.tool] %}
SET_TOOL_PARAMETER PARAMETER='params_path_speed' VALUE=300
SET_GCODE_OFFSET X=0 Y=0 Z=0
G0 Y{tool.params_safe_y} F{tool.params_fast_speed}
G0 X{tool.params_park_x} Z{tool.params_park_z}
G0 Y{tool.params_park_y|float + 100.0}
[gcode_macro TOOL_ALIGN_TEST]
gcode:
{% set min_y = printer.configfile.config["stepper_y"]["position_min"]|float %}
{% set max_z = printer.configfile.config["stepper_z"]["position_max"]|float %}
{% set curpos = printer.gcode_move.gcode_position %}
{% if curpos[1] < min_y or curpos[2] + 10 > max_z %}
RESPOND TYPE=error MSG='Test aborted. Tool set outside of movable area.'
{% else %}
RESPOND TYPE=echo MSG='This macro resets your park position but does not save it. It can be very dangerous and give you false confidence. Use at own risk.'
INITIALIZE_TOOLCHANGER # Detect current tool
STOP_TOOL_PROBE_CRASH_DETECTION
SET_TOOL_PARAMETER PARAMETER='params_park_x' VALUE={curpos[0]}
SET_TOOL_PARAMETER PARAMETER='params_park_y' VALUE={curpos[1]}
SET_TOOL_PARAMETER PARAMETER='params_park_z' VALUE={curpos[2]}
TEST_TOOL_DOCKING RESTORE_AXIS=XYZ
STOP_TOOL_PROBE_CRASH_DETECTION
{% endif %}
[gcode_macro TOOL_ALIGN_DONE]
gcode:
{% set tool = printer[printer.toolchanger.tool] %}
SAVE_TOOL_PARAMETER PARAMETER='params_park_x'
SAVE_TOOL_PARAMETER PARAMETER='params_park_y'
SAVE_TOOL_PARAMETER PARAMETER='params_park_z'
RESET_TOOL_PARAMETER PARAMETER='params_path_speed'
G0 Y{tool.params_safe_y} F{tool.params_fast_speed}
[gcode_macro M106]
description: Override "M106" to allow multiple extruders.
T= Tool number, optional. If this parameter is not provided, the current tool is used.
S= Target temperature
;Need rename is used with multi_fan
;rename_existing: M106.1
gcode:
{% set raw_speed = params.S|default(0)|float %}
{% set fan_speed = (raw_speed / 255.0)|round(2) %}
{% set tn = params.T|default(printer.tool_probe_endstop.active_tool_number)|int %}
{% set tool = printer.toolchanger.tool_names[tn]|default('') %}
{% set fan_name = '' %}
{% if tool in printer %}
{% set fan_name = printer[tool].fan.split(' ')[1] %}
{% endif %}
### other user define FAN
SET_FAN_SPEED FAN={fan_name} SPEED={fan_speed}
[gcode_macro M107]
description: Override "M107" to allow multiple extruders.
T= Tool number, optional. If this parameter is not provided, the current tool is used.
;Need rename is used with multi_fan
;rename_existing: M107.1
gcode:
M106 S0 {rawparams}
[gcode_macro _TOOLCHANGER_TURN_OFF_FANS]
description: Disable all extruder steppers
gcode:
{% for tool_nr in printer.toolchanger.tool_numbers %}
M107 T{tool_nr}
{% endfor %}
[gcode_macro PRINT_START]
gcode:
{% set TOOL_TEMP = params.TOOL_TEMP|default(150)|float %}
{% set BED_TEMP = params.BED_TEMP|default(0)|float %}
M117 Initializing...
INITIALIZE_TOOLCHANGER
STOP_TOOL_PROBE_CRASH_DETECTION
CLEAR_PAUSE
_TOOLCHANGER_PRINT_START_START
M117 Homing
G28
M117 Cleaning the nozzle
CLEAN_NOZZLE TEMP={ TOOL_TEMP - 20 }
M117 Heating up the bed
M190 S{ BED_TEMP }
M117 Calibrating bed
M109 S150 ; Heat up nozzle to soften any leftover filament for homing.
G32 ; Home, gantry tram
M109 S0 # Stop to heat, the actual printing may happen with a different hotend
{% if printer.toolchanger.tools_preheat %}
# Preheat all the hotends in use
{% for tool_nr in printer.toolchanger.tool_numbers %}
{% set tooltemp_param = 'T' ~ tool_nr|string ~ '_TEMP' %}
{% if tooltemp_param in params %}
M104 T{tool_nr} S{params[tooltemp_param]}
{% endif %}
{% endfor %}
{% if params.TOOL is defined %}
T{params.TOOL}
{% endif %}
{% endif %}
M117 Heating up the hotend
G90 ; Absolute positioning
G92 E0 ; Zero extruder
M106 S100 ; Start part cooling fan, 255=100%
G0 Z10 F3000
_MOVE_TO_CENTER
M109 S{ TOOL_TEMP }
START_TOOL_PROBE_CRASH_DETECTION
_TOOLCHANGER_PRINT_START_END
M117 Printing
[gcode_macro PRINT_END]
gcode:
_TOOLCHANGER_PRINT_END_START
STOP_TOOL_PROBE_CRASH_DETECTION
M400 ; wait for buffer to clear
CLEAR_PAUSE
M220 S100
M221 S100
SET_PRESSURE_ADVANCE ADVANCE=0
{% if printer.extruder.temperature >= 180 %}
M83
G91
G1 E-2 F2400 ; retract filament
G1 E-2 Z5 F2400
{% endif %}
M82
G90
SET_GCODE_OFFSET X=0.0 Y=0.0 Z=0.0
TURN_OFF_HEATERS
_TOOLCHANGER_TURN_OFF_FANS ; turn off fan
M140 S0 ; turn off bed
_TOOLCHANGER_PRINT_END_END
M117 Print done