Browse Source

Save 7714 bytes of program memory when doing AUTO_BED_LEVELING_LINEAR (#7276)

We can save more and a pile of RAM by eleminating the eqnBVector and
EqnAMatrix arrays next.
Roxy-3D 8 years ago
parent
commit
9af67e2446
5 changed files with 28 additions and 1653 deletions
  1. 25
    15
      Marlin/Marlin_main.cpp
  2. 2
    2
      Marlin/least_squares_fit.cpp
  3. 1
    1
      Marlin/least_squares_fit.h
  4. 0
    1591
      Marlin/qr_solve.cpp
  5. 0
    44
      Marlin/qr_solve.h

+ 25
- 15
Marlin/Marlin_main.cpp View File

261
 #if HAS_ABL
261
 #if HAS_ABL
262
   #include "vector_3.h"
262
   #include "vector_3.h"
263
   #if ENABLED(AUTO_BED_LEVELING_LINEAR)
263
   #if ENABLED(AUTO_BED_LEVELING_LINEAR)
264
-    #include "qr_solve.h"
264
+    #include "least_squares_fit.h"
265
   #endif
265
   #endif
266
 #elif ENABLED(MESH_BED_LEVELING)
266
 #elif ENABLED(MESH_BED_LEVELING)
267
   #include "mesh_bed_leveling.h"
267
   #include "mesh_bed_leveling.h"
4336
         ABL_VAR int indexIntoAB[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
4336
         ABL_VAR int indexIntoAB[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
4337
 
4337
 
4338
         ABL_VAR float eqnAMatrix[GRID_MAX_POINTS * 3], // "A" matrix of the linear system of equations
4338
         ABL_VAR float eqnAMatrix[GRID_MAX_POINTS * 3], // "A" matrix of the linear system of equations
4339
-                     eqnBVector[GRID_MAX_POINTS],     // "B" vector of Z points
4340
-                     mean;
4339
+                      eqnBVector[GRID_MAX_POINTS],     // "B" vector of Z points
4340
+                      mean;
4341
       #endif
4341
       #endif
4342
 
4342
 
4343
     #elif ENABLED(AUTO_BED_LEVELING_3POINT)
4343
     #elif ENABLED(AUTO_BED_LEVELING_3POINT)
4353
 
4353
 
4354
     #endif // AUTO_BED_LEVELING_3POINT
4354
     #endif // AUTO_BED_LEVELING_3POINT
4355
 
4355
 
4356
+    #if ENABLED(AUTO_BED_LEVELING_LINEAR)
4357
+      struct linear_fit_data lsf_results;
4358
+      incremental_LSF_reset(&lsf_results);
4359
+    #endif
4360
+
4356
     /**
4361
     /**
4357
      * On the initial G29 fetch command parameters.
4362
      * On the initial G29 fetch command parameters.
4358
      */
4363
      */
4549
           abl_should_enable = false;
4554
           abl_should_enable = false;
4550
         }
4555
         }
4551
 
4556
 
4552
-      #elif ENABLED(AUTO_BED_LEVELING_LINEAR)
4553
-
4554
-        mean = 0.0;
4555
-
4556
-      #endif // AUTO_BED_LEVELING_LINEAR
4557
+      #endif // AUTO_BED_LEVELING_BILINEAR
4557
 
4558
 
4558
       #if ENABLED(AUTO_BED_LEVELING_3POINT)
4559
       #if ENABLED(AUTO_BED_LEVELING_3POINT)
4559
 
4560
 
4616
 
4617
 
4617
         #if ENABLED(AUTO_BED_LEVELING_LINEAR)
4618
         #if ENABLED(AUTO_BED_LEVELING_LINEAR)
4618
 
4619
 
4619
-          mean += measured_z;
4620
-          eqnBVector[abl_probe_index] = measured_z;
4621
-          eqnAMatrix[abl_probe_index + 0 * abl2] = xProbe;
4622
-          eqnAMatrix[abl_probe_index + 1 * abl2] = yProbe;
4623
-          eqnAMatrix[abl_probe_index + 2 * abl2] = 1;
4620
+//        mean += measured_z;                                  // I believe this is unused code?
4621
+//        eqnBVector[abl_probe_index] = measured_z;            // I believe this is unused code?
4622
+//        eqnAMatrix[abl_probe_index + 0 * abl2] = xProbe;     // I believe this is unused code?
4623
+//        eqnAMatrix[abl_probe_index + 1 * abl2] = yProbe;     // I believe this is unused code?
4624
+//        eqnAMatrix[abl_probe_index + 2 * abl2] = 1;          // I believe this is unused code?
4624
 
4625
 
4625
         #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
4626
         #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
4626
 
4627
 
4794
               eqnAMatrix[abl_probe_index + 1 * abl2] = yProbe;
4795
               eqnAMatrix[abl_probe_index + 1 * abl2] = yProbe;
4795
               eqnAMatrix[abl_probe_index + 2 * abl2] = 1;
4796
               eqnAMatrix[abl_probe_index + 2 * abl2] = 1;
4796
 
4797
 
4798
+              incremental_LSF(&lsf_results, xProbe, yProbe, measured_z);
4799
+
4800
+          #if ENABLED(AUTO_BED_LEVELING_LINEAR)
4801
+            indexIntoAB[xCount][yCount] = abl_probe_index;
4802
+          #endif
4797
             #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
4803
             #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
4798
 
4804
 
4799
               z_values[xCount][yCount] = measured_z + zoffset;
4805
               z_values[xCount][yCount] = measured_z + zoffset;
4894
        * so Vx = -a Vy = -b Vz = 1 (we want the vector facing towards positive Z
4900
        * so Vx = -a Vy = -b Vz = 1 (we want the vector facing towards positive Z
4895
        */
4901
        */
4896
       float plane_equation_coefficients[3];
4902
       float plane_equation_coefficients[3];
4897
-      qr_solve(plane_equation_coefficients, abl2, 3, eqnAMatrix, eqnBVector);
4903
+
4904
+      finish_incremental_LSF(&lsf_results);
4905
+      plane_equation_coefficients[0] = -lsf_results.A;  // We should be able to eliminate the '-' on these three lines and down below
4906
+      plane_equation_coefficients[1] = -lsf_results.B;  // but that is not yet tested.
4907
+      plane_equation_coefficients[2] = -lsf_results.D;
4898
 
4908
 
4899
       mean /= abl2;
4909
       mean /= abl2;
4900
 
4910
 
4916
       // Create the matrix but don't correct the position yet
4926
       // Create the matrix but don't correct the position yet
4917
       if (!dryrun) {
4927
       if (!dryrun) {
4918
         planner.bed_level_matrix = matrix_3x3::create_look_at(
4928
         planner.bed_level_matrix = matrix_3x3::create_look_at(
4919
-          vector_3(-plane_equation_coefficients[0], -plane_equation_coefficients[1], 1)
4929
+          vector_3(-plane_equation_coefficients[0], -plane_equation_coefficients[1], 1)    // We can eleminate the '-' here and up above
4920
         );
4930
         );
4921
       }
4931
       }
4922
 
4932
 

+ 2
- 2
Marlin/least_squares_fit.cpp View File

34
 
34
 
35
 #include "MarlinConfig.h"
35
 #include "MarlinConfig.h"
36
 
36
 
37
-#if ENABLED(AUTO_BED_LEVELING_UBL)  // Currently only used by UBL, but is applicable to Grid Based (Linear) Bed Leveling
37
+#if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(AUTO_BED_LEVELING_LINEAR)
38
 
38
 
39
 #include "macros.h"
39
 #include "macros.h"
40
 #include <math.h>
40
 #include <math.h>
68
   return 0;
68
   return 0;
69
 }
69
 }
70
 
70
 
71
-#endif // AUTO_BED_LEVELING_UBL
71
+#endif // AUTO_BED_LEVELING_UBL || ENABLED(AUTO_BED_LEVELING_LINEAR)  

+ 1
- 1
Marlin/least_squares_fit.h View File

34
 
34
 
35
 #include "MarlinConfig.h"
35
 #include "MarlinConfig.h"
36
 
36
 
37
-#if ENABLED(AUTO_BED_LEVELING_UBL)  // Currently only used by UBL, but is applicable to Grid Based (Linear) Bed Leveling
37
+#if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(AUTO_BED_LEVELING_LINEAR)    
38
 
38
 
39
 #include "Marlin.h"
39
 #include "Marlin.h"
40
 #include "macros.h"
40
 #include "macros.h"

+ 0
- 1591
Marlin/qr_solve.cpp
File diff suppressed because it is too large
View File


+ 0
- 44
Marlin/qr_solve.h View File

1
-/**
2
- * Marlin 3D Printer Firmware
3
- * Copyright (C) 2016 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
-#include "MarlinConfig.h"
24
-
25
-#if ENABLED(AUTO_BED_LEVELING_LINEAR)
26
-
27
-void daxpy(int n, float da, float dx[], int incx, float dy[], int incy);
28
-float ddot(int n, float dx[], int incx, float dy[], int incy);
29
-float dnrm2(int n, float x[], int incx);
30
-void dqrank(float a[], int lda, int m, int n, float tol, int* kr,
31
-            int jpvt[], float qraux[]);
32
-void dqrdc(float a[], int lda, int n, int p, float qraux[], int jpvt[],
33
-           float work[], int job);
34
-int dqrls(float a[], int lda, int m, int n, float tol, int* kr, float b[],
35
-          float x[], float rsd[], int jpvt[], float qraux[], int itask);
36
-void dqrlss(float a[], int lda, int m, int n, int kr, float b[], float x[],
37
-            float rsd[], int jpvt[], float qraux[]);
38
-int dqrsl(float a[], int lda, int n, int k, float qraux[], float y[],
39
-          float qy[], float qty[], float b[], float rsd[], float ab[], int job);
40
-void dscal(int n, float sa, float x[], int incx);
41
-void dswap(int n, float x[], int incx, float y[], int incy);
42
-void qr_solve(float x[], int m, int n, float a[], float b[]);
43
-
44
-#endif

Loading…
Cancel
Save