Переглянути джерело

G34 automatic point assignment (#16473)

InsanityAutomation 4 роки тому
джерело
коміт
e58d1bf974
Аккаунт користувача з таким Email не знайдено

+ 36
- 17
Marlin/Configuration_adv.h Переглянути файл

@@ -668,11 +668,37 @@
668 668
  */
669 669
 //#define Z_STEPPER_AUTO_ALIGN
670 670
 #if ENABLED(Z_STEPPER_AUTO_ALIGN)
671
-  // Define probe X and Y positions for Z1, Z2 [, Z3]
672
-  #define Z_STEPPER_ALIGN_XY { {  10, 190 }, { 100,  10 }, { 190, 190 } }
671
+  // Define probe X and Y positions for Z1, Z2 [, Z3 [, Z4]]
672
+  // If not defined, probe limits will be used.
673
+  // Override with 'M422 S<index> X<pos> Y<pos>'
674
+  //#define Z_STEPPER_ALIGN_XY { {  10, 190 }, { 100,  10 }, { 190, 190 } }
675
+
676
+  /**
677
+   * Orientation for the automatically-calculated probe positions.
678
+   * Override Z stepper align points with 'M422 S<index> X<pos> Y<pos>'
679
+   *
680
+   * 2 Steppers:  (0)     (1)
681
+   *               |       |   2   |
682
+   *               | 1   2 |       |
683
+   *               |       |   1   |
684
+   *
685
+   * 3 Steppers:  (0)     (1)     (2)     (3)
686
+   *               |   3   | 1     | 2   1 |     2 |
687
+   *               |       |     3 |       | 3     |
688
+   *               | 1   2 | 2     |   3   |     1 |
689
+   *
690
+   * 4 Steppers:  (0)     (1)     (2)     (3)
691
+   *               | 4   3 | 1   4 | 2   1 | 3   2 |
692
+   *               |       |       |       |       |
693
+   *               | 1   2 | 2   3 | 3   4 | 4   1 |
694
+   *
695
+   */
696
+  #ifndef Z_STEPPER_ALIGN_XY
697
+    //#define Z_STEPPERS_ORIENTATION 0
698
+  #endif
673 699
 
674 700
   // Provide Z stepper positions for more rapid convergence in bed alignment.
675
-  // Currently requires triple stepper drivers.
701
+  // Requires triple stepper drivers (i.e., set NUM_Z_STEPPER_DRIVERS to 3)
676 702
   //#define Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS
677 703
   #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
678 704
     // Define Stepper XY positions for Z1, Z2, Z3 corresponding to
@@ -680,23 +706,16 @@
680 706
     // Define one position per Z stepper in stepper driver order.
681 707
     #define Z_STEPPER_ALIGN_STEPPER_XY { { 210.7, 102.5 }, { 152.6, 220.0 }, { 94.5, 102.5 } }
682 708
   #else
683
-    // Amplification factor. Used to scale the correction step up or down.
684
-    // In case the stepper (spindle) position is further out than the test point.
685
-    // Use a value > 1. NOTE: This may cause instability
686
-    #define Z_STEPPER_ALIGN_AMP 1.0
709
+    // Amplification factor. Used to scale the correction step up or down in case
710
+    // the stepper (spindle) position is farther out than the test point.
711
+    #define Z_STEPPER_ALIGN_AMP 1.0       // Use a value > 1.0 NOTE: This may cause instability!
687 712
   #endif
688 713
 
689
-  // Set number of iterations to align
690
-  #define Z_STEPPER_ALIGN_ITERATIONS 3
691
-
692
-  // Enable to restore leveling setup after operation
693
-  #define RESTORE_LEVELING_AFTER_G34
694
-
695 714
   // On a 300mm bed a 5% grade would give a misalignment of ~1.5cm
696
-  #define G34_MAX_GRADE  5  // (%) Maximum incline G34 will handle
697
-
698
-  // Stop criterion. If the accuracy is better than this stop iterating early
699
-  #define Z_STEPPER_ALIGN_ACC 0.02
715
+  #define G34_MAX_GRADE              5    // (%) Maximum incline that G34 will handle
716
+  #define Z_STEPPER_ALIGN_ITERATIONS 5    // Number of iterations to apply during alignment
717
+  #define Z_STEPPER_ALIGN_ACC        0.02 // Stop iterating early if the accuracy is better than this
718
+  #define RESTORE_LEVELING_AFTER_G34      // Restore leveling after G34 is done?
700 719
 #endif
701 720
 
702 721
 // @section motion

+ 137
- 0
Marlin/src/feature/z_stepper_align.cpp Переглянути файл

@@ -0,0 +1,137 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * feature/z_stepper_align.cpp
25
+ */
26
+
27
+#include "../inc/MarlinConfigPre.h"
28
+
29
+#if ENABLED(Z_STEPPER_AUTO_ALIGN)
30
+
31
+#include "z_stepper_align.h"
32
+#include "../module/probe.h"
33
+
34
+ZStepperAlign z_stepper_align;
35
+
36
+xy_pos_t ZStepperAlign::xy[NUM_Z_STEPPER_DRIVERS];
37
+
38
+#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
39
+  xy_pos_t ZStepperAlign::stepper_xy[NUM_Z_STEPPER_DRIVERS];
40
+#endif
41
+
42
+void ZStepperAlign::reset_to_default() {
43
+  #ifdef Z_STEPPER_ALIGN_XY
44
+
45
+    constexpr xy_pos_t xy_init[] = Z_STEPPER_ALIGN_XY;
46
+    static_assert(COUNT(xy_init) == NUM_Z_STEPPER_DRIVERS,
47
+      "Z_STEPPER_ALIGN_XY requires "
48
+      #if NUM_Z_STEPPER_DRIVERS == 4
49
+        "four {X,Y} entries (Z, Z2, Z3, and Z4)."
50
+      #elif NUM_Z_STEPPER_DRIVERS == 3
51
+        "three {X,Y} entries (Z, Z2, and Z3)."
52
+      #else
53
+        "two {X,Y} entries (Z and Z2)."
54
+      #endif
55
+    );
56
+
57
+    constexpr xyz_pos_t dpo = NOZZLE_TO_PROBE_OFFSET;
58
+
59
+    #define LTEST(N) (xy_init[N].x >= _MAX(X_MIN_BED + MIN_PROBE_EDGE_LEFT,  X_MIN_POS + dpo.x) - 0.00001f)
60
+    #define RTEST(N) (xy_init[N].x <= _MIN(X_MAX_BED - MIN_PROBE_EDGE_RIGHT, X_MAX_POS + dpo.x) + 0.00001f)
61
+    #define FTEST(N) (xy_init[N].y >= _MAX(Y_MIN_BED + MIN_PROBE_EDGE_FRONT, Y_MIN_POS + dpo.y) - 0.00001f)
62
+    #define BTEST(N) (xy_init[N].y <= _MIN(Y_MAX_BED - MIN_PROBE_EDGE_BACK,  Y_MAX_POS + dpo.y) + 0.00001f)
63
+
64
+    static_assert(LTEST(0) && RTEST(0), "The 1st Z_STEPPER_ALIGN_XY X is unreachable with the default probe X offset.");
65
+    static_assert(FTEST(0) && BTEST(0), "The 1st Z_STEPPER_ALIGN_XY Y is unreachable with the default probe Y offset.");
66
+    static_assert(LTEST(1) && RTEST(1), "The 2nd Z_STEPPER_ALIGN_XY X is unreachable with the default probe X offset.");
67
+    static_assert(FTEST(1) && BTEST(1), "The 2nd Z_STEPPER_ALIGN_XY Y is unreachable with the default probe Y offset.");
68
+    #if NUM_Z_STEPPER_DRIVERS >= 3
69
+      static_assert(LTEST(2) && RTEST(2), "The 3rd Z_STEPPER_ALIGN_XY X is unreachable with the default probe X offset.");
70
+      static_assert(FTEST(2) && BTEST(2), "The 3rd Z_STEPPER_ALIGN_XY Y is unreachable with the default probe Y offset.");
71
+      #if NUM_Z_STEPPER_DRIVERS >= 4
72
+        static_assert(LTEST(3) && RTEST(3), "The 4th Z_STEPPER_ALIGN_XY X is unreachable with the default probe X offset.");
73
+        static_assert(FTEST(3) && BTEST(3), "The 4th Z_STEPPER_ALIGN_XY Y is unreachable with the default probe Y offset.");
74
+      #endif
75
+    #endif
76
+
77
+  #else // !defined(Z_STEPPER_ALIGN_XY)
78
+
79
+    const xy_pos_t xy_init[] = {
80
+      #if NUM_Z_STEPPER_DRIVERS >= 3  // First probe point...
81
+        #if !Z_STEPPERS_ORIENTATION
82
+          { probe.min_x(), probe.min_y() }, // SW
83
+        #elif Z_STEPPERS_ORIENTATION == 1
84
+          { probe.min_x(), probe.max_y() }, // NW
85
+        #elif Z_STEPPERS_ORIENTATION == 2
86
+          { probe.max_x(), probe.max_y() }, // NE
87
+        #elif Z_STEPPERS_ORIENTATION == 3
88
+          { probe.max_x(), probe.min_y() }, // SE
89
+        #else
90
+          #error "Z_STEPPERS_ORIENTATION must be from 0 to 3 (first point SW, NW, NE, SE)."
91
+        #endif
92
+        #if NUM_Z_STEPPER_DRIVERS == 4    // 3 more points...
93
+          #if !Z_STEPPERS_ORIENTATION
94
+            { probe.min_x(), probe.max_y() }, { probe.max_x(), probe.max_y() }, { probe.max_x(), probe.min_y() }  // SW
95
+          #elif Z_STEPPERS_ORIENTATION == 1
96
+            { probe.max_x(), probe.max_y() }, { probe.max_x(), probe.min_y() }, { probe.min_x(), probe.min_y() }  // NW
97
+          #elif Z_STEPPERS_ORIENTATION == 2
98
+            { probe.max_x(), probe.min_y() }, { probe.min_x(), probe.min_y() }, { probe.min_x(), probe.max_y() }  // NE
99
+          #elif Z_STEPPERS_ORIENTATION == 3
100
+            { probe.min_x(), probe.min_y() }, { probe.min_x(), probe.max_y() }, { probe.max_x(), probe.max_y() }  // SE
101
+          #endif
102
+        #elif !Z_STEPPERS_ORIENTATION     // or 2 more points...
103
+          { probe.max_x(), probe.min_y() }, { X_CENTER, probe.max_y() } // SW
104
+        #elif Z_STEPPERS_ORIENTATION == 1
105
+          { probe.min_x(), probe.min_y() }, { probe.max_x(), Y_CENTER } // NW
106
+        #elif Z_STEPPERS_ORIENTATION == 2
107
+          { probe.min_x(), probe.max_y() }, { X_CENTER, probe.min_y() } // NE
108
+        #elif Z_STEPPERS_ORIENTATION == 3
109
+          { probe.max_x(), probe.max_y() }, { probe.min_x(), Y_CENTER } // SE
110
+        #endif
111
+      #elif Z_STEPPERS_ORIENTATION
112
+        { X_CENTER, probe.min_y() }, { X_CENTER, probe.max_y() }
113
+      #else
114
+        { probe.min_x(), Y_CENTER }, { probe.max_x(), Y_CENTER }
115
+      #endif
116
+    };
117
+
118
+  #endif // !defined(Z_STEPPER_ALIGN_XY)
119
+
120
+  COPY(xy, xy_init);
121
+
122
+  #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
123
+    constexpr xy_pos_t stepper_xy_init[] = Z_STEPPER_ALIGN_STEPPER_XY;
124
+    static_assert(
125
+      COUNT(stepper_xy_init) == NUM_Z_STEPPER_DRIVERS,
126
+      "Z_STEPPER_ALIGN_STEPPER_XY requires "
127
+      #if NUM_Z_STEPPER_DRIVERS == 4
128
+        "four {X,Y} entries (Z, Z2, Z3, and Z4)."
129
+      #elif NUM_Z_STEPPER_DRIVERS == 3
130
+        "three {X,Y} entries (Z, Z2, and Z3)."
131
+      #endif
132
+    );
133
+    COPY(stepper_xy, stepper_xy_init);
134
+  #endif
135
+}
136
+
137
+#endif // Z_STEPPER_AUTO_ALIGN

+ 41
- 0
Marlin/src/feature/z_stepper_align.h Переглянути файл

@@ -0,0 +1,41 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+/**
25
+ * feature/z_stepper_align.h
26
+ */
27
+
28
+#include "../inc/MarlinConfig.h"
29
+
30
+class ZStepperAlign {
31
+  public:
32
+    static xy_pos_t xy[NUM_Z_STEPPER_DRIVERS];
33
+
34
+    #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
35
+      static xy_pos_t stepper_xy[NUM_Z_STEPPER_DRIVERS];
36
+    #endif
37
+
38
+  static void reset_to_default();
39
+};
40
+
41
+extern ZStepperAlign z_stepper_align;

+ 1
- 1
Marlin/src/gcode/bedlevel/G26.cpp Переглянути файл

@@ -707,7 +707,7 @@ void GcodeSuite::G26() {
707 707
     if (location.valid()) {
708 708
       const xy_pos_t circle = _GET_MESH_POS(location.pos);
709 709
 
710
-      // If this mesh location is outside the printable_radius, skip it.
710
+      // If this mesh location is outside the printable radius, skip it.
711 711
       if (!position_is_reachable(circle)) continue;
712 712
 
713 713
       // Determine where to start and end the circle,

+ 46
- 86
Marlin/src/gcode/calibrate/G34_M422.cpp Переглянути файл

@@ -24,6 +24,8 @@
24 24
 
25 25
 #if ENABLED(Z_STEPPER_AUTO_ALIGN)
26 26
 
27
+#include "../../feature/z_stepper_align.h"
28
+
27 29
 #include "../gcode.h"
28 30
 #include "../../module/planner.h"
29 31
 #include "../../module/stepper.h"
@@ -45,68 +47,6 @@
45 47
 #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
46 48
 #include "../../core/debug_out.h"
47 49
 
48
-//
49
-// Sanity check G34 / M422 settings
50
-//
51
-constexpr xy_pos_t test_z_stepper_align_xy[] = Z_STEPPER_ALIGN_XY;
52
-
53
-#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
54
-
55
-  static_assert(COUNT(test_z_stepper_align_xy) >= NUM_Z_STEPPER_DRIVERS,
56
-    "Z_STEPPER_ALIGN_XY requires at least three {X,Y} entries (Z, Z2, Z3, ...)."
57
-  );
58
-
59
-  constexpr float test_z_stepper_align_stepper_xy[][XY] = Z_STEPPER_ALIGN_STEPPER_XY;
60
-  static_assert(
61
-    COUNT(test_z_stepper_align_stepper_xy) == NUM_Z_STEPPER_DRIVERS,
62
-    "Z_STEPPER_ALIGN_STEPPER_XY requires three {X,Y} entries (one per Z stepper)."
63
-  );
64
-
65
-#else
66
-
67
-  static_assert(COUNT(test_z_stepper_align_xy) == NUM_Z_STEPPER_DRIVERS,
68
-    #if NUM_Z_STEPPER_DRIVERS == 4
69
-      "Z_STEPPER_ALIGN_XY requires four {X,Y} entries (Z, Z2, Z3, and Z4)."
70
-    #elif NUM_Z_STEPPER_DRIVERS == 3
71
-      "Z_STEPPER_ALIGN_XY requires three {X,Y} entries (Z, Z2, and Z3)."
72
-    #else
73
-      "Z_STEPPER_ALIGN_XY requires two {X,Y} entries (Z and Z2)."
74
-    #endif
75
-  );
76
-
77
-#endif
78
-
79
-constexpr xyz_pos_t dpo = NOZZLE_TO_PROBE_OFFSET;
80
-
81
-#define LTEST(N) (test_z_stepper_align_xy[N].x >= _MAX(X_MIN_BED + MIN_PROBE_EDGE_LEFT,  X_MIN_POS + dpo.x) - 0.00001f)
82
-#define RTEST(N) (test_z_stepper_align_xy[N].x <= _MIN(X_MAX_BED - MIN_PROBE_EDGE_RIGHT, X_MAX_POS + dpo.x) + 0.00001f)
83
-#define FTEST(N) (test_z_stepper_align_xy[N].y >= _MAX(Y_MIN_BED + MIN_PROBE_EDGE_FRONT, Y_MIN_POS + dpo.y) - 0.00001f)
84
-#define BTEST(N) (test_z_stepper_align_xy[N].y <= _MIN(Y_MAX_BED - MIN_PROBE_EDGE_BACK,  Y_MAX_POS + dpo.y) + 0.00001f)
85
-
86
-static_assert(LTEST(0) && RTEST(0), "The 1st Z_STEPPER_ALIGN_XY X is unreachable with the default probe X offset.");
87
-static_assert(FTEST(0) && BTEST(0), "The 1st Z_STEPPER_ALIGN_XY Y is unreachable with the default probe Y offset.");
88
-static_assert(LTEST(1) && RTEST(1), "The 2nd Z_STEPPER_ALIGN_XY X is unreachable with the default probe X offset.");
89
-static_assert(FTEST(1) && BTEST(1), "The 2nd Z_STEPPER_ALIGN_XY Y is unreachable with the default probe Y offset.");
90
-#if NUM_Z_STEPPER_DRIVERS >= 3
91
-  static_assert(LTEST(2) && RTEST(2), "The 3rd Z_STEPPER_ALIGN_XY X is unreachable with the default probe X offset.");
92
-  static_assert(FTEST(2) && BTEST(2), "The 3rd Z_STEPPER_ALIGN_XY Y is unreachable with the default probe Y offset.");
93
-  #if NUM_Z_STEPPER_DRIVERS >= 4
94
-    static_assert(LTEST(3) && RTEST(3), "The 4th Z_STEPPER_ALIGN_XY X is unreachable with the default probe X offset.");
95
-    static_assert(FTEST(3) && BTEST(3), "The 4th Z_STEPPER_ALIGN_XY Y is unreachable with the default probe Y offset.");
96
-  #endif
97
-#endif
98
-
99
-//
100
-// G34 / M422 shared data
101
-//
102
-static xy_pos_t z_stepper_align_pos[] = Z_STEPPER_ALIGN_XY;
103
-
104
-#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
105
-  static xy_pos_t z_stepper_align_stepper_pos[] = Z_STEPPER_ALIGN_STEPPER_XY;
106
-#endif
107
-
108
-#define G34_PROBE_COUNT COUNT(z_stepper_align_pos)
109
-
110 50
 inline void set_all_z_lock(const bool lock) {
111 51
   stepper.set_z_lock(lock);
112 52
   stepper.set_z2_lock(lock);
@@ -201,11 +141,11 @@ void GcodeSuite::G34() {
201 141
     // iteration this will be re-calculated based on the actual bed position
202 142
     float z_probe = Z_BASIC_CLEARANCE + (G34_MAX_GRADE) * 0.01f * (
203 143
       #if NUM_Z_STEPPER_DRIVERS == 3
204
-         SQRT(_MAX(HYPOT2(z_stepper_align_pos[0].x - z_stepper_align_pos[0].y, z_stepper_align_pos[1].x - z_stepper_align_pos[1].y),
205
-                   HYPOT2(z_stepper_align_pos[1].x - z_stepper_align_pos[1].y, z_stepper_align_pos[2].x - z_stepper_align_pos[2].y),
206
-                   HYPOT2(z_stepper_align_pos[2].x - z_stepper_align_pos[2].y, z_stepper_align_pos[0].x - z_stepper_align_pos[0].y)))
144
+         SQRT(_MAX(HYPOT2(z_stepper_align.xy[0].x - z_stepper_align.xy[0].y, z_stepper_align.xy[1].x - z_stepper_align.xy[1].y),
145
+                   HYPOT2(z_stepper_align.xy[1].x - z_stepper_align.xy[1].y, z_stepper_align.xy[2].x - z_stepper_align.xy[2].y),
146
+                   HYPOT2(z_stepper_align.xy[2].x - z_stepper_align.xy[2].y, z_stepper_align.xy[0].x - z_stepper_align.xy[0].y)))
207 147
       #else
208
-         HYPOT(z_stepper_align_pos[0].x - z_stepper_align_pos[0].y, z_stepper_align_pos[1].x - z_stepper_align_pos[1].y)
148
+         HYPOT(z_stepper_align.xy[0].x - z_stepper_align.xy[0].y, z_stepper_align.xy[1].x - z_stepper_align.xy[1].y)
209 149
       #endif
210 150
     );
211 151
 
@@ -216,31 +156,39 @@ void GcodeSuite::G34() {
216 156
     current_position.z -= z_probe * 0.5f;
217 157
 
218 158
     float last_z_align_move[NUM_Z_STEPPER_DRIVERS] = ARRAY_N(NUM_Z_STEPPER_DRIVERS, 10000.0f, 10000.0f, 10000.0f),
219
-          z_measured[G34_PROBE_COUNT] = { 0 },
159
+          z_measured[NUM_Z_STEPPER_DRIVERS] = { 0 },
220 160
           z_maxdiff = 0.0f,
221 161
           amplification = z_auto_align_amplification;
222 162
 
223 163
     uint8_t iteration;
224 164
     bool err_break = false;
165
+
166
+    #if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
167
+      bool adjustment_reverse = false;
168
+    #endif
169
+
225 170
     for (iteration = 0; iteration < z_auto_align_iterations; ++iteration) {
226 171
       if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> probing all positions.");
227 172
 
228 173
       SERIAL_ECHOLNPAIR("\nITERATION: ", int(iteration + 1));
229 174
 
230 175
       // Initialize minimum value
231
-      float z_measured_min = 100000.0f,
176
+      float z_measured_min =  100000.0f,
232 177
             z_measured_max = -100000.0f;
233 178
 
234 179
       // Probe all positions (one per Z-Stepper)
235
-      for (uint8_t i = 0; i < G34_PROBE_COUNT; ++i) {
180
+      for (uint8_t i = 0; i < NUM_Z_STEPPER_DRIVERS; ++i) {
236 181
         // iteration odd/even --> downward / upward stepper sequence
237
-        const uint8_t iprobe = (iteration & 1) ? G34_PROBE_COUNT - 1 - i : i;
182
+        const uint8_t iprobe = (iteration & 1) ? NUM_Z_STEPPER_DRIVERS - 1 - i : i;
238 183
 
239 184
         // Safe clearance even on an incline
240 185
         if (iteration == 0 || i > 0) do_blocking_move_to_z(z_probe);
241 186
 
187
+        if (DEBUGGING(LEVELING))
188
+          DEBUG_ECHOLNPAIR_P(PSTR("Probing X"), z_stepper_align.xy[iprobe].x, SP_Y_STR, z_stepper_align.xy[iprobe].y);
189
+
242 190
         // Probe a Z height for each stepper.
243
-        const float z_probed_height = probe.probe_at_point(z_stepper_align_pos[iprobe], raise_after, 0, true);
191
+        const float z_probed_height = probe.probe_at_point(z_stepper_align.xy[iprobe], raise_after, 0, true);
244 192
         if (isnan(z_probed_height)) {
245 193
           SERIAL_ECHOLNPGM("Probing failed.");
246 194
           err_break = true;
@@ -279,15 +227,15 @@ void GcodeSuite::G34() {
279 227
         // This allows the actual adjustment logic to be shared by both algorithms.
280 228
         linear_fit_data lfd;
281 229
         incremental_LSF_reset(&lfd);
282
-        for (uint8_t i = 0; i < G34_PROBE_COUNT; ++i) {
283
-          SERIAL_ECHOLNPAIR("PROBEPT_", int(i + 1), ": ", z_measured[i]);
284
-          incremental_LSF(&lfd, z_stepper_align_pos[i], z_measured[i]);
230
+        for (uint8_t i = 0; i < NUM_Z_STEPPER_DRIVERS; ++i) {
231
+          SERIAL_ECHOLNPAIR("PROBEPT_", i + '1', ": ", z_measured[i]);
232
+          incremental_LSF(&lfd, z_stepper_align.xy[i], z_measured[i]);
285 233
         }
286 234
         finish_incremental_LSF(&lfd);
287 235
 
288 236
         z_measured_min = 100000.0f;
289 237
         for (uint8_t i = 0; i < NUM_Z_STEPPER_DRIVERS; ++i) {
290
-          z_measured[i] = -(lfd.A * z_stepper_align_stepper_pos[i].x + lfd.B * z_stepper_align_stepper_pos[i].y);
238
+          z_measured[i] = -(lfd.A * z_stepper_align.stepper_xy[i].x + lfd.B * z_stepper_align.stepper_xy[i].y);
291 239
           z_measured_min = _MIN(z_measured_min, z_measured[i]);
292 240
         }
293 241
 
@@ -309,8 +257,8 @@ void GcodeSuite::G34() {
309 257
       // Correct the individual stepper offsets
310 258
       for (uint8_t zstepper = 0; zstepper < NUM_Z_STEPPER_DRIVERS; ++zstepper) {
311 259
         // Calculate current stepper move
312
-        const float z_align_move = z_measured[zstepper] - z_measured_min,
313
-                    z_align_abs = ABS(z_align_move);
260
+        float z_align_move = z_measured[zstepper] - z_measured_min;
261
+        const float z_align_abs = ABS(z_align_move);
314 262
 
315 263
         #if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
316 264
           // Optimize one iteration's correction based on the first measurements
@@ -318,10 +266,14 @@ void GcodeSuite::G34() {
318 266
         #endif
319 267
 
320 268
         // Check for less accuracy compared to last move
321
-        if (last_z_align_move[zstepper] < z_align_abs - 1.0) {
269
+        if (last_z_align_move[zstepper] < z_align_abs * 0.7f) {
322 270
           SERIAL_ECHOLNPGM("Decreasing accuracy detected.");
323
-          err_break = true;
324
-          break;
271
+          #if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
272
+            adjustment_reverse = !adjustment_reverse;
273
+          #else
274
+            err_break = true;
275
+            break;
276
+          #endif
325 277
         }
326 278
 
327 279
         // Remember the alignment for the next iteration
@@ -342,6 +294,13 @@ void GcodeSuite::G34() {
342 294
           #endif
343 295
         }
344 296
 
297
+        #if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
298
+          // Decreasing accuracy was detected so move was inverted.
299
+          // Will match reversed Z steppers on dual steppers. Triple will need more work to map.
300
+          if (adjustment_reverse)
301
+            z_align_move = -z_align_move;
302
+        #endif
303
+
345 304
         // Do a move to correct part of the misalignment for the current stepper
346 305
         do_blocking_move_to_z(amplification * z_align_move + current_position.z);
347 306
       } // for (zstepper)
@@ -406,12 +365,13 @@ void GcodeSuite::G34() {
406 365
  *   Y<pos>   : Y position to set (Unchanged if omitted)
407 366
  */
408 367
 void GcodeSuite::M422() {
368
+
409 369
   if (!parser.seen_any()) {
410
-    for (uint8_t i = 0; i < G34_PROBE_COUNT; ++i)
411
-      SERIAL_ECHOLNPAIR_P(PSTR("M422 S"), i + 1, SP_X_STR, z_stepper_align_pos[i].x, SP_Y_STR, z_stepper_align_pos[i].y);
370
+    for (uint8_t i = 0; i < NUM_Z_STEPPER_DRIVERS; ++i)
371
+      SERIAL_ECHOLNPAIR_P(PSTR("M422 S"), i + '1', SP_X_STR, z_stepper_align.xy[i].x, SP_Y_STR, z_stepper_align.xy[i].y);
412 372
     #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
413 373
       for (uint8_t i = 0; i < NUM_Z_STEPPER_DRIVERS; ++i)
414
-        SERIAL_ECHOLNPAIR_P(PSTR("M422 W"), i + 1, SP_X_STR, z_stepper_align_stepper_pos[i].x, SP_Y_STR, z_stepper_align_stepper_pos[i].y);
374
+        SERIAL_ECHOLNPAIR_P(PSTR("M422 W"), i + '1', SP_X_STR, z_stepper_align.stepper_xy[i].x, SP_Y_STR, z_stepper_align.stepper_xy[i].y);
415 375
     #endif
416 376
     return;
417 377
   }
@@ -427,9 +387,9 @@ void GcodeSuite::M422() {
427 387
 
428 388
   xy_pos_t *pos_dest = (
429 389
     #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
430
-      !is_probe_point ? z_stepper_align_stepper_pos :
390
+      !is_probe_point ? z_stepper_align.stepper_xy :
431 391
     #endif
432
-    z_stepper_align_pos
392
+    z_stepper_align.xy
433 393
   );
434 394
 
435 395
   if (!is_probe_point
@@ -451,7 +411,7 @@ void GcodeSuite::M422() {
451 411
   int8_t position_index;
452 412
   if (is_probe_point) {
453 413
     position_index = parser.intval('S') - 1;
454
-    if (!WITHIN(position_index, 0, int8_t(G34_PROBE_COUNT) - 1)) {
414
+    if (!WITHIN(position_index, 0, int8_t(NUM_Z_STEPPER_DRIVERS) - 1)) {
455 415
       SERIAL_ECHOLNPGM("?(S) Z-ProbePosition index invalid.");
456 416
       return;
457 417
     }

+ 37
- 1
Marlin/src/module/configuration_store.cpp Переглянути файл

@@ -37,7 +37,7 @@
37 37
  */
38 38
 
39 39
 // Change EEPROM version if the structure changes
40
-#define EEPROM_VERSION "V75"
40
+#define EEPROM_VERSION "V76"
41 41
 #define EEPROM_OFFSET 100
42 42
 
43 43
 // Check the integrity of data offsets.
@@ -66,6 +66,10 @@
66 66
   #include "../feature/bedlevel/bedlevel.h"
67 67
 #endif
68 68
 
69
+#if ENABLED(Z_STEPPER_AUTO_ALIGN)
70
+  #include "../feature/z_stepper_align.h"
71
+#endif
72
+
69 73
 #if ENABLED(EXTENSIBLE_UI)
70 74
   #include "../lcd/extensible_ui/ui_api.h"
71 75
 #endif
@@ -252,6 +256,16 @@ typedef struct SettingsDataStruct {
252 256
   #endif
253 257
 
254 258
   //
259
+  // Z_STEPPER_AUTO_ALIGN, Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS
260
+  //
261
+  #if ENABLED(Z_STEPPER_AUTO_ALIGN)
262
+    xy_pos_t z_stepper_align_xy[NUM_Z_STEPPER_DRIVERS];             // M422 S X Y
263
+    #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
264
+      xy_pos_t z_stepper_align_stepper_xy[NUM_Z_STEPPER_DRIVERS];   // M422 W X Y
265
+    #endif
266
+  #endif
267
+
268
+  //
255 269
   // ULTIPANEL
256 270
   //
257 271
   int16_t ui_preheat_hotend_temp[2],                    // M145 S0 H
@@ -801,6 +815,13 @@ void MarlinSettings::postprocess() {
801 815
       #endif
802 816
     }
803 817
 
818
+    #if ENABLED(Z_STEPPER_AUTO_ALIGN)
819
+      EEPROM_WRITE(z_stepper_align.xy);
820
+      #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
821
+        EEPROM_WRITE(z_stepper_align.stepper_xy);
822
+      #endif
823
+    #endif
824
+
804 825
     //
805 826
     // LCD Preheat settings
806 827
     //
@@ -1669,6 +1690,13 @@ void MarlinSettings::postprocess() {
1669 1690
         #endif
1670 1691
       }
1671 1692
 
1693
+      #if ENABLED(Z_STEPPER_AUTO_ALIGN)
1694
+        EEPROM_READ(z_stepper_align.xy);
1695
+        #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
1696
+          EEPROM_READ(z_stepper_align.stepper_xy);
1697
+        #endif
1698
+      #endif
1699
+
1672 1700
       //
1673 1701
       // LCD Preheat settings
1674 1702
       //
@@ -2474,6 +2502,14 @@ void MarlinSettings::reset() {
2474 2502
   #endif
2475 2503
 
2476 2504
   //
2505
+  // Z Stepper Auto-alignment points
2506
+  //
2507
+
2508
+  #if ENABLED(Z_STEPPER_AUTO_ALIGN)
2509
+    z_stepper_align.reset_to_default();
2510
+  #endif
2511
+
2512
+  //
2477 2513
   // Servo Angles
2478 2514
   //
2479 2515
 

Завантаження…
Відмінити
Зберегти