Browse Source

⚡️ Improve Sensorless homing/probing accuracy for G28, G33, M48 (#24220)

Co-authored-by: Robby Candra <robbycandra.mail@gmail.com>
Co-authored-by: ellensp <530024+ellensp@users.noreply.github.com>
lujios 3 years ago
parent
commit
41f73cb457
No account linked to committer's email address

+ 2
- 0
Marlin/src/gcode/calibrate/G28.cpp View File

321
       stepperW.rms_current(W_CURRENT_HOME);
321
       stepperW.rms_current(W_CURRENT_HOME);
322
       if (DEBUGGING(LEVELING)) debug_current(F(STR_W), tmc_save_current_W, W_CURRENT_HOME);
322
       if (DEBUGGING(LEVELING)) debug_current(F(STR_W), tmc_save_current_W, W_CURRENT_HOME);
323
     #endif
323
     #endif
324
+    safe_delay(SENSORLESS_STALLGUARD_DELAY); // Short delay needed to settle
324
   #endif
325
   #endif
325
 
326
 
326
   #if ENABLED(IMPROVE_HOMING_RELIABILITY)
327
   #if ENABLED(IMPROVE_HOMING_RELIABILITY)
576
     #if HAS_CURRENT_HOME(W)
577
     #if HAS_CURRENT_HOME(W)
577
       stepperW.rms_current(tmc_save_current_W);
578
       stepperW.rms_current(tmc_save_current_W);
578
     #endif
579
     #endif
580
+    safe_delay(SENSORLESS_STALLGUARD_DELAY); // Short delay needed to settle
579
   #endif // HAS_HOMING_CURRENT
581
   #endif // HAS_HOMING_CURRENT
580
 
582
 
581
   ui.refresh();
583
   ui.refresh();

+ 40
- 7
Marlin/src/gcode/calibrate/G33.cpp View File

71
 
71
 
72
 void ac_home() {
72
 void ac_home() {
73
   endstops.enable(true);
73
   endstops.enable(true);
74
-  TERN_(HAS_DELTA_SENSORLESS_PROBING, probe.set_homing_current(true));
74
+  TERN_(SENSORLESS_HOMING, endstops.set_homing_current(true));
75
   home_delta();
75
   home_delta();
76
-  TERN_(HAS_DELTA_SENSORLESS_PROBING, probe.set_homing_current(false));
76
+  TERN_(SENSORLESS_HOMING, endstops.set_homing_current(false));
77
   endstops.not_homing();
77
   endstops.not_homing();
78
 }
78
 }
79
 
79
 
390
  *   X   Don't activate stallguard on X.
390
  *   X   Don't activate stallguard on X.
391
  *   Y   Don't activate stallguard on Y.
391
  *   Y   Don't activate stallguard on Y.
392
  *   Z   Don't activate stallguard on Z.
392
  *   Z   Don't activate stallguard on Z.
393
+ *
394
+ *   S   Save offset_sensorless_adj
393
  */
395
  */
394
 void GcodeSuite::G33() {
396
 void GcodeSuite::G33() {
395
 
397
 
411
     dcr -= probe_at_offset ? _MAX(total_offset, PROBING_MARGIN) : total_offset;
413
     dcr -= probe_at_offset ? _MAX(total_offset, PROBING_MARGIN) : total_offset;
412
   #endif
414
   #endif
413
   NOMORE(dcr, DELTA_PRINTABLE_RADIUS);
415
   NOMORE(dcr, DELTA_PRINTABLE_RADIUS);
414
-  if (parser.seenval('R')) dcr -= _MAX(parser.value_float(),0);
416
+  if (parser.seenval('R')) dcr -= _MAX(parser.value_float(), 0.0f);
417
+  TERN_(HAS_DELTA_SENSORLESS_PROBING, dcr *= sensorless_radius_factor);
415
 
418
 
416
   const float calibration_precision = parser.floatval('C', 0.0f);
419
   const float calibration_precision = parser.floatval('C', 0.0f);
417
   if (calibration_precision < 0) {
420
   if (calibration_precision < 0) {
434
   const bool stow_after_each = parser.seen_test('E');
437
   const bool stow_after_each = parser.seen_test('E');
435
 
438
 
436
   #if HAS_DELTA_SENSORLESS_PROBING
439
   #if HAS_DELTA_SENSORLESS_PROBING
437
-    probe.test_sensitivity.x = !parser.seen_test('X');
438
-    TERN_(HAS_Y_AXIS, probe.test_sensitivity.y = !parser.seen_test('Y'));
439
-    TERN_(HAS_Z_AXIS, probe.test_sensitivity.z = !parser.seen_test('Z'));
440
+    probe.test_sensitivity.set(!parser.seen_test('X'), !parser.seen_test('Y'), !parser.seen_test('Z'));
441
+    const bool do_save_offset_adj = parser.seen_test('S');
440
   #endif
442
   #endif
441
 
443
 
442
   const bool _0p_calibration      = probe_points == 0,
444
   const bool _0p_calibration      = probe_points == 0,
475
 
477
 
476
   if (!_0p_calibration) ac_home();
478
   if (!_0p_calibration) ac_home();
477
 
479
 
480
+  #if HAS_DELTA_SENSORLESS_PROBING
481
+    if (verbose_level > 0 && do_save_offset_adj) {
482
+      offset_sensorless_adj.reset();
483
+
484
+      auto caltower = [&](Probe::sense_bool_t s){
485
+        float z_at_pt[NPP + 1];
486
+        LOOP_CAL_ALL(rad) z_at_pt[rad] = 0.0f;
487
+        probe.test_sensitivity = s;
488
+        if (probe_calibration_points(z_at_pt, 1, dcr, false, false, probe_at_offset))
489
+          probe.set_offset_sensorless_adj(z_at_pt[CEN]);
490
+      };
491
+      caltower({ true, false, false }); // A
492
+      caltower({ false, true, false }); // B
493
+      caltower({ false, false, true }); // C
494
+
495
+      probe.test_sensitivity = { true, true, true }; // reset to all
496
+    }
497
+  #endif
498
+
478
   do { // start iterations
499
   do { // start iterations
479
 
500
 
480
     float z_at_pt[NPP + 1] = { 0.0f };
501
     float z_at_pt[NPP + 1] = { 0.0f };
598
 
619
 
599
     // print report
620
     // print report
600
 
621
 
601
-    if (verbose_level == 3 || verbose_level == 0)
622
+    if (verbose_level == 3 || verbose_level == 0) {
602
       print_calibration_results(z_at_pt, _tower_results, _opposite_results);
623
       print_calibration_results(z_at_pt, _tower_results, _opposite_results);
624
+      #if HAS_DELTA_SENSORLESS_PROBING
625
+        if (verbose_level == 0 && probe_points == 1) {
626
+          if (do_save_offset_adj)
627
+            probe.set_offset_sensorless_adj(z_at_pt[CEN]);
628
+          else
629
+            probe.refresh_largest_sensorless_adj();
630
+        }
631
+      #endif
632
+    }
603
 
633
 
604
     if (verbose_level != 0) { // !dry run
634
     if (verbose_level != 0) { // !dry run
605
       if ((zero_std_dev >= test_precision && iterations > force_iterations) || zero_std_dev <= calibration_precision) { // end iterations
635
       if ((zero_std_dev >= test_precision && iterations > force_iterations) || zero_std_dev <= calibration_precision) { // end iterations
660
   ac_cleanup(TERN_(HAS_MULTI_HOTEND, old_tool_index));
690
   ac_cleanup(TERN_(HAS_MULTI_HOTEND, old_tool_index));
661
 
691
 
662
   TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE));
692
   TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE));
693
+  #if HAS_DELTA_SENSORLESS_PROBING
694
+    probe.test_sensitivity = { true, true, true };
695
+  #endif
663
 }
696
 }
664
 
697
 
665
 #endif // DELTA_AUTO_CALIBRATION
698
 #endif // DELTA_AUTO_CALIBRATION

+ 5
- 0
Marlin/src/inc/Conditionals_adv.h View File

1048
 #if ANY(DISABLE_INACTIVE_X, DISABLE_INACTIVE_Y, DISABLE_INACTIVE_Z, DISABLE_INACTIVE_I, DISABLE_INACTIVE_J, DISABLE_INACTIVE_K, DISABLE_INACTIVE_U, DISABLE_INACTIVE_V, DISABLE_INACTIVE_W, DISABLE_INACTIVE_E)
1048
 #if ANY(DISABLE_INACTIVE_X, DISABLE_INACTIVE_Y, DISABLE_INACTIVE_Z, DISABLE_INACTIVE_I, DISABLE_INACTIVE_J, DISABLE_INACTIVE_K, DISABLE_INACTIVE_U, DISABLE_INACTIVE_V, DISABLE_INACTIVE_W, DISABLE_INACTIVE_E)
1049
   #define HAS_DISABLE_INACTIVE_AXIS 1
1049
   #define HAS_DISABLE_INACTIVE_AXIS 1
1050
 #endif
1050
 #endif
1051
+
1052
+// Delay Sensorless Homing/Probing
1053
+#if EITHER(SENSORLESS_HOMING, SENSORLESS_PROBING) && !defined(SENSORLESS_STALLGUARD_DELAY)
1054
+  #define SENSORLESS_STALLGUARD_DELAY 0
1055
+#endif

+ 1
- 2
Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp View File

193
     if (!ExtUI::isPrintingFromMedia()) return; // avoid race condition when user stays in this menu and printer finishes.
193
     if (!ExtUI::isPrintingFromMedia()) return; // avoid race condition when user stays in this menu and printer finishes.
194
     switch (swap16(*(uint16_t*)val_ptr)) {
194
     switch (swap16(*(uint16_t*)val_ptr)) {
195
       case 0: { // Resume
195
       case 0: { // Resume
196
-
197
         auto cs = getCurrentScreen();
196
         auto cs = getCurrentScreen();
198
         if (runout_mks.runout_status != RUNOUT_WAITING_STATUS && runout_mks.runout_status != UNRUNOUT_STATUS) {
197
         if (runout_mks.runout_status != RUNOUT_WAITING_STATUS && runout_mks.runout_status != UNRUNOUT_STATUS) {
199
           if (cs == MKSLCD_SCREEN_PRINT || cs == MKSLCD_SCREEN_PAUSE)
198
           if (cs == MKSLCD_SCREEN_PRINT || cs == MKSLCD_SCREEN_PAUSE)
213
       } break;
212
       } break;
214
 
213
 
215
       case 1: // Pause
214
       case 1: // Pause
216
-
217
         GotoScreen(MKSLCD_SCREEN_PAUSE);
215
         GotoScreen(MKSLCD_SCREEN_PAUSE);
218
         if (!ExtUI::isPrintingFromMediaPaused()) {
216
         if (!ExtUI::isPrintingFromMediaPaused()) {
219
           nozzle_park_mks.print_pause_start_flag = 1;
217
           nozzle_park_mks.print_pause_start_flag = 1;
222
           //ExtUI::mks_pausePrint();
220
           //ExtUI::mks_pausePrint();
223
         }
221
         }
224
         break;
222
         break;
223
+
225
       case 2: // Abort
224
       case 2: // Abort
226
         HandleUserConfirmationPopUp(VP_SD_AbortPrintConfirmed, nullptr, PSTR("Abort printing"), filelist.filename(), PSTR("?"), true, true, false, true);
225
         HandleUserConfirmationPopUp(VP_SD_AbortPrintConfirmed, nullptr, PSTR("Abort printing"), filelist.filename(), PSTR("?"), true, true, false, true);
227
         break;
226
         break;

+ 7
- 1
Marlin/src/lcd/menu/menu_delta_calibrate.cpp View File

41
   #include "../extui/ui_api.h"
41
   #include "../extui/ui_api.h"
42
 #endif
42
 #endif
43
 
43
 
44
+#if HAS_PROBE_XY_OFFSET
45
+  #include "../../module/probe.h"
46
+#endif
47
+
44
 void _man_probe_pt(const xy_pos_t &xy) {
48
 void _man_probe_pt(const xy_pos_t &xy) {
45
   if (!ui.wait_for_move) {
49
   if (!ui.wait_for_move) {
46
     ui.wait_for_move = true;
50
     ui.wait_for_move = true;
88
   }
92
   }
89
 
93
 
90
   void _goto_tower_a(const_float_t a) {
94
   void _goto_tower_a(const_float_t a) {
91
-    constexpr float dcr = DELTA_PRINTABLE_RADIUS;
95
+    float dcr = DELTA_PRINTABLE_RADIUS - PROBING_MARGIN;
96
+    TERN_(HAS_PROBE_XY_OFFSET, dcr -= HYPOT(probe.offset_xy.x, probe.offset_xy.y));
97
+    TERN_(HAS_DELTA_SENSORLESS_PROBING, dcr *= sensorless_radius_factor);
92
     xy_pos_t tower_vec = { cos(RADIANS(a)), sin(RADIANS(a)) };
98
     xy_pos_t tower_vec = { cos(RADIANS(a)), sin(RADIANS(a)) };
93
     _man_probe_pt(tower_vec * dcr);
99
     _man_probe_pt(tower_vec * dcr);
94
   }
100
   }

+ 6
- 0
Marlin/src/module/delta.cpp View File

60
 abc_float_t delta_diagonal_rod_2_tower;
60
 abc_float_t delta_diagonal_rod_2_tower;
61
 float delta_clip_start_height = Z_MAX_POS;
61
 float delta_clip_start_height = Z_MAX_POS;
62
 abc_float_t delta_diagonal_rod_trim;
62
 abc_float_t delta_diagonal_rod_trim;
63
+#if HAS_DELTA_SENSORLESS_PROBING
64
+  abc_float_t offset_sensorless_adj{0};
65
+  float largest_sensorless_adj = 0;
66
+#endif
63
 
67
 
64
 float delta_safe_distance_from_top();
68
 float delta_safe_distance_from_top();
65
 
69
 
236
     TERN_(U_SENSORLESS, sensorless_t stealth_states_u = start_sensorless_homing_per_axis(U_AXIS));
240
     TERN_(U_SENSORLESS, sensorless_t stealth_states_u = start_sensorless_homing_per_axis(U_AXIS));
237
     TERN_(V_SENSORLESS, sensorless_t stealth_states_v = start_sensorless_homing_per_axis(V_AXIS));
241
     TERN_(V_SENSORLESS, sensorless_t stealth_states_v = start_sensorless_homing_per_axis(V_AXIS));
238
     TERN_(W_SENSORLESS, sensorless_t stealth_states_w = start_sensorless_homing_per_axis(W_AXIS));
242
     TERN_(W_SENSORLESS, sensorless_t stealth_states_w = start_sensorless_homing_per_axis(W_AXIS));
243
+    safe_delay(SENSORLESS_STALLGUARD_DELAY); // Short delay needed to settle
239
   #endif
244
   #endif
240
 
245
 
241
   // Move all carriages together linearly until an endstop is hit.
246
   // Move all carriages together linearly until an endstop is hit.
255
     TERN_(U_SENSORLESS, end_sensorless_homing_per_axis(U_AXIS, stealth_states_u));
260
     TERN_(U_SENSORLESS, end_sensorless_homing_per_axis(U_AXIS, stealth_states_u));
256
     TERN_(V_SENSORLESS, end_sensorless_homing_per_axis(V_AXIS, stealth_states_v));
261
     TERN_(V_SENSORLESS, end_sensorless_homing_per_axis(V_AXIS, stealth_states_v));
257
     TERN_(W_SENSORLESS, end_sensorless_homing_per_axis(W_AXIS, stealth_states_w));
262
     TERN_(W_SENSORLESS, end_sensorless_homing_per_axis(W_AXIS, stealth_states_w));
263
+    safe_delay(SENSORLESS_STALLGUARD_DELAY); // Short delay needed to settle
258
   #endif
264
   #endif
259
 
265
 
260
   endstops.validate_homing_move();
266
   endstops.validate_homing_move();

+ 11
- 0
Marlin/src/module/delta.h View File

38
 extern abc_float_t delta_diagonal_rod_2_tower;
38
 extern abc_float_t delta_diagonal_rod_2_tower;
39
 extern float delta_clip_start_height;
39
 extern float delta_clip_start_height;
40
 extern abc_float_t delta_diagonal_rod_trim;
40
 extern abc_float_t delta_diagonal_rod_trim;
41
+#if HAS_DELTA_SENSORLESS_PROBING
42
+  extern abc_float_t offset_sensorless_adj;
43
+  extern float largest_sensorless_adj;
44
+#endif
41
 
45
 
42
 /**
46
 /**
43
  * Recalculate factors used for delta kinematics whenever
47
  * Recalculate factors used for delta kinematics whenever
46
 void recalc_delta_settings();
50
 void recalc_delta_settings();
47
 
51
 
48
 /**
52
 /**
53
+ * Get a safe radius for calibration
54
+ */
55
+#if HAS_DELTA_SENSORLESS_PROBING
56
+  static constexpr float sensorless_radius_factor = 0.7f;
57
+#endif
58
+
59
+/**
49
  * Delta Inverse Kinematics
60
  * Delta Inverse Kinematics
50
  *
61
  *
51
  * Calculate the tower positions for a given machine
62
  * Calculate the tower positions for a given machine

+ 63
- 0
Marlin/src/module/endstops.cpp View File

31
 #include "temperature.h"
31
 #include "temperature.h"
32
 #include "../lcd/marlinui.h"
32
 #include "../lcd/marlinui.h"
33
 
33
 
34
+#define DEBUG_OUT BOTH(USE_SENSORLESS, DEBUG_LEVELING_FEATURE)
35
+#include "../core/debug_out.h"
36
+
34
 #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
37
 #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
35
   #include HAL_PATH(../HAL, endstop_interrupts.h)
38
   #include HAL_PATH(../HAL, endstop_interrupts.h)
36
 #endif
39
 #endif
1621
   }
1624
   }
1622
 
1625
 
1623
 #endif // PINS_DEBUGGING
1626
 #endif // PINS_DEBUGGING
1627
+
1628
+#if USE_SENSORLESS
1629
+  /**
1630
+   * Change TMC driver currents to N##_CURRENT_HOME, saving the current configuration of each.
1631
+   */
1632
+  void Endstops::set_homing_current(const bool onoff) {
1633
+    #define HAS_CURRENT_HOME(N) (defined(N##_CURRENT_HOME) && N##_CURRENT_HOME != N##_CURRENT)
1634
+    #define HAS_DELTA_X_CURRENT (ENABLED(DELTA) && HAS_CURRENT_HOME(X))
1635
+    #define HAS_DELTA_Y_CURRENT (ENABLED(DELTA) && HAS_CURRENT_HOME(Y))
1636
+    #if HAS_DELTA_X_CURRENT || HAS_DELTA_Y_CURRENT || HAS_CURRENT_HOME(Z)
1637
+      #if HAS_DELTA_X_CURRENT
1638
+        static int16_t saved_current_x;
1639
+      #endif
1640
+      #if HAS_DELTA_Y_CURRENT
1641
+        static int16_t saved_current_y;
1642
+      #endif
1643
+      #if HAS_CURRENT_HOME(Z)
1644
+        static int16_t saved_current_z;
1645
+      #endif
1646
+      auto debug_current_on = [](PGM_P const s, const int16_t a, const int16_t b) {
1647
+        if (DEBUGGING(LEVELING)) { DEBUG_ECHOPGM_P(s); DEBUG_ECHOLNPGM(" current: ", a, " -> ", b); }
1648
+      };
1649
+      if (onoff) {
1650
+        #if HAS_DELTA_X_CURRENT
1651
+          saved_current_x = stepperX.getMilliamps();
1652
+          stepperX.rms_current(X_CURRENT_HOME);
1653
+          debug_current_on(PSTR("X"), saved_current_x, X_CURRENT_HOME);
1654
+        #endif
1655
+        #if HAS_DELTA_Y_CURRENT
1656
+          saved_current_y = stepperY.getMilliamps();
1657
+          stepperY.rms_current(Y_CURRENT_HOME);
1658
+          debug_current_on(PSTR("Y"), saved_current_y, Y_CURRENT_HOME);
1659
+        #endif
1660
+        #if HAS_CURRENT_HOME(Z)
1661
+          saved_current_z = stepperZ.getMilliamps();
1662
+          stepperZ.rms_current(Z_CURRENT_HOME);
1663
+          debug_current_on(PSTR("Z"), saved_current_z, Z_CURRENT_HOME);
1664
+        #endif
1665
+      }
1666
+      else {
1667
+        #if HAS_DELTA_X_CURRENT
1668
+          stepperX.rms_current(saved_current_x);
1669
+          debug_current_on(PSTR("X"), X_CURRENT_HOME, saved_current_x);
1670
+        #endif
1671
+        #if HAS_DELTA_Y_CURRENT
1672
+          stepperY.rms_current(saved_current_y);
1673
+          debug_current_on(PSTR("Y"), Y_CURRENT_HOME, saved_current_y);
1674
+        #endif
1675
+        #if HAS_CURRENT_HOME(Z)
1676
+          stepperZ.rms_current(saved_current_z);
1677
+          debug_current_on(PSTR("Z"), Z_CURRENT_HOME, saved_current_z);
1678
+        #endif
1679
+      }
1680
+
1681
+      TERN_(IMPROVE_HOMING_RELIABILITY, planner.enable_stall_prevention(onoff));
1682
+      safe_delay(SENSORLESS_STALLGUARD_DELAY); // Short delay needed to settle
1683
+
1684
+    #endif // XYZ
1685
+  }
1686
+#endif

+ 5
- 0
Marlin/src/module/endstops.h View File

247
       static void clear_endstop_state();
247
       static void clear_endstop_state();
248
       static bool tmc_spi_homing_check();
248
       static bool tmc_spi_homing_check();
249
     #endif
249
     #endif
250
+  public:
251
+    // Basic functions for Sensorless Homing
252
+    #if USE_SENSORLESS
253
+      static void set_homing_current(const bool onoff);
254
+    #endif
250
 };
255
 };
251
 
256
 
252
 extern Endstops endstops;
257
 extern Endstops endstops;

+ 8
- 2
Marlin/src/module/motion.cpp View File

1663
       }
1663
       }
1664
 
1664
 
1665
       // Disable stealthChop if used. Enable diag1 pin on driver.
1665
       // Disable stealthChop if used. Enable diag1 pin on driver.
1666
-      TERN_(SENSORLESS_HOMING, stealth_states = start_sensorless_homing_per_axis(axis));
1666
+      #if ENABLED(SENSORLESS_HOMING)
1667
+        stealth_states = start_sensorless_homing_per_axis(axis);
1668
+        safe_delay(SENSORLESS_STALLGUARD_DELAY); // Short delay needed to settle
1669
+      #endif
1667
     }
1670
     }
1668
 
1671
 
1669
     #if EITHER(MORGAN_SCARA, MP_SCARA)
1672
     #if EITHER(MORGAN_SCARA, MP_SCARA)
1699
       endstops.validate_homing_move();
1702
       endstops.validate_homing_move();
1700
 
1703
 
1701
       // Re-enable stealthChop if used. Disable diag1 pin on driver.
1704
       // Re-enable stealthChop if used. Disable diag1 pin on driver.
1702
-      TERN_(SENSORLESS_HOMING, end_sensorless_homing_per_axis(axis, stealth_states));
1705
+      #if ENABLED(SENSORLESS_HOMING)
1706
+        end_sensorless_homing_per_axis(axis, stealth_states);
1707
+        safe_delay(SENSORLESS_STALLGUARD_DELAY); // Short delay needed to settle
1708
+      #endif
1703
     }
1709
     }
1704
   }
1710
   }
1705
 
1711
 

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

1663
   // forced to empty, there's no risk the ISR will touch this.
1663
   // forced to empty, there's no risk the ISR will touch this.
1664
   delay_before_delivering = BLOCK_DELAY_FOR_1ST_MOVE;
1664
   delay_before_delivering = BLOCK_DELAY_FOR_1ST_MOVE;
1665
 
1665
 
1666
-  #if HAS_WIRED_LCD
1667
-    // Clear the accumulated runtime
1668
-    clear_block_buffer_runtime();
1669
-  #endif
1666
+  TERN_(HAS_WIRED_LCD, clear_block_buffer_runtime()); // Clear the accumulated runtime
1670
 
1667
 
1671
   // Make sure to drop any attempt of queuing moves for 1 second
1668
   // Make sure to drop any attempt of queuing moves for 1 second
1672
   cleaning_buffer_counter = TEMP_TIMER_FREQUENCY;
1669
   cleaning_buffer_counter = TEMP_TIMER_FREQUENCY;

+ 44
- 61
Marlin/src/module/probe.cpp View File

103
 #endif
103
 #endif
104
 
104
 
105
 #if ENABLED(SENSORLESS_PROBING)
105
 #if ENABLED(SENSORLESS_PROBING)
106
-  Probe::sense_bool_t Probe::test_sensitivity;
106
+  Probe::sense_bool_t Probe::test_sensitivity = { true, true, true };
107
 #endif
107
 #endif
108
 
108
 
109
 #if ENABLED(Z_PROBE_SLED)
109
 #if ENABLED(Z_PROBE_SLED)
531
   #if ENABLED(SENSORLESS_PROBING)
531
   #if ENABLED(SENSORLESS_PROBING)
532
     sensorless_t stealth_states { false };
532
     sensorless_t stealth_states { false };
533
     #if HAS_DELTA_SENSORLESS_PROBING
533
     #if HAS_DELTA_SENSORLESS_PROBING
534
-      if (test_sensitivity.x) stealth_states.x = tmc_enable_stallguard(stepperX);  // Delta watches all DIAG pins for a stall
534
+      if (test_sensitivity.x) stealth_states.x = tmc_enable_stallguard(stepperX); // Delta watches all DIAG pins for a stall
535
       if (test_sensitivity.y) stealth_states.y = tmc_enable_stallguard(stepperY);
535
       if (test_sensitivity.y) stealth_states.y = tmc_enable_stallguard(stepperY);
536
     #endif
536
     #endif
537
-    if (test_sensitivity.z) stealth_states.z = tmc_enable_stallguard(stepperZ);    // All machines will check Z-DIAG for stall
537
+    if (test_sensitivity.z) stealth_states.z = tmc_enable_stallguard(stepperZ);   // All machines will check Z-DIAG for stall
538
+    endstops.set_homing_current(true);                                            // The "homing" current also applies to probing
538
     endstops.enable(true);
539
     endstops.enable(true);
539
-    set_homing_current(true);                                 // The "homing" current also applies to probing
540
   #endif
540
   #endif
541
 
541
 
542
   TERN_(HAS_QUIET_PROBING, set_probing_paused(true));
542
   TERN_(HAS_QUIET_PROBING, set_probing_paused(true));
553
     #endif
553
     #endif
554
   ;
554
   ;
555
 
555
 
556
+  // Offset sensorless probing
557
+  #if HAS_DELTA_SENSORLESS_PROBING
558
+    if (probe_triggered) probe.refresh_largest_sensorless_adj();
559
+  #endif
560
+
556
   TERN_(HAS_QUIET_PROBING, set_probing_paused(false));
561
   TERN_(HAS_QUIET_PROBING, set_probing_paused(false));
557
 
562
 
558
   // Re-enable stealthChop if used. Disable diag1 pin on driver.
563
   // Re-enable stealthChop if used. Disable diag1 pin on driver.
563
       if (test_sensitivity.y) tmc_disable_stallguard(stepperY, stealth_states.y);
568
       if (test_sensitivity.y) tmc_disable_stallguard(stepperY, stealth_states.y);
564
     #endif
569
     #endif
565
     if (test_sensitivity.z) tmc_disable_stallguard(stepperZ, stealth_states.z);
570
     if (test_sensitivity.z) tmc_disable_stallguard(stepperZ, stealth_states.z);
566
-    set_homing_current(false);
571
+    endstops.set_homing_current(false);
567
   #endif
572
   #endif
568
 
573
 
569
   #if ENABLED(BLTOUCH)
574
   #if ENABLED(BLTOUCH)
666
     if (try_to_probe(PSTR("FAST"), z_probe_low_point, z_probe_fast_mm_s,
671
     if (try_to_probe(PSTR("FAST"), z_probe_low_point, z_probe_fast_mm_s,
667
                      sanity_check, Z_CLEARANCE_BETWEEN_PROBES) ) return NAN;
672
                      sanity_check, Z_CLEARANCE_BETWEEN_PROBES) ) return NAN;
668
 
673
 
669
-    const float first_probe_z = current_position.z;
670
-
674
+    const float first_probe_z = DIFF_TERN(HAS_DELTA_SENSORLESS_PROBING, current_position.z, largest_sensorless_adj);
671
     if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("1st Probe Z:", first_probe_z);
675
     if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("1st Probe Z:", first_probe_z);
672
 
676
 
673
     // Raise to give the probe clearance
677
     // Raise to give the probe clearance
709
 
713
 
710
       TERN_(MEASURE_BACKLASH_WHEN_PROBING, backlash.measure_with_probe());
714
       TERN_(MEASURE_BACKLASH_WHEN_PROBING, backlash.measure_with_probe());
711
 
715
 
712
-      const float z = current_position.z;
716
+      const float z = DIFF_TERN(HAS_DELTA_SENSORLESS_PROBING, current_position.z, largest_sensorless_adj);
713
 
717
 
714
       #if EXTRA_PROBING > 0
718
       #if EXTRA_PROBING > 0
715
         // Insert Z measurement into probes[]. Keep it sorted ascending.
719
         // Insert Z measurement into probes[]. Keep it sorted ascending.
760
 
764
 
761
   #elif TOTAL_PROBING == 2
765
   #elif TOTAL_PROBING == 2
762
 
766
 
763
-    const float z2 = current_position.z;
767
+    const float z2 = DIFF_TERN(HAS_DELTA_SENSORLESS_PROBING, current_position.z, largest_sensorless_adj);
764
 
768
 
765
     if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("2nd Probe Z:", z2, " Discrepancy:", first_probe_z - z2);
769
     if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("2nd Probe Z:", z2, " Discrepancy:", first_probe_z - z2);
766
 
770
 
843
       SERIAL_ERROR_MSG(STR_ERR_PROBING_FAILED);
847
       SERIAL_ERROR_MSG(STR_ERR_PROBING_FAILED);
844
     #endif
848
     #endif
845
   }
