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 7.7KB

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