Bladeren bron

G33 Autotune calibration update #10

LVD-AC 6 jaren geleden
bovenliggende
commit
dcfc2503c2

+ 0
- 1
Marlin/src/config/examples/Micromake/C1/README.md Bestand weergeven

@@ -13,4 +13,3 @@ Configuration files for Micromake C1 with…
13 13
   - 128 STEPS configured with jumper on the motherboard (all open for 128 Steps).
14 14
   - Capacitive Probe (Adjust offsets at your convenience)
15 15
   - French language with no accents for Japanese LCD.
16
-  

+ 6
- 0
Marlin/src/config/examples/delta/FLSUN/auto_calibrate/Configuration.h Bestand weergeven

@@ -496,6 +496,12 @@
496 496
   #if ENABLED(DELTA_AUTO_CALIBRATION)
497 497
     // set the default number of probe points : n*n (1 -> 7)
498 498
     #define DELTA_CALIBRATION_DEFAULT_POINTS 4
499
+
500
+    // Enable and set these values based on results of 'G33 A1'
501
+    //#define H_FACTOR 1.01
502
+    //#define R_FACTOR 2.61
503
+    //#define A_FACTOR 0.87
504
+
499 505
   #endif
500 506
 
501 507
   #if ENABLED(DELTA_AUTO_CALIBRATION) || ENABLED(DELTA_CALIBRATION_MENU)

+ 6
- 0
Marlin/src/config/examples/delta/FLSUN/kossel_mini/Configuration.h Bestand weergeven

@@ -496,6 +496,12 @@
496 496
   #if ENABLED(DELTA_AUTO_CALIBRATION)
497 497
     // set the default number of probe points : n*n (1 -> 7)
498 498
     #define DELTA_CALIBRATION_DEFAULT_POINTS 4
499
+
500
+    // Enable and set these values based on results of 'G33 A1'
501
+    //#define H_FACTOR 1.01
502
+    //#define R_FACTOR 2.61
503
+    //#define A_FACTOR 0.87
504
+
499 505
   #endif
500 506
 
501 507
   #if ENABLED(DELTA_AUTO_CALIBRATION) || ENABLED(DELTA_CALIBRATION_MENU)

+ 6
- 0
Marlin/src/config/examples/delta/generic/Configuration.h Bestand weergeven

@@ -486,6 +486,12 @@
486 486
   #if ENABLED(DELTA_AUTO_CALIBRATION)
487 487
     // set the default number of probe points : n*n (1 -> 7)
488 488
     #define DELTA_CALIBRATION_DEFAULT_POINTS 4
489
+
490
+    // Enable and set these values based on results of 'G33 A1'
491
+    //#define H_FACTOR 1.01
492
+    //#define R_FACTOR 2.61
493
+    //#define A_FACTOR 0.87
494
+
489 495
   #endif
490 496
 
491 497
   #if ENABLED(DELTA_AUTO_CALIBRATION) || ENABLED(DELTA_CALIBRATION_MENU)

+ 6
- 0
Marlin/src/config/examples/delta/kossel_mini/Configuration.h Bestand weergeven

@@ -486,6 +486,12 @@
486 486
   #if ENABLED(DELTA_AUTO_CALIBRATION)
487 487
     // set the default number of probe points : n*n (1 -> 7)
488 488
     #define DELTA_CALIBRATION_DEFAULT_POINTS 4
489
+
490
+    // Enable and set these values based on results of 'G33 A1'
491
+    //#define H_FACTOR 1.01
492
+    //#define R_FACTOR 2.61
493
+    //#define A_FACTOR 0.87
494
+
489 495
   #endif
490 496
 
491 497
   #if ENABLED(DELTA_AUTO_CALIBRATION) || ENABLED(DELTA_CALIBRATION_MENU)

+ 6
- 0
Marlin/src/config/examples/delta/kossel_pro/Configuration.h Bestand weergeven

@@ -472,6 +472,12 @@
472 472
   #if ENABLED(DELTA_AUTO_CALIBRATION)
473 473
     // set the default number of probe points : n*n (1 -> 7)
474 474
     #define DELTA_CALIBRATION_DEFAULT_POINTS 4
475
+
476
+    // Enable and set these values based on results of 'G33 A1'
477
+    //#define H_FACTOR 1.01
478
+    //#define R_FACTOR 2.61
479
+    //#define A_FACTOR 0.87
480
+
475 481
   #endif
476 482
 
477 483
   #if ENABLED(DELTA_AUTO_CALIBRATION) || ENABLED(DELTA_CALIBRATION_MENU)

+ 6
- 0
Marlin/src/config/examples/delta/kossel_xl/Configuration.h Bestand weergeven

@@ -490,6 +490,12 @@
490 490
   #if ENABLED(DELTA_AUTO_CALIBRATION)
491 491
     // set the default number of probe points : n*n (1 -> 7)
492 492
     #define DELTA_CALIBRATION_DEFAULT_POINTS 4
493
+
494
+    // Enable and set these values based on results of 'G33 A1'
495
+    //#define H_FACTOR 1.01
496
+    //#define R_FACTOR 2.61
497
+    //#define A_FACTOR 0.87
498
+
493 499
   #endif
494 500
 
495 501
   #if ENABLED(DELTA_AUTO_CALIBRATION) || ENABLED(DELTA_CALIBRATION_MENU)

