My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

least_squares_fit.cpp 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Least Squares Best Fit by Roxy and Ed Williams
  24. *
  25. * This algorithm is high speed and has a very small code footprint.
  26. * Its results are identical to both the Iterative Least-Squares published
  27. * earlier by Roxy and the QR_SOLVE solution. If used in place of QR_SOLVE
  28. * it saves roughly 10K of program memory. It also does not require all of
  29. * coordinates to be present during the calculations. Each point can be
  30. * probed and then discarded.
  31. */
  32. #include "../inc/MarlinConfig.h"
  33. #if NEED_LSF
  34. #include "least_squares_fit.h"
  35. #include <math.h>
  36. int finish_incremental_LSF(struct linear_fit_data *lsf) {
  37. const float N = lsf->N;
  38. if (N == 0.0)
  39. return 1;
  40. const float RN = 1.0f / N,
  41. xbar = lsf->xbar * RN,
  42. ybar = lsf->ybar * RN,
  43. zbar = lsf->zbar * RN,
  44. x2bar = lsf->x2bar * RN - sq(xbar),
  45. y2bar = lsf->y2bar * RN - sq(ybar),
  46. xybar = lsf->xybar * RN - xbar * ybar,
  47. yzbar = lsf->yzbar * RN - ybar * zbar,
  48. xzbar = lsf->xzbar * RN - xbar * zbar,
  49. DD = x2bar * y2bar - sq(xybar);
  50. if (ABS(DD) <= 1e-10 * (lsf->max_absx + lsf->max_absy))
  51. return 1;
  52. lsf->A = (yzbar * xybar - xzbar * y2bar) / DD;
  53. lsf->B = (xzbar * xybar - yzbar * x2bar) / DD;
  54. lsf->D = -(zbar + lsf->A * xbar + lsf->B * ybar);
  55. return 0;
  56. }
  57. #endif // NEED_LSF