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

nozzle.cpp 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. __attribute__((unused)) point_t const &start,
  14. __attribute__((unused)) point_t const &end,
  15. __attribute__((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. __attribute__((unused)) point_t const &start,
  52. __attribute__((unused)) point_t const &end,
  53. __attribute__((unused)) uint8_t const &strokes,
  54. __attribute__((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. __attribute__((unused)) point_t const &start,
  100. __attribute__((unused)) point_t const &middle,
  101. __attribute__((unused)) uint8_t const &strokes,
  102. __attribute__((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. } else {
  120. do_blocking_move_to_z(start.z);
  121. do_blocking_move_to_xy(start.x, start.y);
  122. }
  123. float x, y;
  124. for (uint8_t s = 0; s < strokes; s++) {
  125. for (uint8_t i = 0; i < NOZZLE_CLEAN_CIRCLE_FN; i++) {
  126. x = middle.x + sin((M_2_PI / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius;
  127. y = middle.y + cos((M_2_PI / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius;
  128. do_blocking_move_to_xy(x, y);
  129. }
  130. }
  131. // Let's be safe
  132. do_blocking_move_to_xy(start.x, start.y);
  133. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  134. // Move the nozzle to the initial point
  135. if (start.z <= initial.z) {
  136. // As above order is important
  137. do_blocking_move_to_z(initial.z);
  138. do_blocking_move_to_xy(initial.x, initial.y);
  139. } else {
  140. do_blocking_move_to_xy(initial.x, initial.y);
  141. do_blocking_move_to_z(initial.z);
  142. }
  143. #endif // NOZZLE_CLEAN_GOBACK
  144. #endif // NOZZLE_CLEAN_FEATURE
  145. }
  146. /**
  147. * @brief Clean the nozzle
  148. * @details Starts the selected clean procedure pattern
  149. *
  150. * @param pattern one of the available patterns
  151. * @param argument depends on the cleaning pattern
  152. */
  153. void Nozzle::clean(
  154. __attribute__((unused)) uint8_t const &pattern,
  155. __attribute__((unused)) uint8_t const &strokes,
  156. __attribute__((unused)) float const &radius,
  157. __attribute__((unused)) uint8_t const &objects
  158. ) {
  159. #if ENABLED(NOZZLE_CLEAN_FEATURE)
  160. #if ENABLED(DELTA)
  161. if (current_position[Z_AXIS] > delta_clip_start_height)
  162. do_blocking_move_to_z(delta_clip_start_height);
  163. #endif
  164. switch (pattern) {
  165. case 1:
  166. Nozzle::zigzag(
  167. NOZZLE_CLEAN_START_POINT,
  168. NOZZLE_CLEAN_END_POINT, strokes, objects);
  169. break;
  170. case 2:
  171. Nozzle::circle(
  172. NOZZLE_CLEAN_START_POINT,
  173. NOZZLE_CLEAN_CIRCLE_MIDDLE, strokes, radius);
  174. break;
  175. default:
  176. Nozzle::stroke(
  177. NOZZLE_CLEAN_START_POINT,
  178. NOZZLE_CLEAN_END_POINT, strokes);
  179. }
  180. #endif // NOZZLE_CLEAN_FEATURE
  181. }
  182. void Nozzle::park(
  183. __attribute__((unused)) uint8_t const &z_action
  184. ) {
  185. #if ENABLED(NOZZLE_PARK_FEATURE)
  186. float const z = current_position[Z_AXIS];
  187. point_t const park = NOZZLE_PARK_POINT;
  188. switch(z_action) {
  189. case 1: // force Z-park height
  190. do_blocking_move_to_z(park.z);
  191. break;
  192. case 2: // Raise by Z-park height
  193. do_blocking_move_to_z(
  194. (z + park.z > Z_MAX_POS) ? Z_MAX_POS : z + park.z);
  195. break;
  196. default: // Raise to Z-park height if lower
  197. if (current_position[Z_AXIS] < park.z)
  198. do_blocking_move_to_z(park.z);
  199. }
  200. do_blocking_move_to_xy(park.x, park.y);
  201. #endif // NOZZLE_PARK_FEATURE
  202. }