My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #pragma once
  23. #include "../inc/MarlinConfigPre.h"
  24. #include "../module/planner.h"
  25. constexpr uint8_t all_on = 0xFF, all_off = 0x00;
  26. class Backlash {
  27. public:
  28. #if ENABLED(BACKLASH_GCODE)
  29. static xyz_float_t distance_mm;
  30. static uint8_t correction;
  31. #ifdef BACKLASH_SMOOTHING_MM
  32. static float smoothing_mm;
  33. #endif
  34. static inline void set_correction(const float &v) { correction = _MAX(0, _MIN(1.0, v)) * all_on; }
  35. static inline float get_correction() { return float(ui8_to_percent(correction)) / 100.0f; }
  36. #else
  37. static constexpr uint8_t correction = (BACKLASH_CORRECTION) * 0xFF;
  38. static const xyz_float_t distance_mm;
  39. #ifdef BACKLASH_SMOOTHING_MM
  40. static constexpr float smoothing_mm = BACKLASH_SMOOTHING_MM;
  41. #endif
  42. #endif
  43. #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
  44. private:
  45. static xyz_float_t measured_mm;
  46. static xyz_uint8_t measured_count;
  47. public:
  48. static void measure_with_probe();
  49. #endif
  50. static inline float get_measurement(const AxisEnum a) {
  51. // Return the measurement averaged over all readings
  52. return TERN(MEASURE_BACKLASH_WHEN_PROBING
  53. , measured_count[a] > 0 ? measured_mm[a] / measured_count[a] : 0
  54. , 0
  55. );
  56. TERN(MEASURE_BACKLASH_WHEN_PROBING,,UNUSED(a));
  57. }
  58. static inline bool has_measurement(const AxisEnum a) {
  59. return TERN0(MEASURE_BACKLASH_WHEN_PROBING, measured_count[a] > 0);
  60. TERN(MEASURE_BACKLASH_WHEN_PROBING,,UNUSED(a));
  61. }
  62. static inline bool has_any_measurement() {
  63. return has_measurement(X_AXIS) || has_measurement(Y_AXIS) || has_measurement(Z_AXIS);
  64. }
  65. void add_correction_steps(const int32_t &da, const int32_t &db, const int32_t &dc, const uint8_t dm, block_t * const block);
  66. };
  67. extern Backlash backlash;