ソースを参照

Fix linear/3-point manual leveling buffer overrun

Fixes #10137
Scott Lahteine 7年前
コミット
aa20b3ef7c
1個のファイルの変更30行の追加25行の削除
  1. 30
    25
      Marlin/src/gcode/bedlevel/abl/G29.cpp

+ 30
- 25
Marlin/src/gcode/bedlevel/abl/G29.cpp ファイルの表示

209
     #endif
209
     #endif
210
 
210
 
211
     #if ENABLED(AUTO_BED_LEVELING_LINEAR)
211
     #if ENABLED(AUTO_BED_LEVELING_LINEAR)
212
-      ABL_VAR int abl2;
212
+      ABL_VAR int abl_points;
213
     #elif ENABLED(PROBE_MANUALLY) // Bilinear
213
     #elif ENABLED(PROBE_MANUALLY) // Bilinear
214
-      int constexpr abl2 = GRID_MAX_POINTS;
214
+      int constexpr abl_points = GRID_MAX_POINTS;
215
     #endif
215
     #endif
216
 
216
 
217
     #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
217
     #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
230
   #elif ENABLED(AUTO_BED_LEVELING_3POINT)
230
   #elif ENABLED(AUTO_BED_LEVELING_3POINT)
231
 
231
 
232
     #if ENABLED(PROBE_MANUALLY)
232
     #if ENABLED(PROBE_MANUALLY)
233
-      int constexpr abl2 = 3; // used to show total points
233
+      int constexpr abl_points = 3; // used to show total points
234
     #endif
234
     #endif
235
 
235
 
236
     // Probe at 3 arbitrary points
236
     // Probe at 3 arbitrary points
342
         return;
342
         return;
343
       }
343
       }
344
 
344
 
345
-      abl2 = abl_grid_points_x * abl_grid_points_y;
345
+      abl_points = abl_grid_points_x * abl_grid_points_y;
346
       mean = 0;
346
       mean = 0;
347
 
347
 
348
     #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
348
     #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
458
     if (verbose_level || seenQ) {
458
     if (verbose_level || seenQ) {
459
       SERIAL_PROTOCOLPGM("Manual G29 ");
459
       SERIAL_PROTOCOLPGM("Manual G29 ");
460
       if (g29_in_progress) {
460
       if (g29_in_progress) {
461
-        SERIAL_PROTOCOLPAIR("point ", min(abl_probe_index + 1, abl2));
462
-        SERIAL_PROTOCOLLNPAIR(" of ", abl2);
461
+        SERIAL_PROTOCOLPAIR("point ", min(abl_probe_index + 1, abl_points));
462
+        SERIAL_PROTOCOLLNPAIR(" of ", abl_points);
463
       }
463
       }
464
       else
464
       else
465
         SERIAL_PROTOCOLLNPGM("idle");
465
         SERIAL_PROTOCOLLNPGM("idle");
474
       #endif
474
       #endif
475
     }
475
     }
476
     else {
476
     else {
477
+
478
+      #if ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_3POINT)
479
+        const uint16_t index = abl_probe_index - 1;
480
+      #endif
481
+
477
       // For G29 after adjusting Z.
482
       // For G29 after adjusting Z.
478
       // Save the previous Z before going to the next point
483
       // Save the previous Z before going to the next point
479
       measured_z = current_position[Z_AXIS];
484
       measured_z = current_position[Z_AXIS];
481
       #if ENABLED(AUTO_BED_LEVELING_LINEAR)
486
       #if ENABLED(AUTO_BED_LEVELING_LINEAR)
482
 
487
 
483
         mean += measured_z;
488
         mean += measured_z;
484
-        eqnBVector[abl_probe_index] = measured_z;
485
-        eqnAMatrix[abl_probe_index + 0 * abl2] = xProbe;
486
-        eqnAMatrix[abl_probe_index + 1 * abl2] = yProbe;
487
-        eqnAMatrix[abl_probe_index + 2 * abl2] = 1;
489
+        eqnBVector[index] = measured_z;
490
+        eqnAMatrix[index + 0 * abl_points] = xProbe;
491
+        eqnAMatrix[index + 1 * abl_points] = yProbe;
492
+        eqnAMatrix[index + 2 * abl_points] = 1;
488
 
493
 
489
         incremental_LSF(&lsf_results, xProbe, yProbe, measured_z);
494
         incremental_LSF(&lsf_results, xProbe, yProbe, measured_z);
490
 
495
 
496
+      #elif ENABLED(AUTO_BED_LEVELING_3POINT)
497
+
498
+        points[index].z = measured_z;
499
+
491
       #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
500
       #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
492
 
501
 
493
         z_values[xCount][yCount] = measured_z + zoffset;
502
         z_values[xCount][yCount] = measured_z + zoffset;
500
           }
509
           }
501
         #endif
510
         #endif
502
 
511
 
503
-      #elif ENABLED(AUTO_BED_LEVELING_3POINT)
504
-
505
-        points[abl_probe_index].z = measured_z;
506
-
507
       #endif
512
       #endif
508
     }
513
     }
509
 
514
 
514
     #if ABL_GRID
519
     #if ABL_GRID
515
 
520
 
516
       // Skip any unreachable points
521
       // Skip any unreachable points
