-
Notifications
You must be signed in to change notification settings - Fork 0
/
macros.cfg
460 lines (404 loc) · 18.9 KB
/
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
[include macros_pre_release.cfg]
[gcode_macro PARK_CLEAN]
description: Park the toolhead at the back safe before move nozzle to remove stringing
gcode:
{% set E = params.E|default(1.7)|float %}
{% set Px, Py = printer["gcode_macro _USER_VARIABLES"].park_position_xy|map('float') %}
{% set park_lift_z = printer["gcode_macro _USER_VARIABLES"].park_lift_z %}
{% set St = printer["gcode_macro _USER_VARIABLES"].travel_speed * 60 %}
{% set Sz = printer["gcode_macro _USER_VARIABLES"].z_drop_speed * 60 %}
{% set max_x = printer.toolhead.axis_maximum.x|float %}
{% set max_y = printer.toolhead.axis_maximum.y|float %}
{% set max_z = printer.toolhead.axis_maximum.z|float %}
{% set act_z = printer.toolhead.position.z|float %}
{% if Px >= max_x - 15 %}
{% set Px_safe = max_x - 15 %}
{% elif Px < max_x - 15 %}
{% set Px_safe = Px %}
{% endif %}
{% if Py >= max_y - 15 %}
{% set Py_safe = Py - 15 %}
{% elif Py < max_y %}
{% set Py_safe = Py %}
{% endif %}
{% set z_safe = act_z + park_lift_z %}
{% if z_safe > max_z %}
{% set z_safe = max_z %}
{% endif %}
# retract filament before move up toolhead
{% if printer.extruder.temperature > 185 and firmware_retraction_enabled %}
G10
{% endif %}
G90
G1 Z{z_safe} F{Sz}
G0 X{Px_safe} Y{Py_safe} F{St}
[gcode_macro MAINTENANCE]
gcode:
{% set x_maint = printer.toolhead.axis_maximum.x|float / 2 %}
{% set y_maint = printer.toolhead.axis_minimum.y|float + 15 %}
{% set z_maint = printer.toolhead.axis_maximum.z|float - 100 %}
{% set St = printer["gcode_macro _USER_VARIABLES"].travel_speed * 40 %}
{% set Sz = printer["gcode_macro _USER_VARIABLES"].z_drop_speed * 60 %}
M117 maintenance
# 1 ----- HOMING -------------------
# Home if not already homed
_CG28
SAVE_GCODE_STATE NAME=Maintenance
# 2 ----- MOVE TO FRONT CENTER -----
G90
G1 Z{z_maint} F{Sz} #G1 Z140 F2400
G90
G0 X{x_maint} Y{y_maint} F{St} #G0 X148 Y15 F10000
G91
RESTORE_GCODE_STATE name=Maintenance
M117 Maintenance
[gcode_macro MOVE_TO_MIDDLE_BED]
gcode:
{% set x_ct = printer.toolhead.axis_maximum.x|float / 2 %}
{% set y_ct = printer.toolhead.axis_maximum.y|float / 2 %}
{% set z_ct = printer.toolhead.axis_minimum.z|float + 30 %}
{% set St = printer["gcode_macro _USER_VARIABLES"].travel_speed * 40 %}
{% set Sz = printer["gcode_macro _USER_VARIABLES"].z_drop_speed * 60 %}
# 1 ----- HOMING ------------------
# Home if not already homed
_CG28
SAVE_GCODE_STATE NAME=Middle_bed
# 2 ----- MOVE TO CENTER ----------
G90
G1 Z{z_ct} F{Sz}
G90
G1 X{x_ct} Y{y_ct} F{St}
G91
RESTORE_GCODE_STATE name=Middle_bed
[gcode_macro _USER_VARIABLES]
variable_caselight_off_layer_enabled = True
variable_caselight_off_layer_height = 2
[gcode_macro _RESET_LAYER_GCODE]
description: Clears scheduled gcode commands and state for all layers.
Usage: _RESET_LAYER_GCODE
gcode:
SET_PRINT_STATS_INFO TOTAL_LAYER="{0}" CURRENT_LAYER="{0}"
[gcode_macro STOP_CASELIGHT_LAYER_CHANGE]
description: Stop case light at the define layer.
Usage: STOP_CASELIGHT_LAYER_CHANGE LAYER=
gcode:
{% set cur_layers = printer.print_stats.info.current_layer|int %}
{% set caselight_off_layer_height = params.LAYER|default(printer["gcode_macro _USER_VARIABLES"].ercf_unload_on_end_print)|int %}
{% if printer['gcode_macro _USER_VARIABLES'].caselight_off_layer_enabled %}
{%if cur_layers > caselight_off_layer_height %}
SET_CASELIGHT_LEDS_OFF
{% endif %}
{% endif %}
[gcode_macro SET_CASELIGHT_LEDS_ON]
gcode:
{% set transmit = params.TRANSMIT|default(1) %}
{% if printer["gcode_macro _USER_VARIABLES"].status_leds_caselight_enabled %}
{% set color_name = params.COLOR|default('on')|lower %}
_SET_ALLLEDS_BY_NAME LEDS="caselight" COLOR={color_name} TRANSMIT=1
{% elif printer["gcode_macro _USER_VARIABLES"].light_enabled %}
LIGHT_ON
{% endif %}
[gcode_macro SET_CASELIGHT_LEDS_OFF]
gcode:
{% set transmit = params.TRANSMIT|default(1) %}
{% if printer["gcode_macro _USER_VARIABLES"].status_leds_caselight_enabled %}
_SET_ALLLEDS_BY_NAME LEDS="caselight" COLOR="off" TRANSMIT={transmit}
{% elif printer["gcode_macro _USER_VARIABLES"].light_enabled %}
LIGHT_OFF
{% endif %}
[gcode_macro SEARCH_VARS]
description: Search for variables in the "printer" object from Klipper
gcode:
{% set search = params.S|lower %}
{% set ns = namespace() %}
{% for item in printer %}
{% if ' ' in item %}
{% set ns.path = ['printer', "['%s']" % (item), ''] %}
{% else %}
{% set ns.path = ['printer.', item, ''] %}
{% endif %}
{% if search in ns.path|lower %}
{ action_respond_info(ns.path|join) }
{% endif %}
{% if printer[item].items() %}
{% for childkey, child in printer[item].items() recursive %}
{% set ns.path = ns.path[:loop.depth|int + 1] %}
{% if ' ' in childkey %}
{% set null = ns.path.append("['%s']" % (childkey)) %}
{% else %}
{% set null = ns.path.append(".%s" % (childkey)) %}
{% endif %}
{% if child is mapping %}
{ loop(child.items()) }
{% else %}
{% if search in ns.path|lower %}
{ action_respond_info("%s : %s" % (ns.path|join, child)) }
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
# This macro will allow you to type search_vars s={some word} from the terminal and
# it will respond with all of the matching items in the printer Object.
# Say I wanted to know what the name and path of for the value of the currently loaded bed
# mesh. I could do type search_vars s=profile in my terminal and it will respond with
# any items containing the word ‘profile’.
#
# $ SEARCH_VARS s="profile"
# // printer.bed_mesh.profile_name : default
#
[gcode_macro SEARCH_VARS2]
# Search like 'SEARCH_VARS s="profile"'
gcode:
{% if not params.S %}
{action_respond_info("hmm.. try 'SEARCH_VARS s=\"profile\"'")}
{% else %}
{% set resultcount = namespace(total=0) %}
{% set search = params.S|lower %}
{% set ns = namespace() %}
{% for item in printer %}
{% if ' ' in item %}
{% set ns.path = ['printer', "['%s']" % (item), ''] %}
{% else %}
{% set ns.path = ['printer.', item, ''] %}
{% endif %}
{% if search in ns.path|lower %}
{ action_respond_info(ns.path|join) }
{% set resultcount.total = 1 + resultcount.total %}
{% endif %}
{% if printer[item].items() %}
{% for childkey, child in printer[item].items() recursive %}
{% set ns.path = ns.path[:loop.depth|int + 1] %}
{% if ' ' in childkey %}
{% set null = ns.path.append("['%s']" % (childkey)) %}
{% else %}
{% set null = ns.path.append(".%s" % (childkey)) %}
{% endif %}
{% if child is mapping %}
{ loop(child.items()) }
{% else %}
{% if search in ns.path|lower %}
{ action_respond_info("%s : %s" % (ns.path|join, child)) }
{% set resultcount.total = 1 + resultcount.total %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% if resultcount.total >= 1 %}
{action_respond_info("found \"" + params.S + "\" " + resultcount.total|string +" times.")}
{% else %}
{action_respond_info("\"" + params.S + "\" not found.")}
{% endif %}
{% set resultcount.total = 0|int %}
{% endif %}
#####################################################################
# Macros to debug the printer variable
#####################################################################
# Use:
# - DUMP_PARAMETER print all parameter expect configfile
# - DUMP_PARAMETER P='gcode_macro _TEST' print the defined parameter group
# - DUMP_PARAMETER C='printer' print the defined config values
# - DUMP_PARAMETER S='printer' print the defined settings values
[gcode_macro DUMP_PARAMETER]
description: Debug: Print entries of the printer object
gcode:
{% set config = True if params.C or params.S else False %}
{% set path = 'config' if params.C
else 'settings' if params.S %}
{% set search = params.C if params.C
else params.S if params.S
else params.P if params.P %}
{% set out = [] %}
{% for name1 in printer|sort %}
{% if config %} ; print the searched printer.configfile[path] parameter
{% if name1 is in ['configfile'] %}
{% for name2 in printer[name1][path]|sort %}
{% if name2 is in [search] %}
{% for name3, value in printer[name1][path][name2].items()|sort %}
{% set _dummy = out.append("printer.configfile.%s['%s'].%s = %s" %
(path, name2, name3, value)) %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% else %}
{% for name2, value in printer[name1].items()|sort %} ; search for anything expext printer.configfile
{% if search is not defined and name1 is not in ['configfile'] %} ; print all printer. parameter
{% set _dummy = out.append("printer['%s'].%s = %s" % (name1, name2, value)) %}
{% elif search is defined and name1 is in [search] %} ; print the searched printer. parameter
{% set _dummy = out.append("printer['%s'].%s = %s" % (name1, name2, value)) %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% if out|length > 0 %}
{action_respond_info(out|join("\n"))}
{% else %}
{action_respond_info("Nothing found for \"DUMP_PARAMETER %s\"" % rawparams)}
{% endif %}
[gcode_macro DUMP_PRINT_AREA_LIMITS]
description: Debug: Print information about print volume and probeable area
gcode:
{% set min = printer.toolhead.axis_minimum %}
{% set max = printer.toolhead.axis_maximum %}
{% set probe_offset = {'x' : printer.configfile.settings.probe.x_offset,
'y' : printer.configfile.settings.probe.y_offset} %}
{% set probe_area = {'min' : {'x' : [min.x,(min.x-probe_offset.x)]|max,
'y' : [min.y,(min.y-probe_offset.y)]|max},
'max' : {'x' : [max.x,(max.x-probe_offset.x)]|min,
'y' : [max.y,(max.y-probe_offset.y)]|min}} %}
{action_respond_info("Print Volume Limits:
Min X:%7.1f, Y:%7.1f, Z:%7.1f
Max X:%7.1f, Y:%7.1f, Z:%7.1f
Probe Area Limits:
Min X:%7.1f, Y:%7.1f
Max X:%7.1f, Y:%7.1f" %
(min.x,min.y,min.z,max.x,max.y,max.z,probe_area.min.x,probe_area.min.y, probe_area.max.x,probe_area.max.y))}
#####################################################################
# Macros needed for several debug activities
#####################################################################
## Use:
## - DUMP_CONFIG S='printer'
[gcode_macro DUMP_CONFIG]
description: Debug: Print the selected entrie of the printer config object
gcode:
{% if 'S' in params %}
{% set parameters = [] %}
{% for name1 in printer.configfile.config %}
{% if name1 is in [params.S] %}
{% for name2 in printer.configfile.config[name1]|sort %}
{% set parameters = parameters.append("printer.configfile.config['%s'].%s = %s" % (name1, name2, printer.configfile.config[name1][name2])) %}
{% endfor %}
{% endif %}
{% endfor %}
action_respond_info(parameters|join("\n"))}
{% else %}
{action_respond_info("WARNING: parameter S needed call e.g. DUMP_CONFIG S='printer'")}
{% endif %}
## Use:
## - DUMP_WARNINGS
[gcode_macro DUMP_WARNINGS]
description: Debug: Print all warning messages from klipper
gcode:
{% set parameters = ["printer.configfile.warnings:"] %}
{% for name1 in printer.configfile.warnings %}
{% set parameters = parameters.append("%s -> %s -> %s\n%s" % (name1.type, name1.section, name1.option, name1.message)) %}
{% endfor %}
{action_respond_info(parameters|join("\n"))}
## Use:
## - DUMP_SETTINGS S='printer'
[gcode_macro DUMP_SETTINGS]
description: Debug: Print the selected entrie of the printer settings object
gcode:
{% if 'S' in params %}
{% set parameters = [] %}
{% for name1 in printer.configfile.settings %}
{% if name1 is in [params.S] %}
{% for name2 in printer.configfile.settings[name1]|sort %}
{% set parameters = parameters.append("printer.configfile.settings['%s'].%s = %s" % (name1, name2, printer.configfile.settings[name1][name2])) %}
{% endfor %}
{% endif %}
{% endfor %}
{action_respond_info(parameters|join("\n"))}
{% else %}
{action_respond_info("WARNING: parameter S needed call e.g. DUMP_SETTINGS S='printer'")}
{% endif %}
#####################################################################
# Macros needed for several debug activities
#####################################################################
# Home, get position, throw around toolhead, home again.
# If MCU stepper positions (first line in GET_POSITION) are greater than a full step different (your number of microsteps), then skipping occured.
# We only measure to a full step to accomodate for endstop variance.
# Example: TEST_SPEED SPEED=300 ACCEL=5000 ITERATIONS=10
[gcode_macro TEST_SPEED]
gcode:
# Speed
{% set speed = params.SPEED|default(printer.configfile.settings.printer.max_velocity)|int %}
# Iterations
{% set iterations = params.ITERATIONS|default(5)|int %}
# Acceleration
{% set accel = params.ACCEL|default(printer.configfile.settings.printer.max_accel)|int %}
# Bounding inset for large pattern (helps prevent slamming the toolhead into the sides after small skips, and helps to account for machines with imperfectly set dimensions)
{% set bound = params.BOUND|default(20)|int %}
# Size for small pattern box
{% set smallpatternsize = SMALLPATTERNSIZE|default(20)|int %}
# Large pattern
# Max positions, inset by BOUND
{% set x_min = printer.toolhead.axis_minimum.x + bound %}
{% set x_max = printer.toolhead.axis_maximum.x - bound %}
{% set y_min = printer.toolhead.axis_minimum.y + bound %}
{% set y_max = printer.toolhead.axis_maximum.y - bound %}
# Small pattern at center
# Find X/Y center point
{% set x_center = (printer.toolhead.axis_minimum.x|float + printer.toolhead.axis_maximum.x|float ) / 2 %}
{% set y_center = (printer.toolhead.axis_minimum.y|float + printer.toolhead.axis_maximum.y|float ) / 2 %}
# Set small pattern box around center point
{% set x_center_min = x_center - (smallpatternsize/2) %}
{% set x_center_max = x_center + (smallpatternsize/2) %}
{% set y_center_min = y_center - (smallpatternsize/2) %}
{% set y_center_max = y_center + (smallpatternsize/2) %}
# Save current gcode state (absolute/relative, etc)
SAVE_GCODE_STATE NAME=TEST_SPEED
# Output parameters to g-code terminal
{ action_respond_info("TEST_SPEED: starting %d iterations at speed %d, accel %d" % (iterations, speed, accel)) }
# Home and get position for comparison later:
M400 # Finish moves - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/66
G28
# QGL if not already QGLd (only if QGL section exists in config)
{% if printer.configfile.settings.quad_gantry_level %}
{% if printer.quad_gantry_level.applied == False %}
QUAD_GANTRY_LEVEL
G28 Z
{% endif %}
{% endif %}
# Move 50mm away from max position and home again (to help with hall effect endstop accuracy - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/24)
G90
G1 X{printer.toolhead.axis_maximum.x-50} Y{printer.toolhead.axis_maximum.y-50} F{30*60}
M400 # Finish moves - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/66
G28 X Y
G0 X{printer.toolhead.axis_maximum.x-1} Y{printer.toolhead.axis_maximum.y-1} F{30*60}
G4 P1000
GET_POSITION
# Go to starting position
G0 X{x_min} Y{y_min} Z{bound + 10} F{speed*60}
# Set new limits
SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel} ACCEL_TO_DECEL={accel / 2}
{% for i in range(iterations) %}
# Large pattern diagonals
G0 X{x_min} Y{y_min} F{speed*60}
G0 X{x_max} Y{y_max} F{speed*60}
G0 X{x_min} Y{y_min} F{speed*60}
G0 X{x_max} Y{y_min} F{speed*60}
G0 X{x_min} Y{y_max} F{speed*60}
G0 X{x_max} Y{y_min} F{speed*60}
# Large pattern box
G0 X{x_min} Y{y_min} F{speed*60}
G0 X{x_min} Y{y_max} F{speed*60}
G0 X{x_max} Y{y_max} F{speed*60}
G0 X{x_max} Y{y_min} F{speed*60}
# Small pattern diagonals
G0 X{x_center_min} Y{y_center_min} F{speed*60}
G0 X{x_center_max} Y{y_center_max} F{speed*60}
G0 X{x_center_min} Y{y_center_min} F{speed*60}
G0 X{x_center_max} Y{y_center_min} F{speed*60}
G0 X{x_center_min} Y{y_center_max} F{speed*60}
G0 X{x_center_max} Y{y_center_min} F{speed*60}
# Small patternbox
G0 X{x_center_min} Y{y_center_min} F{speed*60}
G0 X{x_center_min} Y{y_center_max} F{speed*60}
G0 X{x_center_max} Y{y_center_max} F{speed*60}
G0 X{x_center_max} Y{y_center_min} F{speed*60}
{% endfor %}
# Restore max speed/accel/accel_to_decel to their configured values
SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel} ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel_to_decel}
# Re-home and get position again for comparison:
M400 # Finish moves - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/66
G28 # This is a full G28 to fix an issue with CoreXZ - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/12
# Go to XY home positions (in case your homing override leaves it elsewhere)
G90
G0 X{printer.toolhead.axis_maximum.x-1} Y{printer.toolhead.axis_maximum.y-1} F{30*60}
G4 P1000
GET_POSITION
# Restore previous gcode state (absolute/relative, etc)
RESTORE_GCODE_STATE NAME=TEST_SPEED