Browse Source

🚸 Fix, Improve Power-Loss Recovery (#22828)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
MOHAMMAD RASIM 3 years ago
parent
commit
a323d6732b
No account linked to committer's email address

+ 28
- 15
Marlin/src/feature/powerloss.cpp View File

54
 #include "../module/temperature.h"
54
 #include "../module/temperature.h"
55
 #include "../core/serial.h"
55
 #include "../core/serial.h"
56
 
56
 
57
+#if HOMING_Z_WITH_PROBE
58
+  #include "../module/probe.h"
59
+#endif
60
+
57
 #if ENABLED(FWRETRACT)
61
 #if ENABLED(FWRETRACT)
58
   #include "fwretract.h"
62
   #include "fwretract.h"
59
 #endif
63
 #endif
178
     info.valid_foot = info.valid_head;
182
     info.valid_foot = info.valid_head;
179
 
183
 
180
     // Machine state
184
     // Machine state
181
-    info.current_position = current_position;
185
+    // info.sdpos and info.current_position are pre-filled from the Stepper ISR
186
+
182
     info.feedrate = uint16_t(MMS_TO_MMM(feedrate_mm_s));
187
     info.feedrate = uint16_t(MMS_TO_MMM(feedrate_mm_s));
183
     info.zraise = zraise;
188
     info.zraise = zraise;
184
     info.flag.raised = raised;                      // Was Z raised before power-off?
189
     info.flag.raised = raised;                      // Was Z raised before power-off?
265
 
270
 
266
   #endif
271
   #endif
267
 
272
 
273
+#endif // POWER_LOSS_PIN
274
+
275
+#if PIN_EXISTS(POWER_LOSS) || ENABLED(DEBUG_POWER_LOSS_RECOVERY)
276
+
268
   /**
277
   /**
269
    * An outage was detected by a sensor pin.
278
    * An outage was detected by a sensor pin.
270
    *  - If not SD printing, let the machine turn off on its own with no "KILL" screen
279
    *  - If not SD printing, let the machine turn off on its own with no "KILL" screen
273
    *  - If backup power is available Retract E and Raise Z
282
    *  - If backup power is available Retract E and Raise Z
274
    *  - Go to the KILL screen
283
    *  - Go to the KILL screen
275
    */
284
    */
276
-  void PrintJobRecovery::_outage() {
285
+  void PrintJobRecovery::_outage(TERN_(DEBUG_POWER_LOSS_RECOVERY, const bool simulated/*=false*/)) {
277
     #if ENABLED(BACKUP_POWER_SUPPLY)
286
     #if ENABLED(BACKUP_POWER_SUPPLY)
278
       static bool lock = false;
287
       static bool lock = false;
279
       if (lock) return; // No re-entrance from idle() during retract_and_lift()
288
       if (lock) return; // No re-entrance from idle() during retract_and_lift()
301
       retract_and_lift(zraise);
310
       retract_and_lift(zraise);
302
     #endif
311
     #endif
303
 
312
 
304
-    kill(GET_TEXT_F(MSG_OUTAGE_RECOVERY));
313
+    if (TERN0(DEBUG_POWER_LOSS_RECOVERY, simulated)) {
314
+      card.fileHasFinished();
315
+      current_position.reset();
316
+      sync_plan_position();
317
+    }
318
+    else
319
+      kill(GET_TEXT_F(MSG_OUTAGE_RECOVERY));
305
   }
320
   }
306
 
321
 
307
-#endif
322
+#endif // POWER_LOSS_PIN || DEBUG_POWER_LOSS_RECOVERY
308
 
323
 
309
 /**
324
 /**
310
  * Save the recovery info the recovery file
325
  * Save the recovery info the recovery file
390
 
405
 
391
     #if ENABLED(POWER_LOSS_RECOVER_ZHOME) && defined(POWER_LOSS_ZHOME_POS)
406
     #if ENABLED(POWER_LOSS_RECOVER_ZHOME) && defined(POWER_LOSS_ZHOME_POS)
392
       #define HOMING_Z_DOWN 1
407
       #define HOMING_Z_DOWN 1
393
-    #else
394
-      #define HOME_XY_ONLY 1
395
     #endif
408
     #endif
396
 
409
 
397
     float z_now = info.flag.raised ? z_raised : z_print;
410
     float z_now = info.flag.raised ? z_raised : z_print;
398
 
411
 
399
-    // Reset E to 0 and set Z to the real position
400
-    #if HOME_XY_ONLY
412
+    #if !HOMING_Z_DOWN
413
+      // Set Z to the real position
401
       sprintf_P(cmd, PSTR("G92.9Z%s"), dtostrf(z_now, 1, 3, str_1));
414
       sprintf_P(cmd, PSTR("G92.9Z%s"), dtostrf(z_now, 1, 3, str_1));
402
       gcode.process_subcommands_now(cmd);
415
       gcode.process_subcommands_now(cmd);
403
     #endif
416
     #endif
409
       gcode.process_subcommands_now(cmd);
422
       gcode.process_subcommands_now(cmd);
410
     }
423
     }
411
 
424
 
412
-    // Home XY with no Z raise, and also home Z here if Z isn't homing down below.
413
-    gcode.process_subcommands_now(F("G28R0" TERN_(HOME_XY_ONLY, "XY"))); // No raise during G28
425
+    // Home XY with no Z raise
426
+    gcode.process_subcommands_now(F("G28R0XY")); // No raise during G28
414
 
427
 
415
   #endif
428
   #endif
416
 
429
 
417
   #if HOMING_Z_DOWN
430
   #if HOMING_Z_DOWN
418
     // Move to a safe XY position and home Z while avoiding the print.
431
     // Move to a safe XY position and home Z while avoiding the print.
419
-    constexpr xy_pos_t p = POWER_LOSS_ZHOME_POS;
420
-    sprintf_P(cmd, PSTR("G1X%sY%sF1000\nG28Z"), dtostrf(p.x, 1, 3, str_1), dtostrf(p.y, 1, 3, str_2));
432
+    const xy_pos_t p = xy_pos_t(POWER_LOSS_ZHOME_POS) TERN_(HOMING_Z_WITH_PROBE, - probe.offset_xy);
433
+    sprintf_P(cmd, PSTR("G1X%sY%sF1000\nG28HZ"), dtostrf(p.x, 1, 3, str_1), dtostrf(p.y, 1, 3, str_2));
421
     gcode.process_subcommands_now(cmd);
434
     gcode.process_subcommands_now(cmd);
422
   #endif
435
   #endif
423
 
436
 
431
     sprintf_P(cmd, PSTR("M420S%cZ%s"), '0' + (char)info.flag.leveling, dtostrf(info.fade, 1, 1, str_1));
444
     sprintf_P(cmd, PSTR("M420S%cZ%s"), '0' + (char)info.flag.leveling, dtostrf(info.fade, 1, 1, str_1));
432
     gcode.process_subcommands_now(cmd);
445
     gcode.process_subcommands_now(cmd);
433
 
446
 
434
-    #if HOME_XY_ONLY
447
+    #if !HOMING_Z_DOWN
435
       // The physical Z was adjusted at power-off so undo the M420S1 correction to Z with G92.9.
448
       // The physical Z was adjusted at power-off so undo the M420S1 correction to Z with G92.9.
436
       sprintf_P(cmd, PSTR("G92.9Z%s"), dtostrf(z_now, 1, 1, str_1));
449
       sprintf_P(cmd, PSTR("G92.9Z%s"), dtostrf(z_now, 1, 1, str_1));
437
       gcode.process_subcommands_now(cmd);
450
       gcode.process_subcommands_now(cmd);
513
 
526
 
514
   // Un-retract if there was a retract at outage
527
   // Un-retract if there was a retract at outage
515
   #if ENABLED(BACKUP_POWER_SUPPLY) && POWER_LOSS_RETRACT_LEN > 0
528
   #if ENABLED(BACKUP_POWER_SUPPLY) && POWER_LOSS_RETRACT_LEN > 0
516
-    gcode.process_subcommands_now(F("G1E" STRINGIFY(POWER_LOSS_RETRACT_LEN) "F3000"));
529
+    gcode.process_subcommands_now(F("G1F3000E" STRINGIFY(POWER_LOSS_RETRACT_LEN)));
517
   #endif
530
   #endif
518
 
531
 
519
   // Additional purge on resume if configured
532
   // Additional purge on resume if configured
520
   #if POWER_LOSS_PURGE_LEN
533
   #if POWER_LOSS_PURGE_LEN
521
-    sprintf_P(cmd, PSTR("G1 E%d F3000"), (POWER_LOSS_PURGE_LEN) + (POWER_LOSS_RETRACT_LEN));
534
+    sprintf_P(cmd, PSTR("G1F3000E%d"), (POWER_LOSS_PURGE_LEN) + (POWER_LOSS_RETRACT_LEN));
522
     gcode.process_subcommands_now(cmd);
535
     gcode.process_subcommands_now(cmd);
523
   #endif
536
   #endif
524
 
537
 

+ 2
- 2
Marlin/src/feature/powerloss.h View File

216
       static void retract_and_lift(const_float_t zraise);
216
       static void retract_and_lift(const_float_t zraise);
217
     #endif
217
     #endif
218
 
218
 
219
-    #if PIN_EXISTS(POWER_LOSS)
219
+    #if PIN_EXISTS(POWER_LOSS) || ENABLED(DEBUG_POWER_LOSS_RECOVERY)
220
       friend class GcodeSuite;
220
       friend class GcodeSuite;
221
-      static void _outage();
221
+      static void _outage(TERN_(DEBUG_POWER_LOSS_RECOVERY, const bool simulated=false));
222
     #endif
222
     #endif
223
 };
223
 };
224
 
224
 

+ 8
- 3
Marlin/src/gcode/calibrate/G28.cpp View File

395
 
395
 
396
     TERN_(HOME_Z_FIRST, if (doZ) homeaxis(Z_AXIS));
396
     TERN_(HOME_Z_FIRST, if (doZ) homeaxis(Z_AXIS));
397
 
397
 
398
-    const float z_homing_height = parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT;
398
+    const bool seenR = parser.seenval('R');
399
+    const float z_homing_height = seenR ? parser.value_linear_units() : Z_HOMING_HEIGHT;
399
 
400
 
400
-    if (z_homing_height && (LINEAR_AXIS_GANG(doX, || doY, || TERN0(Z_SAFE_HOMING, doZ), || doI, || doJ, || doK))) {
401
+    if (z_homing_height && (seenR || LINEAR_AXIS_GANG(doX, || doY, || TERN0(Z_SAFE_HOMING, doZ), || doI, || doJ, || doK))) {
401
       // Raise Z before homing any other axes and z is not already high enough (never lower z)
402
       // Raise Z before homing any other axes and z is not already high enough (never lower z)
402
       if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Raise Z (before homing) by ", z_homing_height);
403
       if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Raise Z (before homing) by ", z_homing_height);
403
       do_z_clearance(z_homing_height);
404
       do_z_clearance(z_homing_height);
451
           stepper.set_separate_multi_axis(false);
452
           stepper.set_separate_multi_axis(false);
452
         #endif
453
         #endif
453
 
454
 
454
-        TERN(Z_SAFE_HOMING, home_z_safely(), homeaxis(Z_AXIS));
455
+        #if ENABLED(Z_SAFE_HOMING)
456
+          if (TERN1(POWER_LOSS_RECOVERY, !parser.seen_test('H'))) home_z_safely(); else homeaxis(Z_AXIS);
457
+        #else
458
+          homeaxis(Z_AXIS);
459
+        #endif
455
         probe.move_z_after_homing();
460
         probe.move_z_after_homing();
456
       }
461
       }
457
     #endif
462
     #endif

+ 2
- 3
Marlin/src/gcode/feature/powerloss/M413.cpp View File

48
     if (parser.seen_test('W')) recovery.save(true);
48
     if (parser.seen_test('W')) recovery.save(true);
49
     if (parser.seen_test('P')) recovery.purge();
49
     if (parser.seen_test('P')) recovery.purge();
50
     if (parser.seen_test('D')) recovery.debug(F("M413"));
50
     if (parser.seen_test('D')) recovery.debug(F("M413"));
51
-    #if PIN_EXISTS(POWER_LOSS)
52
-      if (parser.seen_test('O')) recovery._outage();
53
-    #endif
51
+    if (parser.seen_test('O')) recovery._outage(true);
52
+    if (parser.seen_test('C')) recovery.check();
54
     if (parser.seen_test('E')) SERIAL_ECHOF(recovery.exists() ? F("PLR Exists\n") : F("No PLR\n"));
53
     if (parser.seen_test('E')) SERIAL_ECHOF(recovery.exists() ? F("PLR Exists\n") : F("No PLR\n"));
55
     if (parser.seen_test('V')) SERIAL_ECHOF(recovery.valid() ? F("Valid\n") : F("Invalid\n"));
54
     if (parser.seen_test('V')) SERIAL_ECHOF(recovery.valid() ? F("Valid\n") : F("Invalid\n"));
56
   #endif
55
   #endif

+ 0
- 2
Marlin/src/inc/SanityCheck.h View File

3447
 #if ENABLED(POWER_LOSS_RECOVERY)
3447
 #if ENABLED(POWER_LOSS_RECOVERY)
3448
   #if ENABLED(BACKUP_POWER_SUPPLY) && !PIN_EXISTS(POWER_LOSS)
3448
   #if ENABLED(BACKUP_POWER_SUPPLY) && !PIN_EXISTS(POWER_LOSS)
3449
     #error "BACKUP_POWER_SUPPLY requires a POWER_LOSS_PIN."
3449
     #error "BACKUP_POWER_SUPPLY requires a POWER_LOSS_PIN."
3450
-  #elif BOTH(POWER_LOSS_RECOVER_ZHOME, Z_SAFE_HOMING)
3451
-    #error "POWER_LOSS_RECOVER_ZHOME cannot be used with Z_SAFE_HOMING."
3452
   #elif BOTH(POWER_LOSS_PULLUP, POWER_LOSS_PULLDOWN)
3450
   #elif BOTH(POWER_LOSS_PULLUP, POWER_LOSS_PULLDOWN)
3453
     #error "You can't enable POWER_LOSS_PULLUP and POWER_LOSS_PULLDOWN at the same time."
3451
     #error "You can't enable POWER_LOSS_PULLUP and POWER_LOSS_PULLDOWN at the same time."
3454
   #elif ENABLED(POWER_LOSS_RECOVER_ZHOME) && Z_HOME_TO_MAX
3452
   #elif ENABLED(POWER_LOSS_RECOVER_ZHOME) && Z_HOME_TO_MAX

+ 5
- 1
Marlin/src/module/planner.cpp View File

2809
 
2809
 
2810
   position = target;  // Update the position
2810
   position = target;  // Update the position
2811
 
2811
 
2812
+  #if ENABLED(POWER_LOSS_RECOVERY)
2813
+    block->sdpos = recovery.command_sdpos();
2814
+    block->start_position = position_float.asLogical();
2815
+  #endif
2816
+
2812
   TERN_(HAS_POSITION_FLOAT, position_float = target_float);
2817
   TERN_(HAS_POSITION_FLOAT, position_float = target_float);
2813
   TERN_(GRADIENT_MIX, mixer.gradient_control(target_float.z));
2818
   TERN_(GRADIENT_MIX, mixer.gradient_control(target_float.z));
2814
-  TERN_(POWER_LOSS_RECOVERY, block->sdpos = recovery.command_sdpos());
2815
 
2819
 
2816
   return true;        // Movement was accepted
2820
   return true;        // Movement was accepted
2817
 
2821
 

+ 2
- 1
Marlin/src/module/planner.h View File

244
 
244
 
245
   #if ENABLED(POWER_LOSS_RECOVERY)
245
   #if ENABLED(POWER_LOSS_RECOVERY)
246
     uint32_t sdpos;
246
     uint32_t sdpos;
247
+    xyze_pos_t start_position;
247
   #endif
248
   #endif
248
 
249
 
249
   #if ENABLED(LASER_POWER_INLINE)
250
   #if ENABLED(LASER_POWER_INLINE)
252
 
253
 
253
 } block_t;
254
 } block_t;
254
 
255
 
255
-#if ANY(LIN_ADVANCE, SCARA_FEEDRATE_SCALING, GRADIENT_MIX, LCD_SHOW_E_TOTAL)
256
+#if ANY(LIN_ADVANCE, SCARA_FEEDRATE_SCALING, GRADIENT_MIX, LCD_SHOW_E_TOTAL, POWER_LOSS_RECOVERY)
256
   #define HAS_POSITION_FLOAT 1
257
   #define HAS_POSITION_FLOAT 1
257
 #endif
258
 #endif
258
 
259
 

+ 4
- 1
Marlin/src/module/stepper.cpp View File

2151
         cutter.apply_power(current_block->cutter_power);
2151
         cutter.apply_power(current_block->cutter_power);
2152
       #endif
2152
       #endif
2153
 
2153
 
2154
-      TERN_(POWER_LOSS_RECOVERY, recovery.info.sdpos = current_block->sdpos);
2154
+      #if ENABLED(POWER_LOSS_RECOVERY)
2155
+        recovery.info.sdpos = current_block->sdpos;
2156
+        recovery.info.current_position = current_block->start_position;
2157
+      #endif
2155
 
2158
 
2156
       #if ENABLED(DIRECT_STEPPING)
2159
       #if ENABLED(DIRECT_STEPPING)
2157
         if (IS_PAGE(current_block)) {
2160
         if (IS_PAGE(current_block)) {

Loading…
Cancel
Save