Skip to content

Commit

Permalink
Powerloss Recovery fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasToka committed Oct 23, 2023
1 parent ca1d4c4 commit 5e7fd52
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
43 changes: 20 additions & 23 deletions Marlin/src/feature/powerloss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ PrintJobRecovery recovery;
gcode.process_subcommands_now(cmd); \
}while(0)

xyze_pos_t resume_pos;
uint32_t resume_sdpos;

/**
* Clear the recovery info
*/
Expand Down Expand Up @@ -176,6 +179,8 @@ void PrintJobRecovery::load() {
if (exists()) {
open(true);
(void)file.read(&info, sizeof(info));
resume_pos = info.current_position;
resume_sdpos = info.sdpos;
close();
}
debug(F("Load"));
Expand Down Expand Up @@ -392,7 +397,7 @@ void PrintJobRecovery::write() {
* Resume the saved print job
*/
void PrintJobRecovery::resume() {
const uint32_t resume_sdpos = info.sdpos; // Get here before the stepper ISR overwrites it
//const uint32_t resume_sdpos = info.sdpos; // Get here before the stepper ISR overwrites it

// Apply the dry-run flag if enabled
if (info.flag.dryrun) marlin_debug_flags |= MARLIN_DEBUG_DRYRUN;
Expand Down Expand Up @@ -434,16 +439,14 @@ void PrintJobRecovery::resume() {
#endif

// Interpret the saved Z according to flags
const float z_print = info.current_position.z,
const float z_print = resume_pos.z,
z_raised = z_print + info.zraise;

DEBUG_ECHO_MSG(">>> z_print: ", z_print, " current_position.z: ", current_position.z, " info.current_position.z: ", info.current_position.z);
//
// Home the axes that can safely be homed, and
// establish the current position as best we can.
//
#if ENABLED(E3S1PRO_RTS) && DISABLED(NOZZLE_CLEAN_FEATURE)
xyze_pos_t save_pos = info.current_position;
#endif
PROCESS_SUBCOMMANDS_NOW(F("G92.9E0")); // Reset E to 0

#if Z_HOME_TO_MAX
Expand All @@ -463,7 +466,7 @@ void PrintJobRecovery::resume() {
#define HOMING_Z_DOWN 1
#endif

float z_now = info.flag.raised ? z_raised : z_print;
float z_now = info.flag.raised ? z_raised : resume_pos.z + info.zraise + 10.000;

#if !HOMING_Z_DOWN
// Set Z to the real position
Expand Down Expand Up @@ -502,16 +505,6 @@ void PrintJobRecovery::resume() {
#endif
#endif

#if ENABLED(E3S1PRO_RTS) && DISABLED(NOZZLE_CLEAN_FEATURE)
// Parking head to allow clean before of heating the hotend
gcode.process_subcommands_now(F("G27"));
rtscheck.RTS_SndData(ExchangePageBase + 13, ExchangepageAddr);
change_page_font = 13;
sdcard_pause_check = true;
wait_for_user_response();
info.current_position = save_pos;
#endif

#if ENABLED(POWER_LOSS_RECOVER_ZHOME)
// Z was homed down to the bed, so move up to the raised height.
z_now = z_raised;
Expand Down Expand Up @@ -586,22 +579,19 @@ void PrintJobRecovery::resume() {

// Move back over to the saved XY
PROCESS_SUBCOMMANDS_NOW(TS(
F("G1F3000X"), p_float_t(info.current_position.x, 3), 'Y', p_float_t(info.current_position.y, 3)
F("G1F3000X"), p_float_t(resume_pos.x, 3), 'Y', p_float_t(resume_pos.y, 3)
));

// Move back down to the saved Z for printing
PROCESS_SUBCOMMANDS_NOW(TS(F("G1F600Z"), p_float_t(z_print, 3)));
PROCESS_SUBCOMMANDS_NOW(TS(F("G1F600Z"), p_float_t(resume_pos.z, 3)));

//DEBUG_ECHOLN(cmd);
DEBUG_ECHO_MSG(">>> z_print:", z_print, "current_position.z:", current_position.z);
PROCESS_SUBCOMMANDS_NOW(F("M114"));
//safe_delay(10000);
DEBUG_ECHO_MSG(">>> z_print: ", z_print, " z_now: ", z_now, " current_position.z: ", current_position.z, " info.current_position.z: ", info.current_position.z);

// Restore the feedrate
PROCESS_SUBCOMMANDS_NOW(TS(F("G1F"), info.feedrate));

// Restore E position with G92.9
PROCESS_SUBCOMMANDS_NOW(TS(F("G92.9E"), p_float_t(info.current_position.e, 3)));
PROCESS_SUBCOMMANDS_NOW(TS(F("G92.9E"), p_float_t(resume_pos.e, 3)));

TERN_(GCODE_REPEAT_MARKERS, repeat = info.stored_repeat);
TERN_(HAS_HOME_OFFSET, home_offset = info.home_offset);
Expand Down Expand Up @@ -630,6 +620,12 @@ void PrintJobRecovery::resume() {
DEBUG_ECHO(info.current_position[i]);
}
DEBUG_EOL();
DEBUG_ECHOPGM("resume_pos: ");
LOOP_LOGICAL_AXES(i) {
if (i) DEBUG_CHAR(',');
DEBUG_ECHO(resume_pos[i]);
}
DEBUG_EOL();

DEBUG_ECHOLNPGM("feedrate: ", info.feedrate);

Expand Down Expand Up @@ -712,6 +708,7 @@ void PrintJobRecovery::resume() {

DEBUG_ECHOLNPGM("sd_filename: ", info.sd_filename);
DEBUG_ECHOLNPGM("sdpos: ", info.sdpos);
DEBUG_ECHOLNPGM("resume_sdpos: ", resume_sdpos);
DEBUG_ECHOLNPGM("print_job_elapsed: ", info.print_job_elapsed);

DEBUG_ECHOPGM("axis_relative:");
Expand Down
7 changes: 5 additions & 2 deletions Marlin/src/module/stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2535,8 +2535,11 @@ hal_timer_t Stepper::block_phase_isr() {
#endif

#if ENABLED(POWER_LOSS_RECOVERY)
recovery.info.sdpos = current_block->sdpos;
recovery.info.current_position = current_block->start_position;
const uint32_t sdpos = current_block->sdpos;
if (sdpos) {
recovery.info.sdpos = sdpos;
recovery.info.current_position = current_block->start_position;
}
#endif

#if ENABLED(DIRECT_STEPPING)
Expand Down

0 comments on commit 5e7fd52

Please sign in to comment.