My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

nozzle.h 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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. #ifndef __NOZZLE_H__
  23. #define __NOZZLE_H__
  24. #include "Marlin.h"
  25. #include "point_t.h"
  26. #if ENABLED(NOZZLE_CLEAN_FEATURE)
  27. constexpr float nozzle_clean_start_point[4] = NOZZLE_CLEAN_START_POINT,
  28. nozzle_clean_end_point[4] = NOZZLE_CLEAN_END_POINT,
  29. nozzle_clean_length = fabs(nozzle_clean_start_point[X_AXIS] - nozzle_clean_end_point[X_AXIS]), //abs x size of wipe pad
  30. nozzle_clean_height = fabs(nozzle_clean_start_point[Y_AXIS] - nozzle_clean_end_point[Y_AXIS]); //abs y size of wipe pad
  31. constexpr bool nozzle_clean_horizontal = nozzle_clean_length >= nozzle_clean_height; //whether to zig-zag horizontally or vertically
  32. #endif //NOZZLE_CLEAN_FEATURE
  33. /**
  34. * @brief Nozzle class
  35. *
  36. * @todo: Do not ignore the end.z value and allow XYZ movements
  37. */
  38. class Nozzle {
  39. private:
  40. /**
  41. * @brief Stroke clean pattern
  42. * @details Wipes the nozzle back and forth in a linear movement
  43. *
  44. * @param start point_t defining the starting point
  45. * @param end point_t defining the ending point
  46. * @param strokes number of strokes to execute
  47. */
  48. static void stroke(
  49. __attribute__((unused)) point_t const &start,
  50. __attribute__((unused)) point_t const &end,
  51. __attribute__((unused)) uint8_t const &strokes
  52. ) __attribute__((optimize ("Os"))) {
  53. #if ENABLED(NOZZLE_CLEAN_FEATURE)
  54. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  55. // Store the current coords
  56. point_t const initial = {
  57. current_position[X_AXIS],
  58. current_position[Y_AXIS],
  59. current_position[Z_AXIS],
  60. current_position[E_AXIS]
  61. };
  62. #endif // NOZZLE_CLEAN_GOBACK
  63. // Move to the starting point
  64. do_blocking_move_to_xy(start.x, start.y);
  65. do_blocking_move_to_z(start.z);
  66. // Start the stroke pattern
  67. for (uint8_t i = 0; i < (strokes >>1); i++) {
  68. do_blocking_move_to_xy(end.x, end.y);
  69. do_blocking_move_to_xy(start.x, start.y);
  70. }
  71. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  72. // Move the nozzle to the initial point
  73. do_blocking_move_to(initial.x, initial.y, initial.z);
  74. #endif // NOZZLE_CLEAN_GOBACK
  75. #endif // NOZZLE_CLEAN_FEATURE
  76. }
  77. /**
  78. * @brief Zig-zag clean pattern
  79. * @details Apply a zig-zag cleanning pattern
  80. *
  81. * @param start point_t defining the starting point
  82. * @param end point_t defining the ending point
  83. * @param strokes number of strokes to execute
  84. * @param objects number of objects to create
  85. */
  86. static void zigzag(
  87. __attribute__((unused)) point_t const &start,
  88. __attribute__((unused)) point_t const &end,
  89. __attribute__((unused)) uint8_t const &strokes,
  90. __attribute__((unused)) uint8_t const &objects
  91. ) __attribute__((optimize ("Os"))) {
  92. #if ENABLED(NOZZLE_CLEAN_FEATURE)
  93. float A = nozzle_clean_horizontal ? nozzle_clean_height : nozzle_clean_length; // [twice the] Amplitude
  94. float P = ( nozzle_clean_horizontal ? nozzle_clean_length : nozzle_clean_height ) / (objects << 1); // Period
  95. // Don't allow impossible triangles
  96. if (A <= 0.0f || P <= 0.0f ) return;
  97. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  98. // Store the current coords
  99. point_t const initial = {
  100. current_position[X_AXIS],
  101. current_position[Y_AXIS],
  102. current_position[Z_AXIS],
  103. current_position[E_AXIS]
  104. };
  105. #endif // NOZZLE_CLEAN_GOBACK
  106. for (uint8_t j = 0; j < strokes; j++) {
  107. for (uint8_t i = 0; i < (objects << 1); i++) {
  108. float const x = start.x + ( nozzle_clean_horizontal ? i * P : (A/P) * (P - fabs(fmod((i*P), (2*P)) - P)) );
  109. float const y = start.y + (!nozzle_clean_horizontal ? i * P : (A/P) * (P - fabs(fmod((i*P), (2*P)) - P)) );
  110. do_blocking_move_to_xy(x, y);
  111. if (i == 0) do_blocking_move_to_z(start.z);
  112. }
  113. for (int i = (objects << 1); i > -1; i--) {
  114. float const x = start.x + ( nozzle_clean_horizontal ? i * P : (A/P) * (P - fabs(fmod((i*P), (2*P)) - P)) );
  115. float const y = start.y + (!nozzle_clean_horizontal ? i * P : (A/P) * (P - fabs(fmod((i*P), (2*P)) - P)) );
  116. do_blocking_move_to_xy(x, y);
  117. }
  118. }
  119. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  120. // Move the nozzle to the initial point
  121. do_blocking_move_to_z(initial.z);
  122. do_blocking_move_to_xy(initial.x, initial.y);
  123. #endif // NOZZLE_CLEAN_GOBACK
  124. #endif // NOZZLE_CLEAN_FEATURE
  125. }
  126. public:
  127. /**
  128. * @brief Clean the nozzle
  129. * @details Starts the selected clean procedure pattern
  130. *
  131. * @param pattern one of the available patterns
  132. * @param argument depends on the cleaning pattern
  133. */
  134. static void clean(
  135. __attribute__((unused)) uint8_t const &pattern,
  136. __attribute__((unused)) uint8_t const &strokes,
  137. __attribute__((unused)) uint8_t const &objects = 0
  138. ) __attribute__((optimize ("Os"))) {
  139. #if ENABLED(NOZZLE_CLEAN_FEATURE)
  140. #if ENABLED(DELTA)
  141. if (current_position[Z_AXIS] > delta_clip_start_height)
  142. do_blocking_move_to_z(delta_clip_start_height);
  143. #endif
  144. switch (pattern) {
  145. case 1:
  146. Nozzle::zigzag(
  147. NOZZLE_CLEAN_START_POINT,
  148. NOZZLE_CLEAN_END_POINT, strokes, objects);
  149. break;
  150. default:
  151. Nozzle::stroke(
  152. NOZZLE_CLEAN_START_POINT,
  153. NOZZLE_CLEAN_END_POINT, strokes);
  154. }
  155. #endif // NOZZLE_CLEAN_FEATURE
  156. }
  157. static void park(
  158. __attribute__((unused)) uint8_t const &z_action
  159. ) __attribute__((optimize ("Os"))) {
  160. #if ENABLED(NOZZLE_PARK_FEATURE)
  161. float const z = current_position[Z_AXIS];
  162. point_t const park = NOZZLE_PARK_POINT;
  163. switch(z_action) {
  164. case 1: // force Z-park height
  165. do_blocking_move_to_z(park.z);
  166. break;
  167. case 2: // Raise by Z-park height
  168. do_blocking_move_to_z(
  169. (z + park.z > Z_MAX_POS) ? Z_MAX_POS : z + park.z);
  170. break;
  171. default: // Raise to Z-park height if lower
  172. if (current_position[Z_AXIS] < park.z)
  173. do_blocking_move_to_z(park.z);
  174. }
  175. do_blocking_move_to_xy(park.x, park.y);
  176. #endif // NOZZLE_PARK_FEATURE
  177. }
  178. };
  179. #endif