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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. #include "../inc/MarlinConfigPre.h"
  23. #if ENABLED(BACKLASH_COMPENSATION)
  24. #include "backlash.h"
  25. #include "../module/motion.h"
  26. #include "../module/planner.h"
  27. #ifdef BACKLASH_DISTANCE_MM
  28. #if ENABLED(BACKLASH_GCODE)
  29. xyz_float_t Backlash::distance_mm = BACKLASH_DISTANCE_MM;
  30. #else
  31. const xyz_float_t Backlash::distance_mm = BACKLASH_DISTANCE_MM;
  32. #endif
  33. #endif
  34. #if ENABLED(BACKLASH_GCODE)
  35. uint8_t Backlash::correction = (BACKLASH_CORRECTION) * 0xFF;
  36. #ifdef BACKLASH_SMOOTHING_MM
  37. float Backlash::smoothing_mm = BACKLASH_SMOOTHING_MM;
  38. #endif
  39. #endif
  40. #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
  41. xyz_float_t Backlash::measured_mm{0};
  42. xyz_uint8_t Backlash::measured_count{0};
  43. #endif
  44. Backlash backlash;
  45. /**
  46. * To minimize seams in the printed part, backlash correction only adds
  47. * steps to the current segment (instead of creating a new segment, which
  48. * causes discontinuities and print artifacts).
  49. *
  50. * With a non-zero BACKLASH_SMOOTHING_MM value the backlash correction is
  51. * spread over multiple segments, smoothing out artifacts even more.
  52. */
  53. void Backlash::add_correction_steps(const int32_t &da, const int32_t &db, const int32_t &dc, const uint8_t dm, block_t * const block) {
  54. static uint8_t last_direction_bits;
  55. uint8_t changed_dir = last_direction_bits ^ dm;
  56. // Ignore direction change unless steps are taken in that direction
  57. #if DISABLED(CORE_BACKLASH) || ENABLED(MARKFORGED_XY)
  58. if (!da) CBI(changed_dir, X_AXIS);
  59. if (!db) CBI(changed_dir, Y_AXIS);
  60. if (!dc) CBI(changed_dir, Z_AXIS);
  61. #elif CORE_IS_XY
  62. if (!(da + db)) CBI(changed_dir, X_AXIS);
  63. if (!(da - db)) CBI(changed_dir, Y_AXIS);
  64. if (!dc) CBI(changed_dir, Z_AXIS);
  65. #elif CORE_IS_XZ
  66. if (!(da + dc)) CBI(changed_dir, X_AXIS);
  67. if (!(da - dc)) CBI(changed_dir, Z_AXIS);
  68. if (!db) CBI(changed_dir, Y_AXIS);
  69. #elif CORE_IS_YZ
  70. if (!(db + dc)) CBI(changed_dir, Y_AXIS);
  71. if (!(db - dc)) CBI(changed_dir, Z_AXIS);
  72. if (!da) CBI(changed_dir, X_AXIS);
  73. #endif
  74. last_direction_bits ^= changed_dir;
  75. if (correction == 0) return;
  76. #ifdef BACKLASH_SMOOTHING_MM
  77. // The segment proportion is a value greater than 0.0 indicating how much residual_error
  78. // is corrected for in this segment. The contribution is based on segment length and the
  79. // smoothing distance. Since the computation of this proportion involves a floating point
  80. // division, defer computation until needed.
  81. float segment_proportion = 0;
  82. // Residual error carried forward across multiple segments, so correction can be applied
  83. // to segments where there is no direction change.
  84. static xyz_long_t residual_error{0};
  85. #else
  86. // No direction change, no correction.
  87. if (!changed_dir) return;
  88. // No leftover residual error from segment to segment
  89. xyz_long_t residual_error{0};
  90. #endif
  91. const float f_corr = float(correction) / 255.0f;
  92. LOOP_LINEAR_AXES(axis) {
  93. if (distance_mm[axis]) {
  94. const bool reversing = TEST(dm,axis);
  95. // When an axis changes direction, add axis backlash to the residual error
  96. if (TEST(changed_dir, axis))
  97. residual_error[axis] += (reversing ? -f_corr : f_corr) * distance_mm[axis] * planner.settings.axis_steps_per_mm[axis];
  98. // Decide how much of the residual error to correct in this segment
  99. int32_t error_correction = residual_error[axis];
  100. #ifdef BACKLASH_SMOOTHING_MM
  101. if (error_correction && smoothing_mm != 0) {
  102. // Take up a portion of the residual_error in this segment, but only when
  103. // the current segment travels in the same direction as the correction
  104. if (reversing == (error_correction < 0)) {
  105. if (segment_proportion == 0) segment_proportion = _MIN(1.0f, block->millimeters / smoothing_mm);
  106. error_correction = CEIL(segment_proportion * error_correction);
  107. }
  108. else
  109. error_correction = 0; // Don't take up any backlash in this segment, as it would subtract steps
  110. }
  111. #endif
  112. // This correction reduces the residual error and adds block steps
  113. if (error_correction) {
  114. block->steps[axis] += ABS(error_correction);
  115. #if ENABLED(CORE_BACKLASH)
  116. switch (axis) {
  117. case CORE_AXIS_1:
  118. //block->steps[CORE_AXIS_2] += influence_distance_mm[axis] * planner.settings.axis_steps_per_mm[CORE_AXIS_2];
  119. //SERIAL_ECHOLNPGM("CORE_AXIS_1 dir change. distance=", distance_mm[axis], " r.err=", residual_error[axis],
  120. // " da=", da, " db=", db, " block->steps[axis]=", block->steps[axis], " err_corr=", error_correction);
  121. break;
  122. case CORE_AXIS_2:
  123. //block->steps[CORE_AXIS_1] += influence_distance_mm[axis] * planner.settings.axis_steps_per_mm[CORE_AXIS_1];;
  124. //SERIAL_ECHOLNPGM("CORE_AXIS_2 dir change. distance=", distance_mm[axis], " r.err=", residual_error[axis],
  125. // " da=", da, " db=", db, " block->steps[axis]=", block->steps[axis], " err_corr=", error_correction);
  126. break;
  127. case NORMAL_AXIS: break;
  128. }
  129. residual_error[axis] = 0; // No residual_error needed for next CORE block, I think...
  130. #else
  131. residual_error[axis] -= error_correction;
  132. #endif
  133. }
  134. }
  135. }
  136. }
  137. #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
  138. #include "../module/probe.h"
  139. // Measure Z backlash by raising nozzle in increments until probe deactivates
  140. void Backlash::measure_with_probe() {
  141. if (measured_count.z == 255) return;
  142. const float start_height = current_position.z;
  143. while (current_position.z < (start_height + BACKLASH_MEASUREMENT_LIMIT) && PROBE_TRIGGERED())
  144. do_blocking_move_to_z(current_position.z + BACKLASH_MEASUREMENT_RESOLUTION, MMM_TO_MMS(BACKLASH_MEASUREMENT_FEEDRATE));
  145. // The backlash from all probe points is averaged, so count the number of measurements
  146. measured_mm.z += current_position.z - start_height;
  147. measured_count.z++;
  148. }
  149. #endif
  150. #endif // BACKLASH_COMPENSATION