forked from viesturz/klipper-toolchanger
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtoolchanger-extra-macros.cfg
More file actions
278 lines (238 loc) · 9.85 KB
/
toolchanger-extra-macros.cfg
File metadata and controls
278 lines (238 loc) · 9.85 KB
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
# OPTIONAL - Examples only
# Original written by Viesturs Zarins
[gcode_macro CLEAN_NOZZLE]
gcode:
;_TOOLCHANGER_CLEAN_NOZZLE
[gcode_macro TOOLCHANGE_DEMO]
description: [SAMPLES=<int>]
Run random tool changes.
SAMPLES= Number of changes to run, default is 20.
gcode:
{% set t = params.SAMPLES|default(20)|int %}
{% for n in range(t) %}
T{ printer.toolchanger.tool_numbers | random }
{% endfor %}
[gcode_macro G32]
gcode:
BED_MESH_CLEAR
QUAD_GANTRY_LEVEL
G28 Z
[gcode_macro PRINT_STATUS]
gcode:
{% set obj = params.OBJ %}
RESPOND TYPE=echo MSG="Status for M190 {obj} is { printer[obj] }"
[gcode_macro UNSAFE_LOWER_BED]
description: Lower the bed 100mm without homing
gcode:
G90
SET_KINEMATIC_POSITION Z=100
G0 Z0 F600
M84
[gcode_macro UNSAFE_RAISE_BED]
description: Raise the bed 100mm without homing
gcode:
G90
SET_KINEMATIC_POSITION Z=0
G0 Z100 F600
M84
[gcode_macro LOAD_FILAMENT]
gcode:
M117 Loading
M104 S240
G90 ; Absolute pos
G1 X100 Y00 Z90 F1800 ; Move to center
M109 S240 ;Heat up the filament
M83 ; set extruder to relative
G1 E50 F300 ; extrude 5 cm
G1 E50 F300 ; extrude 5 cm
G1 E-4 F1800 ; retract some
M82 ; set extruder to absolute
M400 ; wait for buffer to clear
M104 S0 ; Stop heating
M117 Loading done
[gcode_macro UNLOAD_FILAMENT]
gcode:
M117 Unloading
M109 S240 ;Heat up the filament
M83 ; set extruder to relative
G1 E5 F500 ; extrude 5 mm
G1 E-50 F1000 ; retract 5 cm
G1 E-50 F1000 ; retract 5 cm
M82 ; set extruder to absolute
M400 ; wait for buffer to clear
TURN_OFF_HEATERS
M117 Unloading done
[gcode_macro UNLOAD_ONE_FILAMENT]
gcode:
M117 Unloading {params.TOOL}
M109 T{params.TOOL} S240 ;Wait until heated
{% set start_extruder = printer.toolhead.extruder %}
{% set tool_name = printer.toolchanger.tool_names[params.TOOL|int] %}
{% set extruder = printer[tool_name].extruder %}
M109 T{params.TOOL} S240 ;Heat up the filament
ACTIVATE_EXTRUDER EXTRUDER={extruder}
M83 ; set extruder to relative
G1 E5 F500 ; extrude 5 mm
G1 E-50 F1000 ; retract 5 cm
G1 E-50 F1000 ; retract 5 cm
M82 ; set extruder to absolute
M400 ; wait for buffer to clear
TURN_OFF_HEATERS
ACTIVATE_EXTRUDER EXTRUDER={start_extruder}
M117 Unloading done
[gcode_macro UNLOAD_ALL_FILAMENT]
gcode:
{% set start_extruder = printer.toolhead.extruder %}
{% set tools = printer.toolchanger.tool_names %}
M117 Unloading
{% for tool in tools %}
M104 T{printer[tool].tool_number} S240 ;Heat up the filament
{% endfor %}
{% for tool in tools %}
M109 T{printer[tool].tool_number} S240 ;Wait until heated
ACTIVATE_EXTRUDER EXTRUDER={printer[tool].extruder}
M83 ; set extruder to relative
G1 E5 F500 ; extrude 5 mm
G1 E-50 F1000 ; retract 5 cm
G1 E-50 F1000 ; retract 5 cm
{% endfor %}
M400 ; Finish all th emoves
M82 ; set extruder to absolute
TURN_OFF_HEATERS
ACTIVATE_EXTRUDER EXTRUDER={start_extruder}
M117 Unloading done
[gcode_macro CHANGE_NOZZLE]
gcode:
M117 Nozzle change
M104 S240
G90 ; Absolute pos
G1 X175 Y0 Z100 F1800 ; Move to front
M109 S240 ;Heat up the filament
M83 ; set extruder to relative
G1 E5 F250 ; extrude 5 mm
G1 E-50 F1000 ; retract 5 cm
M82 ; set extruder to absolute
M117 Ready to swap
[gcode_macro M109]
rename_existing: M109.9999
description: [T<index>] [S<temperature>] [D<Deadband>]
Set tool temperature and wait.
T= Tool number [optional]. If this parameter is not provided, the current tool is used.
S= Target temperature
D= Dead-band, allows the temperature variance +/- the deadband
variable_default_deadband: 1.0
gcode:
{% set s = params.S|float %}
{% set deadband = default_deadband|float %}
{% if params.D is defined %}
{% set deadband = params.D|float %}
{% endif %}
{% set tn = params.T|default(printer.tool_probe_endstop.active_tool_number)|int %}
{% set tool = printer.toolchanger.tool_names[tn]|default('') %}
{% set extruder = printer[tool].extruder %}
SET_HEATER_TEMPERATURE HEATER={extruder} TARGET={s}
{% if s > 0 %}
TEMPERATURE_WAIT SENSOR={extruder} MINIMUM={s-(deadband/2)} MAXIMUM={s+(deadband/2)} ; Wait for hotend temp (within D degrees)
{% endif %}
[gcode_macro PRIME_LINES]
description: Prime all active tools before printing.
INITIAL_TOOL= Tool number, optional.
variable_tools_per_x: 6 # Number of tools primed in a single row
variable_lines_per_tool: 4 # Number of prime lines per tool
variable_line_step_y: 2 # Distance between lines in Y axis
variable_spacing: 7 # Distance between each tools prime lines
variable_ratio: 4 # Distance to move per 1mm of extrusion
variable_x_neg_offset: 5 # Distance from Edge of the bed on the -X axis
variable_x_pos_offset: 5 # Distance from Edge of the bed on the +X axis
variable_y_offset: 5 # Distance from Edge of the bed on the -Y axis
variable_pre_prime: 8 # Amount of extrude to do before starting prime line
variable_wipe_length: 6 # Wipe length after prime
variable_initial_tool_retract: 0.2 # Retraction distance for the initial tool (if defined) after prime
variable_docked_tool_retract: 0.5 # Retraction distance for docked tools after prime
variable_z_prime_pos: 0.3 # Distance from bed on Z axis while priming
variable_z_move_pos: 1 # Distance from bed on Z axis while moving
variable_move_speed: 10000 # Travel move speed
variable_prime_speed: 1000 # Prime move speed
variable_wipe_speed: 3000 # Wipe move speed
variable_temp_drop: 30 # Amount of temperature drop applied to nozzles that are being docked
gcode:
SAVE_GCODE_STATE NAME=PRIME_LINE_STATE
{% set max_x = printer.configfile.config["stepper_x"]["position_max"]|float %}
{% set max_y = printer.configfile.config["stepper_y"]["position_max"]|float %}
{% set line_length = (max_x-(x_neg_offset+x_pos_offset)-(spacing*(tools_per_x-1)))/tools_per_x %}
{% set print_tools = [] %}
# Figure out the required tools by which tools are preheating
{% for tn in printer.toolchanger.tool_numbers %}
{% set extruder_id = "extruder" + tn|string if tn > 0 else "extruder" %}
{% if printer[extruder_id].target >= printer.configfile.settings[extruder_id].min_extrude_temp %}
{% set gengar = print_tools.append(tn) %}
{% endif %}
{% endfor %}
# Make sure the initial print tool is the last to prime
{% if params.INITIAL_TOOL is defined %}
{% set initial_tool = params.INITIAL_TOOL|int %}
{% if print_tools|length > 1 %}
{% set snorlax = print_tools.pop(print_tools.index(initial_tool)) %}
{% set lickitung = print_tools.append(initial_tool) %}
{% endif %}
{% if printer.toolchanger.tool_number != initial_tool and printer.toolchanger.tool_number != print_tools[0] and printer.toolchanger.tool_number in print_tools %}
{% set mimikyu = print_tools.pop(print_tools.index(printer.toolchanger.tool_number)) %}
{% set bulbasaur = print_tools.insert(0, printer.toolchanger.tool_number) %}
{% endif %}
{% else %}
{% set initial_tool = None %}
{% endif %}
{% for tn in print_tools %}
# Change tool
T{tn}
{% set extruder_id = "extruder" + tn|string if tn > 0 else "extruder" %}
{% set t_idx = print_tools.index(tn) %}
{% set y_idx = (t_idx/tools_per_x)|int %}
{% set x_tool_list = print_tools[y_idx*tools_per_x:] %}
{% set x_idx = x_tool_list.index(tn) %}
{% set prime_start_x = x_neg_offset + (x_idx*line_length) + (x_idx*spacing) %}
{% set prime_start_y = y_offset + (line_step_y*(lines_per_tool-1)) + (y_idx*spacing) %}
# Move to position
G0 X{prime_start_x} Y{prime_start_y} Z{z_move_pos} F{move_speed}
G0 Z{z_prime_pos} F{move_speed}
# Wait for temp
M109 S{printer[extruder_id].target} T{tn}
# Prime Tool
M117 Priming T{tn}
M83
G92 E0
G91
G1 E{pre_prime} F{prime_speed}
{% for i in range(lines_per_tool) %}
{% set last_line = i == lines_per_tool-1 %}
{% set segment = ((line_length/ratio)-2)|int if last_line else ((line_length/ratio)+1)|int %}
{% if i % 2 == 0 %}
{% for _i in range(1, segment) %}
G1 X{ratio} E1 F{prime_speed}
{% endfor %}
{% else %}
{% for _i in range(1, segment) %}
G1 X-{ratio} E1 F{prime_speed}
{% endfor %}
{% endif %}
{% if not last_line %}
G1 Y-{line_step_y} E{(line_step_y/ratio)*1} F{move_speed}
{% endif %}
{% endfor %}
G1 E-{initial_tool_retract if tn == initial_tool else docked_tool_retract} F{wipe_speed}
G0 X{-0.5 if lines_per_tool % 2 == 0 else 0.5} F{wipe_speed}
G0 X{wipe_length-0.5 if lines_per_tool % 2 == 0 else -(wipe_length-0.5)} F{wipe_speed}
G0 Z{z_move_pos}
# Reduce temp for tools that are not required yet
{% if params.INITIAL_TOOL is defined %}
{% if initial_tool in print_tools %}
{% if tn != initial_tool %}
M104 S{printer[extruder_id].target-temp_drop} T{tn}
{% endif %}
{% endif %}
{% endif %}
G90
{% endfor %}
RESTORE_GCODE_STATE NAME=PRIME_LINE_STATE
# Use the correct offset for the current tool
_APPLY_ACTIVE_TOOL_GCODE_OFFSETS