+ 317
- 154
Marlin/src/gcode/calibrate/G33.cpp Bestand weergeven

@@ -37,35 +37,6 @@
37 37
   #include "../../feature/bedlevel/bedlevel.h"
38 38
 #endif
39 39
 
40
-/**
41
- * G33 - Delta '1-4-7-point' Auto-Calibration
42
- *       Calibrate height, endstops, delta radius, and tower angles.
43
- *
44
- * Parameters:
45
- *
46
- *   Pn  Number of probe points:
47
- *
48
- *      P0     No probe. Normalize only.
49
- *      P1     Probe center and set height only.
50
- *      P2     Probe center and towers. Set height, endstops, and delta radius.
51
- *      P3     Probe all positions: center, towers and opposite towers. Set all.
52
- *      P4-P7  Probe all positions at different locations and average them.
53
- *
54
- *   T0  Don't calibrate tower angle corrections
55
- *
56
- *   Cn.nn Calibration precision; when omitted calibrates to maximum precision
57
- *
58
- *   Fn  Force to run at least n iterations and takes the best result
59
- *
60
- *   Vn  Verbose level:
61
- *
62
- *      V0  Dry-run mode. Report settings and probe results. No calibration.
63
- *      V1  Report settings
64
- *      V2  Report settings and probe results
65
- *
66
- *   E   Engage the probe for each point
67
- */
68
-
69 40
 static void print_signed_float(const char * const prefix, const float &f) {
70 41
   SERIAL_PROTOCOLPGM("  ");
71 42
   serialprintPGM(prefix);
@@ -77,21 +48,55 @@ static void print_signed_float(const char * const prefix, const float &f) {
77 48
 static void print_G33_settings(const bool end_stops, const bool tower_angles) {
78 49
   SERIAL_PROTOCOLPAIR(".Height:", DELTA_HEIGHT + home_offset[Z_AXIS]);
79 50
   if (end_stops) {
80
-    print_signed_float(PSTR("  Ex"), delta_endstop_adj[A_AXIS]);
51
+    print_signed_float(PSTR("Ex"), delta_endstop_adj[A_AXIS]);
81 52
     print_signed_float(PSTR("Ey"), delta_endstop_adj[B_AXIS]);
82 53
     print_signed_float(PSTR("Ez"), delta_endstop_adj[C_AXIS]);
83
-    SERIAL_PROTOCOLPAIR("    Radius:", delta_radius);
84 54
   }
85
-  SERIAL_EOL();
55
+  if (end_stops && tower_angles) {
56
+    SERIAL_PROTOCOLPAIR("  Radius:", delta_radius);
57
+    SERIAL_EOL();
58
+    SERIAL_CHAR('.');
59
+    SERIAL_PROTOCOL_SP(13);
60
+  }
86 61
   if (tower_angles) {
87
-    SERIAL_PROTOCOLPGM(".Tower angle :  ");
88 62
     print_signed_float(PSTR("Tx"), delta_tower_angle_trim[A_AXIS]);
89 63
     print_signed_float(PSTR("Ty"), delta_tower_angle_trim[B_AXIS]);
90 64
     print_signed_float(PSTR("Tz"), delta_tower_angle_trim[C_AXIS]);
65
+  }
66
+  if ((!end_stops && tower_angles) || (end_stops && !tower_angles)) { // XOR
67
+    SERIAL_PROTOCOLPAIR("  Radius:", delta_radius);
68
+  }
69
+  SERIAL_EOL();
70
+}
71
+
72
+static void print_G33_results(const float z_at_pt[13], const bool tower_points, const bool opposite_points) {
73
+  SERIAL_PROTOCOLPGM(".    ");
74
+  print_signed_float(PSTR("c"), z_at_pt[0]);
75
+  if (tower_points) {
76
+    print_signed_float(PSTR(" x"), z_at_pt[1]);
77
+    print_signed_float(PSTR(" y"), z_at_pt[5]);
78
+    print_signed_float(PSTR(" z"), z_at_pt[9]);
79
+  }
80
+  if (tower_points && opposite_points) {
91 81
     SERIAL_EOL();
82
+    SERIAL_CHAR('.');
83
+    SERIAL_PROTOCOL_SP(13);
92 84
   }
85
+  if (opposite_points) {
86
+    print_signed_float(PSTR("yz"), z_at_pt[7]);
87
+    print_signed_float(PSTR("zx"), z_at_pt[11]);
88
+    print_signed_float(PSTR("xy"), z_at_pt[3]);
89
+  }
90
+  SERIAL_EOL();
93 91
 }
94 92
 
93
+/**
94
+ * After G33:
95
+ *  - Move to the print ceiling (DELTA_HOME_TO_SAFE_ZONE only)
96
+ *  - Stow the probe
97
+ *  - Restore endstops state
98
+ *  - Select the old tool, if needed
99
+ */
95 100
 static void G33_cleanup(
96 101
   #if HOTENDS > 1
97 102
     const uint8_t old_tool_index
@@ -107,6 +112,216 @@ static void G33_cleanup(
107 112
   #endif
108 113
 }
109 114
 
115
+static float probe_G33_points(float z_at_pt[13], const int8_t probe_points, const bool towers_set, const bool stow_after_each) {
116
+  const bool _0p_calibration      = probe_points == 0,
117
+             _1p_calibration      = probe_points == 1,
118
+             _4p_calibration      = probe_points == 2,
119
+             _4p_opposite_points  = _4p_calibration && !towers_set,
120
+             _7p_calibration      = probe_points >= 3 || probe_points == 0,
121
+             _7p_half_circle      = probe_points == 3,
122
+             _7p_double_circle    = probe_points == 5,
123
+             _7p_triple_circle    = probe_points == 6,
124
+             _7p_quadruple_circle = probe_points == 7,
125
+             _7p_intermed_points  = probe_points >= 4,
126
+             _7p_multi_circle     = probe_points >= 5;
127
+
128
+  #if DISABLED(PROBE_MANUALLY)
129
+    const float dx = (X_PROBE_OFFSET_FROM_EXTRUDER),
130
+                dy = (Y_PROBE_OFFSET_FROM_EXTRUDER);
131
+  #endif
132
+
133
+  for (uint8_t i = 0; i < COUNT(z_at_pt); i++) z_at_pt[i] = 0.0;
134
+
135
+  if (!_0p_calibration) {
136
+
137
+    if (!_7p_half_circle && !_7p_triple_circle) { // probe the center
138
+      #if ENABLED(PROBE_MANUALLY)
139
+        z_at_pt[0] += lcd_probe_pt(0, 0);
140
+      #else
141
+        z_at_pt[0] += probe_pt(dx, dy, stow_after_each, 1, false);
142
+      #endif
143
+    }
144
+
145
+    if (_7p_calibration) { // probe extra center points
146
+      for (int8_t axis = _7p_multi_circle ? COUNT(z_at_pt) - 2 : COUNT(z_at_pt) - 4; axis > 0; axis -= _7p_multi_circle ? 2 : 4) {
147
+        const float a = RADIANS(180 + 30 * axis), r = delta_calibration_radius * 0.1;
148
+        #if ENABLED(PROBE_MANUALLY)
149
+          z_at_pt[0] += lcd_probe_pt(cos(a) * r, sin(a) * r);
150
+        #else
151
+          z_at_pt[0] += probe_pt(cos(a) * r + dx, sin(a) * r + dy, stow_after_each, 1);
152
+        #endif
153
+      }
154
+      z_at_pt[0] /= float(_7p_double_circle ? 7 : probe_points);
155
+    }
156
+
157
+    if (!_1p_calibration) {  // probe the radius
158
+      bool zig_zag = true;
159
+      const uint8_t start = _4p_opposite_points ? 3 : 1,
160
+                    step = _4p_calibration ? 4 : _7p_half_circle ? 2 : 1;
161
+      for (uint8_t axis = start; axis < COUNT(z_at_pt); axis += step) {
162
+        const float zigadd = (zig_zag ? 0.5 : 0.0),
163
+                    offset_circles = _7p_quadruple_circle ? zigadd + 1.0 :
164
+                                     _7p_triple_circle    ? zigadd + 0.5 :
165
+                                     _7p_double_circle    ? zigadd : 0;
166
+        for (float circles = -offset_circles ; circles <= offset_circles; circles++) {
167
+          const float a = RADIANS(180 + 30 * axis),
168
+                      r = delta_calibration_radius * (1 + circles * (zig_zag ? 0.1 : -0.1));
169
+          #if ENABLED(PROBE_MANUALLY)
170
+            z_at_pt[axis] += lcd_probe_pt(cos(a) * r, sin(a) * r);
171
+          #else
172
+            z_at_pt[axis] += probe_pt(cos(a) * r + dx, sin(a) * r + dy, stow_after_each, 1);
173
+          #endif
174
+        }
175
+        zig_zag = !zig_zag;
176
+        z_at_pt[axis] /= (2 * offset_circles + 1);
177
+      }
178
+    }
179
+
180
+    if (_7p_intermed_points) // average intermediates to tower and opposites
181
+      for (uint8_t axis = 1; axis < COUNT(z_at_pt); axis += 2)
182
+        z_at_pt[axis] = (z_at_pt[axis] + (z_at_pt[axis + 1] + z_at_pt[(axis + 10) % 12 + 1]) / 2.0) / 2.0;
183
+
184
+    float S1 = z_at_pt[0],
185
+          S2 = sq(z_at_pt[0]);
186
+    int16_t N = 1;
187
+    if (!_1p_calibration) // std dev from zero plane
188
+      for (uint8_t axis = (_4p_opposite_points ? 3 : 1); axis < COUNT(z_at_pt); axis += (_4p_calibration ? 4 : 2)) {
189
+        S1 += z_at_pt[axis];
190
+        S2 += sq(z_at_pt[axis]);
191
+        N++;
192
+      }
193
+    return round(SQRT(S2 / N) * 1000.0) / 1000.0 + 0.00001;
194
+  }
195
+
196
+  return 0.00001;
197
+}
198
+
199
+#if DISABLED(PROBE_MANUALLY)
200
+
201
+  static void G33_auto_tune() {
202
+    float z_at_pt[13]      = { 0.0 },
203
+          z_at_pt_base[13] = { 0.0 },
204
+          z_temp, h_fac = 0.0, r_fac = 0.0, a_fac = 0.0, norm = 0.8;
205
+
206
+    #define ZP(N,I) ((N) * z_at_pt[I])
207
+    #define Z06(I)  ZP(6, I)
208
+    #define Z03(I)  ZP(3, I)
209
+    #define Z02(I)  ZP(2, I)
210
+    #define Z01(I)  ZP(1, I)
211
+    #define Z32(I)  ZP(3/2, I)
212
+
213
+    SERIAL_PROTOCOLPGM("AUTO TUNE baseline");
214
+    SERIAL_EOL();
215
+    probe_G33_points(z_at_pt_base, 3, true, false);
216
+    print_G33_results(z_at_pt_base, true, true);
217
+
218
+    LOOP_XYZ(axis) {
219
+      delta_endstop_adj[axis] -= 1.0;
220
+
221
+      endstops.enable(true);
222
+      if (!home_delta()) return;
223
+      endstops.not_homing();
224
+
225
+      SERIAL_PROTOCOLPGM("Tuning E");
226
+      SERIAL_CHAR(tolower(axis_codes[axis]));
227
+      SERIAL_EOL();
228
+
229
+      probe_G33_points(z_at_pt, 3, true, false);
230
+      for (int8_t i = 0; i < COUNT(z_at_pt); i++) z_at_pt[i] -= z_at_pt_base[i];
231
+      print_G33_results(z_at_pt, true, true);
232
+      delta_endstop_adj[axis] += 1.0;
233
+      switch (axis) {
234
+        case A_AXIS :
235
+          h_fac += 4.0 / (Z03(0) +Z01(1)                         +Z32(11) +Z32(3)); // Offset by X-tower end-stop
236
+          break;
237
+        case B_AXIS :
238
+          h_fac += 4.0 / (Z03(0)         +Z01(5)         +Z32(7)          +Z32(3)); // Offset by Y-tower end-stop
239
+          break;
240
+        case C_AXIS :
241
+          h_fac += 4.0 / (Z03(0)                 +Z01(9) +Z32(7) +Z32(11)        ); // Offset by Z-tower end-stop
242
+          break;
243
+      }
244
+    }
245
+    h_fac /= 3.0;
246
+    h_fac *= norm; // Normalize to 1.02 for Kossel mini
247
+
248
+    for (int8_t zig_zag = -1; zig_zag < 2; zig_zag += 2) {
249
+      delta_radius += 1.0 * zig_zag;
250
+      recalc_delta_settings(delta_radius, delta_diagonal_rod, delta_tower_angle_trim);
251
+
252
+      endstops.enable(true);
253
+      if (!home_delta()) return;
254
+      endstops.not_homing();
255
+
256
+      SERIAL_PROTOCOLPGM("Tuning R");
257
+      SERIAL_PROTOCOL(zig_zag == -1 ? "-" : "+");
258
+      SERIAL_EOL();
259
+      probe_G33_points(z_at_pt, 3, true, false);
260
+      for (int8_t i = 0; i < COUNT(z_at_pt); i++) z_at_pt[i] -= z_at_pt_base[i];
261
+      print_G33_results(z_at_pt, true, true);
262
+      delta_radius -= 1.0 * zig_zag;
263
+      recalc_delta_settings(delta_radius, delta_diagonal_rod, delta_tower_angle_trim);
264
+      r_fac -= zig_zag * 6.0 / (Z03(1) + Z03(5) + Z03(9) + Z03(7) + Z03(11) + Z03(3)); // Offset by delta radius
265
+    }
266
+    r_fac /= 2.0;
267
+    r_fac *= 3 * norm; // Normalize to 2.25 for Kossel mini
268
+
269
+    LOOP_XYZ(axis) {
270
+      delta_tower_angle_trim[axis] += 1.0;
271
+      delta_endstop_adj[(axis + 1) % 3] -= 1.0 / 4.5;
272
+      delta_endstop_adj[(axis + 2) % 3] += 1.0 / 4.5;
273
+      z_temp = MAX3(delta_endstop_adj[A_AXIS], delta_endstop_adj[B_AXIS], delta_endstop_adj[C_AXIS]);
274
+      home_offset[Z_AXIS] -= z_temp;
275
+      LOOP_XYZ(axis) delta_endstop_adj[axis] -= z_temp;
276
+      recalc_delta_settings(delta_radius, delta_diagonal_rod, delta_tower_angle_trim);
277
+
278
+      endstops.enable(true);
279
+      if (!home_delta()) return;
280
+      endstops.not_homing();
281
+
282
+      SERIAL_PROTOCOLPGM("Tuning T");
283
+      SERIAL_CHAR(tolower(axis_codes[axis]));
284
+      SERIAL_EOL();
285
+
286
+      probe_G33_points(z_at_pt, 3, true, false);
287
+      for (int8_t i = 0; i < COUNT(z_at_pt); i++) z_at_pt[i] -= z_at_pt_base[i];
288
+      print_G33_results(z_at_pt, true, true);
289
+
290
+      delta_tower_angle_trim[axis] -= 1.0;
291
+      delta_endstop_adj[(axis+1) % 3] += 1.0/4.5;
292
+      delta_endstop_adj[(axis+2) % 3] -= 1.0/4.5;
293
+      z_temp = MAX3(delta_endstop_adj[A_AXIS], delta_endstop_adj[B_AXIS], delta_endstop_adj[C_AXIS]);
294
+      home_offset[Z_AXIS] -= z_temp;
295
+      LOOP_XYZ(axis) delta_endstop_adj[axis] -= z_temp;
296
+      recalc_delta_settings(delta_radius, delta_diagonal_rod, delta_tower_angle_trim);
297
+      switch (axis) {
298
+        case A_AXIS :
299
+        a_fac += 4.0 / (       Z06(5) -Z06(9)         +Z06(11) -Z06(3)); // Offset by alpha tower angle
300
+        break;
301
+        case B_AXIS :
302
+        a_fac += 4.0 / (-Z06(1)       +Z06(9) -Z06(7)          +Z06(3)); // Offset by beta tower angle
303
+        break;
304
+        case C_AXIS :
305
+        a_fac += 4.0 / (Z06(1) -Z06(5)        +Z06(7) -Z06(11)        ); // Offset by gamma tower angle
306
+        break;
307
+      }
308
+    }
309
+    a_fac /= 3.0;
310
+    a_fac *= norm; // Normalize to 0.83 for Kossel mini
311
+
312
+    endstops.enable(true);
313
+    if (!home_delta()) return;
314
+    endstops.not_homing();
315
+    print_signed_float(PSTR( "H_FACTOR: "), h_fac);
316
+    print_signed_float(PSTR(" R_FACTOR: "), r_fac);
317
+    print_signed_float(PSTR(" A_FACTOR: "), a_fac);
318
+    SERIAL_EOL();
319
+    SERIAL_PROTOCOLPGM("Copy these values to Configuration.h");
320
+    SERIAL_EOL();
321
+  }
322
+
323
+#endif // !PROBE_MANUALLY
324
+
110 325
 /**
111 326
  * G33 - Delta '1-4-7-point' Auto-Calibration
112 327
  *       Calibrate height, endstops, delta radius, and tower angles.
@@ -114,21 +329,21 @@ static void G33_cleanup(
114 329
  * Parameters:
115 330
  *
116 331
  *   Pn  Number of probe points:
117
- *
118 332
  *      P0     No probe. Normalize only.
119 333
  *      P1     Probe center and set height only.
120
- *      P2     Probe center and towers. Set height, endstops, and delta radius.
334
+ *      P2     Probe center and towers. Set height, endstops and delta radius.
121 335
  *      P3     Probe all positions: center, towers and opposite towers. Set all.
122 336
  *      P4-P7  Probe all positions at different locations and average them.
123 337
  *
124
- *   T0  Don't calibrate tower angle corrections
338
+ *   T   Don't calibrate tower angle corrections
125 339
  *
126
- *   Cn.nn Calibration precision; when omitted calibrates to maximum precision
340
+ *   Cn.nn  Calibration precision; when omitted calibrates to maximum precision
127 341
  *
128 342
  *   Fn  Force to run at least n iterations and takes the best result
129 343
  *
130
- *   Vn  Verbose level:
344
+ *   A   Auto tune calibartion factors (set in Configuration.h)
131 345
  *
346
+ *   Vn  Verbose level:
132 347
  *      V0  Dry-run mode. Report settings and probe results. No calibration.
133 348
  *      V1  Report settings
134 349
  *      V2  Report settings and probe results
@@ -162,26 +377,24 @@ void GcodeSuite::G33() {
162 377
   }
163 378
 
164 379
   const bool towers_set           = !parser.boolval('T'),
380
+             auto_tune            = parser.boolval('A'),
165 381
              stow_after_each      = parser.boolval('E'),
166 382
              _0p_calibration      = probe_points == 0,
167 383
              _1p_calibration      = probe_points == 1,
168 384
              _4p_calibration      = probe_points == 2,
169
-             _4p_towers_points    = _4p_calibration && towers_set,
170
-             _4p_opposite_points  = _4p_calibration && !towers_set,
171
-             _7p_calibration      = probe_points >= 3 || _0p_calibration,
172
-             _7p_half_circle      = probe_points == 3,
385
+             _tower_results       = (_4p_calibration && towers_set)
386
+                                    || probe_points >= 3 || probe_points == 0,
387
+             _opposite_results    = (_4p_calibration && !towers_set)
388
+                                    || probe_points >= 3 || probe_points == 0,
389
+             _endstop_results     = probe_points != 1,
390
+             _angle_results       = (probe_points >= 3 || probe_points == 0) && towers_set,
173 391
              _7p_double_circle    = probe_points == 5,
174 392
              _7p_triple_circle    = probe_points == 6,
175
-             _7p_quadruple_circle = probe_points == 7,
176
-             _7p_multi_circle     = _7p_double_circle || _7p_triple_circle || _7p_quadruple_circle,
177
-             _7p_intermed_points  = _7p_calibration && !_7p_half_circle;
393
+             _7p_quadruple_circle = probe_points == 7;
178 394
   const static char save_message[] PROGMEM = "Save with M500 and/or copy to Configuration.h";
179
-  const float dx = (X_PROBE_OFFSET_FROM_EXTRUDER),
180
-              dy = (Y_PROBE_OFFSET_FROM_EXTRUDER);
181 395
   int8_t iterations = 0;
182 396
   float test_precision,
183 397
         zero_std_dev = (verbose_level ? 999.0 : 0.0), // 0.0 in dry-run mode : forced end
184
-        zero_std_dev_old = zero_std_dev,
185 398
         zero_std_dev_min = zero_std_dev,
186 399
         e_old[ABC] = {
187 400
           delta_endstop_adj[A_AXIS],
@@ -196,12 +409,14 @@ void GcodeSuite::G33() {
196 409
           delta_tower_angle_trim[C_AXIS]
197 410
         };
198 411
 
412
+  SERIAL_PROTOCOLLNPGM("G33 Auto Calibrate");
413
+
199 414
   if (!_1p_calibration && !_0p_calibration) {  // test if the outer radius is reachable
200 415
     const float circles = (_7p_quadruple_circle ? 1.5 :
201 416
                            _7p_triple_circle    ? 1.0 :
202 417
                            _7p_double_circle    ? 0.5 : 0),
203 418
                 r = (1 + circles * 0.1) * delta_calibration_radius;
204
-    for (uint8_t axis = 1; axis < 13; ++axis) {
419
+    for (uint8_t axis = 1; axis <= 12; ++axis) {
205 420
       const float a = RADIANS(180 + 30 * axis);
206 421
       if (!position_is_reachable_xy(cos(a) * r, sin(a) * r)) {
207 422
         SERIAL_PROTOCOLLNPGM("?(M665 B)ed radius is implausible.");
@@ -209,7 +424,6 @@ void GcodeSuite::G33() {
209 424
       }
210 425
     }
211 426
   }
212
-  SERIAL_PROTOCOLLNPGM("G33 Auto Calibrate");
213 427
 
214 428
   stepper.synchronize();
215 429
   #if HAS_LEVELING
@@ -232,7 +446,17 @@ void GcodeSuite::G33() {
232 446
     endstops.not_homing();
233 447
   }
234 448
 
235
-  // print settings
449
+  if (auto_tune) {
450
+    #if ENABLED(PROBE_MANUALLY)
451
+      SERIAL_PROTOCOLLNPGM("A probe is needed for auto-tune");
452
+    #else
453
+      G33_auto_tune();
454
+    #endif
455
+    G33_CLEANUP();
456
+    return;
457
+  }
458
+
459
+  // Report settings
236 460
 
237 461
   const char *checkingac = PSTR("Checking... AC"); // TODO: Make translatable string
238 462
   serialprintPGM(checkingac);
@@ -240,78 +464,19 @@ void GcodeSuite::G33() {
240 464
   SERIAL_EOL();
241 465
   lcd_setstatusPGM(checkingac);
242 466
 
243
-  print_G33_settings(!_1p_calibration, _7p_calibration && towers_set);
467
+  print_G33_settings(_endstop_results, _angle_results);
244 468
 
245 469
   do {
246 470
 
247 471
     float z_at_pt[13] = { 0.0 };
248 472
 
249
-    test_precision = zero_std_dev_old != 999.0 ? (zero_std_dev + zero_std_dev_old) / 2 : zero_std_dev;
473
+    test_precision = zero_std_dev;
250 474
 
251 475
     iterations++;
252 476
 
253 477
     // Probe the points
254 478
 
255
-    if (!_0p_calibration){
256
-      if (!_7p_half_circle && !_7p_triple_circle) { // probe the center
257
-        #if ENABLED(PROBE_MANUALLY)
258
-          z_at_pt[0] += lcd_probe_pt(0, 0);
259
-        #else
260
-          z_at_pt[0] += probe_pt(dx, dy, stow_after_each, 1, false);
261
-          if (isnan(z_at_pt[0])) return G33_CLEANUP();
262
-        #endif
263
-      }
264
-      if (_7p_calibration) { // probe extra center points
265
-        for (int8_t axis = _7p_multi_circle ? 11 : 9; axis > 0; axis -= _7p_multi_circle ? 2 : 4) {
266
-          const float a = RADIANS(180 + 30 * axis), r = delta_calibration_radius * 0.1;
267
-          #if ENABLED(PROBE_MANUALLY)
268
-            z_at_pt[0] += lcd_probe_pt(cos(a) * r, sin(a) * r);
269
-          #else
270
-            z_at_pt[0] += probe_pt(cos(a) * r + dx, sin(a) * r + dy, stow_after_each, 1);
271
-            if (isnan(z_at_pt[0])) return G33_CLEANUP();
272
-          #endif
273
-        }
274
-        z_at_pt[0] /= float(_7p_double_circle ? 7 : probe_points);
275
-      }
276
-      if (!_1p_calibration) {  // probe the radius
277
-        bool zig_zag = true;
278
-        const uint8_t start = _4p_opposite_points ? 3 : 1,
279
-                       step = _4p_calibration ? 4 : _7p_half_circle ? 2 : 1;
280
-        for (uint8_t axis = start; axis < 13; axis += step) {
281
-          const float zigadd = (zig_zag ? 0.5 : 0.0),
282
-                      offset_circles = _7p_quadruple_circle ? zigadd + 1.0 :
283
-                                       _7p_triple_circle    ? zigadd + 0.5 :
284
-                                       _7p_double_circle    ? zigadd : 0;
285
-          for (float circles = -offset_circles ; circles <= offset_circles; circles++) {
286
-            const float a = RADIANS(180 + 30 * axis),
287
-                        r = delta_calibration_radius * (1 + circles * (zig_zag ? 0.1 : -0.1));
288
-            #if ENABLED(PROBE_MANUALLY)
289
-              z_at_pt[axis] += lcd_probe_pt(cos(a) * r, sin(a) * r);
290
-            #else
291
-              z_at_pt[axis] += probe_pt(cos(a) * r + dx, sin(a) * r + dy, stow_after_each, 1);
292
-              if (isnan(z_at_pt[axis])) return G33_CLEANUP();
293
-            #endif
294
-          }
295
-          zig_zag = !zig_zag;
296
-          z_at_pt[axis] /= (2 * offset_circles + 1);
297
-        }
298
-      }
299
-      if (_7p_intermed_points) // average intermediates to tower and opposites
300
-        for (uint8_t axis = 1; axis < 13; axis += 2)
301
-          z_at_pt[axis] = (z_at_pt[axis] + (z_at_pt[axis + 1] + z_at_pt[(axis + 10) % 12 + 1]) / 2.0) / 2.0;
302
-    }
303
-
304
-    float S1 = z_at_pt[0],
305
-          S2 = sq(z_at_pt[0]);
306
-    int16_t N = 1;
307
-    if (!_1p_calibration) // std dev from zero plane
308
-      for (uint8_t axis = (_4p_opposite_points ? 3 : 1); axis < 13; axis += (_4p_calibration ? 4 : 2)) {
309
-        S1 += z_at_pt[axis];
310
-        S2 += sq(z_at_pt[axis]);
311
-        N++;
312
-      }
313
-    zero_std_dev_old = zero_std_dev;
314
-    zero_std_dev = round(SQRT(S2 / N) * 1000.0) / 1000.0 + 0.00001;
479
+    zero_std_dev = probe_G33_points(z_at_pt, probe_points, towers_set, stow_after_each);
315 480
 
316 481
     // Solve matrices
317 482
 
@@ -325,9 +490,24 @@ void GcodeSuite::G33() {
325 490
 
326 491
       float e_delta[ABC] = { 0.0 }, r_delta = 0.0, t_delta[ABC] = { 0.0 };
327 492
       const float r_diff = delta_radius - delta_calibration_radius,
328
-                  h_factor = (1.00 + r_diff * 0.001) / 6.0,                                       // 1.02 for r_diff = 20mm
329
-                  r_factor = (-(1.75 + 0.005 * r_diff + 0.001 * sq(r_diff))) / 6.0,               // 2.25 for r_diff = 20mm
330
-                  a_factor = (66.66 / delta_calibration_radius) / (iterations == 1 ? 16.0 : 2.0); // 0.83 for cal_rd = 80mm
493
+                  h_factor = 1 / 6.0 *
494
+                    #ifdef H_FACTOR
495
+                      (H_FACTOR),                                       // Set in Configuration.h
496
+                    #else
497
+                      (1.00 + r_diff * 0.001),                          // 1.02 for r_diff = 20mm
498
+                    #endif
499
+                  r_factor = 1 / 6.0 *
500
+                    #ifdef R_FACTOR
501
+                      -(R_FACTOR),                                      // Set in Configuration.h
502
+                    #else
503
+                      -(1.75 + 0.005 * r_diff + 0.001 * sq(r_diff)),    // 2.25 for r_diff = 20mm
504
+                    #endif
505
+                  a_factor = 1 / 6.0 *
506
+                    #ifdef A_FACTOR
507
+                      (A_FACTOR);                                       // Set in Configuration.h
508
+                    #else
509
+                      (66.66 / delta_calibration_radius);               // 0.83 for cal_rd = 80mm
510
+                    #endif
331 511
 
332 512
       #define ZP(N,I) ((N) * z_at_pt[I])
333 513
       #define Z6(I) ZP(6, I)
@@ -341,15 +521,11 @@ void GcodeSuite::G33() {
341 521
 
342 522
       switch (probe_points) {
343 523
         case 0:
344
-          #if DISABLED(PROBE_MANUALLY)
345
-            test_precision = 0.00; // forced end
346
-          #endif
524
+          test_precision = 0.00; // forced end
347 525
           break;
348 526
 
349 527
         case 1:
350
-          #if DISABLED(PROBE_MANUALLY)
351
-            test_precision = 0.00; // forced end
352
-          #endif
528
+          test_precision = 0.00; // forced end
353 529
           LOOP_XYZ(axis) e_delta[axis] = Z1(0);
354 530
           break;
355 531
 
@@ -375,9 +551,9 @@ void GcodeSuite::G33() {
375 551
           r_delta         = (Z6(0) - Z1(1) - Z1(5) - Z1(9) - Z1(7) - Z1(11) - Z1(3)) * r_factor;
376 552
 
377 553
           if (towers_set) {
378
-            t_delta[A_AXIS] = (       - Z2(5) + Z2(9)         - Z2(11) + Z2(3)) * a_factor;
379
-            t_delta[B_AXIS] = ( Z2(1)         - Z2(9) + Z2(7)          - Z2(3)) * a_factor;
380
-            t_delta[C_AXIS] = (-Z2(1) + Z2(5)         - Z2(7) + Z2(11)        ) * a_factor;
554
+            t_delta[A_AXIS] = (       - Z4(5) + Z4(9)         - Z4(11) + Z4(3)) * a_factor;
555
+            t_delta[B_AXIS] = ( Z4(1)         - Z4(9) + Z4(7)          - Z4(3)) * a_factor;
556
+            t_delta[C_AXIS] = (-Z4(1) + Z4(5)         - Z4(7) + Z4(11)        ) * a_factor;
381 557
             e_delta[A_AXIS] += (t_delta[B_AXIS] - t_delta[C_AXIS]) / 4.5;
382 558
             e_delta[B_AXIS] += (t_delta[C_AXIS] - t_delta[A_AXIS]) / 4.5;
383 559
             e_delta[C_AXIS] += (t_delta[A_AXIS] - t_delta[B_AXIS]) / 4.5;
@@ -395,11 +571,14 @@ void GcodeSuite::G33() {
395 571
       home_offset[Z_AXIS] = zh_old;
396 572
       COPY(delta_tower_angle_trim, ta_old);
397 573
     }
574
+
398 575
     if (verbose_level != 0) {                                    // !dry run
399 576
       // normalise angles to least squares
400
-      float a_sum = 0.0;
401
-      LOOP_XYZ(axis) a_sum += delta_tower_angle_trim[axis];
402
-      LOOP_XYZ(axis) delta_tower_angle_trim[axis] -= a_sum / 3.0;
577
+      if (_angle_results) {
578
+        float a_sum = 0.0;
579
+        LOOP_XYZ(axis) a_sum += delta_tower_angle_trim[axis];
580
+        LOOP_XYZ(axis) delta_tower_angle_trim[axis] -= a_sum / 3.0;
581
+      }
403 582
 
404 583
       // adjust delta_height and endstops by the max amount
405 584
       const float z_temp = MAX3(delta_endstop_adj[A_AXIS], delta_endstop_adj[B_AXIS], delta_endstop_adj[C_AXIS]);
@@ -411,30 +590,13 @@ void GcodeSuite::G33() {
411 590
 
412 591
     // print report
413 592
 
414
-    if (verbose_level != 1) {
415
-      SERIAL_PROTOCOLPGM(".    ");
416
-      print_signed_float(PSTR("c"), z_at_pt[0]);
417
-      if (_4p_towers_points || _7p_calibration) {
418
-        print_signed_float(PSTR("   x"), z_at_pt[1]);
419
-        print_signed_float(PSTR(" y"), z_at_pt[5]);
420
-        print_signed_float(PSTR(" z"), z_at_pt[9]);
421
-      }
422
-      if (!_4p_opposite_points) SERIAL_EOL();
423
-      if ((_4p_opposite_points) || _7p_calibration) {
424
-        if (_7p_calibration) {
425
-          SERIAL_CHAR('.');
426
-          SERIAL_PROTOCOL_SP(13);
427
-        }
428
-        print_signed_float(PSTR("  yz"), z_at_pt[7]);
429
-        print_signed_float(PSTR("zx"), z_at_pt[11]);
430
-        print_signed_float(PSTR("xy"), z_at_pt[3]);
431
-        SERIAL_EOL();
432
-      }
433
-    }
593
+    if (verbose_level != 1)
594
+      print_G33_results(z_at_pt, _tower_results, _opposite_results);
595
+
434 596
     if (verbose_level != 0) {                                    // !dry run
435 597
       if ((zero_std_dev >= test_precision && iterations > force_iterations) || zero_std_dev <= calibration_precision) {  // end iterations
436 598
         SERIAL_PROTOCOLPGM("Calibration OK");
437
-        SERIAL_PROTOCOL_SP(36);
599
+        SERIAL_PROTOCOL_SP(32);
438 600
         #if DISABLED(PROBE_MANUALLY)
439 601
           if (zero_std_dev >= test_precision && !_1p_calibration)
440 602
             SERIAL_PROTOCOLPGM("rolling back.");
@@ -452,7 +614,7 @@ void GcodeSuite::G33() {
452 614
         else
453 615
           sprintf_P(&mess[15], PSTR("%03i.x"), (int)round(zero_std_dev_min));
454 616
         lcd_setstatus(mess);
455
-        print_G33_settings(!_1p_calibration, _7p_calibration && towers_set);
617
+        print_G33_settings(_endstop_results, _angle_results);
456 618
         serialprintPGM(save_message);
457 619
         SERIAL_EOL();
458 620
       }
@@ -463,18 +625,18 @@ void GcodeSuite::G33() {
463 625
         else
464 626
           sprintf_P(mess, PSTR("No convergence"));
465 627
         SERIAL_PROTOCOL(mess);
466
-        SERIAL_PROTOCOL_SP(36);
628
+        SERIAL_PROTOCOL_SP(32);
467 629
         SERIAL_PROTOCOLPGM("std dev:");
468 630
         SERIAL_PROTOCOL_F(zero_std_dev, 3);
469 631
         SERIAL_EOL();
470 632
         lcd_setstatus(mess);
471
-        print_G33_settings(!_1p_calibration, _7p_calibration && towers_set);
633
+        print_G33_settings(_endstop_results, _angle_results);
472 634
       }
473 635
     }
474 636
     else {                                                       // dry run
475 637
       const char *enddryrun = PSTR("End DRY-RUN");
476 638
       serialprintPGM(enddryrun);
477
-      SERIAL_PROTOCOL_SP(39);
639
+      SERIAL_PROTOCOL_SP(35);
478 640
       SERIAL_PROTOCOLPGM("std dev:");
479 641
       SERIAL_PROTOCOL_F(zero_std_dev, 3);
480 642
       SERIAL_EOL();
@@ -490,7 +652,8 @@ void GcodeSuite::G33() {
490 652
     }
491 653
 
492 654
     endstops.enable(true);
493
-    home_delta();
655
+    if (!home_delta())
656
+      return;
494 657
     endstops.not_homing();
495 658
 
496 659
   }

Laden…
Annuleren
Opslaan