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.
pull/1/head
Roxy-3D 7 years ago
committed by GitHub
parent
commit
9af67e2446
  1. 40
      Marlin/Marlin_main.cpp
  2. 4
      Marlin/least_squares_fit.cpp
  3. 2
      Marlin/least_squares_fit.h
  4. 1591
      Marlin/qr_solve.cpp
  5. 44
      Marlin/qr_solve.h

40
Marlin/Marlin_main.cpp

@ -261,7 +261,7 @@
#if HAS_ABL
#include "vector_3.h"
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
#include "qr_solve.h"
#include "least_squares_fit.h"
#endif
#elif ENABLED(MESH_BED_LEVELING)
#include "mesh_bed_leveling.h"
@ -4336,8 +4336,8 @@ void home_all_axes() { gcode_G28(true); }
ABL_VAR int indexIntoAB[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
ABL_VAR float eqnAMatrix[GRID_MAX_POINTS * 3], // "A" matrix of the linear system of equations
eqnBVector[GRID_MAX_POINTS], // "B" vector of Z points
mean;
eqnBVector[GRID_MAX_POINTS], // "B" vector of Z points
mean;
#endif
#elif ENABLED(AUTO_BED_LEVELING_3POINT)
@ -4353,6 +4353,11 @@ void home_all_axes() { gcode_G28(true); }
#endif // AUTO_BED_LEVELING_3POINT
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
struct linear_fit_data lsf_results;
incremental_LSF_reset(&lsf_results);
#endif
/**
* On the initial G29 fetch command parameters.
*/
@ -4549,11 +4554,7 @@ void home_all_axes() { gcode_G28(true); }
abl_should_enable = false;
}
#elif ENABLED(AUTO_BED_LEVELING_LINEAR)
mean = 0.0;
#endif // AUTO_BED_LEVELING_LINEAR
#endif // AUTO_BED_LEVELING_BILINEAR
#if ENABLED(AUTO_BED_LEVELING_3POINT)
@ -4616,11 +4617,11 @@ void home_all_axes() { gcode_G28(true); }
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
mean += measured_z;
eqnBVector[abl_probe_index] = measured_z;
eqnAMatrix[abl_probe_index + 0 * abl2] = xProbe;
eqnAMatrix[abl_probe_index + 1 * abl2] = yProbe;
eqnAMatrix[abl_probe_index + 2 * abl2] = 1;
// mean += measured_z; // I believe this is unused code?
// eqnBVector[abl_probe_index] = measured_z; // I believe this is unused code?
// eqnAMatrix[abl_probe_index + 0 * abl2] = xProbe; // I believe this is unused code?
// eqnAMatrix[abl_probe_index + 1 * abl2] = yProbe; // I believe this is unused code?
// eqnAMatrix[abl_probe_index + 2 * abl2] = 1; // I believe this is unused code?
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
@ -4794,6 +4795,11 @@ void home_all_axes() { gcode_G28(true); }
eqnAMatrix[abl_probe_index + 1 * abl2] = yProbe;
eqnAMatrix[abl_probe_index + 2 * abl2] = 1;
incremental_LSF(&lsf_results, xProbe, yProbe, measured_z);
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
indexIntoAB[xCount][yCount] = abl_probe_index;
#endif
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
z_values[xCount][yCount] = measured_z + zoffset;
@ -4894,7 +4900,11 @@ void home_all_axes() { gcode_G28(true); }
* so Vx = -a Vy = -b Vz = 1 (we want the vector facing towards positive Z
*/
float plane_equation_coefficients[3];
qr_solve(plane_equation_coefficients, abl2, 3, eqnAMatrix, eqnBVector);
finish_incremental_LSF(&lsf_results);
plane_equation_coefficients[0] = -lsf_results.A; // We should be able to eliminate the '-' on these three lines and down below
plane_equation_coefficients[1] = -lsf_results.B; // but that is not yet tested.
plane_equation_coefficients[2] = -lsf_results.D;
mean /= abl2;
@ -4916,7 +4926,7 @@ void home_all_axes() { gcode_G28(true); }
// Create the matrix but don't correct the position yet
if (!dryrun) {
planner.bed_level_matrix = matrix_3x3::create_look_at(
vector_3(-plane_equation_coefficients[0], -plane_equation_coefficients[1], 1)
vector_3(-plane_equation_coefficients[0], -plane_equation_coefficients[1], 1) // We can eleminate the '-' here and up above
);
}

4
Marlin/least_squares_fit.cpp

@ -34,7 +34,7 @@
#include "MarlinConfig.h"
#if ENABLED(AUTO_BED_LEVELING_UBL) // Currently only used by UBL, but is applicable to Grid Based (Linear) Bed Leveling
#if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(AUTO_BED_LEVELING_LINEAR)
#include "macros.h"
#include <math.h>
@ -68,4 +68,4 @@ int finish_incremental_LSF(struct linear_fit_data *lsf) {
return 0;
}
#endif // AUTO_BED_LEVELING_UBL
#endif // AUTO_BED_LEVELING_UBL || ENABLED(AUTO_BED_LEVELING_LINEAR)

2
Marlin/least_squares_fit.h

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

1591
Marlin/qr_solve.cpp

File diff suppressed because it is too large

44
Marlin/qr_solve.h

@ -1,44 +0,0 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "MarlinConfig.h"
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
void daxpy(int n, float da, float dx[], int incx, float dy[], int incy);
float ddot(int n, float dx[], int incx, float dy[], int incy);
float dnrm2(int n, float x[], int incx);
void dqrank(float a[], int lda, int m, int n, float tol, int* kr,
int jpvt[], float qraux[]);
void dqrdc(float a[], int lda, int n, int p, float qraux[], int jpvt[],
float work[], int job);
int dqrls(float a[], int lda, int m, int n, float tol, int* kr, float b[],
float x[], float rsd[], int jpvt[], float qraux[], int itask);
void dqrlss(float a[], int lda, int m, int n, int kr, float b[], float x[],
float rsd[], int jpvt[], float qraux[]);
int dqrsl(float a[], int lda, int n, int k, float qraux[], float y[],
float qy[], float qty[], float b[], float rsd[], float ab[], int job);
void dscal(int n, float sa, float x[], int incx);
void dswap(int n, float x[], int incx, float y[], int incy);
void qr_solve(float x[], int m, int n, float a[], float b[]);
#endif
Loading…
Cancel
Save