I am currently working on a more complex approach of Power Loss Recovery, but while working on that, I made this simple power loss recovery script in Python, that can recover any print by the last recorded Z height. It works as follows:
Slicer’s start G-Code ends with ; POWER_PANIC_PRESERVE
Slicer’s layer change G-Code will invoke UPDATE_Z Z= to set the z height
UPDATE_Z will save the variable to variables.cfg
When power is lost, you still have to manually heat up the bed
You can get the last recorded z from variables.cfg
Run the script: python3 /path/to/script.py <Z HEIGHT FROM PREVIOUS STEP> <NAME OF GCODE FILE>
Look in your G-Codes folder, and there should be a G-Code file that starts with RECOVER-SOFT-
Use SET_KINEMATIC_POSITION Z= to set the z height without homing Z
Use the move panel to move Z 10mm up
Run G28 X Y to home X and Y
For now, you will still need to edit your recovered G-Code to remove any homing G-Code from the start G-Code.
Set your velocity limit to something slow e.g. 20mm
Start the recovery G-Code and make sure your print doesn’t fall off the bed.
Increase print speed slowly to avoid knocking the print off the bed.
import sys
import pathlib
nums = []
gcodes = pathlib.Path('/home/pi/printer_data/gcodes/')
with open(gcodes / sys.argv[2]) as gfile:
ulines = []
gcode = ''
i = 0
for line in gfile.readlines():
ulines.append(line)
if line.startswith(f';Z:{sys.argv[1]}'):
nums.append(i)
i += 1
num = nums[0]
preserve_line = 0
for uline in ulines:
if 'POWER_PANIC_PRESERVE' in uline:
break
preserve_line += 1
if preserve_line >= len(ulines) - 1:
preserve_line = 200
print(preserve_line, len(ulines), nums, num)
final = '\n'.join(ulines[0:preserve_line]) + '\n'.join(ulines[num:])
with open(gcodes / ('RECOVER-SOFT-'+str(sys.argv[2])), 'w') as file:
file.write(final)
Add the following to the end of your slicer’s start G-Code (NOT in your PRINT_START macro if you have one)
; POWER_PANIC_PRESERVE
Add the following to your slicer’s after layer change G-Code (this syntax is for PrusaSlicer)
UPDATE_Z Z=[layer_z]
If anyone finds this helpful or has ideas to improve it, please let me know.
I downloaded script above changed the path to corresponding variables and files but it seems it does not use variables even requires some permision to find these files.
Oh. I was confused about the script accessing Gcode thumbnails. For the script I uploaded:
The config file is in the right place. The python file doesn’t go in the klippy extras folder (I should make that clear in the instructions for the future). The python file goes in your home directory (or a folder in it). In my case, I have it in ~/klipper-simple-powerloss-recovery/powerloss.py.
Okey i am in work till 22:00(CET) but will try at arriving. And how can run that script? Trough Putty or terminal? Or can you send some manual? I would like create simple macro for that.
Did you follow the steps? Step 2 at the top of this page is very important. The error you’re facing is what would be expected if step 2 wasn’t followed.
Yes and wasn’t successfull. i made my own makro between the layers and then just edit gcode a have different start makro for continuing. Just now I need find out how to make acceleration lower for start and the higher for next layers.
Can you explain what happened when you tried to recover the file? The most common source of failure in a power loss is the bed cooling down, releasing the print.
No
After Shutdown when we start the machine.
This file is not available in G codes : 1. Look in your G-Codes folder, and there should be a G-Code file that starts with RECOVER-SOFT-
Only last file with sign showing interruption is there.
Did you alter your start GCode properly? The ; POWER_PANIC_PRESERVE line should be after your heating commands, after G28 XY, and before G28 Z. It can’t be in your Klipper PRINT_START. It has to be in your slicer gcode.