|
@@ -144,7 +144,7 @@ void PrintJobRecovery::prepare() {
|
144
|
144
|
/**
|
145
|
145
|
* Save the current machine state to the power-loss recovery file
|
146
|
146
|
*/
|
147
|
|
-void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=0*/) {
|
|
147
|
+void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POWER_LOSS_ZRAISE*/, const bool raised/*=false*/) {
|
148
|
148
|
|
149
|
149
|
// We don't check IS_SD_PRINTING here so a save may occur during a pause
|
150
|
150
|
|
|
@@ -181,14 +181,12 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=0*/
|
181
|
181
|
info.current_position = current_position;
|
182
|
182
|
info.feedrate = uint16_t(MMS_TO_MMM(feedrate_mm_s));
|
183
|
183
|
info.zraise = zraise;
|
|
184
|
+ info.flag.raised = raised; // Was Z raised before power-off?
|
184
|
185
|
|
185
|
186
|
TERN_(GCODE_REPEAT_MARKERS, info.stored_repeat = repeat);
|
186
|
187
|
TERN_(HAS_HOME_OFFSET, info.home_offset = home_offset);
|
187
|
188
|
TERN_(HAS_POSITION_SHIFT, info.position_shift = position_shift);
|
188
|
|
-
|
189
|
|
- #if HAS_MULTI_EXTRUDER
|
190
|
|
- info.active_extruder = active_extruder;
|
191
|
|
- #endif
|
|
189
|
+ TERN_(HAS_MULTI_EXTRUDER, info.active_extruder = active_extruder);
|
192
|
190
|
|
193
|
191
|
#if DISABLED(NO_VOLUMETRICS)
|
194
|
192
|
info.flag.volumetric_enabled = parser.volumetric_enabled;
|
|
@@ -289,8 +287,9 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=0*/
|
289
|
287
|
constexpr float zraise = 0;
|
290
|
288
|
#endif
|
291
|
289
|
|
292
|
|
- // Save, including the limited Z raise
|
293
|
|
- if (IS_SD_PRINTING()) save(true, zraise);
|
|
290
|
+ // Save the current position, distance that Z was (or should be) raised,
|
|
291
|
+ // and a flag whether the raise was already done here.
|
|
292
|
+ if (IS_SD_PRINTING()) save(true, zraise, ENABLED(BACKUP_POWER_SUPPLY));
|
294
|
293
|
|
295
|
294
|
// Disable all heaters to reduce power loss
|
296
|
295
|
thermalManager.disable_all_heaters();
|
|
@@ -350,10 +349,10 @@ void PrintJobRecovery::resume() {
|
350
|
349
|
}
|
351
|
350
|
#endif
|
352
|
351
|
|
353
|
|
- // Restore all hotend temperatures
|
|
352
|
+ // Heat hotend enough to soften material
|
354
|
353
|
#if HAS_HOTEND
|
355
|
354
|
HOTEND_LOOP() {
|
356
|
|
- const celsius_t et = info.target_temperature[e];
|
|
355
|
+ const celsius_t et = _MAX(info.target_temperature[e], 180);
|
357
|
356
|
if (et) {
|
358
|
357
|
#if HAS_MULTI_HOTEND
|
359
|
358
|
sprintf_P(cmd, PSTR("T%iS"), e);
|
|
@@ -365,37 +364,59 @@ void PrintJobRecovery::resume() {
|
365
|
364
|
}
|
366
|
365
|
#endif
|
367
|
366
|
|
|
367
|
+ // Interpret the saved Z according to flags
|
|
368
|
+ const float z_print = info.current_position.z,
|
|
369
|
+ z_raised = z_print + info.zraise;
|
|
370
|
+
|
368
|
371
|
//
|
369
|
372
|
// Home the axes that can safely be homed, and
|
370
|
373
|
// establish the current position as best we can.
|
371
|
374
|
//
|
|
375
|
+
|
|
376
|
+ gcode.process_subcommands_now_P(PSTR("G92.9E0")); // Reset E to 0
|
|
377
|
+
|
372
|
378
|
#if Z_HOME_DIR > 0
|
373
|
379
|
|
374
|
|
- // If Z homing goes to max...
|
|
380
|
+ float z_now = z_raised;
|
|
381
|
+
|
|
382
|
+ // If Z homing goes to max then just move back to the "raised" position
|
375
|
383
|
gcode.process_subcommands_now_P(PSTR(
|
376
|
|
- "G92.9 E0\n" // Reset E to 0
|
377
|
|
- "G28R0" // Home all axes (no raise)
|
378
|
|
- ));
|
|
384
|
+ "G28R0\n" // Home all axes (no raise)
|
|
385
|
+ "G1Z%sF1200" // Move Z down to (raised) height
|
|
386
|
+ ),
|
|
387
|
+ dtostrf(z_now, 1, 3, str_1)
|
|
388
|
+ );
|
379
|
389
|
|
380
|
390
|
#else
|
381
|
391
|
|
382
|
|
- // If a Z raise occurred at outage restore Z, otherwise raise Z now
|
383
|
|
- sprintf_P(cmd, PSTR("G92.9 E0 " TERN(BACKUP_POWER_SUPPLY, "Z%s", "Z0\nG1Z%s")), dtostrf(info.zraise, 1, 3, str_1));
|
384
|
|
- gcode.process_subcommands_now(cmd);
|
|
392
|
+ #if ENABLED(POWER_LOSS_RECOVER_ZHOME) && defined(POWER_LOSS_ZHOME_POS)
|
|
393
|
+ #define HOMING_Z_DOWN 1
|
|
394
|
+ #else
|
|
395
|
+ #define HOME_XY_ONLY 1
|
|
396
|
+ #endif
|
385
|
397
|
|
386
|
|
- // Home safely with no Z raise
|
387
|
|
- gcode.process_subcommands_now_P(PSTR(
|
388
|
|
- "G28R0" // No raise during G28
|
389
|
|
- #if IS_CARTESIAN && (DISABLED(POWER_LOSS_RECOVER_ZHOME) || defined(POWER_LOSS_ZHOME_POS))
|
390
|
|
- "XY" // Don't home Z on Cartesian unless overridden
|
391
|
|
- #endif
|
392
|
|
- ));
|
|
398
|
+ float z_now = info.flag.raised ? z_raised : z_print;
|
|
399
|
+
|
|
400
|
+ // Reset E to 0 and set Z to the real position
|
|
401
|
+ #if HOME_XY_ONLY
|
|
402
|
+ sprintf_P(cmd, PSTR("G92.9Z%s"), dtostrf(z_now, 1, 3, str_1));
|
|
403
|
+ gcode.process_subcommands_now(cmd);
|
|
404
|
+ #endif
|
|
405
|
+
|
|
406
|
+ // Does Z need to be raised now? It should be raised before homing XY.
|
|
407
|
+ if (z_raised > z_now) {
|
|
408
|
+ z_now = z_raised;
|
|
409
|
+ sprintf_P(cmd, PSTR("G1Z%sF600"), dtostrf(z_now, 1, 3, str_1));
|
|
410
|
+ gcode.process_subcommands_now(cmd);
|
|
411
|
+ }
|
|
412
|
+
|
|
413
|
+ // Home XY with no Z raise, and also home Z here if Z isn't homing down below.
|
|
414
|
+ gcode.process_subcommands_now_P(PSTR("G28R0" TERN_(HOME_XY_ONLY, "XY"))); // No raise during G28
|
393
|
415
|
|
394
|
416
|
#endif
|
395
|
417
|
|
396
|
|
- #if ENABLED(POWER_LOSS_RECOVER_ZHOME) && defined(POWER_LOSS_ZHOME_POS)
|
397
|
|
- // Move to a safe XY position where Z can home while avoiding the print.
|
398
|
|
- // If Z_SAFE_HOMING is enabled, its position must also be outside the print area!
|
|
418
|
+ #if HOMING_Z_DOWN
|
|
419
|
+ // Move to a safe XY position and home Z while avoiding the print.
|
399
|
420
|
constexpr xy_pos_t p = POWER_LOSS_ZHOME_POS;
|
400
|
421
|
sprintf_P(cmd, PSTR("G1X%sY%sF1000\nG28Z"), dtostrf(p.x, 1, 3, str_1), dtostrf(p.y, 1, 3, str_2));
|
401
|
422
|
gcode.process_subcommands_now(cmd);
|
|
@@ -404,9 +425,24 @@ void PrintJobRecovery::resume() {
|
404
|
425
|
// Mark all axes as having been homed (no effect on current_position)
|
405
|
426
|
set_all_homed();
|
406
|
427
|
|
|
428
|
+ #if HAS_LEVELING
|
|
429
|
+ // Restore Z fade and possibly re-enable bed leveling compensation.
|
|
430
|
+ // Leveling may already be enabled due to the ENABLE_LEVELING_AFTER_G28 option.
|
|
431
|
+ // TODO: Add a G28 parameter to leave leveling disabled.
|
|
432
|
+ sprintf_P(cmd, PSTR("M420S%cZ%s"), '0' + (char)info.flag.leveling, dtostrf(info.fade, 1, 1, str_1));
|
|
433
|
+ gcode.process_subcommands_now(cmd);
|
|
434
|
+
|
|
435
|
+ #if HOME_XY_ONLY
|
|
436
|
+ // The physical Z was adjusted at power-off so undo the M420S1 correction to Z with G92.9.
|
|
437
|
+ sprintf_P(cmd, PSTR("G92.9Z%s"), dtostrf(z_now, 1, 1, str_1));
|
|
438
|
+ gcode.process_subcommands_now(cmd);
|
|
439
|
+ #endif
|
|
440
|
+ #endif
|
|
441
|
+
|
407
|
442
|
#if ENABLED(POWER_LOSS_RECOVER_ZHOME)
|
408
|
|
- // Z was homed. Now move Z back up to the saved Z height, plus the POWER_LOSS_ZRAISE.
|
409
|
|
- sprintf_P(cmd, PSTR("G1Z%sF500"), dtostrf(info.current_position.z + POWER_LOSS_ZRAISE, 1, 3, str_1));
|
|
443
|
+ // Z was homed down to the bed, so move up to the raised height.
|
|
444
|
+ z_now = z_raised;
|
|
445
|
+ sprintf_P(cmd, PSTR("G1Z%sF600"), dtostrf(z_now, 1, 3, str_1));
|
410
|
446
|
gcode.process_subcommands_now(cmd);
|
411
|
447
|
#endif
|
412
|
448
|
|
|
@@ -429,8 +465,23 @@ void PrintJobRecovery::resume() {
|
429
|
465
|
#endif
|
430
|
466
|
#endif
|
431
|
467
|
|
432
|
|
- // Select the previously active tool (with no_move)
|
433
|
|
- #if HAS_MULTI_EXTRUDER
|
|
468
|
+ // Restore all hotend temperatures
|
|
469
|
+ #if HAS_HOTEND
|
|
470
|
+ HOTEND_LOOP() {
|
|
471
|
+ const celsius_t et = info.target_temperature[e];
|
|
472
|
+ if (et) {
|
|
473
|
+ #if HAS_MULTI_HOTEND
|
|
474
|
+ sprintf_P(cmd, PSTR("T%iS"), e);
|
|
475
|
+ gcode.process_subcommands_now(cmd);
|
|
476
|
+ #endif
|
|
477
|
+ sprintf_P(cmd, PSTR("M109S%i"), et);
|
|
478
|
+ gcode.process_subcommands_now(cmd);
|
|
479
|
+ }
|
|
480
|
+ }
|
|
481
|
+ #endif
|
|
482
|
+
|
|
483
|
+ // Restore the previously active tool (with no_move)
|
|
484
|
+ #if HAS_MULTI_EXTRUDER || HAS_MULTI_HOTEND
|
434
|
485
|
sprintf_P(cmd, PSTR("T%i S"), info.active_extruder);
|
435
|
486
|
gcode.process_subcommands_now(cmd);
|
436
|
487
|
#endif
|
|
@@ -457,15 +508,6 @@ void PrintJobRecovery::resume() {
|
457
|
508
|
fwretract.current_hop = info.retract_hop;
|
458
|
509
|
#endif
|
459
|
510
|
|
460
|
|
- #if HAS_LEVELING
|
461
|
|
- // Restore leveling state before 'G92 Z' to ensure
|
462
|
|
- // the Z stepper count corresponds to the native Z.
|
463
|
|
- if (info.fade || info.flag.leveling) {
|
464
|
|
- sprintf_P(cmd, PSTR("M420S%cZ%s"), '0' + (char)info.flag.leveling, dtostrf(info.fade, 1, 1, str_1));
|
465
|
|
- gcode.process_subcommands_now(cmd);
|
466
|
|
- }
|
467
|
|
- #endif
|
468
|
|
-
|
469
|
511
|
#if ENABLED(GRADIENT_MIX)
|
470
|
512
|
memcpy(&mixer.gradient, &info.gradient, sizeof(info.gradient));
|
471
|
513
|
#endif
|
|
@@ -492,14 +534,8 @@ void PrintJobRecovery::resume() {
|
492
|
534
|
);
|
493
|
535
|
gcode.process_subcommands_now(cmd);
|
494
|
536
|
|
495
|
|
- // Move back to the saved Z
|
496
|
|
- dtostrf(info.current_position.z, 1, 3, str_1);
|
497
|
|
- #if Z_HOME_DIR > 0 || ENABLED(POWER_LOSS_RECOVER_ZHOME)
|
498
|
|
- sprintf_P(cmd, PSTR("G1 Z%s F500"), str_1);
|
499
|
|
- #else
|
500
|
|
- gcode.process_subcommands_now_P(PSTR("G1 Z0 F200"));
|
501
|
|
- sprintf_P(cmd, PSTR("G92.9 Z%s"), str_1);
|
502
|
|
- #endif
|
|
537
|
+ // Move back down to the saved Z for printing
|
|
538
|
+ sprintf_P(cmd, PSTR("G1Z%sF600"), dtostrf(z_print, 1, 3, str_1));
|
503
|
539
|
gcode.process_subcommands_now(cmd);
|
504
|
540
|
|
505
|
541
|
// Restore the feedrate
|
|
@@ -552,7 +588,15 @@ void PrintJobRecovery::resume() {
|
552
|
588
|
}
|
553
|
589
|
DEBUG_EOL();
|
554
|
590
|
|
555
|
|
- DEBUG_ECHOLNPAIR("zraise: ", info.zraise);
|
|
591
|
+ DEBUG_ECHOLNPAIR("feedrate: ", info.feedrate);
|
|
592
|
+
|
|
593
|
+ DEBUG_ECHOLNPAIR("zraise: ", info.zraise, " ", info.flag.raised ? "(before)" : "");
|
|
594
|
+
|
|
595
|
+ #if ENABLED(GCODE_REPEAT_MARKERS)
|
|
596
|
+ DEBUG_ECHOLNPAIR("repeat index: ", info.stored_repeat.index);
|
|
597
|
+ LOOP_L_N(i, info.stored_repeat.index)
|
|
598
|
+ DEBUG_ECHOLNPAIR("..... sdpos: ", info.stored_repeat.marker.sdpos, " count: ", info.stored_repeat.marker.counter);
|
|
599
|
+ #endif
|
556
|
600
|
|
557
|
601
|
#if HAS_HOME_OFFSET
|
558
|
602
|
DEBUG_ECHOPGM("home_offset: ");
|
|
@@ -572,12 +616,16 @@ void PrintJobRecovery::resume() {
|
572
|
616
|
DEBUG_EOL();
|
573
|
617
|
#endif
|
574
|
618
|
|
575
|
|
- DEBUG_ECHOLNPAIR("feedrate: ", info.feedrate);
|
576
|
|
-
|
577
|
619
|
#if HAS_MULTI_EXTRUDER
|
578
|
620
|
DEBUG_ECHOLNPAIR("active_extruder: ", info.active_extruder);
|
579
|
621
|
#endif
|
580
|
622
|
|
|
623
|
+ #if DISABLED(NO_VOLUMETRICS)
|
|
624
|
+ DEBUG_ECHOPGM("filament_size:");
|
|
625
|
+ LOOP_L_N(i, EXTRUDERS) DEBUG_ECHOLNPAIR(" ", info.filament_size[i]);
|
|
626
|
+ DEBUG_EOL();
|
|
627
|
+ #endif
|
|
628
|
+
|
581
|
629
|
#if HAS_HOTEND
|
582
|
630
|
DEBUG_ECHOPGM("target_temperature: ");
|
583
|
631
|
HOTEND_LOOP() {
|
|
@@ -601,8 +649,9 @@ void PrintJobRecovery::resume() {
|
601
|
649
|
#endif
|
602
|
650
|
|
603
|
651
|
#if HAS_LEVELING
|
604
|
|
- DEBUG_ECHOLNPAIR("leveling: ", info.flag.leveling, " fade: ", info.fade);
|
|
652
|
+ DEBUG_ECHOLNPAIR("leveling: ", info.flag.leveling ? "ON" : "OFF", " fade: ", info.fade);
|
605
|
653
|
#endif
|
|
654
|
+
|
606
|
655
|
#if ENABLED(FWRETRACT)
|
607
|
656
|
DEBUG_ECHOPGM("retract: ");
|
608
|
657
|
for (int8_t e = 0; e < EXTRUDERS; e++) {
|
|
@@ -612,11 +661,28 @@ void PrintJobRecovery::resume() {
|
612
|
661
|
DEBUG_EOL();
|
613
|
662
|
DEBUG_ECHOLNPAIR("retract_hop: ", info.retract_hop);
|
614
|
663
|
#endif
|
|
664
|
+
|
|
665
|
+ // Mixing extruder and gradient
|
|
666
|
+ #if BOTH(MIXING_EXTRUDER, GRADIENT_MIX)
|
|
667
|
+ DEBUG_ECHOLNPAIR("gradient: ", info.gradient.enabled ? "ON" : "OFF");
|
|
668
|
+ #endif
|
|
669
|
+
|
615
|
670
|
DEBUG_ECHOLNPAIR("sd_filename: ", info.sd_filename);
|
616
|
671
|
DEBUG_ECHOLNPAIR("sdpos: ", info.sdpos);
|
617
|
672
|
DEBUG_ECHOLNPAIR("print_job_elapsed: ", info.print_job_elapsed);
|
618
|
|
- DEBUG_ECHOLNPAIR("dryrun: ", AS_DIGIT(info.flag.dryrun));
|
619
|
|
- DEBUG_ECHOLNPAIR("allow_cold_extrusion: ", info.flag.allow_cold_extrusion);
|
|
673
|
+
|
|
674
|
+ DEBUG_ECHOPGM("axis_relative:");
|
|
675
|
+ if (TEST(info.axis_relative, REL_X)) DEBUG_ECHOPGM(" REL_X");
|
|
676
|
+ if (TEST(info.axis_relative, REL_Y)) DEBUG_ECHOPGM(" REL_Y");
|
|
677
|
+ if (TEST(info.axis_relative, REL_Z)) DEBUG_ECHOPGM(" REL_Z");
|
|
678
|
+ if (TEST(info.axis_relative, REL_E)) DEBUG_ECHOPGM(" REL_E");
|
|
679
|
+ if (TEST(info.axis_relative, E_MODE_ABS)) DEBUG_ECHOPGM(" E_MODE_ABS");
|
|
680
|
+ if (TEST(info.axis_relative, E_MODE_REL)) DEBUG_ECHOPGM(" E_MODE_REL");
|
|
681
|
+ DEBUG_EOL();
|
|
682
|
+
|
|
683
|
+ DEBUG_ECHOLNPAIR("flag.dryrun: ", AS_DIGIT(info.flag.dryrun));
|
|
684
|
+ DEBUG_ECHOLNPAIR("flag.allow_cold_extrusion: ", AS_DIGIT(info.flag.allow_cold_extrusion));
|
|
685
|
+ DEBUG_ECHOLNPAIR("flag.volumetric_enabled: ", AS_DIGIT(info.flag.volumetric_enabled));
|
620
|
686
|
}
|
621
|
687
|
else
|
622
|
688
|
DEBUG_ECHOLNPGM("INVALID DATA");
|