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 2 years ago
parent
commit
41f73cb457
No account linked to committer's email address

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

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

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

@@ -71,9 +71,9 @@ float lcd_probe_pt(const xy_pos_t &xy);
71 71
 
72 72
 void ac_home() {
73 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 75
   home_delta();
76
-  TERN_(HAS_DELTA_SENSORLESS_PROBING, probe.set_homing_current(false));
76
+  TERN_(SENSORLESS_HOMING, endstops.set_homing_current(false));
77 77
   endstops.not_homing();
78 78
 }
79 79
 
@@ -390,6 +390,8 @@ static float auto_tune_a(const float dcr) {
390 390
  *   X   Don't activate stallguard on X.
391 391
  *   Y   Don't activate stallguard on Y.
392 392
  *   Z   Don't activate stallguard on Z.
393
+ *
394
+ *   S   Save offset_sensorless_adj
393 395
  */
394 396
 void GcodeSuite::G33() {
395 397
 
@@ -411,7 +413,8 @@ void GcodeSuite::G33() {
411 413
     dcr -= probe_at_offset ? _MAX(total_offset, PROBING_MARGIN) : total_offset;
412 414
   #endif
413 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 419
   const float calibration_precision = parser.floatval('C', 0.0f);
417 420
   if (calibration_precision < 0) {
@@ -434,9 +437,8 @@ void GcodeSuite::G33() {
434 437
   const bool stow_after_each = parser.seen_test('E');
435 438
 
436 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 442
   #endif
441 443
 
442 444
   const bool _0p_calibration      = probe_points == 0,
@@ -475,6 +477,25 @@ void GcodeSuite::G33() {
475 477
 
476 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 499
   do { // start iterations
479 500
 
480 501
     float z_at_pt[NPP + 1] = { 0.0f };
@@ -598,8 +619,17 @@ void GcodeSuite::G33() {
598 619
 
599 620
     // print report
600 621
 
601
-    if (verbose_level == 3 || verbose_level == 0)
622
+    if (verbose_level == 3 || verbose_level == 0) {
602 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 634
     if (verbose_level != 0) { // !dry run
605 635
       if ((zero_std_dev >= test_precision && iterations > force_iterations) || zero_std_dev <= calibration_precision) { // end iterations
@@ -660,6 +690,9 @@ void GcodeSuite::G33() {
660 690
   ac_cleanup(TERN_(HAS_MULTI_HOTEND, old_tool_index));
661 691
 
662 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 698
 #endif // DELTA_AUTO_CALIBRATION

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

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

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

@@ -41,6 +41,10 @@
41 41
   #include "../extui/ui_api.h"
42 42
 #endif
43 43
 
44
+#if HAS_PROBE_XY_OFFSET
45
+  #include "../../module/probe.h"
46
+#endif
47
+
44 48
 void _man_probe_pt(const xy_pos_t &xy) {
45 49
   if (!ui.wait_for_move) {
46 50
     ui.wait_for_move = true;
@@ -88,7 +92,9 @@ void _man_probe_pt(const xy_pos_t &xy) {
88 92
   }
89 93
 
90 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 98
     xy_pos_t tower_vec = { cos(RADIANS(a)), sin(RADIANS(a)) };
93 99
     _man_probe_pt(tower_vec * dcr);
94 100
   }

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

@@ -60,6 +60,10 @@ xy_float_t delta_tower[ABC];
60 60
 abc_float_t delta_diagonal_rod_2_tower;
61 61
 float delta_clip_start_height = Z_MAX_POS;
62 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 68
 float delta_safe_distance_from_top();
65 69
 
@@ -236,6 +240,7 @@ void home_delta() {
236 240
     TERN_(U_SENSORLESS, sensorless_t stealth_states_u = start_sensorless_homing_per_axis(U_AXIS));
237 241
     TERN_(V_SENSORLESS, sensorless_t stealth_states_v = start_sensorless_homing_per_axis(V_AXIS));
238 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 244
   #endif
240 245
 
241 246
   // Move all carriages together linearly until an endstop is hit.
@@ -255,6 +260,7 @@ void home_delta() {
255 260
     TERN_(U_SENSORLESS, end_sensorless_homing_per_axis(U_AXIS, stealth_states_u));
256 261
     TERN_(V_SENSORLESS, end_sensorless_homing_per_axis(V_AXIS, stealth_states_v));
257 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 264
   #endif
259 265
 
260 266
   endstops.validate_homing_move();

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

@@ -38,6 +38,10 @@ extern xy_float_t delta_tower[ABC];
38 38
 extern abc_float_t delta_diagonal_rod_2_tower;
39 39
 extern float delta_clip_start_height;
40 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 47
  * Recalculate factors used for delta kinematics whenever
@@ -46,6 +50,13 @@ extern abc_float_t delta_diagonal_rod_trim;
46 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 60
  * Delta Inverse Kinematics
50 61
  *
51 62
  * Calculate the tower positions for a given machine

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

@@ -31,6 +31,9 @@
31 31
 #include "temperature.h"
32 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 37
 #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
35 38
   #include HAL_PATH(../HAL, endstop_interrupts.h)
36 39
 #endif
@@ -1621,3 +1624,63 @@ void Endstops::update() {
1621 1624
   }
1622 1625
 
1623 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,6 +247,11 @@ class Endstops {
247 247
       static void clear_endstop_state();
248 248
       static bool tmc_spi_homing_check();
249 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 257
 extern Endstops endstops;

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

@@ -1663,7 +1663,10 @@ void prepare_line_to_destination() {
1663 1663
       }
1664 1664
 
1665 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 1672
     #if EITHER(MORGAN_SCARA, MP_SCARA)
@@ -1699,7 +1702,10 @@ void prepare_line_to_destination() {
1699 1702
       endstops.validate_homing_move();
1700 1703
 
1701 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,10 +1663,7 @@ void Planner::quick_stop() {
1663 1663
   // forced to empty, there's no risk the ISR will touch this.
1664 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 1668
   // Make sure to drop any attempt of queuing moves for 1 second
1672 1669
   cleaning_buffer_counter = TEMP_TIMER_FREQUENCY;

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

@@ -103,7 +103,7 @@ xyz_pos_t Probe::offset; // Initialized by settings.load()
103 103
 #endif
104 104
 
105 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 107
 #endif
108 108
 
109 109
 #if ENABLED(Z_PROBE_SLED)
@@ -531,12 +531,12 @@ bool Probe::probe_down_to_z(const_float_t z, const_feedRate_t fr_mm_s) {
531 531
   #if ENABLED(SENSORLESS_PROBING)
532 532
     sensorless_t stealth_states { false };
533 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 535
       if (test_sensitivity.y) stealth_states.y = tmc_enable_stallguard(stepperY);
536 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 539
     endstops.enable(true);
539
-    set_homing_current(true);                                 // The "homing" current also applies to probing
540 540
   #endif
541 541
 
542 542
   TERN_(HAS_QUIET_PROBING, set_probing_paused(true));
@@ -553,6 +553,11 @@ bool Probe::probe_down_to_z(const_float_t z, const_feedRate_t fr_mm_s) {
553 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 561
   TERN_(HAS_QUIET_PROBING, set_probing_paused(false));
557 562
 
558 563
   // Re-enable stealthChop if used. Disable diag1 pin on driver.
@@ -563,7 +568,7 @@ bool Probe::probe_down_to_z(const_float_t z, const_feedRate_t fr_mm_s) {
563 568
       if (test_sensitivity.y) tmc_disable_stallguard(stepperY, stealth_states.y);
564 569
     #endif
565 570
     if (test_sensitivity.z) tmc_disable_stallguard(stepperZ, stealth_states.z);
566
-    set_homing_current(false);
571
+    endstops.set_homing_current(false);
567 572
   #endif
568 573
 
569 574
   #if ENABLED(BLTOUCH)
@@ -666,8 +671,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
666 671
     if (try_to_probe(PSTR("FAST"), z_probe_low_point, z_probe_fast_mm_s,
667 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 675
     if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("1st Probe Z:", first_probe_z);
672 676
 
673 677
     // Raise to give the probe clearance
@@ -709,7 +713,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
709 713
 
710 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 718
       #if EXTRA_PROBING > 0
715 719
         // Insert Z measurement into probes[]. Keep it sorted ascending.
@@ -760,7 +764,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
760 764
 
761 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 769
     if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("2nd Probe Z:", z2, " Discrepancy:", first_probe_z - z2);
766 770
 
@@ -843,7 +847,7 @@ float Probe::probe_at_point(const_float_t rx, const_float_t ry, const ProbePtRai
843 847
       SERIAL_ERROR_MSG(STR_ERR_PROBING_FAILED);
844 848
     #endif
845 849
   }
846
-
850
+  DEBUG_ECHOLNPGM("measured_z: ", measured_z);
847 851
   return measured_z;
848 852
 }
849 853
 
@@ -896,60 +900,39 @@ float Probe::probe_at_point(const_float_t rx, const_float_t ry, const ProbePtRai
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 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 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 937
     #endif
955 938
   }

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

@@ -66,7 +66,13 @@ class Probe {
66 66
 public:
67 67
 
68 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 76
     static sense_bool_t test_sensitivity;
71 77
   #endif
72 78
 
@@ -299,7 +305,8 @@ public:
299 305
   #if USE_SENSORLESS
300 306
     static void enable_stallguard_diag1();
301 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 310
   #endif
304 311
 
305 312
 private:

Loading…
Cancel
Save