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.

backlash.h 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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. #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. #ifdef BACKLASH_DISTANCE_MM
  29. #if ENABLED(BACKLASH_GCODE)
  30. static float distance_mm[XYZ];
  31. #else
  32. static const float distance_mm[XYZ];
  33. //static constexpr float distance_mm[XYZ] = BACKLASH_DISTANCE_MM; // compiler barks at this
  34. #endif
  35. #endif
  36. #if ENABLED(BACKLASH_GCODE)
  37. static uint8_t correction;
  38. #ifdef BACKLASH_SMOOTHING_MM
  39. static float smoothing_mm;
  40. #endif
  41. static inline void set_correction(const float &v) { correction = MAX(0, MIN(1.0, v)) * all_on; }
  42. static inline float get_correction() { return float(ui8_to_percent(correction)) / 100.0f; }
  43. #else
  44. static constexpr uint8_t correction = (BACKLASH_CORRECTION) * 0xFF;
  45. #ifdef BACKLASH_SMOOTHING_MM
  46. static constexpr float smoothing_mm = BACKLASH_SMOOTHING_MM;
  47. #endif
  48. static inline void set_correction(float) { }
  49. static inline float get_correction() { return float(ui8_to_percent(correction)) / 100.0f; }
  50. #endif
  51. #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
  52. private:
  53. static float measured_mm[XYZ];
  54. static uint8_t measured_count[XYZ];
  55. public:
  56. static void measure_with_probe();
  57. #endif
  58. static inline float get_measurement(const uint8_t e) {
  59. // Return the measurement averaged over all readings
  60. return (
  61. #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
  62. measured_count[e] > 0 ? measured_mm[e] / measured_count[e] :
  63. #endif
  64. 0
  65. );
  66. #if DISABLED(MEASURE_BACKLASH_WHEN_PROBING)
  67. UNUSED(e);
  68. #endif
  69. }
  70. static inline bool has_measurement(const uint8_t e) {
  71. return (false
  72. #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
  73. || (measured_count[e] > 0)
  74. #endif
  75. );
  76. #if DISABLED(MEASURE_BACKLASH_WHEN_PROBING)
  77. UNUSED(e);
  78. #endif
  79. }
  80. static inline bool has_any_measurement() {
  81. return has_measurement(X_AXIS) || has_measurement(Y_AXIS) || has_measurement(Z_AXIS);
  82. }
  83. void add_correction_steps(const int32_t &da, const int32_t &db, const int32_t &dc, const uint8_t dm, block_t * const block);
  84. };
  85. extern Backlash backlash;