849
   }
846
-
850
+  DEBUG_ECHOLNPGM("measured_z: ", measured_z);
847
   return measured_z;
851
   return measured_z;
848
 }
852
 }
849
 
853
 
896
   }
900
   }
897
 
901
 
898
   /**
902
   /**
899
-   * Change the current in the TMC drivers to N##_CURRENT_HOME. And we save the current configuration of each TMC driver.
903
+   * Set the sensorless Z offset
900
    */
904
    */
901
-  void Probe::set_homing_current(const bool onoff) {
902
-    #define _defined(N) defined(N)
903
-    #define HAS_CURRENT_HOME(N) (N##_CURRENT_HOME > 0 && N##_CURRENT_HOME != N##_CURRENT)
904
-    #define _HOME_ELEM(N) HAS_CURRENT_HOME(N) ||
905
-    #if MAIN_AXIS_MAP(_HOME_ELEM) 0
906
-      #if ENABLED(DELTA)
907
-        static int16_t saved_current_X, saved_current_Y;
908
-      #endif
909
-      #if HAS_CURRENT_HOME(Z)
910
-        static int16_t saved_current_Z;
905
+  void Probe::set_offset_sensorless_adj(const_float_t sz) {
906
+    #if ENABLED(SENSORLESS_PROBING)
907
+      DEBUG_SECTION(pso, "Probe::set_offset_sensorless_adj", true);
908
+      #if HAS_DELTA_SENSORLESS_PROBING
909
+        if (test_sensitivity.x) offset_sensorless_adj.a = sz;
910
+        if (test_sensitivity.y) offset_sensorless_adj.b = sz;
911
       #endif
911
       #endif
912
-      #if ((ENABLED(DELTA) && (HAS_CURRENT_HOME(X) || HAS_CURRENT_HOME(Y))) || HAS_CURRENT_HOME(Z))
913
-        auto debug_current_on = [](PGM_P const s, const int16_t a, const int16_t b) {
914
-          if (DEBUGGING(LEVELING)) { DEBUG_ECHOPGM_P(s); DEBUG_ECHOLNPGM(" current: ", a, " -> ", b); }
915
-        };
912
+      if (test_sensitivity.z) offset_sensorless_adj.c = sz;
913
+    #endif
914
+  }
915
+
916
+  /**
917
+   * Refresh largest_sensorless_adj based on triggered endstops
918
+   */
919
+  void Probe::refresh_largest_sensorless_adj() {
920
+    #if ENABLED(SENSORLESS_PROBING)
921
+      DEBUG_SECTION(rso, "Probe::refresh_largest_sensorless_adj", true);
922
+      largest_sensorless_adj = -3;                                             // A reference away from any real probe height
923
+      #if HAS_DELTA_SENSORLESS_PROBING
924
+        if (TEST(endstops.state(), X_MAX)) {
925
+          NOLESS(largest_sensorless_adj, offset_sensorless_adj.a);
926
+          DEBUG_ECHOLNPGM("Endstop_X: ", largest_sensorless_adj, " TowerX");
927
+        }
928
+        if (TEST(endstops.state(), Y_MAX)) {
929
+          NOLESS(largest_sensorless_adj, offset_sensorless_adj.b);
930
+          DEBUG_ECHOLNPGM("Endstop_Y: ", largest_sensorless_adj, " TowerY");
931
+        }
916
       #endif
932
       #endif
917
-      if (onoff) {
918
-        #if ENABLED(DELTA)
919
-          #if HAS_CURRENT_HOME(X)
920
-            saved_current_X = stepperX.getMilliamps();
921
-            stepperX.rms_current(X_CURRENT_HOME);
922
-            debug_current_on(PSTR("X"), saved_current_X, X_CURRENT_HOME);
923
-          #endif
924
-          #if HAS_CURRENT_HOME(Y)
925
-            saved_current_Y = stepperY.getMilliamps();
926
-            stepperY.rms_current(Y_CURRENT_HOME);
927
-            debug_current_on(PSTR("Y"), saved_current_Y, Y_CURRENT_HOME);
928
-          #endif
929
-        #endif
930
-        #if HAS_CURRENT_HOME(Z)
931
-          saved_current_Z = stepperZ.getMilliamps();
932
-          stepperZ.rms_current(Z_CURRENT_HOME);
933
-          debug_current_on(PSTR("Z"), saved_current_Z, Z_CURRENT_HOME);
934
-        #endif
935
-        TERN_(IMPROVE_HOMING_RELIABILITY, planner.enable_stall_prevention(true));
936
-      }
937
-      else {
938
-        #if ENABLED(DELTA)
939
-          #if HAS_CURRENT_HOME(X)
940
-            stepperX.rms_current(saved_current_X);
941
-            debug_current_on(PSTR("X"), X_CURRENT_HOME, saved_current_X);
942
-          #endif
943
-          #if HAS_CURRENT_HOME(Y)
944
-            stepperY.rms_current(saved_current_Y);
945
-            debug_current_on(PSTR("Y"), Y_CURRENT_HOME, saved_current_Y);
946
-          #endif
947
-        #endif
948
-        #if HAS_CURRENT_HOME(Z)
949
-          stepperZ.rms_current(saved_current_Z);
950
-          debug_current_on(PSTR("Z"), Z_CURRENT_HOME, saved_current_Z);
951
-        #endif
952
-        TERN_(IMPROVE_HOMING_RELIABILITY, planner.enable_stall_prevention(false));
933
+      if (TEST(endstops.state(), Z_MAX)) {
934
+        NOLESS(largest_sensorless_adj, offset_sensorless_adj.c);
935
+        DEBUG_ECHOLNPGM("Endstop_Z: ", largest_sensorless_adj, " TowerZ");
953
       }
936
       }
954
     #endif
937
     #endif
955
   }
938
   }

+ 9
- 2
Marlin/src/module/probe.h View File

66
 public:
66
 public:
67
 
67
 
68
   #if ENABLED(SENSORLESS_PROBING)
68
   #if ENABLED(SENSORLESS_PROBING)
69
-    typedef struct { bool x:1, y:1, z:1; } sense_bool_t;
69
+    typedef struct {
70
+      #if HAS_DELTA_SENSORLESS_PROBING
71
+        bool x:1, y:1, z:1;
72
+      #else
73
+        bool z;
74
+      #endif
75
+    } sense_bool_t;
70
     static sense_bool_t test_sensitivity;
76
     static sense_bool_t test_sensitivity;
71
   #endif
77
   #endif
72
 
78
 
299
   #if USE_SENSORLESS
305
   #if USE_SENSORLESS
300
     static void enable_stallguard_diag1();
306
     static void enable_stallguard_diag1();
301
     static void disable_stallguard_diag1();
307
     static void disable_stallguard_diag1();
302
-    static void set_homing_current(const bool onoff);
308
+    static void set_offset_sensorless_adj(const_float_t sz);
309
+    static void refresh_largest_sensorless_adj();
303
   #endif
310
   #endif
304
 
311
 
305
 private:
312
 private:

Loading…
Cancel
Save