Skip to content

Commit 8aafef0

Browse files
committed
Simplify PLR on pause
1 parent b92fe8f commit 8aafef0

File tree

6 files changed

+60
-41
lines changed

6 files changed

+60
-41
lines changed

Marlin/src/feature/pause.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,12 @@ bool pause_print(const_float_t retract, const xyz_pos_t &park_point, const bool
419419
unscaled_e_move(retract, PAUSE_PARK_RETRACT_FEEDRATE);
420420
}
421421

422-
// Park the nozzle by moving up by z_lift and then moving to (x_pos, y_pos)
423-
if (!axes_should_home())
422+
// Park the nozzle by doing a Minimum Z Raise followed by an XY Move
423+
float park_raise = 0;
424+
if (!axes_should_home()) {
425+
park_raise = nozzle.park_mode_0_height(park_point.z) - current_position.z;
424426
nozzle.park(0, park_point);
427+
}
425428

426429
#if ENABLED(DUAL_X_CARRIAGE)
427430
const int8_t saved_ext = active_extruder;
@@ -439,14 +442,8 @@ bool pause_print(const_float_t retract, const xyz_pos_t &park_point, const bool
439442
// Disable the Extruder for manual change
440443
disable_active_extruder();
441444

442-
#if ENABLED(POWER_LOSS_RECOVERY)
443-
if (was_sd_printing && recovery.enabled) { // For an SD print
444-
const xyze_pos_t tmp = current_position;
445-
current_position = resume_position;
446-
recovery.save(true, tmp.z - resume_position.z, true);
447-
current_position = tmp;
448-
}
449-
#endif
445+
// Save PLR info in case the power goes out while parked
446+
TERN_(POWER_LOSS_RECOVERY, if (was_sd_printing && recovery.enabled) recovery.save(true, park_raise, true));
450447

451448
return true;
452449
}

Marlin/src/feature/pause.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ extern uint8_t did_pause_print;
8989
bool pause_print(
9090
const_float_t retract, // (mm) Retraction length
9191
const xyz_pos_t &park_point, // Parking XY Position and Z Raise
92-
const bool show_lcd=false // Set LCD status messages?
93-
const_float_t unload_length=0, // (mm) Filament Change Unload Length - 0 to skip
92+
const bool show_lcd=false, // Set LCD status messages?
93+
const_float_t unload_length=0 // (mm) Filament Change Unload Length - 0 to skip
9494
DXC_PARAMS // Dual-X-Carriage extruder index
9595
);
9696

9797
void wait_for_confirmation(
9898
const bool is_reload=false, // Reload Filament? (otherwise Resume Print)
99-
const int8_t max_beep_count=0, // Beep alert for attention
99+
const int8_t max_beep_count=0 // Beep alert for attention
100100
DXC_PARAMS // Dual-X-Carriage extruder index
101101
);
102102

