My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

nozzle.cpp 7.5KB

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