-
Notifications
You must be signed in to change notification settings - Fork 4
/
power_loss_simple.cfg
165 lines (124 loc) · 5.65 KB
/
power_loss_simple.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
# Power Loss Recovery
# uncomment if you not using it yet:
#[force_move]
#enable_force_move: True
#[save_variables]
#filename: ~/printer_data/config/variables.cfg
# usage:
# Add POWER_LOSS_CLEAR to the end gcode, then choose one of following options:
#
# a)
# Add POWER_LOSS_TIMER_START to start gcode and POWER_LOSS_TIMER_STOP to end gcode
#
# b)
# Add POWER_LOSS_SAVE to layser change gcode
#
# c)
# Call POWER_LOSS from power loss detector call like BTT UPS
# To recover print:
#
# Call POWER_LOSS_RECOVERY
[delayed_gcode power_loss_check]
initial_duration: 1
gcode:
{% set power_loss_save = printer.save_variables.variables.power_loss_save %}
{% if power_loss_save != 0 and "file_path" in power_loss_save %}
RESPOND PREFIX="[power_loss_simple]" MSG="Detected unfinished print: {power_loss_save.file_path}"
RESPOND PREFIX="" MSG="type POWER_LOSS_RECOVERY to continue printing"
RESPOND PREFIX="" MSG="or POWER_LOSS_CLEAR to drop it"
{% endif %}
[gcode_macro POWER_LOSS_RECOVERY]
gcode:
RESPOND PREFIX="[power_loss_simple]" MSG="Restoring print after power loss"
{% set power_loss_save = printer.save_variables.variables.power_loss_save %}
M117 File: {power_loss_save.file_path}
# load file
M23 {power_loss_save.file_path}
M26 S{power_loss_save.file_position}
# heating up
M104 S{power_loss_save.extruder_temp|int}
M140 S{power_loss_save.bed_temp|int}
M109 S{power_loss_save.extruder_temp|int}
M190 S{power_loss_save.bed_temp|int}
G28 X Y
SET_GCODE_OFFSET Z={power_loss_save.z_offset} MOVE=0
# big enough value to cover safe_z_home.z_hop value
SET_KINEMATIC_POSITION Z=20
# default speed for prepare movements
G1 F{50 * 60}
# move to position and left a little before poo
G1 X{power_loss_save.gcode_position_x - 5} Y{power_loss_save.gcode_position_y}
# lowering in case z home is active
G91
{% if "safe_z_home" in printer.configfile.config %}
G1 Z-{printer.configfile.config.safe_z_home.z_hop}
{% endif %}
M117 Extruding filament before print, please remove ooze if possible
# some extra poo
M83
G1 E2 F120
M117 Moving to position
# move to position
{% if printer.save_variables.variables.power_loss_extra_z > 0 %}
G1 Z-{printer.save_variables.variables.power_loss_extra_z}
{% endif %}
G1 X5
# restoring all parameters
M221 S{power_loss_save.extrude_factor}
M220 S{power_loss_save.speed_factor}
{% if power_loss_save.absolute_extrude|default(False) %}
M117 Absolute extrusion
M82
{% else %}
M117 Relative extrusion
M83
{% endif %}
{% if power_loss_save.absolute_coordinates|default(False) %}
M117 Absolute coordinates
G90
{% else %}
M117 Relative coordinates
G91
{% endif %}
SET_KINEMATIC_POSITION Z={power_loss_save.kin_position_z}
M117 Applying miscelanious parameters
SET_PRESSURE_ADVANCE ADVANCE={power_loss_save.pressure_advance} SMOOTH_TIME={power_loss_save.smooth_time}
SET_VELOCITY_LIMIT ACCEL={power_loss_save.accel} ACCEL_TO_DECEL={power_loss_save.accel_to_decel} VELOCITY={power_loss_save.velocity} SQUARE_CORNER_VELOCITY={power_loss_save.sqv}
# apply last speed
G1 F{power_loss_save.speed}
M106 S{power_loss_save.fan_speed|int}
# resume printing
M24
[gcode_macro POWER_LOSS]
gcode:
M117 Power loss! Saving print state now!
POWER_LOSS_SAVE
# raising to not damage model
G91
G1 Z10
SAVE_VARIABLE VARIABLE="power_loss_extra_z" VALUE=10
# uncomment and change to desired park position
#G90
#G1 X0 Y0
# save_config is optional, it's there for saving bed mesh, actually. can be safely commented out, and then pause may be uncommented
SAVE_CONFIG
#PAUSE
[gcode_macro POWER_LOSS_SAVE]
gcode:
SAVE_VARIABLE VARIABLE="power_loss_save" VALUE="{{ 'file_path': printer.print_stats.filename, 'file_position': printer.virtual_sdcard.file_position, 'speed_factor': (printer.gcode_move.speed_factor * 100)|int, 'speed': printer.gcode_move.speed|int, 'extrude_factor': (printer.gcode_move.extrude_factor * 100)|int, 'absolute_coordinates': printer.gcode_move.absolute_coordinates, 'absolute_extrude': printer.gcode_move.absolute_extrude, 'gcode_position_x': printer.gcode_move.gcode_position.x, 'gcode_position_y': printer.gcode_move.gcode_position.y, 'gcode_position_z': printer.gcode_move.gcode_position.z, 'gcode_position_e': printer.gcode_move.gcode_position.e, 'kin_position_x': printer.toolhead.position.x, 'kin_position_y': printer.toolhead.position.y, 'kin_position_z': printer.toolhead.position.z, 'kin_position_e': printer.toolhead.position.e, 'fan_speed': (printer.fan.speed * 255)|int, 'z_offset': printer.gcode_move.homing_origin.z, 'extruder_temp': printer.extruder.target|int, 'bed_temp': printer.heater_bed.target|int, 'pressure_advance': printer.extruder.pressure_advance, 'smooth_time': printer.extruder.smooth_time, 'retract_length': printer.firmware_retraction.retract_length|int, 'retract_speed': printer.firmware_retraction.retract_speed|int, 'unretract_speed': printer.firmware_retraction.unretract_speed|int, 'velocity': printer.toolhead.max_velocity|int, 'accel': printer.toolhead.max_accel|int, 'accel_to_decel': printer.toolhead.max_accel_to_decel|int, 'sqv': printer.toolhead.square_corner_velocity|int }}"
[gcode_macro POWER_LOSS_TIMER_START]
gcode:
UPDATE_DELAYED_GCODE ID=POWER_LOSS_SAVE DURATION=1
[gcode_macro POWER_LOSS_TIMER_STOP]
gcode:
UPDATE_DELAYED_GCODE ID=POWER_LOSS_SAVE DURATION=0
[gcode_macro POWER_LOSS_CLEAR]
gcode:
SAVE_VARIABLE VARIABLE="power_loss_save" VALUE=0
SAVE_VARIABLE VARIABLE="power_loss_extra_z" VALUE=0
RESPOND PREFIX="[power_loss_simple]" MSG="Print state cleared"
[delayed_gcode POWER_LOSS_SAVE]
initial_duration: 0
gcode:
POWER_LOSS_SAVE
UPDATE_DELAYED_GCODE ID=POWER_LOSS_SAVE DURATION=1