-
Notifications
You must be signed in to change notification settings - Fork 3
/
tool_pp.cfg
271 lines (230 loc) · 9.2 KB
/
tool_pp.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
## Pickup or park a tool
##
## Parameters:
# TOOL - tool index
# MODE - 0 for park, 1 for pickup
[gcode_macro TOOL_PP]
variable_parameter_TOOL: 0
variable_parameter_MODE: 1
gcode:
{% set continue = 1 %}
## mode correct ?
{% if continue == 1 %}
{% if params.MODE|int == 1 or params.MODE|int == 0 %}
{% if params.MODE|int == 1 %}
M118 PP > Mode: 1 - Pickup
{% endif %}
{% if params.MODE|int == 0 %}
M118 PP > Mode: 0 - Park
{% endif %}
{% else %}
M118 PP > Error: Unknown mode { params.MODE }
{% set continue = 0 %}
{% endif %}
{% endif %}
## tool parameter ?
{% if continue == 1 %}
{% if params.TOOL is defined %}
M118 PP > Selected tool: { params.TOOL }
{% else %}
M118 PP > Error: No tool specified
{% set continue = 0 %}
{% endif %}
{% endif %}
## homed ?
{% if continue == 1 %}
{% if printer["gcode_macro homing_status"].homed|int == 0 %}
M118 PP > Error: Not homed!
{% set continue = 0 %}
{% endif %}
{% endif %}
## tool defined ?
{% if continue==1 %}
{% if printer["gcode_macro tool_config_"~params.TOOL] is defined and printer["gcode_macro tool_config_"~params.TOOL].enabled is defined %}
M118 PP > Tool { params.TOOL } defined
{% else %}
M118 PP > Error: Tool not defined
{% set continue = 0 %}
{% endif %}
{% endif %}
## tool enabled ?
{% if continue==1 %}
{% if printer["gcode_macro tool_config_"~params.TOOL].enabled|int == 1 %}
M118 PP > Tool { params.TOOL } enabled
{% else %}
M118 PP > Error: Tool not enabled
{% set continue = 0 %}
{% endif %}
{% endif %}
## display tool name
{% if continue==1 %}
{% if printer["gcode_macro tool_config_"~params.TOOL].name is defined %}
M118 PP > Tool name: { printer["gcode_macro tool_config_"~params.TOOL].name }
{% endif %}
{% endif %}
## try to pickup a tool while another one is mounted ??
# not implemented yet
# fake pickup - do nothing more
{% if continue==1 %}
{% if params.MODE|int == 1 and printer["gcode_macro tool_config_"~params.TOOL].no_pickup is defined and printer["gcode_macro tool_config_"~params.TOOL].no_pickup|int == 1 %}
M118 PP > Fake Pickup, skipping everything else
{% set continue = 0 %}
{% endif %}
{% endif %}
# fake park - do nothing more
{% if continue==1 %}
{% if params.MODE|int == 0 and printer["gcode_macro tool_config_"~params.TOOL].no_park is defined and printer["gcode_macro tool_config_"~params.TOOL].no_park|int == 1 %}
M118 PP > Fake Park, skipping everything else
{% set continue = 0 %}
{% endif %}
{% endif %}
# reset gcode offset
{% if continue==1 %}
M118 PP > GCode Offset: 0,0,0
SET_GCODE_OFFSET X=0 Y=0 Z=0
{% endif %}
#check tool configuration
{% if continue==1 %}
{% if printer["gcode_macro tool_config_"~params.TOOL].near_x is defined and printer["gcode_macro tool_config_"~params.TOOL].near_y is defined %}
M118 PP > Tool near config ok
{% else %}
M118 PP > Tool missing near x/y configuration
{% set continue = 0 %}
{% endif %}
{% endif %}
#check tool configuration
{% if continue==1 %}
{% if printer["gcode_macro tool_config_"~params.TOOL].end_x is defined and printer["gcode_macro tool_config_"~params.TOOL].end_y is defined %}
M118 PP > Tool end config ok
{% else %}
M118 PP > Tool missing end x/y configuration
{% set continue = 0 %}
{% endif %}
{% endif %}
# xyz position saved
{% if continue==1 %}
M118 PP > Printer at {printer.gcode.gcode_position.x},{printer.gcode.gcode_position.y} height:{printer.gcode.gcode_position.z}
{% set p_x = printer.gcode.gcode_position.x %}
{% set p_y = printer.gcode.gcode_position.y %}
{% set p_z = printer.gcode.gcode_position.z %}
{% set x = printer.gcode.gcode_position.x %}
{% set y = printer.gcode.gcode_position.y %}
{% set z = printer.gcode.gcode_position.z %}
{% set speed_fast = printer["gcode_macro toolch_config"].speed_fast|int %}
{% set speed_slow = printer["gcode_macro toolch_config"].speed_slow|int %}
{% endif %}
# make sure the print head won't colide with tools
{% if continue==1 %}
{% if y < printer["gcode_macro toolch_config"].safe_y|float %}
M118 PP > Moving to safe y
G0 Y{printer["gcode_macro toolch_config"].safe_y|float} F{speed_fast}
{% set y = printer["gcode_macro toolch_config"].safe_y|float %}
{% endif %}
{% endif %}
## approach tool path
{% if continue==1 %}
M118 PP > Moving near tool X{printer["gcode_macro tool_config_"~params.TOOL].near_x|float} Y{printer["gcode_macro tool_config_"~params.TOOL].near_y|float} F{speed_fast}
G0 X{printer["gcode_macro tool_config_"~params.TOOL].near_x|float} Y{printer["gcode_macro tool_config_"~params.TOOL].near_y|float} F{speed_fast}
{% set y = printer["gcode_macro tool_config_"~params.TOOL].near_y|float %}
{% set x = printer["gcode_macro tool_config_"~params.TOOL].near_x|float %}
{% endif %}
## prepare befor plunge
{% if continue==1 %}
# park - do nothing
{% if params.MODE|int == 0 %}
M118 PP > Keeping status of lock
{% endif %}
# pickup - make sure we're unlocked
{% if params.MODE|int == 1 %}
M118 PP > Unlocking...
TOOLCH_UNLOCK
{% endif %}
{% endif %}
## move to bottom
{% if continue==1 %}
M118 PP > Moving to bottom of tool X{printer["gcode_macro tool_config_"~params.TOOL].end_x|float} Y{printer["gcode_macro tool_config_"~params.TOOL].end_y|float} F{speed_slow}
G0 X{printer["gcode_macro tool_config_"~params.TOOL].end_x|float} Y{printer["gcode_macro tool_config_"~params.TOOL].end_y|float} F{speed_slow}
{% set y = printer["gcode_macro tool_config_"~params.TOOL].end_y|float %}
{% set x = printer["gcode_macro tool_config_"~params.TOOL].end_x|float %}
{% endif %}
## toolchanger fully pushed in the parking space
{% if continue==1 %}
# park - unlock
{% if params.MODE|int == 0 %}
M118 PP > Unlocking...
TOOLCH_UNLOCK
{% endif %}
# pickup - lock
{% if params.MODE|int == 1 %}
M118 PP > Locking...
TOOLCH_LOCK
{% endif %}
{% endif %}
## move back out to approach
## TODO: change speeds based on tool presence ? or move to fast everytime ?
{% if continue==1 %}
M118 PP > Moving near tool X{printer["gcode_macro tool_config_"~params.TOOL].near_x|float} Y{printer["gcode_macro tool_config_"~params.TOOL].near_y|float} F{speed_slow}
G0 X{printer["gcode_macro tool_config_"~params.TOOL].near_x|float} Y{printer["gcode_macro tool_config_"~params.TOOL].near_y|float} F{speed_slow}
{% set y = printer["gcode_macro tool_config_"~params.TOOL].near_y|float %}
{% set x = printer["gcode_macro tool_config_"~params.TOOL].near_x|float %}
{% endif %}
# move to safe Y position
{% if continue==1 %}
{% if y < printer["gcode_macro toolch_config"].safe_y|float %}
M118 PP > Moving to safe y
G0 Y{printer["gcode_macro toolch_config"].safe_y|float} F{speed_fast}
{% set y = printer["gcode_macro toolch_config"].safe_y|float %}
{% endif %}
{% endif %}
## set last tool - only on pickup
{% if continue==1 %}
{% if params.MODE|int == 1 %}
{% if printer["gcode_macro tool_config_"~params.TOOL].no_last is defined and printer["gcode_macro tool_config_"~params.TOOL].no_last|int == 1 %}
M118 PP > no_last flag set, skipping set as last tool
{% else %}
M118 PP > Seting last tool: {params.TOOL|int}
SET_GCODE_VARIABLE MACRO=toolch_config VARIABLE=last_tool VALUE={params.TOOL|int}
{% endif %}
{% endif %}
{% endif %}
## set current tool
{% if continue==1 %}
# park
{% if params.MODE|int == 0 %}
SET_GCODE_VARIABLE MACRO=toolch_config VARIABLE=current_tool VALUE={printer["gcode_macro toolch_config"].no_tool}
M118 PP > Setting current tool: {printer["gcode_macro toolch_config"].no_tool}
{% endif %}
# pickup
{% if params.MODE|int == 1 %}
SET_GCODE_VARIABLE MACRO=toolch_config VARIABLE=current_tool VALUE={params.TOOL|int}
M118 PP > Setting current tool: {params.TOOL|int}
{% endif %}
{% endif %}
# load tool offset
{% if continue==1 %}
# only on pickup
{% if params.MODE|int == 1 %}
{% set o_x = 0 %}
{% set o_y = 0 %}
{% set o_z = 0 %}
{% if printer["gcode_macro tool_config_"~params.TOOL].offset_x is defined %}
{% set o_x = printer["gcode_macro tool_config_"~params.TOOL].offset_x|float %}
{% endif %}
{% if printer["gcode_macro tool_config_"~params.TOOL].offset_y is defined %}
{% set o_y = printer["gcode_macro tool_config_"~params.TOOL].offset_y|float %}
{% endif %}
{% if printer["gcode_macro tool_config_"~params.TOOL].offset_z is defined %}
{% set o_z = printer["gcode_macro tool_config_"~params.TOOL].offset_z|float %}
{% endif %}
{% if o_x==0 and o_y==0 and o_z==0 %}
M118 PP > GCode Offset kept at 0,0,0
{% else %}
M118 PP > GCode Offset: {o_x},{o_y},{o_z}
SET_GCODE_OFFSET X={o_x} Y={o_y} Z={o_z}
{% if o_z!= 0 %}
M118 PP > Z move to same relative z
G0 Z{z}
{% endif %}
{% endif %}
{% endif %}
{% endif %}