Marlin/src/feature/powerloss.cpp

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ void PrintJobRecovery::prepare() {
149149
*/
150150
void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=0*/, const bool raised/*=false*/) {
151151

152+
// We don't check IS_SD_PRINTING here so a save may occur during a pause
153+
152154
#if SAVE_INFO_INTERVAL_MS > 0
153155
static millis_t next_save_ms; // = 0
154156
millis_t ms = millis();
@@ -292,7 +294,8 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=0*/
292294
constexpr float zraise = 0;
293295
#endif
294296

295-
// Save, including the limited Z raise
297+
// Save the current position, distance that Z will be raised,
298+
// and a flag whether the raise was already done here.
296299
if (IS_SD_PRINTING()) save(true, zraise, ENABLED(BACKUP_POWER_SUPPLY));
297300

298301
// Disable all heaters to reduce power loss
@@ -368,22 +371,29 @@ void PrintJobRecovery::resume() {
368371
}
369372
#endif
370373

371-
// Reset E, raise Z, home XY...
374+
//
375+
// Home the axes that can safely be homed, and
376+
// establish the current position as best we can
377+
//
372378
#if Z_HOME_DIR > 0
373379

374-
// If Z homing goes to max, just reset E and home all
380+
// If Z homing goes to max...
375381
gcode.process_subcommands_now_P(PSTR(
376-
"G92.9 E0\n"
377-
"G28R0"
382+
"G92.9 E0\n" // Reset E to 0
383+
"G28R0" // Home all axes (no raise)
378384
));
379385

380386
#else // "G92.9 E0 ..."
381387

388+
// Reset Z and E to 0
382389
gcode.process_subcommands_now_P("G92.9E0Z0");
383390

384-
// If a Z raise occurred at outage set Z to the Z raise value (over zero), otherwise raise Z now
385-
sprintf_P(cmd, info.flag.raised ? PSTR("G92.9Z%s") : PSTR("G1Z%sF200"), dtostrf(info.zraise, 1, 3, str_1));
386-
gcode.process_subcommands_now(cmd);
391+
// Is there a "raise" value?
392+
if (info.zraise) {
393+
// If a Z raise occurred at outage set Z to the Z raise value, otherwise raise Z now
394+
sprintf_P(cmd, info.flag.raised ? PSTR("G92.9Z%s") : PSTR("G1Z%sF500"), dtostrf(info.zraise, 1, 3, str_1));
395+
gcode.process_subcommands_now(cmd);
396+
}
387397

388398
// Home safely with no Z raise
389399
gcode.process_subcommands_now_P(PSTR(
@@ -395,19 +405,20 @@ void PrintJobRecovery::resume() {
395405

396406
#endif
397407

398-
#ifdef POWER_LOSS_ZHOME_POS
399-
// If defined move to a safe Z homing position that avoids the print
408+
#if ENABLED(POWER_LOSS_RECOVER_ZHOME) && defined(POWER_LOSS_ZHOME_POS)
409+
// Move to a safe XY position where Z can home while avoiding the print.
410+
// If Z_SAFE_HOMING is enabled, its position must also be outside the print area!
400411
constexpr xy_pos_t p = POWER_LOSS_ZHOME_POS;
401-
sprintf_P(cmd, PSTR("G1 X%s Y%s F1000\nG28Z"), dtostrf(p.x, 1, 3, str_1), dtostrf(p.y, 1, 3, str_2));
412+
sprintf_P(cmd, PSTR("G1X%sY%sF1000\nG28Z"), dtostrf(p.x, 1, 3, str_1), dtostrf(p.y, 1, 3, str_2));
402413
gcode.process_subcommands_now(cmd);
403414
#endif
404415

405-
// Ensure that all axes are marked as homed
416+
// Mark all axes as having been homed (no effect on current_position)
406417
set_all_homed();
407418

408419
#if ENABLED(POWER_LOSS_RECOVER_ZHOME)
409-
// Now move to ZsavedPos + POWER_LOSS_ZRAISE
410-
sprintf_P(cmd, PSTR("G1 Z%s F500"), dtostrf(info.current_position.z + POWER_LOSS_ZRAISE, 1, 3, str_1));
420+
// Z was homed. Now move Z back up to the saved Z height, plus the POWER_LOSS_ZRAISE.
421+
sprintf_P(cmd, PSTR("G1Z%sF500"), dtostrf(info.current_position.z + POWER_LOSS_ZRAISE, 1, 3, str_1));
411422
gcode.process_subcommands_now(cmd);
412423
#endif
413424

@@ -447,7 +458,7 @@ void PrintJobRecovery::resume() {
447458
}
448459
#endif
449460

450-
// Restore retract and hop state
461+
// Restore retract and hop state from an active `G10` command
451462
#if ENABLED(FWRETRACT)
452463
LOOP_L_N(e, EXTRUDERS) {
453464
if (info.retract[e] != 0.0) {
@@ -462,7 +473,7 @@ void PrintJobRecovery::resume() {
462473
// Restore leveling state before 'G92 Z' to ensure
463474
// the Z stepper count corresponds to the native Z.
464475
if (info.fade || info.flag.leveling) {
465-
sprintf_P(cmd, PSTR("M420 S%i Z%s"), int(info.flag.leveling), dtostrf(info.fade, 1, 1, str_1));
476+
sprintf_P(cmd, PSTR("M420S%cZ%s"), '0' + (char)info.flag.leveling, dtostrf(info.fade, 1, 1, str_1));
466477
gcode.process_subcommands_now(cmd);
467478
}
468479
#endif
@@ -472,11 +483,11 @@ void PrintJobRecovery::resume() {
472483
#endif
473484

474485
// Un-retract if there was a retract at outage
475-
#if POWER_LOSS_RETRACT_LEN
486+
#if ENABLED(BACKUP_POWER_SUPPLY) && POWER_LOSS_RETRACT_LEN > 0
476487
gcode.process_subcommands_now_P(PSTR("G1 E" STRINGIFY(POWER_LOSS_RETRACT_LEN) " F3000"));
477488
#endif
478489

479-
// Additional purge if configured
490+
// Additional purge on resume if configured
480491
#if POWER_LOSS_PURGE_LEN
481492
sprintf_P(cmd, PSTR("G1 E%d F3000"), (POWER_LOSS_PURGE_LEN) + (POWER_LOSS_RETRACT_LEN));
482493
gcode.process_subcommands_now(cmd);

Marlin/src/lcd/extui/lib/dgus/mks/DGUSDisplayDef.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,15 @@ constexpr feedRate_t park_speed_xy = TERN(NOZZLE_PARK_FEATURE, NOZZLE_PARK_XY_FE
8282
void MKS_pause_print_move() {
8383
queue.exhaust();
8484
position_before_pause = current_position;
85+
86+
// Save the current position, the raise amount, and 'already raised'
87+
TERN_(POWER_LOSS_RECOVERY, if (recovery.enabled) recovery.save(true, mks_park_pos.z, true));
88+
8589
destination.z = _MIN(current_position.z + mks_park_pos.z, Z_MAX_POS);
8690
prepare_internal_move_to_destination(park_speed_z);
91+
8792
destination.set(X_MIN_POS + mks_park_pos.x, Y_MIN_POS + mks_park_pos.y);
8893
prepare_internal_move_to_destination(park_speed_xy);
89-
TERN_(POWER_LOSS_RECOVERY, if (recovery.enabled) recovery.save(true, mks_park_pos.z, true));
9094
}
9195

9296
void MKS_resume_print_move() {

Marlin/src/libs/nozzle.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,18 @@ Nozzle nozzle;
225225

226226
#if ENABLED(NOZZLE_PARK_FEATURE)
227227

228+
float Nozzle::park_mode_0_height(const_float_t park_z) {
229+
// Apply a minimum raise, if specified. Use park.z as a minimum height instead.
230+
return _MAX(park_z, // Minimum height over 0 based on input
231+
_MIN(Z_MAX_POS, // Maximum height is fixed
232+
#ifdef NOZZLE_PARK_Z_RAISE_MIN
233+
NOZZLE_PARK_Z_RAISE_MIN + // Minimum raise...
234+
#endif
235+
current_position.z // ...over current position
236+
)
237+
);
238+
}
239+
228240
void Nozzle::park(const uint8_t z_action, const xyz_pos_t &park/*=NOZZLE_PARK_POINT*/) {
229241
constexpr feedRate_t fr_xy = NOZZLE_PARK_XY_FEEDRATE, fr_z = NOZZLE_PARK_Z_FEEDRATE;
230242

@@ -237,15 +249,9 @@ Nozzle nozzle;
237249
do_blocking_move_to_z(_MIN(current_position.z + park.z, Z_MAX_POS), fr_z);
238250
break;
239251

240-
default: {
241-
// Apply a minimum raise, overriding G27 Z
242-
const float min_raised_z =_MIN(Z_MAX_POS, current_position.z
243-
#ifdef NOZZLE_PARK_Z_RAISE_MIN
244-
+ NOZZLE_PARK_Z_RAISE_MIN
245-
#endif
246-
);
247-
do_blocking_move_to_z(_MAX(park.z, min_raised_z), fr_z);
248-
} break;
252+
default: // Raise by NOZZLE_PARK_Z_RAISE_MIN, use park.z as a minimum height
253+
do_blocking_move_to_z(park_mode_0_height(park.z), fr_z);
254+
break;
249255
}
250256

251257
do_blocking_move_to_xy(

Marlin/src/libs/nozzle.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class Nozzle {
8383

8484
#if ENABLED(NOZZLE_PARK_FEATURE)
8585

86+
static float park_mode_0_height(const_float_t park_z) _Os;
8687
static void park(const uint8_t z_action, const xyz_pos_t &park=NOZZLE_PARK_POINT) _Os;
8788

8889
#endif

0 commit comments

Comments
 (0)