Browse Source

✨ Update G34 for 4x Z steppers (#22039)

Scott Lahteine 4 years ago
parent
commit
53a82511ff
No account linked to committer's email address
1 changed files with 50 additions and 39 deletions
  1. 50
    39
      Marlin/src/gcode/calibrate/G34_M422.cpp

+ 50
- 39
Marlin/src/gcode/calibrate/G34_M422.cpp View File

48
 #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
48
 #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
49
 #include "../../core/debug_out.h"
49
 #include "../../core/debug_out.h"
50
 
50
 
51
+#if NUM_Z_STEPPER_DRIVERS >= 3
52
+  #define TRIPLE_Z 1
53
+  #if NUM_Z_STEPPER_DRIVERS >= 4
54
+    #define QUAD_Z 1
55
+  #endif
56
+#endif
57
+
51
 /**
58
 /**
52
  * G34: Z-Stepper automatic alignment
59
  * G34: Z-Stepper automatic alignment
53
  *
60
  *
82
     switch (parser.intval('Z')) {
89
     switch (parser.intval('Z')) {
83
       case 1: stepper.set_z1_lock(state); break;
90
       case 1: stepper.set_z1_lock(state); break;
84
       case 2: stepper.set_z2_lock(state); break;
91
       case 2: stepper.set_z2_lock(state); break;
85
-      #if NUM_Z_STEPPER_DRIVERS >= 3
92
+      #if TRIPLE_Z
86
         case 3: stepper.set_z3_lock(state); break;
93
         case 3: stepper.set_z3_lock(state); break;
87
-        #if NUM_Z_STEPPER_DRIVERS >= 4
94
+        #if QUAD_Z
88
           case 4: stepper.set_z4_lock(state); break;
95
           case 4: stepper.set_z4_lock(state); break;
89
         #endif
96
         #endif
90
       #endif
97
       #endif
99
   #if ENABLED(Z_STEPPER_AUTO_ALIGN)
106
   #if ENABLED(Z_STEPPER_AUTO_ALIGN)
100
     do { // break out on error
107
     do { // break out on error
101
 
108
 
102
-      #if NUM_Z_STEPPER_DRIVERS == 4
103
-        SERIAL_ECHOLNPGM("Alignment for 4 steppers is Experimental!");
104
-      #elif NUM_Z_STEPPER_DRIVERS > 4
105
-        SERIAL_ECHOLNPGM("Alignment not supported for over 4 steppers");
106
-        break;
107
-      #endif
108
-
109
       const int8_t z_auto_align_iterations = parser.intval('I', Z_STEPPER_ALIGN_ITERATIONS);
109
       const int8_t z_auto_align_iterations = parser.intval('I', Z_STEPPER_ALIGN_ITERATIONS);
110
       if (!WITHIN(z_auto_align_iterations, 1, 30)) {
110
       if (!WITHIN(z_auto_align_iterations, 1, 30)) {
111
         SERIAL_ECHOLNPGM("?(I)teration out of bounds (1-30).");
111
         SERIAL_ECHOLNPGM("?(I)teration out of bounds (1-30).");
157
         const xy_pos_t diff = z_stepper_align.xy[i] - z_stepper_align.xy[j];
157
         const xy_pos_t diff = z_stepper_align.xy[i] - z_stepper_align.xy[j];
158
         return HYPOT2(diff.x, diff.y);
158
         return HYPOT2(diff.x, diff.y);
159
       };
159
       };
160
-      float z_probe = Z_BASIC_CLEARANCE + (G34_MAX_GRADE) * 0.01f * SQRT(
161
-        #if NUM_Z_STEPPER_DRIVERS == 3
162
-          _MAX(magnitude2(0, 1), magnitude2(1, 2), magnitude2(2, 0))
163
-        #elif NUM_Z_STEPPER_DRIVERS == 4
164
-          _MAX(magnitude2(0, 1), magnitude2(1, 2), magnitude2(2, 3),
165
-                magnitude2(3, 0), magnitude2(0, 2), magnitude2(1, 3))
166
-        #else
167
-          magnitude2(0, 1)
160
+      float z_probe = Z_BASIC_CLEARANCE + (G34_MAX_GRADE) * 0.01f * SQRT(_MAX(0, magnitude2(0, 1)
161
+        #if TRIPLE_Z
162
+          , magnitude2(2, 1), magnitude2(2, 0)
163
+          #if QUAD_Z
164
+            , magnitude2(3, 2), magnitude2(3, 1), magnitude2(3, 0)
165
+          #endif
168
         #endif
166
         #endif
169
-      );
167
+      ));
170
 
168
 
171
       // Home before the alignment procedure
169
       // Home before the alignment procedure
172
       if (!all_axes_trusted()) home_all_axes();
170
       if (!all_axes_trusted()) home_all_axes();
178
       // This hack is un-done at the end of G34 - either by re-homing, or by using the probed heights of the last iteration.
176
       // This hack is un-done at the end of G34 - either by re-homing, or by using the probed heights of the last iteration.
179
 
177
 
180
       #if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
178
       #if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
181
-        float last_z_align_move[NUM_Z_STEPPER_DRIVERS] = ARRAY_N(NUM_Z_STEPPER_DRIVERS, 10000.0f, 10000.0f, 10000.0f, 10000.0f);
179
+        float last_z_align_move[NUM_Z_STEPPER_DRIVERS] = ARRAY_N_1(NUM_Z_STEPPER_DRIVERS, 10000.0f);
182
       #else
180
       #else
183
         float last_z_align_level_indicator = 10000.0f;
181
         float last_z_align_level_indicator = 10000.0f;
184
       #endif
182
       #endif
280
             z_measured_min = _MIN(z_measured_min, z_measured[i]);
278
             z_measured_min = _MIN(z_measured_min, z_measured[i]);
281
           }
279
           }
282
 
280
 
283
-          SERIAL_ECHOLNPAIR("CALCULATED STEPPER POSITIONS: Z1=", z_measured[0], " Z2=", z_measured[1], " Z3=", z_measured[2]);
281
+          SERIAL_ECHOLNPAIR(
282
+            LIST_N(DOUBLE(NUM_Z_STEPPER_DRIVERS),
283
+              "Calculated Z1=", z_measured[0],
284
+                        " Z2=", z_measured[1],
285
+                        " Z3=", z_measured[2],
286
+                        " Z4=", z_measured[3]
287
+            )
288
+          );
284
         #endif
289
         #endif
285
 
290
 
286
         SERIAL_ECHOLNPAIR("\n"
291
         SERIAL_ECHOLNPAIR("\n"
287
-          "DIFFERENCE Z1-Z2=", ABS(z_measured[0] - z_measured[1])
288
-          #if NUM_Z_STEPPER_DRIVERS == 3
289
-            , " Z2-Z3=", ABS(z_measured[1] - z_measured[2])
292
+          "Z2-Z1=", ABS(z_measured[1] - z_measured[0])
293
+          #if TRIPLE_Z
294
+            , " Z3-Z2=", ABS(z_measured[2] - z_measured[1])
290
             , " Z3-Z1=", ABS(z_measured[2] - z_measured[0])
295
             , " Z3-Z1=", ABS(z_measured[2] - z_measured[0])
296
+            #if QUAD_Z
297
+              , " Z4-Z3=", ABS(z_measured[3] - z_measured[2])
298
+              , " Z4-Z2=", ABS(z_measured[3] - z_measured[1])
299
+              , " Z4-Z1=", ABS(z_measured[3] - z_measured[0])
300
+            #endif
291
           #endif
301
           #endif
292
         );
302
         );
303
+
293
         #if HAS_STATUS_MESSAGE
304
         #if HAS_STATUS_MESSAGE
294
           char fstr1[10];
305
           char fstr1[10];
295
-          #if NUM_Z_STEPPER_DRIVERS == 2
296
-            char msg[6 + (6 + 5) * 1 + 1];
297
-          #else
298
-            char msg[6 + (6 + 5) * 3 + 1], fstr2[10], fstr3[10];
299
-          #endif
300
-          sprintf_P(msg,
301
-            PSTR("Diffs Z1-Z2=%s"
302
-              #if NUM_Z_STEPPER_DRIVERS == 3
303
-                " Z2-Z3=%s"
304
-                " Z3-Z1=%s"
306
+          char msg[6 + (6 + 5) * NUM_Z_STEPPER_DRIVERS + 1]
307
+            #if TRIPLE_Z
308
+              , fstr2[10], fstr3[10]
309
+              #if QUAD_Z
310
+                , fstr4[10], fstr5[10], fstr6[10]
305
               #endif
311
               #endif
306
-            ), dtostrf(ABS(z_measured[0] - z_measured[1]), 1, 3, fstr1)
307
-            #if NUM_Z_STEPPER_DRIVERS == 3
308
-              , dtostrf(ABS(z_measured[1] - z_measured[2]), 1, 3, fstr2)
309
-              , dtostrf(ABS(z_measured[2] - z_measured[0]), 1, 3, fstr3)
310
             #endif
312
             #endif
313
+          ;
314
+          sprintf_P(msg,
315
+            PSTR("1:2=%s" TERN_(TRIPLE_Z, " 3-2=%s 3-1=%s") TERN_(QUAD_Z, " 4-3=%s 4-2=%s 4-1=%s")),
316
+            dtostrf(ABS(z_measured[1] - z_measured[0]), 1, 3, fstr1)
317
+            OPTARG(TRIPLE_Z, dtostrf(ABS(z_measured[2] - z_measured[1]), 1, 3, fstr2))
318
+            OPTARG(TRIPLE_Z, dtostrf(ABS(z_measured[2] - z_measured[0]), 1, 3, fstr3))
319
+            OPTARG(QUAD_Z,   dtostrf(ABS(z_measured[3] - z_measured[2]), 1, 3, fstr4))
320
+            OPTARG(QUAD_Z,   dtostrf(ABS(z_measured[3] - z_measured[1]), 1, 3, fstr5))
321
+            OPTARG(QUAD_Z,   dtostrf(ABS(z_measured[3] - z_measured[0]), 1, 3, fstr6))
311
           );
322
           );
312
           ui.set_status(msg);
323
           ui.set_status(msg);
313
         #endif
324
         #endif
314
 
325
 
315
-        auto decreasing_accuracy = [](const_float_t v1, const_float_t v2){
326
+        auto decreasing_accuracy = [](const_float_t v1, const_float_t v2) {
316
           if (v1 < v2 * 0.7f) {
327
           if (v1 < v2 * 0.7f) {
317
             SERIAL_ECHOLNPGM("Decreasing Accuracy Detected.");
328
             SERIAL_ECHOLNPGM("Decreasing Accuracy Detected.");
318
             LCD_MESSAGEPGM(MSG_DECREASING_ACCURACY);
329
             LCD_MESSAGEPGM(MSG_DECREASING_ACCURACY);
437
       #endif
448
       #endif
438
 
449
 
439
     }while(0);
450
     }while(0);
440
-  #endif
451
+  #endif // Z_STEPPER_AUTO_ALIGN
441
 }
452
 }
442
 
453
 
443
 #endif // Z_MULTI_ENDSTOPS || Z_STEPPER_AUTO_ALIGN
454
 #endif // Z_MULTI_ENDSTOPS || Z_STEPPER_AUTO_ALIGN

Loading…
Cancel
Save