-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeatbed_Soak.cfg
176 lines (148 loc) · 7.6 KB
/
Heatbed_Soak.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
# # # PRINTBED SOAK # # #
# WHAT THIS DOES
#
# Usage:
# HEAT_SOAK [TARGET=<0-120>] [DURATION=<0-1800>]
# Heats print bed to the given target temperature
# After the target temperature is achieved, we enter a heat soaking state
# The amount of time taken to reach the target temperature is added to a minimum heat soak
# duration to allow for time for the heat bed temperature to equalise
# This allows the macro to handle pre-heated print beds without forcing added delays beyond
# the minimum heat soak duration
# A default minimum soak duration of 120s is used. This can be over-ridden by the DURATION parameter
[gcode_macro HEAT_SOAK]
description: Heats the print bed up to a target temperature and soaks it for a while
variable_soak_target_temp: 0
variable_soak_state: None ## heating, soaking, cancelled, done
## in seconds
variable_soak_check_interval: 10
variable_soak_time_remaining: 0
variable_total_time_elapsed: 0
gcode:
{% set TARGET_TEMP = params.TARGET | default(0) | float %}
{% set SOAK_TIME = (params.DURATION | default(120) | int) %}
{% set STATE = "done" %}
# Sanity Check Parameters and enforce sensible limits
# Ensure TARGET_TEMP is in the range 0-120
# Ensure SOAK_TIME is in the range 0-1800
{% if TARGET_TEMP < 0 %}
{% set TARGET_TEMP = 0 %}
{% endif %}
{% if TARGET_TEMP > 120 %}
{% set TARGET_TEMP = 120 %}
{% endif %}
{% if SOAK_TIME < 0 %}
{% set SOAK_TIME = 0 %}
{% endif %}
{% if SOAK_TIME > 1800 %}
{% set SOAK_TIME = 1800 %}
{% endif %}
# Here we always ensure that the print bed heater is set for TARGET_TEMP
SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={ TARGET_TEMP }
# Determine our heat soaking state
{% if TARGET_TEMP > 0 %}
{% if printer.heater_bed.temperature < TARGET_TEMP %}
{% set STATE = "heating" %} # Bed needs to be warmed up to temperature first before soaking
{% else %}
{% if SOAK_TIME > 0 %}
{% set STATE = "soaking" %} # Bed is at temperature, but we still need to soak for a while
{% endif %}
{% endif %}
{% endif %}
# Set our soak state and ensure total_time_elapsed is reset to 0
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_state VALUE="'{ STATE }'"
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=total_time_elapsed VALUE=0
{% if STATE == "done" %}
{ action_respond_info("Print Bed already at or above target temperature and soak time is zero") }
{ action_respond_info("Exiting Heat Soak after 0 seconds") }
## reset all soak variable, except state, which may be queried via the api
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_target_temp VALUE=0
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_time_remaining VALUE=0
{% else %}
{% if STATE == "soaking" %}
{ action_respond_info("Print Bed already at or above target temperature") }
{ action_respond_info("Heat Soaking for %d seconds" % (SOAK_TIME)) }
{% set SOAK_TIME = SOAK_TIME - soak_check_interval %}
{% else %}
{ action_respond_info("Waiting for print bed to heat up") }
{ action_respond_info("Target Temperature : %f" % (TARGET_TEMP)) }
{% endif %}
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_target_temp VALUE={ TARGET_TEMP }
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_time_remaining VALUE={ SOAK_TIME }
UPDATE_DELAYED_GCODE ID=heat_soaker DURATION={ soak_check_interval }
PAUSE_BASE # Pause the print during heat soak procedure
{% endif %}
[gcode_macro CANCEL_HEAT_SOAK]
description: cancels an in-progress HEAT_SOAK cycle
gcode:
{ action_respond_info("Cancelling Print Bed Heating + Soak Procedure") }
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_state VALUE="'cancelled'"
UPDATE_DELAYED_GCODE ID=heat_soaker DURATION=1
[delayed_gcode heat_soaker]
; ## debug
; { action_respond_info( printer['gcode_macro HEAT_SOAK'] | tojson )}
gcode:
{% set heat_soak = printer['gcode_macro HEAT_SOAK'] %}
{% set state = heat_soak.soak_state %}
{% set old_state = heat_soak.soak_state %}
## Determine total time elapsed and soak_duration
{% set total_time_elapsed = heat_soak.total_time_elapsed + heat_soak.soak_check_interval %}
{% set soak_time_remaining = heat_soak.soak_time_remaining %}
{% if state == "heating" and printer.heater_bed.temperature >= heat_soak.soak_target_temp %}
# Add time taken so far to minimum heat soak duration
{% set soak_time_remaining = heat_soak.soak_time_remaining + total_time_elapsed %}
# Report what's going on and move to soaking state
{ action_respond_info("Print Bed Heating Completed after %d seconds" % (total_time_elapsed)) }
{ action_respond_info("Heat Soaking for %d seconds" % (soak_time_remaining)) }
{% set state = "soaking" %}
{% endif %}
{% if state == "soaking" and soak_time_remaining == 0 %}
{% set state = "done" %}
{% endif %}
{% if state == "done" %}
# Heat Soak Sequence completed. Resume print
{ action_respond_info("Heat Soak Completed") }
RESUME_BASE
{% endif %}
{% if state == "cancelled" %}
# Heat Soak Sequence cancelled. Turn off heaters and cancel the print
{ action_respond_info("Print Bed Heating/Soaking Cancelled") }
TURN_OFF_HEATERS
CANCEL_PRINT
{% endif %}
{% if state != old_state %}
# Report to user any state change that occurred
# { action_respond_info("Heat Soak State : %s" % (state)) }
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_state VALUE="'{ state }'"
{% endif %}
# Handle loop finishing actions based upon current state
{% if state in ("soaking" , "heating") %}
{% if state == "heating" %}
{% if total_time_elapsed % 30 == 0 %} # Provide time taken feedback every 30s
{ action_respond_info("Heating Time Elapsed : %d" % (total_time_elapsed)) }
{% endif %}
{% else %}
# Must be in soaking state then
{% if soak_time_remaining % 30 == 0 %} # Provide soak time remaining feedback every 30s
{ action_respond_info("Soak Time Remaining : %d" % (soak_time_remaining)) }
{% endif %}
# Adjust remaining soak time ahead of next soak check interval
{% if soak_time_remaining > heat_soak.soak_check_interval %}
{% set soak_time_remaining = soak_time_remaining - heat_soak.soak_check_interval %}
{% else %}
{% set soak_time_remaining = 0 %}
{% endif %}
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_time_remaining VALUE={ soak_time_remaining }
{% endif %}
# Trigger ourselves to be called again after heat_soack.soak_check_interval seconds
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=total_time_elapsed VALUE={ total_time_elapsed }
UPDATE_DELAYED_GCODE ID=heat_soaker DURATION={ heat_soak.soak_check_interval }
## dwell for 1ms to prevent from going idle
G4 P1
{% else %}
{ action_respond_info("Exiting Heat Soak after %d seconds" % (total_time_elapsed)) }
## reset all soak variable, except state, which may be queried via the api
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_target_temp VALUE=0
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_time_remaining VALUE=0
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=total_time_elapsed VALUE=0
{% endif %}