517
-      while (abl_probe_index < abl2) {
522
+      while (abl_probe_index < abl_points) {
518
 
523
 
519
         // Set xCount, yCount based on abl_probe_index, with zig-zag
524
         // Set xCount, yCount based on abl_probe_index, with zig-zag
520
         PR_OUTER_VAR = abl_probe_index / PR_INNER_END;
525
         PR_OUTER_VAR = abl_probe_index / PR_INNER_END;
541
       }
546
       }
542
 
547
 
543
       // Is there a next point to move to?
548
       // Is there a next point to move to?
544
-      if (abl_probe_index < abl2) {
549
+      if (abl_probe_index < abl_points) {
545
         _manual_goto_xy(xProbe, yProbe); // Can be used here too!
550
         _manual_goto_xy(xProbe, yProbe); // Can be used here too!
546
         #if HAS_SOFTWARE_ENDSTOPS
551
         #if HAS_SOFTWARE_ENDSTOPS
547
           // Disable software endstops to allow manual adjustment
552
           // Disable software endstops to allow manual adjustment
565
     #elif ENABLED(AUTO_BED_LEVELING_3POINT)
570
     #elif ENABLED(AUTO_BED_LEVELING_3POINT)
566
 
571
 
567
       // Probe at 3 arbitrary points
572
       // Probe at 3 arbitrary points
568
-      if (abl_probe_index < abl2) {
573
+      if (abl_probe_index < abl_points) {
569
         xProbe = points[abl_probe_index].x;
574
         xProbe = points[abl_probe_index].x;
570
         yProbe = points[abl_probe_index].y;
575
         yProbe = points[abl_probe_index].y;
571
         _manual_goto_xy(xProbe, yProbe);
576
         _manual_goto_xy(xProbe, yProbe);
661
 
666
 
662
             mean += measured_z;
667
             mean += measured_z;
663
             eqnBVector[abl_probe_index] = measured_z;
668
             eqnBVector[abl_probe_index] = measured_z;
664
-            eqnAMatrix[abl_probe_index + 0 * abl2] = xProbe;
665
-            eqnAMatrix[abl_probe_index + 1 * abl2] = yProbe;
666
-            eqnAMatrix[abl_probe_index + 2 * abl2] = 1;
669
+            eqnAMatrix[abl_probe_index + 0 * abl_points] = xProbe;
670
+            eqnAMatrix[abl_probe_index + 1 * abl_points] = yProbe;
671
+            eqnAMatrix[abl_probe_index + 2 * abl_points] = 1;
667
 
672
 
668
             incremental_LSF(&lsf_results, xProbe, yProbe, measured_z);
673
             incremental_LSF(&lsf_results, xProbe, yProbe, measured_z);
669
 
674
 
771
       plane_equation_coefficients[1] = -lsf_results.B;  // but that is not yet tested.
776
       plane_equation_coefficients[1] = -lsf_results.B;  // but that is not yet tested.
772
       plane_equation_coefficients[2] = -lsf_results.D;
777
       plane_equation_coefficients[2] = -lsf_results.D;
773
 
778
 
774
-      mean /= abl2;
779
+      mean /= abl_points;
775
 
780
 
776
       if (verbose_level) {
781
       if (verbose_level) {
777
         SERIAL_PROTOCOLPGM("Eqn coefficients: a: ");
782
         SERIAL_PROTOCOLPGM("Eqn coefficients: a: ");
815
           for (uint8_t xx = 0; xx < abl_grid_points_x; xx++) {
820
           for (uint8_t xx = 0; xx < abl_grid_points_x; xx++) {
816
             int ind = indexIntoAB[xx][yy];
821
             int ind = indexIntoAB[xx][yy];
817
             float diff = eqnBVector[ind] - mean,
822
             float diff = eqnBVector[ind] - mean,
818
-                  x_tmp = eqnAMatrix[ind + 0 * abl2],
819
-                  y_tmp = eqnAMatrix[ind + 1 * abl2],
823
+                  x_tmp = eqnAMatrix[ind + 0 * abl_points],
824
+                  y_tmp = eqnAMatrix[ind + 1 * abl_points],
820
                   z_tmp = 0;
825
                   z_tmp = 0;
821
 
826
 
822
             apply_rotation_xyz(planner.bed_level_matrix, x_tmp, y_tmp, z_tmp);
827
             apply_rotation_xyz(planner.bed_level_matrix, x_tmp, y_tmp, z_tmp);
839
           for (int8_t yy = abl_grid_points_y - 1; yy >= 0; yy--) {
844
           for (int8_t yy = abl_grid_points_y - 1; yy >= 0; yy--) {
840
             for (uint8_t xx = 0; xx < abl_grid_points_x; xx++) {
845
             for (uint8_t xx = 0; xx < abl_grid_points_x; xx++) {
841
               int ind = indexIntoAB[xx][yy];
846
               int ind = indexIntoAB[xx][yy];
842
-              float x_tmp = eqnAMatrix[ind + 0 * abl2],
843
-                    y_tmp = eqnAMatrix[ind + 1 * abl2],
847
+              float x_tmp = eqnAMatrix[ind + 0 * abl_points],
848
+                    y_tmp = eqnAMatrix[ind + 1 * abl_points],
844
                     z_tmp = 0;
849
                     z_tmp = 0;
845
 
850
 
846
               apply_rotation_xyz(planner.bed_level_matrix, x_tmp, y_tmp, z_tmp);
851
               apply_rotation_xyz(planner.bed_level_matrix, x_tmp, y_tmp, z_tmp);

読み込み中…
キャンセル
保存