Browse Source

Safe Z homing for Power Loss Recovery (#16909)

Nick 4 years ago
parent
commit
e66e51fa6d
No account linked to committer's email address

+ 6
- 1
Marlin/Configuration_adv.h View File

1256
   #if ENABLED(POWER_LOSS_RECOVERY)
1256
   #if ENABLED(POWER_LOSS_RECOVERY)
1257
     #define PLR_ENABLED_DEFAULT   false // Power Loss Recovery enabled by default. (Set with 'M413 Sn' & M500)
1257
     #define PLR_ENABLED_DEFAULT   false // Power Loss Recovery enabled by default. (Set with 'M413 Sn' & M500)
1258
     //#define BACKUP_POWER_SUPPLY       // Backup power / UPS to move the steppers on power loss
1258
     //#define BACKUP_POWER_SUPPLY       // Backup power / UPS to move the steppers on power loss
1259
-    //#define POWER_LOSS_RECOVER_ZHOME  // Z homing is needed for proper recovery. 99.9% of the time this should be disabled!
1260
     //#define POWER_LOSS_ZRAISE       2 // (mm) Z axis raise on resume (on power loss with UPS)
1259
     //#define POWER_LOSS_ZRAISE       2 // (mm) Z axis raise on resume (on power loss with UPS)
1261
     //#define POWER_LOSS_PIN         44 // Pin to detect power loss. Set to -1 to disable default pin on boards without module.
1260
     //#define POWER_LOSS_PIN         44 // Pin to detect power loss. Set to -1 to disable default pin on boards without module.
1262
     //#define POWER_LOSS_STATE     HIGH // State of pin indicating power loss
1261
     //#define POWER_LOSS_STATE     HIGH // State of pin indicating power loss
1268
     // Without a POWER_LOSS_PIN the following option helps reduce wear on the SD card,
1267
     // Without a POWER_LOSS_PIN the following option helps reduce wear on the SD card,
1269
     // especially with "vase mode" printing. Set too high and vases cannot be continued.
1268
     // especially with "vase mode" printing. Set too high and vases cannot be continued.
1270
     #define POWER_LOSS_MIN_Z_CHANGE 0.05 // (mm) Minimum Z change before saving power-loss data
1269
     #define POWER_LOSS_MIN_Z_CHANGE 0.05 // (mm) Minimum Z change before saving power-loss data
1270
+
1271
+    // Enable if Z homing is needed for proper recovery. 99.9% of the time this should be disabled!
1272
+    //#define POWER_LOSS_RECOVER_ZHOME
1273
+    #if ENABLED(POWER_LOSS_RECOVER_ZHOME)
1274
+      //#define POWER_LOSS_ZHOME_POS { 0, 0 } // Safe XY position to home Z while avoiding objects on the bed
1275
+    #endif
1271
   #endif
1276
   #endif
1272
 
1277
 
1273
   /**
1278
   /**

+ 12
- 5
Marlin/src/feature/powerloss.cpp View File

384
     // Home safely with no Z raise
384
     // Home safely with no Z raise
385
     gcode.process_subcommands_now_P(PSTR(
385
     gcode.process_subcommands_now_P(PSTR(
386
       "G28R0"                               // No raise during G28
386
       "G28R0"                               // No raise during G28
387
-      #if IS_CARTESIAN && DISABLED(POWER_LOSS_RECOVER_ZHOME)
387
+      #if IS_CARTESIAN && (DISABLED(POWER_LOSS_RECOVER_ZHOME) || defined(POWER_LOSS_ZHOME_POS))
388
         "XY"                                // Don't home Z on Cartesian unless overridden
388
         "XY"                                // Don't home Z on Cartesian unless overridden
389
       #endif
389
       #endif
390
     ));
390
     ));
391
 
391
 
392
   #endif
392
   #endif
393
 
393
 
394
-  // Pretend that all axes are homed
394
+  #ifdef POWER_LOSS_ZHOME_POS
395
+    // If defined move to a safe Z homing position that avoids the print
396
+    constexpr xy_pos_t homepos = POWER_LOSS_ZHOME_POS;
397
+    sprintf_P(cmd, PSTR("G1 X%s Y%s F1000\nG28Z", dtostrf(homepos.x, 1, 3, str_1), dtostrf(homepos.y, 1, 3, str_2)));
398
+    gcode.process_subcommands_now(cmd);
399
+  #endif
400
+
401
+  // Ensure that all axes are marked as homed
395
   set_all_homed();
402
   set_all_homed();
396
 
403
 
397
   #if ENABLED(POWER_LOSS_RECOVER_ZHOME)
404
   #if ENABLED(POWER_LOSS_RECOVER_ZHOME)
398
-    // Z has been homed so restore Z to ZsavedPos + POWER_LOSS_ZRAISE
405
+    // Now move to ZsavedPos + POWER_LOSS_ZRAISE
399
     sprintf_P(cmd, PSTR("G1 F500 Z%s"), dtostrf(info.current_position.z + POWER_LOSS_ZRAISE, 1, 3, str_1));
406
     sprintf_P(cmd, PSTR("G1 F500 Z%s"), dtostrf(info.current_position.z + POWER_LOSS_ZRAISE, 1, 3, str_1));
400
     gcode.process_subcommands_now(cmd);
407
     gcode.process_subcommands_now(cmd);
401
   #endif
408
   #endif
467
 
474
 
468
   // Additional purge if configured
475
   // Additional purge if configured
469
   #if POWER_LOSS_PURGE_LEN
476
   #if POWER_LOSS_PURGE_LEN
470
-    sprintf_P(cmd, PSTR("G1 E%d F200"), (POWER_LOSS_PURGE_LEN) + (POWER_LOSS_RETRACT_LEN));
477
+    sprintf_P(cmd, PSTR("G1 E%d F3000"), (POWER_LOSS_PURGE_LEN) + (POWER_LOSS_RETRACT_LEN));
471
     gcode.process_subcommands_now(cmd);
478
     gcode.process_subcommands_now(cmd);
472
   #endif
479
   #endif
473
 
480
 
485
   // Move back to the saved Z
492
   // Move back to the saved Z
486
   dtostrf(info.current_position.z, 1, 3, str_1);
493
   dtostrf(info.current_position.z, 1, 3, str_1);
487
   #if Z_HOME_DIR > 0 || ENABLED(POWER_LOSS_RECOVER_ZHOME)
494
   #if Z_HOME_DIR > 0 || ENABLED(POWER_LOSS_RECOVER_ZHOME)
488
-    sprintf_P(cmd, PSTR("G1 Z%s F200"), str_1);
495
+    sprintf_P(cmd, PSTR("G1 Z%s F500"), str_1);
489
   #else
496
   #else
490
     gcode.process_subcommands_now_P(PSTR("G1 Z0 F200"));
497
     gcode.process_subcommands_now_P(PSTR("G1 Z0 F200"));
491
     sprintf_P(cmd, PSTR("G92.9 Z%s"), str_1);
498
     sprintf_P(cmd, PSTR("G92.9 Z%s"), str_1);

+ 11
- 7
Marlin/src/inc/SanityCheck.h View File

1641
  * Allen Key
1641
  * Allen Key
1642
  * Deploying the Allen Key probe uses big moves in z direction. Too dangerous for an unhomed z-axis.
1642
  * Deploying the Allen Key probe uses big moves in z direction. Too dangerous for an unhomed z-axis.
1643
  */
1643
  */
1644
-#if BOTH(Z_PROBE_ALLEN_KEY, Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) && (Z_HOME_DIR < 0)
1644
+#if BOTH(Z_PROBE_ALLEN_KEY, Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) && Z_HOME_DIR < 0
1645
   #error "You can't home to a Z min endstop with a Z_PROBE_ALLEN_KEY."
1645
   #error "You can't home to a Z min endstop with a Z_PROBE_ALLEN_KEY."
1646
 #endif
1646
 #endif
1647
 
1647
 
2913
   #endif
2913
   #endif
2914
 #endif
2914
 #endif
2915
 
2915
 
2916
-#if ENABLED(BACKUP_POWER_SUPPLY) && !PIN_EXISTS(POWER_LOSS)
2917
-  #error "BACKUP_POWER_SUPPLY requires a POWER_LOSS_PIN."
2918
-#endif
2919
-
2920
-#if BOTH(POWER_LOSS_PULLUP, POWER_LOSS_PULLDOWN)
2921
-  #error "You can't enable POWER_LOSS_PULLUP and POWER_LOSS_PULLDOWN at the same time."
2916
+#if ENABLED(POWER_LOSS_RECOVERY)
2917
+  #if ENABLED(BACKUP_POWER_SUPPLY) && !PIN_EXISTS(POWER_LOSS)
2918
+    #error "BACKUP_POWER_SUPPLY requires a POWER_LOSS_PIN."
2919
+  #elif BOTH(POWER_LOSS_RECOVER_ZHOME, Z_SAFE_HOMING)
2920
+    #error "POWER_LOSS_RECOVER_ZHOME cannot be used with Z_SAFE_HOMING."
2921
+  #elif BOTH(POWER_LOSS_PULLUP, POWER_LOSS_PULLDOWN)
2922
+    #error "You can't enable POWER_LOSS_PULLUP and POWER_LOSS_PULLDOWN at the same time."
2923
+  #elif BOTH(IS_CARTESIAN, POWER_LOSS_RECOVER_ZHOME) && Z_HOME_DIR < 0 && !defined(POWER_LOSS_ZHOME_POS)
2924
+    #error "POWER_LOSS_RECOVER_ZHOME requires POWER_LOSS_ZHOME_POS for a Cartesian that homes to ZMIN."
2925
+  #endif
2922
 #endif
2926
 #endif
2923
 
2927
 
2924
 #if ENABLED(Z_STEPPER_AUTO_ALIGN)
2928
 #if ENABLED(Z_STEPPER_AUTO_ALIGN)

+ 4
- 4
Marlin/src/module/probe.cpp View File

340
    *  - If a preheat input is higher than the current target, raise the target temperature.
340
    *  - If a preheat input is higher than the current target, raise the target temperature.
341
    *  - If a preheat input is higher than the current temperature, wait for stabilization.
341
    *  - If a preheat input is higher than the current temperature, wait for stabilization.
342
    */
342
    */
343
-  void Probe::preheat_for_probing(const uint16_t hotend_temp, const uint16_t bed_temp) {
343
+  void Probe::preheat_for_probing(const int16_t hotend_temp, const int16_t bed_temp) {
344
     #if HAS_HOTEND && (PROBING_NOZZLE_TEMP || LEVELING_NOZZLE_TEMP)
344
     #if HAS_HOTEND && (PROBING_NOZZLE_TEMP || LEVELING_NOZZLE_TEMP)
345
       #define WAIT_FOR_NOZZLE_HEAT
345
       #define WAIT_FOR_NOZZLE_HEAT
346
     #endif
346
     #endif
351
     DEBUG_ECHOPGM("Preheating ");
351
     DEBUG_ECHOPGM("Preheating ");
352
 
352
 
353
     #if ENABLED(WAIT_FOR_NOZZLE_HEAT)
353
     #if ENABLED(WAIT_FOR_NOZZLE_HEAT)
354
-      const uint16_t hotendPreheat = hotend_temp > thermalManager.degTargetHotend(0) ? hotend_temp : 0;
354
+      const int16_t hotendPreheat = hotend_temp > thermalManager.degTargetHotend(0) ? hotend_temp : 0;
355
       if (hotendPreheat) {
355
       if (hotendPreheat) {
356
         DEBUG_ECHOPAIR("hotend (", hotendPreheat, ")");
356
         DEBUG_ECHOPAIR("hotend (", hotendPreheat, ")");
357
         thermalManager.setTargetHotend(hotendPreheat, 0);
357
         thermalManager.setTargetHotend(hotendPreheat, 0);
358
       }
358
       }
359
     #elif ENABLED(WAIT_FOR_BED_HEAT)
359
     #elif ENABLED(WAIT_FOR_BED_HEAT)
360
-      constexpr uint16_t hotendPreheat = 0;
360
+      constexpr int16_t hotendPreheat = 0;
361
     #endif
361
     #endif
362
 
362
 
363
     #if ENABLED(WAIT_FOR_BED_HEAT)
363
     #if ENABLED(WAIT_FOR_BED_HEAT)
364
-      const uint16_t bedPreheat = bed_temp > thermalManager.degTargetBed() ? bed_temp : 0;
364
+      const int16_t bedPreheat = bed_temp > thermalManager.degTargetBed() ? bed_temp : 0;
365
       if (bedPreheat) {
365
       if (bedPreheat) {
366
         if (hotendPreheat) DEBUG_ECHOPGM(" and ");
366
         if (hotendPreheat) DEBUG_ECHOPGM(" and ");
367
         DEBUG_ECHOPAIR("bed (", bedPreheat, ")");
367
         DEBUG_ECHOPAIR("bed (", bedPreheat, ")");

+ 1
- 1
Marlin/src/module/probe.h View File

61
     static xyz_pos_t offset;
61
     static xyz_pos_t offset;
62
 
62
 
63
     #if EITHER(PREHEAT_BEFORE_PROBING, PREHEAT_BEFORE_LEVELING)
63
     #if EITHER(PREHEAT_BEFORE_PROBING, PREHEAT_BEFORE_LEVELING)
64
-      static void preheat_for_probing(const uint16_t hotend_temp, const uint16_t bed_temp);
64
+      static void preheat_for_probing(const int16_t hotend_temp, const int16_t bed_temp);
65
     #endif
65
     #endif
66
 
66
 
67
     static bool set_deployed(const bool deploy);
67
     static bool set_deployed(const bool deploy);

+ 5
- 3
buildroot/tests/rambo-tests View File

22
 opt_add HEATER_CHAMBER_PIN 45
22
 opt_add HEATER_CHAMBER_PIN 45
23
 opt_set GRID_MAX_POINTS_X 16
23
 opt_set GRID_MAX_POINTS_X 16
24
 opt_set FANMUX0_PIN 53
24
 opt_set FANMUX0_PIN 53
25
-opt_disable USE_WATCHDOG
25
+opt_set Z_HOME_DIR 1
26
+opt_enable USE_ZMAX_PLUG
27
+opt_disable USE_ZMIN_PLUG Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN USE_WATCHDOG
26
 opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER LCD_PROGRESS_BAR LCD_PROGRESS_BAR_TEST \
28
 opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER LCD_PROGRESS_BAR LCD_PROGRESS_BAR_TEST \
27
-           FIX_MOUNTED_PROBE Z_SAFE_HOMING CODEPENDENT_XY_HOMING PIDTEMPBED PROBE_TEMP_COMPENSATION \
29
+           FIX_MOUNTED_PROBE CODEPENDENT_XY_HOMING PIDTEMPBED PROBE_TEMP_COMPENSATION \
28
            PREHEAT_BEFORE_PROBING PROBING_HEATERS_OFF PROBING_FANS_OFF PROBING_STEPPERS_OFF WAIT_FOR_BED_HEATER \
30
            PREHEAT_BEFORE_PROBING PROBING_HEATERS_OFF PROBING_FANS_OFF PROBING_STEPPERS_OFF WAIT_FOR_BED_HEATER \
29
            EEPROM_SETTINGS SDSUPPORT SD_REPRINT_LAST_SELECTED_FILE BINARY_FILE_TRANSFER \
31
            EEPROM_SETTINGS SDSUPPORT SD_REPRINT_LAST_SELECTED_FILE BINARY_FILE_TRANSFER \
30
            BLINKM PCA9533 PCA9632 RGB_LED RGB_LED_R_PIN RGB_LED_G_PIN RGB_LED_B_PIN LED_CONTROL_MENU \
32
            BLINKM PCA9533 PCA9632 RGB_LED RGB_LED_R_PIN RGB_LED_G_PIN RGB_LED_B_PIN LED_CONTROL_MENU \
38
            SKEW_CORRECTION SKEW_CORRECTION_FOR_Z SKEW_CORRECTION_GCODE \
40
            SKEW_CORRECTION SKEW_CORRECTION_FOR_Z SKEW_CORRECTION_GCODE \
39
            BACKLASH_COMPENSATION BACKLASH_GCODE BAUD_RATE_GCODE BEZIER_CURVE_SUPPORT \
41
            BACKLASH_COMPENSATION BACKLASH_GCODE BAUD_RATE_GCODE BEZIER_CURVE_SUPPORT \
40
            FWRETRACT ARC_P_CIRCLES CNC_WORKSPACE_PLANES CNC_COORDINATE_SYSTEMS \
42
            FWRETRACT ARC_P_CIRCLES CNC_WORKSPACE_PLANES CNC_COORDINATE_SYSTEMS \
41
-           PSU_CONTROL AUTO_POWER_CONTROL POWER_LOSS_RECOVERY POWER_LOSS_PIN POWER_LOSS_STATE \
43
+           PSU_CONTROL AUTO_POWER_CONTROL POWER_LOSS_RECOVERY POWER_LOSS_PIN POWER_LOSS_STATE POWER_LOSS_RECOVER_ZHOME \
42
            SLOW_PWM_HEATERS THERMAL_PROTECTION_CHAMBER LIN_ADVANCE EXTRA_LIN_ADVANCE_K \
44
            SLOW_PWM_HEATERS THERMAL_PROTECTION_CHAMBER LIN_ADVANCE EXTRA_LIN_ADVANCE_K \
43
            HOST_ACTION_COMMANDS HOST_PROMPT_SUPPORT PINS_DEBUGGING MAX7219_DEBUG M114_DETAIL
45
            HOST_ACTION_COMMANDS HOST_PROMPT_SUPPORT PINS_DEBUGGING MAX7219_DEBUG M114_DETAIL
44
 opt_add DEBUG_POWER_LOSS_RECOVERY
46
 opt_add DEBUG_POWER_LOSS_RECOVERY

Loading…
Cancel
Save