From 10ed195531edcfcfc31e16f1fb8528a7a1018e54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 2 Jul 2023 16:36:28 +0000 Subject: [PATCH] power panic: use saved position consistently 1) current_position[Z_AXIS] is not always correct. saved_pos[Z_AXIS] should always represent the correct resume position for the Z-axis 2) Use the saved position to fetch the Z-offset value from the mesh bed leveling grid. In case the extruder is parked during power panic, the previous code may extract the wrong mesh bed leveling offset (due to extruder being located at different X and Y axis coordinates) --- Firmware/power_panic.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Firmware/power_panic.cpp b/Firmware/power_panic.cpp index 7c25d85ed..7e9685796 100644 --- a/Firmware/power_panic.cpp +++ b/Firmware/power_panic.cpp @@ -103,7 +103,11 @@ void uvlo_() { // Store the print logical Z position, which we need to recover (a slight error here would be // recovered on the next Gcode instruction, while a physical location error would not) float logical_z = saved_pos[Z_AXIS]; - if(mbl_was_active) logical_z = current_position[Z_AXIS] - mbl.get_z(st_get_position_mm(X_AXIS), st_get_position_mm(Y_AXIS)); + if(mbl_was_active) { + // Mesh bed leveling was being actively applied to the Z-position. Revert the + // mesh bed leveling offset value. + logical_z -= mbl.get_z(saved_pos[X_AXIS], saved_pos[Y_AXIS]); + } eeprom_update_float((float*)EEPROM_UVLO_CURRENT_POSITION_Z, logical_z); // Store the print E position before we lose track