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)
This commit is contained in:
Guðni Már Gilbert 2023-07-02 16:36:28 +00:00 committed by DRracer
parent 392c46c7ad
commit 10ed195531
1 changed files with 5 additions and 1 deletions

View File

@ -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