-
Notifications
You must be signed in to change notification settings - Fork 101
/
macro.cfg
356 lines (346 loc) · 21.3 KB
/
macro.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
## User Paramaters
## BED_TEMP : Target temperature for the Bed. Is also used to decide
## if heatsoak is needed
## EXTRUDER_TEMP : Target temperature for the Extruder
## CHAMBER_TEMP : Target temperature for the chamber fan controll
## SOAK : Soak time in minutes
## DELTA_B : Allowed delta between actual bed temperature and target
## temperature for the decision if heat soak is needed.
## DELTA_C : Allowed delta between actual chamber temperature and target
## will wait until target reached or time is zero
## CHAMBER_SOAK : Extra Soak time if Chamber is not on target - DELTA_C
## EXTRA_SOAK : Enables Chamber Soak ('true'/'false')
## LAYER_HEIGHT : Hight of prime_line should be set to layer_hight
## Z_ADJUST : Add extra z offset via slicer
## FILTER : Activate Nevermore 1 On 0 Off default On
[gcode_macro PRINT_START]
description: All cmd needed at print start
variable_var: {'temp' : {'extruder': 245.0, 'bed': 100.0, 'chamber': 40.0, 'endstop': 0.0},
'delta' : {'chamber': 5.0, 'bed': 10},
'time' : {'soak' : 1800, 'soak_extra': 900},
'redo_qgl' : True,
'prime_height': 0.0,
'z_adjust' : 0.0,
'filter' : True}
## Valid state
## Prepare : Store Params
## HeatBed : heat up bed and decide if soak is needed
## HeatSoak : loop the time specified with SOAK
## Chamber : decide if extra soak is needed
## ChamberSoak: loop the time specified with EXTRA_SOAK or Chamber target reached
## Final : all what needs to be done after wait time
variable_state: 'Prepare'
gcode:
{% set user = printer['gcode_macro _USER_VARIABLE'] %}
{% set actBed = printer['temperature_sensor bed'].temperature|float|round(1) if 'temperature_sensor bed' in printer
else printer.heater_bed.temperature|float|round(1) %} ; get actual temp from extra sensor or heater sensor
############################## Prepare phase only done at the first exection of PRINT_START ##############################
{% if state == 'Prepare' %}
############# Store input parameters #############
{% set var = {'temp': {'extruder': params.EXTRUDER_TEMP|default(245)|float|round(1),
'bed' : params.BED_TEMP|default(100)|float|round(1),
'chamber' : params.CHAMBER_TEMP|default(50)|float|round(1),
'endstop' : 0.0},
'delta': {'chamber': params.DELTA_C|default(5)|float|round(1),
'bed' : params.DELTA_B|default(10)|float|round(1)},
'time' : {'soak' : params.SOAK|default(30)|int * 60,
'soak_extra': params.CHAMBER_SOAK|default(15)|int * 60 if params.EXTRA_SOAK|default('true') == 'true' and
user.hw.chamber.ena
else 0},
'redo_qgl' : True,
'prime_height': params.LAYER_HEIGHT|float * user.print_start.prime_mult|float if LAYER_HEIGHT in params
else user.prime.pos.z|float,
'z_adjust' : params.Z_ADJUST|default(0.0)|float,
'filter' : False if params.FILTER|default(1)|int == 0 else True} %}
{% if user.hw.relay.ena %} _HEATER_ON {% endif %}
{% if user.hw.caselight.ena %} _CASELIGHT_ON {% endif %} ; switch on light
{% if user.hw.display.ena %} _LCD_KNOB COLOR=RED BLINK=1 {% endif %}
{% if user.hw.chamber.fan %} M141 S0 {% endif %} ; exhaust fan off
{% if user.hw.filter.ena and var.filter %} _FILTER_ON {% endif %} ; activate filter
_CG28 ; home if needed
G90 ; absolute position
G0 Z{user.park.bed.z} F{user.speed.z_hop} ; move nozzle to z high first
G0 X{user.park.bed.x} Y{user.park.bed.y} F{user.speed.travel} ; home to get toolhead in the middle
PAUSE_BASE
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=var VALUE="{var}"
SET_GCODE_VARIABLE MACRO=CANCEL_PRINT VARIABLE=execute VALUE=False
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=state VALUE='"HeatBed"'
UPDATE_DELAYED_GCODE ID=_START_PRINT_WAIT DURATION=0.5
############################## HeatBed Phase heat up the bed ##############################
{% elif state == 'HeatBed' %}
# get max allow bed temp from config. Lower it by 5C to avoid shutdown
{% set cfg_bed_max = printer.configfile.settings.heater_bed.max_temp|float|round(1) - 5.0 %}
{% set targetBed = var.temp.bed - var.delta.bed %}
{% set soakBed = [(var.temp.bed + user.print_start.bed_up), cfg_bed_max]|min %}
{% if (var.time.soak <= 0) or (actBed >= targetBed) %} ; check if soak time is 0 or if the bed is still hot
M117 Heating Extruder
{% set text = 'heat soak disabled' if var.time.soak <= 0 else 'heat soak not needed' %}
_PRINT_AR T="{"Bed temp: act %3.1f°C min %3.1f°C (target(%3.1f°C) - delta(%2.1f°C)) %s" %
(actBed,targetBed,var.temp.bed,var.delta.bed,text)}"
{% set _dummy = var.update({'redo_qgl' : False}) %}
M140 S{var.temp.bed} ; heat bed
M109 S{var.temp.extruder} ; heat extruder and wait
M190 S{var.temp.bed} ; heat bed and wait
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=state VALUE='"Chamber"'
UPDATE_DELAYED_GCODE ID=_START_PRINT_WAIT DURATION=0.5
{% else %}
M117 Heating Bed
_PRINT_AR T="{"Bed temp: act %3.1f°C min %3.1f°C (target(%3.1f°C) - delta(%2.1f°C)) heat soak needed" %
(actBed,targetBed,var.temp.bed,var.delta.bed)}"
_PRINT_AR T="{"Set Bed temp to %3.1f°C instead of %3.1f°C for faster heat soak" % (soakBed,var.temp.bed)}"
M106 S90 ; switch part cooling ~35% to move air in chamber
M140 S{soakBed} ; heat bed
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=state VALUE='"HeatSoak"'
{% set next_duration = user.print_start.ival if var.time.soak > user.print_start.ival else var.time.soak %}
{% set _dummy = var.time.update({'soak': var.time.soak - user.print_start.ival}) if var.time.soak > user.print_start.ival
else var.time.update({'soak': 0}) %}
UPDATE_DELAYED_GCODE ID=_START_PRINT_WAIT DURATION={next_duration}
{% endif%}
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=var VALUE="{var}"
_RUNOUT_INFO
############################## Heatsoak Phase call the delay macro until time is over ##############################
{% elif state == 'HeatSoak' %}
############# Get filament runout info #############
{% if user.hw.runout.sensor %}
{% if printer["filament_" + user.hw.runout.type + "_sensor runout"].enabled|lower == 'true' %}
{% set filament_detected = printer["filament_" + user.hw.runout.type + "_sensor runout"].filament_detected %}
{% elif 'filament_loaded' in printer.save_variables.variables %}
{% set filament_detected = printer.save_variables.variables.filament_loaded %}
{% else %}
{% set filament_detected = True %}
{% endif %}
{% elif user.hw.runout.type == 'file' %}
{% set filament_detected = printer.save_variables.variables.filament_loaded %}
{% else %}
{% set filament_detected = True %}
{% endif %}
{% if filament_detected %}
{% if var.time.soak <= (user.print_start.time.extruder + var.temp.extruder - 240) and
var.temp.extruder != printer.extruder.target %} ; check time to start heating extruder
M104 S{var.temp.extruder} ; heat extruder
{% endif %}
{% if var.time.soak <= user.print_start.time.bed and bed != printer.heater_bed.target|int %} ; check time to reduce bed temp
M140 S{var.temp.bed} ; heat bed
{% endif %}
{% if var.time.soak > 0 %} ; check remaining time
{% set next_duration = var.time.soak if user.print_start.ival >= var.time.soak else user.print_start.ival %}
{% set _dummy = var.time.update({'soak': 0}) if user.print_start.ival >= var.time.soak
else var.time.update({'soak': var.time.soak - user.print_start.ival}) %}}
UPDATE_DELAYED_GCODE ID=_START_PRINT_WAIT DURATION={next_duration}
{% else %}
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=state VALUE='"Chamber"'
UPDATE_DELAYED_GCODE ID=_START_PRINT_WAIT DURATION=0.5
_PRINT_AR T="{"Bed act temp=%3.1fC heat soak done" % (actBed)}"
{% endif%}
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=var VALUE="{var}"
{% else %}
_PRINT_AR T="No Filament loaded, print aborded!"
CANCEL_PRINT PARK=1 ERROR=1
{% endif %}
############################## Decide if extended soaking is needed ##############################
{% elif state == 'Chamber' %}
{% set targetChamber = var.temp.chamber - var.delta.chamber %}
{% set actChamber = printer["temperature_" + user.hw.chamber.type + " chamber"].temperature|round(1) if user.hw.chamber.ena
else 0 %}
{% if var.time.soak_extra > 0 and actChamber < targetChamber %}
_PRINT_AR T="{"Chamber temp: act %2.1f°C min %2.1f°C (target(%2.1f°C) - delta(%2.1f°C)) extra heat soak needed" %
(actChamber,targetChamber,var.temp.chamber,var.delta.chamber)}"
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=state VALUE='"ChamberSoak"'
UPDATE_DELAYED_GCODE ID=_START_PRINT_WAIT DURATION=0.5
{% else %}
{% set text = 'extra heat soak disabled' if var.time.soak_extra <= 0 else 'extra heat soak not needed' %}
_PRINT_AR T="{"Chamber temp: act %2.1f°C min %2.1f°C (target(%2.1f°C) - delta(%2.1f°C)) %s" %
(actChamber,targetChamber,var.temp.chamber,var.delta.chamber,text)}"
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=state VALUE='"Final"'
UPDATE_DELAYED_GCODE ID=_START_PRINT_WAIT DURATION=0.5
{% endif %}
############################## extra Heat Soak terminated by chamber temp ##############################
{% elif state == 'ChamberSoak' %}
{% set targetChamber = var.temp.chamber - var.delta.chamber %}
{% set actChamber = printer["temperature_" + user.hw.chamber.type + " chamber"].temperature|round(1) if user.hw.chamber.ena
else 0 %}
{% if var.time.soak_extra > 0 and actChamber < targetChamber %} ; check remaining time and temp difference
{% set next_duration = var.time.soak_extra if user.print_start.ival >= var.time.soak_extra else user.print_start.ival %}
{% set _dummy = var.time.update({'soak_extra': 0}) if user.print_start.ival >= var.time.soak_extra
else var.time.update({'soak_extra': var.time.soak_extra - user.print_start.ival}) %}}
UPDATE_DELAYED_GCODE ID=_START_PRINT_WAIT DURATION={next_duration}
{% else %}
{% set text = 'extra heat soak timed out' if var.time.soak_extra == 0 else 'chamber temp reached' %}
_PRINT_AR T="{"Chamber temp: act %2.1f°C min %2.1f°C (target(%2.1f°C) - delta(%2.1f°C)) %s" %
(actChamber,targetChamber,var.temp.chamber,var.delta.chamber,text)}"
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=state VALUE='"Final"'
UPDATE_DELAYED_GCODE ID=_START_PRINT_WAIT DURATION=0.5
{% endif %}
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=var VALUE="{var}"
############################## all whats need to run at the end ##############################
{% elif state == 'Final' %}
RESUME_BASE
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=state VALUE='"Prepare"' ; set state for next print
{% if user.hw.display.ena %} _LCD_KNOB COLOR=RED {% endif %}
M106 S0 ; turn off part cooling fan
G34 ; home & QGL
{% if user.hw.chamber.fan %} M141 S{var.temp.chamber} {% endif %} ; set target temp for exhaust fan
NOZZLECLEAN
SET_GCODE_VARIABLE MACRO=_HOME_Z VARIABLE=calibrate_z_next VALUE={user.hw.auto_z_offset.auto}
G28 Z
{% if user.hw.auto_z_offset.auto %} CALIBRATE_Z {% endif %}
{% if user.hw.auto_z_offset.manu %} _SET_PLATE_OFFSET {% endif %}
SET_GCODE_OFFSET Z_ADJUST={var.z_adjust} MOVE=1
_PRINT_OFFSET
PRIME_LINE PRIME_HEIGHT={var.prime_height}
{% if user.hw.endstop_temp.ena %}
{% set _dummy = var.temp.update({'endstop': printer['temperature_sensor endstop'].temperature}) %}
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=var VALUE="{var}"
{% endif %}
G21 ; set units to millimeters
G90 ; use absolute coordinates
M83 ; use relative distances for extrusion
UPDATE_DELAYED_GCODE ID=_CLEAR_DISPLAY DURATION=1
{% endif %}
[delayed_gcode _START_PRINT_WAIT]
gcode:
{% macro print_time(text, time) %} ; print remaining time
M117 {'%s' % text} {(time|int // 60)}:{'%02d' % (time|int % 60)}
{% endmacro %}
{% if printer['gcode_macro PRINT_START'].state == 'HeatSoak'%}
{ print_time("HEAT SOAK", printer['gcode_macro PRINT_START'].var.time.soak) }
{% elif printer['gcode_macro PRINT_START'].state == 'ChamberSoak' %}
{ print_time("SOAK", printer['gcode_macro PRINT_START'].var.time.soak_extra) }
{% endif %}
# Check CANCLE_PRINT was executed
{% if printer['gcode_macro CANCEL_PRINT'].execute|lower == 'false' %}
PRINT_START ; Junp back to PRINT_START
{% else %} ; break loop and insure state is correct for the next print start
SET_GCODE_VARIABLE MACRO=CANCEL_PRINT VARIABLE=execute VALUE=False
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=state VALUE='"Prepare"'
UPDATE_DELAYED_GCODE ID=_CLEAR_DISPLAY DURATION=1
{% endif %}
[gcode_macro PRINT_END]
description: All commands after the print
gcode:
{% set user = printer['gcode_macro _USER_VARIABLE'] %}
{% set filter_off = user.peripheral.filter.run_after_print %}
{% set vent_on = user.peripheral.vent.on_val %}
{% set vent_off = user.peripheral.vent.run_after_print %}
# calculate save move
{% set max = printer.toolhead.axis_maximum %}
{% set act = printer.toolhead.position %}
{% set safe = {'x': 20.0 if act.x|float < (max.x|float - 20.0) else -20.0,
'y': 20.0 if act.y|float < (max.y|float - 20.0) else -20.0,
'z': 2.0 if act.z|float < (max.z|float - 2.0) else (max.z|float - act.z|float)} %}
M400 ; wait for buffer to clear
SAVE_GCODE_STATE NAME=STATE_PRINT_END
G92 E0 ; zero the extruder
M83 ; relative extrusion
G1 E-{user.filament.retract.end} F{user.speed.retract} ; retract filament
G91 ; relative positioning
G0 X{safe.x} Y{safe.y} Z{safe.z} F{user.speed.travel} ; move nozzle to remove stringing
TURN_OFF_HEATERS ; turn off heaters
M107 ; turn off fan
{% if user.hw.chamber.fan %} M141 S{vent_on} {% endif %} ; vent chamber (setting fan to below ambient)
G90 ; absolute positioning
G0 X{user.park.pause.x} Y{user.park.pause.y} F{user.speed.travel} ; park nozzle at brush bin
_ADD_PRINT_TIME
_SD_PRINT_STATS R='done'
_SD_PRINTER_STATS
{% if user.hw.display.ena %} _LCD_KNOB COLOR=GREEN {% endif %}
{% if user.hw.caselight.ena %} _CASELIGHT_OFF {% endif %}
{% if user.hw.chamber.fan %} UPDATE_DELAYED_GCODE ID=_DELAY_VENT_OFF DURATION={vent_off} {% endif %}
{% if user.hw.filter.ena %} UPDATE_DELAYED_GCODE ID=_DELAY_FILTER_OFF DURATION={filter_off} {% endif %}
{% if user.hw.endstop_temp.ena %}
{action_respond_info("PRINT_END
BED temp: act %3.1f°C
Endstop temp: start %3.1f°C end %3.1f°C" % (printer['temperature_sensor bed'].temperature if 'temperature_sensor bed' in printer
else printer.heater_bed.temperature,
printer['gcode_macro PRINT_START'].var.temp.endstop,
printer['temperature_sensor endstop'].temperature))}
{% endif %}
{% if user.unload_sd|lower == 'true' %} UPDATE_DELAYED_GCODE ID=_DELAY_SDCARD_RESET_FILE DURATION=10 {% endif %}
UPDATE_DELAYED_GCODE ID=_CLEAR_DISPLAY DURATION=10
RESTORE_GCODE_STATE NAME=STATE_PRINT_END
M220 S100 ; set feedrate percentage back to default
M221 S100 ; set speed percentage back to default
[gcode_macro G34]
description: Reset bed mesh, offset and execute QGL
gcode:
_PRINT_AR T="Home & QGL" SHOW_LCD=true
BED_MESH_CLEAR
SET_GCODE_OFFSET Z=0 MOVE=1
{% if printer['gcode_macro PRINT_START'].var.redo_qgl|lower == 'true' %}
_PRINT_AR T="QGL forced by PRINT_START"
QUAD_GANTRY_LEVEL PARK=false HOME=false
{% elif printer.quad_gantry_level.applied|lower == 'false' %}
_PRINT_AR T="QGL not executed yet"
QUAD_GANTRY_LEVEL PARK=false HOME=false
{% endif %}
UPDATE_DELAYED_GCODE ID=_CLEAR_DISPLAY DURATION=1
[gcode_macro M204]
description: Set and limit acceleration to cfg value
rename_existing: M204.1
gcode:
{% set accel = params.S|float if 'S' in params and params.S|float > 0
else [params.P|float,params.T|float]|min if 'P' in params and 'T' in params and
params.P|float > 0 and params.T|float > 0 %}
{% if accel is defined %}
{% set lim_accel = [accel, printer.configfile.settings.printer.max_accel ]|min %}
{% set lim_accel_to_decel = [accel / 2, printer.configfile.settings.printer.max_accel_to_decel]|min %}
SET_VELOCITY_LIMIT ACCEL={lim_accel} ACCEL_TO_DECEL={lim_accel_to_decel}
{% else %}
{action_respond_info("Invalid M204 command \"M204 %s\"" % rawparams)}
{% endif %}
[gcode_macro M900]
description: Set pressure advance
gcode:
SET_PRESSURE_ADVANCE ADVANCE={params.K|default(0)}
[gcode_macro _PRINT_OFFSET]
description: Helper: Print gcode offsets defined by script or user in PRINT_START
gcode:
{% set user = printer['gcode_macro _USER_VARIABLE'] %}
{% set text = ["GCODE OFFSET for Z applied from:"] %}
{% if user.hw.auto_z_offset.manu %}
{% set _dummy = text.append("Plate %s %.3fmm" %
(printer.save_variables.variables.plates.array[printer.save_variables.variables.plates.index].name,
printer.save_variables.variables.plates.array[printer.save_variables.variables.plates.index].offset)) %}
{% endif %}
{% if user.hw.auto_z_offset.auto %}
{% set _dummy = text.append("Z_CALIBRATE %.3fmm" % printer.z_calibration.last_z_offset) %}
{% endif %}
{% set _dummy = text.append("User %.3fmm" % printer['gcode_macro PRINT_START'].var.z_adjust) %}
{% set _dummy = text.append("Total %.3fmm" % printer.gcode_move.homing_origin.z) %}
{action_respond_info(text|join("\n"))}
[gcode_macro _RUNOUT_INFO]
description: Helper: Print runout sensor status
gcode:
{% set user = printer['gcode_macro _USER_VARIABLE'] %}
{% set out = ['RUNOUT: ' + user.hw.runout.type|capitalize + ' Sensor'] if user.hw.runout.sensor
else ['RUNOUT: Stored in file'] if user.hw.runout.type == 'file'
else ['RUNOUT: Not monitored'] %}
{% set enable = printer["filament_" + user.hw.runout.type + "_sensor runout"].enabled if user.hw.runout.sensor
else False %}
{% set _dummy = out.append('Enabled: ' + enable|lower) if user.hw.runout.sensor %}
{% set detected = printer["filament_" + user.hw.runout.type + "_sensor runout"].filament_detected if enable
else printer.save_variables.variables.filament_loaded if user.hw.runout.type == 'file' %}
{% set _dummy = out.append('Detect Filament: ' + detected|lower) if detected is defined %}
{action_respond_info(out|join("\n"))}
## PrusaSlicer/SuperSlicer:
## Add at the start gcode section
## _LAYER TOTAL=[total_layer_count] RESPOND=0
##
## Add at the layer change gcode section
## _LAYER CURRENT={layer_num+1}
[gcode_macro _LAYER]
description: Pass the current layer and the total amount of layers by your Slicer.
variable_layer: {'current': 0, 'total':0}
gcode:
{% set _dummy = layer.update({'total':params.TOTAL|int}) if ('TOTAL' in params and params.TOTAL|int > 0) %}
{% set _dummy = layer.update({'current':params.CURRENT|default(0)|int}) %}
SET_GCODE_VARIABLE MACRO=_LAYER VARIABLE=layer VALUE="{layer}"
{% if params.RESPOND|default(printer['gcode_macro _USER_VARIABLE'].respond.layer)|int == 1 %}
{action_respond_info("Layer %s of %s" % (layer.current, layer.total))}
{% endif %}
[gcode_macro TOGGLE_LAYER_OUTPUT]
description: Enable/Disable Console output of _LAYER
gcode:
{% set respond = printer['gcode_macro _USER_VARIABLE'].respond %}
{% set _dummy = respond.update({'layer':1}) if respond.layer|int == 0 else respond.update({'layer':0}) %}
SET_GCODE_VARIABLE MACRO=_USER_VARIABLE VARIABLE=respond VALUE="{respond}"