My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

nozzle.cpp 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #include "nozzle.h"
  2. #include "Marlin.h"
  3. #include "point_t.h"
  4. /**
  5. * @brief Stroke clean pattern
  6. * @details Wipes the nozzle back and forth in a linear movement
  7. *
  8. * @param start point_t defining the starting point
  9. * @param end point_t defining the ending point
  10. * @param strokes number of strokes to execute
  11. */
  12. void Nozzle::stroke(
  13. _UNUSED point_t const &start,
  14. _UNUSED point_t const &end,
  15. _UNUSED uint8_t const &strokes
  16. ) {
  17. #if ENABLED(NOZZLE_CLEAN_FEATURE)
  18. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  19. // Store the current coords
  20. point_t const initial = {
  21. current_position[X_AXIS],
  22. current_position[Y_AXIS],
  23. current_position[Z_AXIS],
  24. current_position[E_AXIS]
  25. };
  26. #endif // NOZZLE_CLEAN_GOBACK
  27. // Move to the starting point
  28. do_blocking_move_to_xy(start.x, start.y);
  29. do_blocking_move_to_z(start.z);
  30. // Start the stroke pattern
  31. for (uint8_t i = 0; i < (strokes >>1); i++) {
  32. do_blocking_move_to_xy(end.x, end.y);
  33. do_blocking_move_to_xy(start.x, start.y);
  34. }
  35. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  36. // Move the nozzle to the initial point
  37. do_blocking_move_to(initial.x, initial.y, initial.z);
  38. #endif // NOZZLE_CLEAN_GOBACK
  39. #endif // NOZZLE_CLEAN_FEATURE
  40. }
  41. /**
  42. * @brief Zig-zag clean pattern
  43. * @details Apply a zig-zag cleanning pattern
  44. *
  45. * @param start point_t defining the starting point
  46. * @param end point_t defining the ending point
  47. * @param strokes number of strokes to execute
  48. * @param objects number of objects to create
  49. */
  50. void Nozzle::zigzag(
  51. _UNUSED point_t const &start,
  52. _UNUSED point_t const &end,
  53. _UNUSED uint8_t const &strokes,
  54. _UNUSED uint8_t const &objects
  55. ) {
  56. #if ENABLED(NOZZLE_CLEAN_FEATURE)
  57. const float A = nozzle_clean_horizontal ? nozzle_clean_height : nozzle_clean_length, // [twice the] Amplitude
  58. P = (nozzle_clean_horizontal ? nozzle_clean_length : nozzle_clean_height) / (objects << 1); // Period
  59. // Don't allow impossible triangles
  60. if (A <= 0.0f || P <= 0.0f ) return;
  61. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  62. // Store the current coords
  63. point_t const initial = {
  64. current_position[X_AXIS],
  65. current_position[Y_AXIS],
  66. current_position[Z_AXIS],
  67. current_position[E_AXIS]
  68. };
  69. #endif // NOZZLE_CLEAN_GOBACK
  70. for (uint8_t j = 0; j < strokes; j++) {
  71. for (uint8_t i = 0; i < (objects << 1); i++) {
  72. float const x = start.x + ( nozzle_clean_horizontal ? i * P : (A/P) * (P - FABS(FMOD((i*P), (2*P)) - P)) );
  73. float const y = start.y + (!nozzle_clean_horizontal ? i * P : (A/P) * (P - FABS(FMOD((i*P), (2*P)) - P)) );
  74. do_blocking_move_to_xy(x, y);
  75. if (i == 0) do_blocking_move_to_z(start.z);
  76. }
  77. for (int i = (objects << 1); i > -1; i--) {
  78. float const x = start.x + ( nozzle_clean_horizontal ? i * P : (A/P) * (P - FABS(FMOD((i*P), (2*P)) - P)) );
  79. float const y = start.y + (!nozzle_clean_horizontal ? i * P : (A/P) * (P - FABS(FMOD((i*P), (2*P)) - P)) );
  80. do_blocking_move_to_xy(x, y);
  81. }
  82. }
  83. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  84. // Move the nozzle to the initial point
  85. do_blocking_move_to_z(initial.z);
  86. do_blocking_move_to_xy(initial.x, initial.y);
  87. #endif // NOZZLE_CLEAN_GOBACK
  88. #endif // NOZZLE_CLEAN_FEATURE
  89. }
  90. /**
  91. * @brief Circular clean pattern
  92. * @details Apply a circular cleaning pattern
  93. *
  94. * @param start point_t defining the middle of circle
  95. * @param strokes number of strokes to execute
  96. * @param radius radius of circle
  97. */
  98. void Nozzle::circle(
  99. _UNUSED point_t const &start,
  100. _UNUSED point_t const &middle,
  101. _UNUSED uint8_t const &strokes,
  102. _UNUSED float const &radius
  103. ) {
  104. #if ENABLED(NOZZLE_CLEAN_FEATURE)
  105. if (strokes == 0) return;
  106. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  107. // Store the current coords
  108. point_t const initial = {
  109. current_position[X_AXIS],
  110. current_position[Y_AXIS],
  111. current_position[Z_AXIS],
  112. current_position[E_AXIS]
  113. };
  114. #endif // NOZZLE_CLEAN_GOBACK
  115. if (start.z <= current_position[Z_AXIS]) {
  116. // Order of movement is pretty darn important here
  117. do_blocking_move_to_xy(start.x, start.y);
  118. do_blocking_move_to_z(start.z);
  119. }
  120. else {
  121. do_blocking_move_to_z(start.z);
  122. do_blocking_move_to_xy(start.x, start.y);
  123. }
  124. float x, y;
  125. for (uint8_t s = 0; s < strokes; s++) {
  126. for (uint8_t i = 0; i < NOZZLE_CLEAN_CIRCLE_FN; i++) {
  127. x = middle.x + sin((M_2_PI / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius;
  128. y = middle.y + cos((M_2_PI / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius;
  129. do_blocking_move_to_xy(x, y);
  130. }
  131. }
  132. // Let's be safe
  133. do_blocking_move_to_xy(start.x, start.y);
  134. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  135. // Move the nozzle to the initial point
  136. if (start.z <= initial.z) {
  137. // As above order is important
  138. do_blocking_move_to_z(initial.z);
  139. do_blocking_move_to_xy(initial.x, initial.y);
  140. }
  141. else {
  142. do_blocking_move_to_xy(initial.x, initial.y);
  143. do_blocking_move_to_z(initial.z);
  144. }
  145. #endif // NOZZLE_CLEAN_GOBACK
  146. #endif // NOZZLE_CLEAN_FEATURE
  147. }
  148. /**
  149. * @brief Clean the nozzle
  150. * @details Starts the selected clean procedure pattern
  151. *
  152. * @param pattern one of the available patterns
  153. * @param argument depends on the cleaning pattern
  154. */
  155. void Nozzle::clean(
  156. _UNUSED uint8_t const &pattern,
  157. _UNUSED uint8_t const &strokes,
  158. _UNUSED float const &radius,
  159. _UNUSED uint8_t const &objects
  160. ) {
  161. #if ENABLED(NOZZLE_CLEAN_FEATURE)
  162. #if ENABLED(DELTA)
  163. if (current_position[Z_AXIS] > delta_clip_start_height)
  164. do_blocking_move_to_z(delta_clip_start_height);
  165. #endif
  166. switch (pattern) {
  167. case 1:
  168. Nozzle::zigzag(
  169. NOZZLE_CLEAN_START_POINT,
  170. NOZZLE_CLEAN_END_POINT, strokes, objects);
  171. break;
  172. case 2:
  173. Nozzle::circle(
  174. NOZZLE_CLEAN_START_POINT,
  175. NOZZLE_CLEAN_CIRCLE_MIDDLE, strokes, radius);
  176. break;
  177. default:
  178. Nozzle::stroke(
  179. NOZZLE_CLEAN_START_POINT,
  180. NOZZLE_CLEAN_END_POINT, strokes);
  181. }
  182. #endif // NOZZLE_CLEAN_FEATURE
  183. }
  184. void Nozzle::park(
  185. _UNUSED uint8_t const &z_action
  186. ) {
  187. #if ENABLED(NOZZLE_PARK_FEATURE)
  188. float const z = current_position[Z_AXIS];
  189. point_t const park = NOZZLE_PARK_POINT;
  190. switch(z_action) {
  191. case 1: // force Z-park height
  192. do_blocking_move_to_z(park.z);
  193. break;
  194. case 2: // Raise by Z-park height
  195. do_blocking_move_to_z(
  196. (z + park.z > Z_MAX_POS) ? Z_MAX_POS : z + park.z);
  197. break;
  198. default: // Raise to Z-park height if lower
  199. if (current_position[Z_AXIS] < park.z)
  200. do_blocking_move_to_z(park.z);
  201. }
  202. do_blocking_move_to_xy(park.x, park.y);
  203. #endif // NOZZLE_PARK_FEATURE
  204. }