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.5KB

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