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.

nozzle.cpp 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. #include "../inc/MarlinConfig.h"
  23. #if EITHER(NOZZLE_CLEAN_FEATURE, NOZZLE_PARK_FEATURE)
  24. #include "nozzle.h"
  25. Nozzle nozzle;
  26. #include "../Marlin.h"
  27. #include "../module/motion.h"
  28. #include "point_t.h"
  29. #if ENABLED(NOZZLE_CLEAN_FEATURE)
  30. /**
  31. * @brief Stroke clean pattern
  32. * @details Wipes the nozzle back and forth in a linear movement
  33. *
  34. * @param start point_t defining the starting point
  35. * @param end point_t defining the ending point
  36. * @param strokes number of strokes to execute
  37. */
  38. void Nozzle::stroke(const point_t &start, const point_t &end, const uint8_t &strokes) {
  39. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  40. const float ix = current_position[X_AXIS], iy = current_position[Y_AXIS], iz = current_position[Z_AXIS];
  41. #endif
  42. // Move to the starting point
  43. #if ENABLED(NOZZLE_CLEAN_NO_Z)
  44. do_blocking_move_to_xy(start.x, start.y);
  45. #else
  46. do_blocking_move_to(start.x, start.y, start.z);
  47. #endif
  48. // Start the stroke pattern
  49. for (uint8_t i = 0; i < (strokes >> 1); i++) {
  50. do_blocking_move_to_xy(end.x, end.y);
  51. do_blocking_move_to_xy(start.x, start.y);
  52. }
  53. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  54. do_blocking_move_to(ix, iy, iz);
  55. #endif
  56. }
  57. /**
  58. * @brief Zig-zag clean pattern
  59. * @details Apply a zig-zag cleaning pattern
  60. *
  61. * @param start point_t defining the starting point
  62. * @param end point_t defining the ending point
  63. * @param strokes number of strokes to execute
  64. * @param objects number of triangles to do
  65. */
  66. void Nozzle::zigzag(const point_t &start, const point_t &end, const uint8_t &strokes, const uint8_t &objects) {
  67. const float diffx = end.x - start.x, diffy = end.y - start.y;
  68. if (!diffx || !diffy) return;
  69. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  70. const float ix = current_position[X_AXIS], iy = current_position[Y_AXIS], iz = current_position[Z_AXIS];
  71. #endif
  72. #if ENABLED(NOZZLE_CLEAN_NO_Z)
  73. do_blocking_move_to_xy(start.x, start.y);
  74. #else
  75. do_blocking_move_to(start.x, start.y, start.z);
  76. #endif
  77. const uint8_t zigs = objects << 1;
  78. const bool horiz = ABS(diffx) >= ABS(diffy); // Do a horizontal wipe?
  79. const float P = (horiz ? diffx : diffy) / zigs; // Period of each zig / zag
  80. const point_t *side;
  81. for (uint8_t j = 0; j < strokes; j++) {
  82. for (int8_t i = 0; i < zigs; i++) {
  83. side = (i & 1) ? &end : &start;
  84. if (horiz)
  85. do_blocking_move_to_xy(start.x + i * P, side->y);
  86. else
  87. do_blocking_move_to_xy(side->x, start.y + i * P);
  88. }
  89. for (int8_t i = zigs; i >= 0; i--) {
  90. side = (i & 1) ? &end : &start;
  91. if (horiz)
  92. do_blocking_move_to_xy(start.x + i * P, side->y);
  93. else
  94. do_blocking_move_to_xy(side->x, start.y + i * P);
  95. }
  96. }
  97. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  98. do_blocking_move_to(ix, iy, iz);
  99. #endif
  100. }
  101. /**
  102. * @brief Circular clean pattern
  103. * @details Apply a circular cleaning pattern
  104. *
  105. * @param start point_t defining the middle of circle
  106. * @param strokes number of strokes to execute
  107. * @param radius radius of circle
  108. */
  109. void Nozzle::circle(const point_t &start, const point_t &middle, const uint8_t &strokes, const float &radius) {
  110. if (strokes == 0) return;
  111. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  112. const float ix = current_position[X_AXIS], iy = current_position[Y_AXIS], iz = current_position[Z_AXIS];
  113. #endif
  114. #if ENABLED(NOZZLE_CLEAN_NO_Z)
  115. do_blocking_move_to_xy(start.x, start.y);
  116. #else
  117. do_blocking_move_to(start.x, start.y, start.z);
  118. #endif
  119. for (uint8_t s = 0; s < strokes; s++)
  120. for (uint8_t i = 0; i < NOZZLE_CLEAN_CIRCLE_FN; i++)
  121. do_blocking_move_to_xy(
  122. middle.x + sin((RADIANS(360) / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius,
  123. middle.y + cos((RADIANS(360) / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius
  124. );
  125. // Let's be safe
  126. do_blocking_move_to_xy(start.x, start.y);
  127. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  128. do_blocking_move_to(ix, iy, iz);
  129. #endif
  130. }
  131. /**
  132. * @brief Clean the nozzle
  133. * @details Starts the selected clean procedure pattern
  134. *
  135. * @param pattern one of the available patterns
  136. * @param argument depends on the cleaning pattern
  137. */
  138. void Nozzle::clean(const uint8_t &pattern, const uint8_t &strokes, const float &radius, const uint8_t &objects, const uint8_t cleans) {
  139. point_t start = NOZZLE_CLEAN_START_POINT;
  140. point_t end = NOZZLE_CLEAN_END_POINT;
  141. if (pattern == 2) {
  142. if (!(cleans & (_BV(X_AXIS) | _BV(Y_AXIS)))) {
  143. SERIAL_ECHOLNPGM("Warning : Clean Circle requires XY");
  144. return;
  145. }
  146. end = NOZZLE_CLEAN_CIRCLE_MIDDLE;
  147. }
  148. else {
  149. if (!TEST(cleans, X_AXIS)) start.x = end.x = current_position[X_AXIS];
  150. if (!TEST(cleans, Y_AXIS)) start.y = end.y = current_position[Y_AXIS];
  151. }
  152. if (!TEST(cleans, Z_AXIS)) start.z = end.z = current_position[Z_AXIS];
  153. switch (pattern) {
  154. case 1:
  155. zigzag(start, end, strokes, objects);
  156. break;
  157. case 2:
  158. circle(start, end, strokes, radius);
  159. break;
  160. default:
  161. stroke(start, end, strokes);
  162. }
  163. }
  164. #endif // NOZZLE_CLEAN_FEATURE
  165. #if ENABLED(NOZZLE_PARK_FEATURE)
  166. void Nozzle::park(const uint8_t z_action, const point_t &park/*=NOZZLE_PARK_POINT*/) {
  167. const float fr_xy = NOZZLE_PARK_XY_FEEDRATE,
  168. fr_z = NOZZLE_PARK_Z_FEEDRATE;
  169. switch (z_action) {
  170. case 1: // Go to Z-park height
  171. do_blocking_move_to_z(park.z, fr_z);
  172. break;
  173. case 2: // Raise by Z-park height
  174. do_blocking_move_to_z(_MIN(current_position[Z_AXIS] + park.z, Z_MAX_POS), fr_z);
  175. break;
  176. default: // Raise to at least the Z-park height
  177. do_blocking_move_to_z(_MAX(park.z, current_position[Z_AXIS]), fr_z);
  178. }
  179. do_blocking_move_to_xy(park.x, park.y, fr_xy);
  180. report_current_position();
  181. }
  182. #endif // NOZZLE_PARK_FEATURE
  183. #endif // NOZZLE_CLEAN_FEATURE || NOZZLE_PARK_FEATURE