瀏覽代碼

Put ABL state into a class

Scott Lahteine 3 年之前
父節點
當前提交
8d083eb248
共有 4 個文件被更改,包括 216 次插入214 次删除
  1. 213
    211
      Marlin/src/gcode/bedlevel/abl/G29.cpp
  2. 1
    1
      Marlin/src/inc/Conditionals_LCD.h
  3. 1
    1
      Marlin/src/inc/SanityCheck.h
  4. 1
    1
      buildroot/tests/rambo

+ 213
- 211
Marlin/src/gcode/bedlevel/abl/G29.cpp 查看文件

@@ -68,22 +68,77 @@
68 68
   #include "../../../module/tool_change.h"
69 69
 #endif
70 70
 
71
-#if ABL_GRID
71
+#if ABL_USES_GRID
72 72
   #if ENABLED(PROBE_Y_FIRST)
73
-    #define PR_OUTER_VAR meshCount.x
74
-    #define PR_OUTER_END abl_grid_points.x
75
-    #define PR_INNER_VAR meshCount.y
76
-    #define PR_INNER_END abl_grid_points.y
73
+    #define PR_OUTER_VAR  abl.meshCount.x
74
+    #define PR_OUTER_SIZE abl.grid_points.x
75
+    #define PR_INNER_VAR  abl.meshCount.y
76
+    #define PR_INNER_SIZE abl.grid_points.y
77 77
   #else
78
-    #define PR_OUTER_VAR meshCount.y
79
-    #define PR_OUTER_END abl_grid_points.y
80
-    #define PR_INNER_VAR meshCount.x
81
-    #define PR_INNER_END abl_grid_points.x
78
+    #define PR_OUTER_VAR  abl.meshCount.y
79
+    #define PR_OUTER_SIZE abl.grid_points.y
80
+    #define PR_INNER_VAR  abl.meshCount.x
81
+    #define PR_INNER_SIZE abl.grid_points.x
82 82
   #endif
83 83
 #endif
84 84
 
85 85
 #define G29_RETURN(b) return TERN_(G29_RETRY_AND_RECOVER, b)
86 86
 
87
+// For manual probing values persist over multiple G29
88
+class G29_State {
89
+public:
90
+  int       verbose_level;
91
+  xy_pos_t  probePos;
92
+  float     measured_z;
93
+  bool      dryrun,
94
+            reenable;
95
+
96
+  #if EITHER(PROBE_MANUALLY, AUTO_BED_LEVELING_LINEAR)
97
+    int abl_probe_index;
98
+  #endif
99
+
100
+  #if ABL_USES_GRID
101
+
102
+    xy_int8_t meshCount;
103
+
104
+    xy_pos_t probe_position_lf,
105
+             probe_position_rb;
106
+
107
+    xy_float_t gridSpacing; // = { 0.0f, 0.0f }
108
+
109
+    #if ENABLED(AUTO_BED_LEVELING_LINEAR)
110
+      bool                topography_map;
111
+      xy_uint8_t          grid_points;
112
+    #else // Bilinear
113
+      static constexpr xy_uint8_t grid_points = { GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y };
114
+    #endif
115
+
116
+    #if ENABLED(AUTO_BED_LEVELING_LINEAR)
117
+      int abl_points;
118
+    #elif ENABLED(AUTO_BED_LEVELING_3POINT)
119
+      static constexpr int abl_points = 3;
120
+    #else
121
+      static constexpr int abl_points = GRID_MAX_POINTS;
122
+    #endif
123
+
124
+    #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
125
+      float Z_offset;
126
+    #endif
127
+
128
+    #if ENABLED(AUTO_BED_LEVELING_LINEAR)
129
+      int indexIntoAB[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
130
+      float eqnAMatrix[(GRID_MAX_POINTS) * 3], // "A" matrix of the linear system of equations
131
+            eqnBVector[GRID_MAX_POINTS],       // "B" vector of Z points
132
+            mean;
133
+    #endif
134
+  #endif
135
+};
136
+
137
+#if ABL_USES_GRID && EITHER(AUTO_BED_LEVELING_3POINT, AUTO_BED_LEVELING_BILINEAR)
138
+  constexpr xy_uint8_t G29_State::grid_points;
139
+  constexpr int G29_State::abl_points;
140
+#endif
141
+
87 142
 /**
88 143
  * G29: Detailed Z probe, probes the bed at 3 or more points.
89 144
  *      Will fail if the printer has not been homed with G28.
@@ -163,6 +218,8 @@
163 218
  */
164 219
 G29_TYPE GcodeSuite::G29() {
165 220
 
221
+  TERN_(PROBE_MANUALLY, static) G29_State abl;
222
+
166 223
   reset_stepper_timeout();
167 224
 
168 225
   const bool seenQ = EITHER(DEBUG_LEVELING_FEATURE, PROBE_MANUALLY) && parser.seen('Q');
@@ -193,63 +250,10 @@ G29_TYPE GcodeSuite::G29() {
193 250
   // Don't allow auto-leveling without homing first
194 251
   if (homing_needed_error()) G29_RETURN(false);
195 252
 
196
-  // Define local vars 'static' for manual probing, 'auto' otherwise
197
-  #define ABL_VAR TERN_(PROBE_MANUALLY, static)
198
-
199
-  ABL_VAR int verbose_level;
200
-  ABL_VAR xy_pos_t probePos;
201
-  ABL_VAR float measured_z;
202
-  ABL_VAR bool dryrun, abl_should_enable;
203
-
204
-  #if EITHER(PROBE_MANUALLY, AUTO_BED_LEVELING_LINEAR)
205
-    ABL_VAR int abl_probe_index;
206
-  #endif
207
-
208
-  #if ABL_GRID
209
-
210
-    #if ENABLED(PROBE_MANUALLY)
211
-      ABL_VAR xy_int8_t meshCount;
212
-    #endif
213
-
214
-    ABL_VAR xy_pos_t probe_position_lf, probe_position_rb;
215
-    ABL_VAR xy_float_t gridSpacing = { 0, 0 };
216
-
217
-    #if ENABLED(AUTO_BED_LEVELING_LINEAR)
218
-      ABL_VAR bool do_topography_map;
219
-      ABL_VAR xy_uint8_t abl_grid_points;
220
-    #else // Bilinear
221
-      constexpr xy_uint8_t abl_grid_points = { GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y };
222
-    #endif
223
-
224
-    #if ENABLED(AUTO_BED_LEVELING_LINEAR)
225
-      ABL_VAR int abl_points;
226
-    #else
227
-      int constexpr abl_points = GRID_MAX_POINTS;
228
-    #endif
229
-
230
-    #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
231
-
232
-      ABL_VAR float zoffset;
233
-
234
-    #elif ENABLED(AUTO_BED_LEVELING_LINEAR)
235
-
236
-      ABL_VAR int indexIntoAB[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
237
-
238
-      ABL_VAR float eqnAMatrix[(GRID_MAX_POINTS) * 3], // "A" matrix of the linear system of equations
239
-                    eqnBVector[GRID_MAX_POINTS],       // "B" vector of Z points
240
-                    mean;
241
-    #endif
242
-
243
-  #elif ENABLED(AUTO_BED_LEVELING_3POINT)
244
-
245
-    #if ENABLED(PROBE_MANUALLY)
246
-      int constexpr abl_points = 3; // used to show total points
247
-    #endif
248
-
253
+  #if ENABLED(AUTO_BED_LEVELING_3POINT)
249 254
     vector_3 points[3];
250 255
     probe.get_three_points(points);
251
-
252
-  #endif // AUTO_BED_LEVELING_3POINT
256
+  #endif
253 257
 
254 258
   #if ENABLED(AUTO_BED_LEVELING_LINEAR)
255 259
     struct linear_fit_data lsf_results;
@@ -263,10 +267,10 @@ G29_TYPE GcodeSuite::G29() {
263 267
     TERN_(HAS_MULTI_HOTEND, if (active_extruder) tool_change(0));
264 268
 
265 269
     #if EITHER(PROBE_MANUALLY, AUTO_BED_LEVELING_LINEAR)
266
-      abl_probe_index = -1;
270
+      abl.abl_probe_index = -1;
267 271
     #endif
268 272
 
269
-    abl_should_enable = planner.leveling_active;
273
+    abl.reenable = planner.leveling_active;
270 274
 
271 275
     #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
272 276
 
@@ -289,8 +293,8 @@ G29_TYPE GcodeSuite::G29() {
289 293
 
290 294
         if (!isnan(rx) && !isnan(ry)) {
291 295
           // Get nearest i / j from rx / ry
292
-          i = (rx - bilinear_start.x + 0.5 * gridSpacing.x) / gridSpacing.x;
293
-          j = (ry - bilinear_start.y + 0.5 * gridSpacing.y) / gridSpacing.y;
296
+          i = (rx - bilinear_start.x + 0.5 * abl.gridSpacing.x) / abl.gridSpacing.x;
297
+          j = (ry - bilinear_start.y + 0.5 * abl.gridSpacing.y) / abl.gridSpacing.y;
294 298
           LIMIT(i, 0, GRID_MAX_POINTS_X - 1);
295 299
           LIMIT(j, 0, GRID_MAX_POINTS_Y - 1);
296 300
         }
@@ -299,8 +303,8 @@ G29_TYPE GcodeSuite::G29() {
299 303
           z_values[i][j] = rz;
300 304
           TERN_(ABL_BILINEAR_SUBDIVISION, bed_level_virt_interpolate());
301 305
           TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(i, j, rz));
302
-          set_bed_leveling_enabled(abl_should_enable);
303
-          if (abl_should_enable) report_current_position();
306
+          set_bed_leveling_enabled(abl.reenable);
307
+          if (abl.reenable) report_current_position();
304 308
         }
305 309
         G29_RETURN(false);
306 310
       } // parser.seen('W')
@@ -317,47 +321,47 @@ G29_TYPE GcodeSuite::G29() {
317 321
       G29_RETURN(false);
318 322
     }
319 323
 
320
-    verbose_level = parser.intval('V');
321
-    if (!WITHIN(verbose_level, 0, 4)) {
324
+    abl.verbose_level = parser.intval('V');
325
+    if (!WITHIN(abl.verbose_level, 0, 4)) {
322 326
       SERIAL_ECHOLNPGM("?(V)erbose level implausible (0-4).");
323 327
       G29_RETURN(false);
324 328
     }
325 329
 
326
-    dryrun = parser.boolval('D') || TERN0(PROBE_MANUALLY, no_action);
330
+    abl.dryrun = parser.boolval('D') || TERN0(PROBE_MANUALLY, no_action);
327 331
 
328 332
     #if ENABLED(AUTO_BED_LEVELING_LINEAR)
329 333
 
330 334
       incremental_LSF_reset(&lsf_results);
331 335
 
332
-      do_topography_map = verbose_level > 2 || parser.boolval('T');
336
+      abl.topography_map = abl.verbose_level > 2 || parser.boolval('T');
333 337
 
334 338
       // X and Y specify points in each direction, overriding the default
335 339
       // These values may be saved with the completed mesh
336
-      abl_grid_points.set(
340
+      abl.grid_points.set(
337 341
         parser.byteval('X', GRID_MAX_POINTS_X),
338 342
         parser.byteval('Y', GRID_MAX_POINTS_Y)
339 343
       );
340
-      if (parser.seenval('P')) abl_grid_points.x = abl_grid_points.y = parser.value_int();
344
+      if (parser.seenval('P')) abl.grid_points.x = abl.grid_points.y = parser.value_int();
341 345
 
342
-      if (!WITHIN(abl_grid_points.x, 2, GRID_MAX_POINTS_X)) {
346
+      if (!WITHIN(abl.grid_points.x, 2, GRID_MAX_POINTS_X)) {
343 347
         SERIAL_ECHOLNPGM("?Probe points (X) implausible (2-" STRINGIFY(GRID_MAX_POINTS_X) ").");
344 348
         G29_RETURN(false);
345 349
       }
346
-      if (!WITHIN(abl_grid_points.y, 2, GRID_MAX_POINTS_Y)) {
350
+      if (!WITHIN(abl.grid_points.y, 2, GRID_MAX_POINTS_Y)) {
347 351
         SERIAL_ECHOLNPGM("?Probe points (Y) implausible (2-" STRINGIFY(GRID_MAX_POINTS_Y) ").");
348 352
         G29_RETURN(false);
349 353
       }
350 354
 
351
-      abl_points = abl_grid_points.x * abl_grid_points.y;
352
-      mean = 0;
355
+      abl.abl_points = abl.grid_points.x * abl.grid_points.y;
356
+      abl.mean = 0;
353 357
 
354 358
     #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
355 359
 
356
-      zoffset = parser.linearval('Z');
360
+      abl.Z_offset = parser.linearval('Z');
357 361
 
358 362
     #endif
359 363
 
360
-    #if ABL_GRID
364
+    #if ABL_USES_GRID
361 365
 
362 366
       xy_probe_feedrate_mm_s = MMM_TO_MMS(parser.linearval('S', XY_PROBE_FEEDRATE));
363 367
 
@@ -366,32 +370,32 @@ G29_TYPE GcodeSuite::G29() {
366 370
 
367 371
       if (parser.seen('H')) {
368 372
         const int16_t size = (int16_t)parser.value_linear_units();
369
-        probe_position_lf.set(_MAX((X_CENTER) - size / 2, x_min), _MAX((Y_CENTER) - size / 2, y_min));
370
-        probe_position_rb.set(_MIN(probe_position_lf.x + size, x_max), _MIN(probe_position_lf.y + size, y_max));
373
+        abl.probe_position_lf.set(_MAX((X_CENTER) - size / 2, x_min), _MAX((Y_CENTER) - size / 2, y_min));
374
+        abl.probe_position_rb.set(_MIN(abl.probe_position_lf.x + size, x_max), _MIN(abl.probe_position_lf.y + size, y_max));
371 375
       }
372 376
       else {
373
-        probe_position_lf.set(parser.linearval('L', x_min), parser.linearval('F', y_min));
374
-        probe_position_rb.set(parser.linearval('R', x_max), parser.linearval('B', y_max));
377
+        abl.probe_position_lf.set(parser.linearval('L', x_min), parser.linearval('F', y_min));
378
+        abl.probe_position_rb.set(parser.linearval('R', x_max), parser.linearval('B', y_max));
375 379
       }
376 380
 
377
-      if (!probe.good_bounds(probe_position_lf, probe_position_rb)) {
381
+      if (!probe.good_bounds(abl.probe_position_lf, abl.probe_position_rb)) {
378 382
         if (DEBUGGING(LEVELING)) {
379
-          DEBUG_ECHOLNPAIR("G29 L", probe_position_lf.x, " R", probe_position_rb.x,
380
-                              " F", probe_position_lf.y, " B", probe_position_rb.y);
383
+          DEBUG_ECHOLNPAIR("G29 L", abl.probe_position_lf.x, " R", abl.probe_position_rb.x,
384
+                              " F", abl.probe_position_lf.y, " B", abl.probe_position_rb.y);
381 385
         }
382 386
         SERIAL_ECHOLNPGM("? (L,R,F,B) out of bounds.");
383 387
         G29_RETURN(false);
384 388
       }
385 389
 
386 390
       // Probe at the points of a lattice grid
387
-      gridSpacing.set((probe_position_rb.x - probe_position_lf.x) / (abl_grid_points.x - 1),
388
-                      (probe_position_rb.y - probe_position_lf.y) / (abl_grid_points.y - 1));
391
+      abl.gridSpacing.set((abl.probe_position_rb.x - abl.probe_position_lf.x) / (abl.grid_points.x - 1),
392
+                            (abl.probe_position_rb.y - abl.probe_position_lf.y) / (abl.grid_points.y - 1));
389 393
 
390
-    #endif // ABL_GRID
394
+    #endif // ABL_USES_GRID
391 395
 
392
-    if (verbose_level > 0) {
396
+    if (abl.verbose_level > 0) {
393 397
       SERIAL_ECHOPGM("G29 Auto Bed Leveling");
394
-      if (dryrun) SERIAL_ECHOPGM(" (DRYRUN)");
398
+      if (abl.dryrun) SERIAL_ECHOPGM(" (DRYRUN)");
395 399
       SERIAL_EOL();
396 400
     }
397 401
 
@@ -410,7 +414,7 @@ G29_TYPE GcodeSuite::G29() {
410 414
       remember_feedrate_scaling_off();
411 415
 
412 416
       #if ENABLED(PREHEAT_BEFORE_LEVELING)
413
-        if (!dryrun) probe.preheat_for_probing(LEVELING_NOZZLE_TEMP, LEVELING_BED_TEMP);
417
+        if (!abl.dryrun) probe.preheat_for_probing(LEVELING_NOZZLE_TEMP, LEVELING_BED_TEMP);
414 418
       #endif
415 419
     }
416 420
 
@@ -423,24 +427,24 @@ G29_TYPE GcodeSuite::G29() {
423 427
       if (ENABLED(BLTOUCH))
424 428
         do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE);
425 429
       else if (probe.deploy()) {
426
-        set_bed_leveling_enabled(abl_should_enable);
430
+        set_bed_leveling_enabled(abl.reenable);
427 431
         G29_RETURN(false);
428 432
       }
429 433
     #endif
430 434
 
431 435
     #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
432 436
       if (TERN1(PROBE_MANUALLY, !no_action)
433
-        && (gridSpacing != bilinear_grid_spacing || probe_position_lf != bilinear_start)
437
+        && (abl.gridSpacing != bilinear_grid_spacing || abl.probe_position_lf != bilinear_start)
434 438
       ) {
435 439
         // Reset grid to 0.0 or "not probed". (Also disables ABL)
436 440
         reset_bed_level();
437 441
 
438 442
         // Initialize a grid with the given dimensions
439
-        bilinear_grid_spacing = gridSpacing;
440
-        bilinear_start = probe_position_lf;
443
+        bilinear_grid_spacing = abl.gridSpacing;
444
+        bilinear_start = abl.probe_position_lf;
441 445
 
442 446
         // Can't re-enable (on error) until the new grid is written
443
-        abl_should_enable = false;
447
+        abl.reenable = false;
444 448
       }
445 449
     #endif // AUTO_BED_LEVELING_BILINEAR
446 450
 
@@ -451,7 +455,7 @@ G29_TYPE GcodeSuite::G29() {
451 455
     // For manual probing, get the next index to probe now.
452 456
     // On the first probe this will be incremented to 0.
453 457
     if (!no_action) {
454
-      ++abl_probe_index;
458
+      ++abl.abl_probe_index;
455 459
       g29_in_progress = true;
456 460
     }
457 461
 
@@ -459,17 +463,17 @@ G29_TYPE GcodeSuite::G29() {
459 463
     if (seenA && g29_in_progress) {
460 464
       SERIAL_ECHOLNPGM("Manual G29 aborted");
461 465
       SET_SOFT_ENDSTOP_LOOSE(false);
462
-      set_bed_leveling_enabled(abl_should_enable);
466
+      set_bed_leveling_enabled(abl.reenable);
463 467
       g29_in_progress = false;
464 468
       TERN_(LCD_BED_LEVELING, ui.wait_for_move = false);
465 469
     }
466 470
 
467 471
     // Query G29 status
468
-    if (verbose_level || seenQ) {
472
+    if (abl.verbose_level || seenQ) {
469 473
       SERIAL_ECHOPGM("Manual G29 ");
470 474
       if (g29_in_progress) {
471
-        SERIAL_ECHOPAIR("point ", _MIN(abl_probe_index + 1, abl_points));
472
-        SERIAL_ECHOLNPAIR(" of ", abl_points);
475
+        SERIAL_ECHOPAIR("point ", _MIN(abl.abl_probe_index + 1, abl.abl_points));
476
+        SERIAL_ECHOLNPAIR(" of ", abl.abl_points);
473 477
       }
474 478
       else
475 479
         SERIAL_ECHOLNPGM("idle");
@@ -477,7 +481,7 @@ G29_TYPE GcodeSuite::G29() {
477 481
 
478 482
     if (no_action) G29_RETURN(false);
479 483
 
480
-    if (abl_probe_index == 0) {
484
+    if (abl.abl_probe_index == 0) {
481 485
       // For the initial G29 S2 save software endstop state
482 486
       SET_SOFT_ENDSTOP_LOOSE(true);
483 487
       // Move close to the bed before the first point
@@ -486,34 +490,34 @@ G29_TYPE GcodeSuite::G29() {
486 490
     else {
487 491
 
488 492
       #if EITHER(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_3POINT)
489
-        const uint16_t index = abl_probe_index - 1;
493
+        const uint16_t index = abl.abl_probe_index - 1;
490 494
       #endif
491 495
 
492 496
       // For G29 after adjusting Z.
493 497
       // Save the previous Z before going to the next point
494
-      measured_z = current_position.z;
498
+      abl.measured_z = current_position.z;
495 499
 
496 500
       #if ENABLED(AUTO_BED_LEVELING_LINEAR)
497 501
 
498
-        mean += measured_z;
499
-        eqnBVector[index] = measured_z;
500
-        eqnAMatrix[index + 0 * abl_points] = probePos.x;
501
-        eqnAMatrix[index + 1 * abl_points] = probePos.y;
502
-        eqnAMatrix[index + 2 * abl_points] = 1;
502
+        abl.mean += abl.measured_z;
503
+        abl.eqnBVector[index] = abl.measured_z;
504
+        abl.eqnAMatrix[index + 0 * abl.abl_points] = abl.probePos.x;
505
+        abl.eqnAMatrix[index + 1 * abl.abl_points] = abl.probePos.y;
506
+        abl.eqnAMatrix[index + 2 * abl.abl_points] = 1;
503 507
 
504
-        incremental_LSF(&lsf_results, probePos, measured_z);
508
+        incremental_LSF(&lsf_results, abl.probePos, abl.measured_z);
505 509
 
506 510
       #elif ENABLED(AUTO_BED_LEVELING_3POINT)
507 511
 
508
-        points[index].z = measured_z;
512
+        points[index].z = abl.measured_z;
509 513
 
510 514
       #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
511 515
 
512
-        const float newz = measured_z + zoffset;
513
-        z_values[meshCount.x][meshCount.y] = newz;
514
-        TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(meshCount, newz));
516
+        const float newz = abl.measured_z + abl.Z_offset;
517
+        z_values[abl.meshCount.x][abl.meshCount.y] = newz;
518
+        TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(abl.meshCount, newz));
515 519
 
516
-        if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR_P(PSTR("Save X"), meshCount.x, SP_Y_STR, meshCount.y, SP_Z_STR, measured_z + zoffset);
520
+        if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR_P(PSTR("Save X"), abl.meshCount.x, SP_Y_STR, abl.meshCount.y, SP_Z_STR, abl.measured_z + abl.Z_offset);
517 521
 
518 522
       #endif
519 523
     }
@@ -522,31 +526,31 @@ G29_TYPE GcodeSuite::G29() {
522 526
     // If there's another point to sample, move there with optional lift.
523 527
     //
524 528
 
525
-    #if ABL_GRID
529
+    #if ABL_USES_GRID
526 530
 
527 531
       // Skip any unreachable points
528
-      while (abl_probe_index < abl_points) {
532
+      while (abl.abl_probe_index < abl.abl_points) {
529 533
 
530
-        // Set meshCount.x, meshCount.y based on abl_probe_index, with zig-zag
531
-        PR_OUTER_VAR = abl_probe_index / PR_INNER_END;
532
-        PR_INNER_VAR = abl_probe_index - (PR_OUTER_VAR * PR_INNER_END);
534
+        // Set abl.meshCount.x, abl.meshCount.y based on abl.abl_probe_index, with zig-zag
535
+        PR_OUTER_VAR = abl.abl_probe_index / PR_INNER_SIZE;
536
+        PR_INNER_VAR = abl.abl_probe_index - (PR_OUTER_VAR * PR_INNER_SIZE);
533 537
 
534 538
         // Probe in reverse order for every other row/column
535
-        const bool zig = (PR_OUTER_VAR & 1); // != ((PR_OUTER_END) & 1);
536
-        if (zig) PR_INNER_VAR = (PR_INNER_END - 1) - PR_INNER_VAR;
539
+        const bool zig = (PR_OUTER_VAR & 1); // != ((PR_OUTER_SIZE) & 1);
540
+        if (zig) PR_INNER_VAR = (PR_INNER_SIZE - 1) - PR_INNER_VAR;
537 541
 
538
-        probePos = probe_position_lf + gridSpacing * meshCount.asFloat();
542
+        abl.probePos = abl.probe_position_lf + abl.gridSpacing * abl.meshCount.asFloat();
539 543
 
540
-        TERN_(AUTO_BED_LEVELING_LINEAR, indexIntoAB[meshCount.x][meshCount.y] = abl_probe_index);
544
+        TERN_(AUTO_BED_LEVELING_LINEAR, abl.indexIntoAB[abl.meshCount.x][abl.meshCount.y] = abl.abl_probe_index);
541 545
 
542 546
         // Keep looping till a reachable point is found
543
-        if (position_is_reachable(probePos)) break;
544
-        ++abl_probe_index;
547
+        if (position_is_reachable(abl.probePos)) break;
548
+        ++abl.abl_probe_index;
545 549
       }
546 550
 
547 551
       // Is there a next point to move to?
548
-      if (abl_probe_index < abl_points) {
549
-        _manual_goto_xy(probePos); // Can be used here too!
552
+      if (abl.abl_probe_index < abl.abl_points) {
553
+        _manual_goto_xy(abl.probePos); // Can be used here too!
550 554
         // Disable software endstops to allow manual adjustment
551 555
         // If G29 is not completed, they will not be re-enabled
552 556
         SET_SOFT_ENDSTOP_LOOSE(true);
@@ -562,9 +566,9 @@ G29_TYPE GcodeSuite::G29() {
562 566
     #elif ENABLED(AUTO_BED_LEVELING_3POINT)
563 567
 
564 568
       // Probe at 3 arbitrary points
565
-      if (abl_probe_index < abl_points) {
566
-        probePos = points[abl_probe_index];
567
-        _manual_goto_xy(probePos);
569
+      if (abl.abl_probe_index < abl.abl_points) {
570
+        abl.probePos = points[abl.abl_probe_index];
571
+        _manual_goto_xy(abl.probePos);
568 572
         // Disable software endstops to allow manual adjustment
569 573
         // If G29 is not completed, they will not be re-enabled
570 574
         SET_SOFT_ENDSTOP_LOOSE(true);
@@ -577,13 +581,13 @@ G29_TYPE GcodeSuite::G29() {
577 581
         // Re-enable software endstops, if needed
578 582
         SET_SOFT_ENDSTOP_LOOSE(false);
579 583
 
580
-        if (!dryrun) {
584
+        if (!abl.dryrun) {
581 585
           vector_3 planeNormal = vector_3::cross(points[0] - points[1], points[2] - points[1]).get_normal();
582 586
           if (planeNormal.z < 0) planeNormal *= -1;
583 587
           planner.bed_level_matrix = matrix_3x3::create_look_at(planeNormal);
584 588
 
585 589
           // Can't re-enable (on error) until the new grid is written
586
-          abl_should_enable = false;
590
+          abl.reenable = false;
587 591
         }
588 592
 
589 593
       }
@@ -594,84 +598,82 @@ G29_TYPE GcodeSuite::G29() {
594 598
   {
595 599
     const ProbePtRaise raise_after = parser.boolval('E') ? PROBE_PT_STOW : PROBE_PT_RAISE;
596 600
 
597
-    measured_z = 0;
598
-
599
-    #if ABL_GRID
601
+    abl.measured_z = 0;
600 602
 
601
-      bool zig = PR_OUTER_END & 1;  // Always end at RIGHT and BACK_PROBE_BED_POSITION
603
+    #if ABL_USES_GRID
602 604
 
603
-      measured_z = 0;
605
+      bool zig = PR_OUTER_SIZE & 1;  // Always end at RIGHT and BACK_PROBE_BED_POSITION
604 606
 
605
-      xy_int8_t meshCount;
607
+      abl.measured_z = 0;
606 608
 
607 609
       // Outer loop is X with PROBE_Y_FIRST enabled
608 610
       // Outer loop is Y with PROBE_Y_FIRST disabled
609
-      for (PR_OUTER_VAR = 0; PR_OUTER_VAR < PR_OUTER_END && !isnan(measured_z); PR_OUTER_VAR++) {
611
+      for (PR_OUTER_VAR = 0; PR_OUTER_VAR < PR_OUTER_SIZE && !isnan(abl.measured_z); PR_OUTER_VAR++) {
610 612
 
611 613
         int8_t inStart, inStop, inInc;
612 614
 
613
-        if (zig) {                    // Zig away from origin
614
-          inStart = 0;                // Left or front
615
-          inStop = PR_INNER_END;      // Right or back
616
-          inInc = 1;                  // Zig right
615
+        if (zig) {                      // Zig away from origin
616
+          inStart = 0;                  // Left or front
617
+          inStop = PR_INNER_SIZE;       // Right or back
618
+          inInc = 1;                    // Zig right
617 619
         }
618
-        else {                        // Zag towards origin
619
-          inStart = PR_INNER_END - 1; // Right or back
620
-          inStop = -1;                // Left or front
621
-          inInc = -1;                 // Zag left
620
+        else {                          // Zag towards origin
621
+          inStart = PR_INNER_SIZE - 1;  // Right or back
622
+          inStop = -1;                  // Left or front
623
+          inInc = -1;                   // Zag left
622 624
         }
623 625
 
624 626
         zig ^= true; // zag
625 627
 
626 628
         // An index to print current state
627
-        uint8_t pt_index = (PR_OUTER_VAR) * (PR_INNER_END) + 1;
629
+        uint8_t pt_index = (PR_OUTER_VAR) * (PR_INNER_SIZE) + 1;
628 630
 
629 631
         // Inner loop is Y with PROBE_Y_FIRST enabled
630 632
         // Inner loop is X with PROBE_Y_FIRST disabled
631 633
         for (PR_INNER_VAR = inStart; PR_INNER_VAR != inStop; pt_index++, PR_INNER_VAR += inInc) {
632 634
 
633
-          probePos = probe_position_lf + gridSpacing * meshCount.asFloat();
635
+          abl.probePos = abl.probe_position_lf + abl.gridSpacing * abl.meshCount.asFloat();
634 636
 
635
-          TERN_(AUTO_BED_LEVELING_LINEAR, indexIntoAB[meshCount.x][meshCount.y] = ++abl_probe_index); // 0...
637
+          TERN_(AUTO_BED_LEVELING_LINEAR, abl.indexIntoAB[abl.meshCount.x][abl.meshCount.y] = ++abl.abl_probe_index); // 0...
636 638
 
637 639
           // Avoid probing outside the round or hexagonal area
638
-          if (TERN0(IS_KINEMATIC, !probe.can_reach(probePos))) continue;
640
+          if (TERN0(IS_KINEMATIC, !probe.can_reach(abl.probePos))) continue;
639 641
 
640
-          if (verbose_level) SERIAL_ECHOLNPAIR("Probing mesh point ", pt_index, "/", abl_points, ".");
641
-          TERN_(HAS_STATUS_MESSAGE, ui.status_printf_P(0, PSTR(S_FMT " %i/%i"), GET_TEXT(MSG_PROBING_MESH), int(pt_index), int(abl_points)));
642
+          if (abl.verbose_level) SERIAL_ECHOLNPAIR("Probing mesh point ", pt_index, "/", abl.abl_points, ".");
643
+          TERN_(HAS_STATUS_MESSAGE, ui.status_printf_P(0, PSTR(S_FMT " %i/%i"), GET_TEXT(MSG_PROBING_MESH), int(pt_index), int(abl.abl_points)));
642 644
 
643
-          measured_z = faux ? 0.001f * random(-100, 101) : probe.probe_at_point(probePos, raise_after, verbose_level);
645
+          abl.measured_z = faux ? 0.001f * random(-100, 101) : probe.probe_at_point(abl.probePos, raise_after, abl.verbose_level);
644 646
 
645
-          if (isnan(measured_z)) {
646
-            set_bed_leveling_enabled(abl_should_enable);
647
+          if (isnan(abl.measured_z)) {
648
+            set_bed_leveling_enabled(abl.reenable);
647 649
             break; // Breaks out of both loops
648 650
           }
649 651
 
650 652
           #if ENABLED(PROBE_TEMP_COMPENSATION)
651
-            temp_comp.compensate_measurement(TSI_BED, thermalManager.degBed(), measured_z);
652
-            temp_comp.compensate_measurement(TSI_PROBE, thermalManager.degProbe(), measured_z);
653
-            TERN_(USE_TEMP_EXT_COMPENSATION, temp_comp.compensate_measurement(TSI_EXT, thermalManager.degHotend(), measured_z));
653
+            temp_comp.compensate_measurement(TSI_BED, thermalManager.degBed(), abl.measured_z);
654
+            temp_comp.compensate_measurement(TSI_PROBE, thermalManager.degProbe(), abl.measured_z);
655
+            TERN_(USE_TEMP_EXT_COMPENSATION, temp_comp.compensate_measurement(TSI_EXT, thermalManager.degHotend(), abl.measured_z));
654 656
           #endif
655 657
 
656 658
           #if ENABLED(AUTO_BED_LEVELING_LINEAR)
657 659
 
658
-            mean += measured_z;
659
-            eqnBVector[abl_probe_index] = measured_z;
660
-            eqnAMatrix[abl_probe_index + 0 * abl_points] = probePos.x;
661
-            eqnAMatrix[abl_probe_index + 1 * abl_points] = probePos.y;
662
-            eqnAMatrix[abl_probe_index + 2 * abl_points] = 1;
660
+            abl.mean += abl.measured_z;
661
+            abl.eqnBVector[abl.abl_probe_index] = abl.measured_z;
662
+            abl.eqnAMatrix[abl.abl_probe_index + 0 * abl.abl_points] = abl.probePos.x;
663
+            abl.eqnAMatrix[abl.abl_probe_index + 1 * abl.abl_points] = abl.probePos.y;
664
+            abl.eqnAMatrix[abl.abl_probe_index + 2 * abl.abl_points] = 1;
663 665
 
664
-            incremental_LSF(&lsf_results, probePos, measured_z);
666
+            incremental_LSF(&lsf_results, abl.probePos, abl.measured_z);
665 667
 
666 668
           #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
667 669
 
668
-            const float z = measured_z + zoffset;
669
-            z_values[meshCount.x][meshCount.y] = z;
670
-            TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(meshCount, z));
670
+            const float z = abl.measured_z + abl.Z_offset;
671
+            z_values[abl.meshCount.x][abl.meshCount.y] = z;
672
+            TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(abl.meshCount, z));
671 673
 
672 674
           #endif
673 675
 
674
-          abl_should_enable = false;
676
+          abl.reenable = false;
675 677
           idle_no_sleep();
676 678
 
677 679
         } // inner
@@ -682,26 +684,26 @@ G29_TYPE GcodeSuite::G29() {
682 684
       // Probe at 3 arbitrary points
683 685
 
684 686
       LOOP_L_N(i, 3) {
685
-        if (verbose_level) SERIAL_ECHOLNPAIR("Probing point ", i + 1, "/3.");
687
+        if (abl.verbose_level) SERIAL_ECHOLNPAIR("Probing point ", i + 1, "/3.");
686 688
         TERN_(HAS_STATUS_MESSAGE, ui.status_printf_P(0, PSTR(S_FMT " %i/3"), GET_TEXT(MSG_PROBING_MESH), int(i + 1)));
687 689
 
688 690
         // Retain the last probe position
689
-        probePos = points[i];
690
-        measured_z = faux ? 0.001 * random(-100, 101) : probe.probe_at_point(probePos, raise_after, verbose_level);
691
-        if (isnan(measured_z)) {
692
-          set_bed_leveling_enabled(abl_should_enable);
691
+        abl.probePos = points[i];
692
+        abl.measured_z = faux ? 0.001 * random(-100, 101) : probe.probe_at_point(abl.probePos, raise_after, abl.verbose_level);
693
+        if (isnan(abl.measured_z)) {
694
+          set_bed_leveling_enabled(abl.reenable);
693 695
           break;
694 696
         }
695
-        points[i].z = measured_z;
697
+        points[i].z = abl.measured_z;
696 698
       }
697 699
 
698
-      if (!dryrun && !isnan(measured_z)) {
700
+      if (!abl.dryrun && !isnan(abl.measured_z)) {
699 701
         vector_3 planeNormal = vector_3::cross(points[0] - points[1], points[2] - points[1]).get_normal();
700 702
         if (planeNormal.z < 0) planeNormal *= -1;
701 703
         planner.bed_level_matrix = matrix_3x3::create_look_at(planeNormal);
702 704
 
703 705
         // Can't re-enable (on error) until the new grid is written
704
-        abl_should_enable = false;
706
+        abl.reenable = false;
705 707
       }
706 708
 
707 709
     #endif // AUTO_BED_LEVELING_3POINT
@@ -710,8 +712,8 @@ G29_TYPE GcodeSuite::G29() {
710 712
 
711 713
     // Stow the probe. No raise for FIX_MOUNTED_PROBE.
712 714
     if (probe.stow()) {
713
-      set_bed_leveling_enabled(abl_should_enable);
714
-      measured_z = NAN;
715
+      set_bed_leveling_enabled(abl.reenable);
716
+      abl.measured_z = NAN;
715 717
     }
716 718
   }
717 719
   #endif // !PROBE_MANUALLY
@@ -734,10 +736,10 @@ G29_TYPE GcodeSuite::G29() {
734 736
   #endif
735 737
 
736 738
   // Calculate leveling, print reports, correct the position
737
-  if (!isnan(measured_z)) {
739
+  if (!isnan(abl.measured_z)) {
738 740
     #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
739 741
 
740
-      if (!dryrun) extrapolate_unprobed_bed_level();
742
+      if (!abl.dryrun) extrapolate_unprobed_bed_level();
741 743
       print_bilinear_leveling_grid();
742 744
 
743 745
       refresh_bed_level();
@@ -763,39 +765,39 @@ G29_TYPE GcodeSuite::G29() {
763 765
       plane_equation_coefficients.b = -lsf_results.B;  // but that is not yet tested.
764 766
       plane_equation_coefficients.d = -lsf_results.D;
765 767
 
766
-      mean /= abl_points;
768
+      abl.mean /= abl.abl_points;
767 769
 
768
-      if (verbose_level) {
770
+      if (abl.verbose_level) {
769 771
         SERIAL_ECHOPAIR_F("Eqn coefficients: a: ", plane_equation_coefficients.a, 8);
770 772
         SERIAL_ECHOPAIR_F(" b: ", plane_equation_coefficients.b, 8);
771 773
         SERIAL_ECHOPAIR_F(" d: ", plane_equation_coefficients.d, 8);
772
-        if (verbose_level > 2)
773
-          SERIAL_ECHOPAIR_F("\nMean of sampled points: ", mean, 8);
774
+        if (abl.verbose_level > 2)
775
+          SERIAL_ECHOPAIR_F("\nMean of sampled points: ", abl.mean, 8);
774 776
         SERIAL_EOL();
775 777
       }
776 778
 
777 779
       // Create the matrix but don't correct the position yet
778
-      if (!dryrun)
780
+      if (!abl.dryrun)
779 781
         planner.bed_level_matrix = matrix_3x3::create_look_at(
780 782
           vector_3(-plane_equation_coefficients.a, -plane_equation_coefficients.b, 1)    // We can eliminate the '-' here and up above
781 783
         );
782 784
 
783 785
       // Show the Topography map if enabled
784
-      if (do_topography_map) {
786
+      if (abl.topography_map) {
785 787
 
786 788
         float min_diff = 999;
787 789
 
788 790
         auto print_topo_map = [&](PGM_P const title, const bool get_min) {
789 791
           SERIAL_ECHOPGM_P(title);
790
-          for (int8_t yy = abl_grid_points.y - 1; yy >= 0; yy--) {
791
-            LOOP_L_N(xx, abl_grid_points.x) {
792
-              const int ind = indexIntoAB[xx][yy];
793
-              xyz_float_t tmp = { eqnAMatrix[ind + 0 * abl_points],
794
-                                  eqnAMatrix[ind + 1 * abl_points], 0 };
792
+          for (int8_t yy = abl.grid_points.y - 1; yy >= 0; yy--) {
793
+            LOOP_L_N(xx, abl.grid_points.x) {
794
+              const int ind = abl.indexIntoAB[xx][yy];
795
+              xyz_float_t tmp = { abl.eqnAMatrix[ind + 0 * abl.abl_points],
796
+                                  abl.eqnAMatrix[ind + 1 * abl.abl_points], 0 };
795 797
               apply_rotation_xyz(planner.bed_level_matrix, tmp);
796
-              if (get_min) NOMORE(min_diff, eqnBVector[ind] - tmp.z);
797
-              const float subval = get_min ? mean : tmp.z + min_diff,
798
-                            diff = eqnBVector[ind] - subval;
798
+              if (get_min) NOMORE(min_diff, abl.eqnBVector[ind] - tmp.z);
799
+              const float subval = get_min ? abl.mean : tmp.z + min_diff,
800
+                            diff = abl.eqnBVector[ind] - subval;
799 801
               SERIAL_CHAR(' '); if (diff >= 0.0) SERIAL_CHAR('+');   // Include + for column alignment
800 802
               SERIAL_ECHO_F(diff, 5);
801 803
             } // xx
@@ -815,10 +817,10 @@ G29_TYPE GcodeSuite::G29() {
815 817
                                "   |           |\n"
816 818
                                "   O-- FRONT --+\n"
817 819
                                " (0,0)\n"), true);
818
-        if (verbose_level > 3)
820
+        if (abl.verbose_level > 3)
819 821
           print_topo_map(PSTR("\nCorrected Bed Height vs. Bed Topology:\n"), false);
820 822
 
821
-      } //do_topography_map
823
+      } // abl.topography_map
822 824
 
823 825
     #endif // AUTO_BED_LEVELING_LINEAR
824 826
 
@@ -826,10 +828,10 @@ G29_TYPE GcodeSuite::G29() {
826 828
 
827 829
       // For LINEAR and 3POINT leveling correct the current position
828 830
 
829
-      if (verbose_level > 0)
831
+      if (abl.verbose_level > 0)
830 832
         planner.bed_level_matrix.debug(PSTR("\n\nBed Level Correction Matrix:"));
831 833
 
832
-      if (!dryrun) {
834
+      if (!abl.dryrun) {
833 835
         //
834 836
         // Correct the current XYZ position based on the tilted plane.
835 837
         //
@@ -840,10 +842,10 @@ G29_TYPE GcodeSuite::G29() {
840 842
         planner.force_unapply_leveling(converted); // use conversion machinery
841 843
 
842 844
         // Use the last measured distance to the bed, if possible
843
-        if ( NEAR(current_position.x, probePos.x - probe.offset_xy.x)
844
-          && NEAR(current_position.y, probePos.y - probe.offset_xy.y)
845
+        if ( NEAR(current_position.x, abl.probePos.x - probe.offset_xy.x)
846
+          && NEAR(current_position.y, abl.probePos.y - probe.offset_xy.y)
845 847
         ) {
846
-          const float simple_z = current_position.z - measured_z;
848
+          const float simple_z = current_position.z - abl.measured_z;
847 849
           if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Probed Z", simple_z, "  Matrix Z", converted.z, "  Discrepancy ", simple_z - converted.z);
848 850
           converted.z = simple_z;
849 851
         }
@@ -856,7 +858,7 @@ G29_TYPE GcodeSuite::G29() {
856 858
 
857 859
     #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
858 860
 
859
-      if (!dryrun) {
861
+      if (!abl.dryrun) {
860 862
         if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("G29 uncorrected Z:", current_position.z);
861 863
 
862 864
         // Unapply the offset because it is going to be immediately applied
@@ -870,8 +872,8 @@ G29_TYPE GcodeSuite::G29() {
870 872
     #endif // ABL_PLANAR
871 873
 
872 874
     // Auto Bed Leveling is complete! Enable if possible.
873
-    planner.leveling_active = dryrun ? abl_should_enable : true;
874
-  } // !isnan(measured_z)
875
+    planner.leveling_active = !abl.dryrun || abl.reenable;
876
+  } // !isnan(abl.measured_z)
875 877
 
876 878
   // Restore state after probing
877 879
   if (!faux) restore_feedrate_and_scaling();
@@ -895,7 +897,7 @@ G29_TYPE GcodeSuite::G29() {
895 897
 
896 898
   report_current_position();
897 899
 
898
-  G29_RETURN(isnan(measured_z));
900
+  G29_RETURN(isnan(abl.measured_z));
899 901
 }
900 902
 
901 903
 #endif // HAS_ABL_NOT_UBL

+ 1
- 1
Marlin/src/inc/Conditionals_LCD.h 查看文件

@@ -842,7 +842,7 @@
842 842
   #define ABL_PLANAR 1
843 843
 #endif
844 844
 #if EITHER(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_BILINEAR)
845
-  #define ABL_GRID 1
845
+  #define ABL_USES_GRID 1
846 846
 #endif
847 847
 #if ANY(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_3POINT)
848 848
   #define HAS_ABL_NOT_UBL 1

+ 1
- 1
Marlin/src/inc/SanityCheck.h 查看文件

@@ -1262,7 +1262,7 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
1262 1262
     #error "DELTA_AUTO_CALIBRATION requires a probe or LCD Controller."
1263 1263
   #elif ENABLED(DELTA_CALIBRATION_MENU) && !HAS_LCD_MENU
1264 1264
     #error "DELTA_CALIBRATION_MENU requires an LCD Controller."
1265
-  #elif ABL_GRID
1265
+  #elif ABL_USES_GRID
1266 1266
     #if (GRID_MAX_POINTS_X & 1) == 0 || (GRID_MAX_POINTS_Y & 1) == 0
1267 1267
       #error "DELTA requires GRID_MAX_POINTS_X and GRID_MAX_POINTS_Y to be odd numbers."
1268 1268
     #elif GRID_MAX_POINTS_X < 3

+ 1
- 1
buildroot/tests/rambo 查看文件

@@ -88,7 +88,7 @@ opt_enable EEPROM_SETTINGS EEPROM_CHITCHAT REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CO
88 88
           PRINTCOUNTER SERVICE_NAME_1 SERVICE_INTERVAL_1 M114_DETAIL
89 89
 opt_add M100_FREE_MEMORY_DUMPER
90 90
 opt_add M100_FREE_MEMORY_CORRUPTOR
91
-exec_test $1 $2 "MINIRAMBO | RRDGFSC | M100 | PWM_MOTOR_CURRENT | PRINTCOUNTER | Advanced Pause ..." "$3"
91
+exec_test $1 $2 "MINIRAMBO | RRDGFSC | ABL Bilinear Manual | M100 | PWM_MOTOR_CURRENT | M600..." "$3"
92 92
 
93 93
 #
94 94
 # Test many less common options

Loading…
取消
儲存