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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. #include "../Marlin.h"
  26. #include "../module/motion.h"
  27. #include "point_t.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 point_t defining the starting point
  34. * @param end point_t defining the ending point
  35. * @param strokes number of strokes to execute
  36. */
  37. void Nozzle::stroke(const point_t &start, const point_t &end, const uint8_t &strokes) {
  38. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  39. const float ix = current_position[X_AXIS], iy = current_position[Y_AXIS], iz = current_position[Z_AXIS];
  40. #endif
  41. // Move to the starting point
  42. do_blocking_move_to(start.x, start.y, start.z);
  43. // Start the stroke pattern
  44. for (uint8_t i = 0; i < (strokes >> 1); i++) {
  45. do_blocking_move_to_xy(end.x, end.y);
  46. do_blocking_move_to_xy(start.x, start.y);
  47. }
  48. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  49. do_blocking_move_to(ix, iy, iz);
  50. #endif
  51. }
  52. /**
  53. * @brief Zig-zag clean pattern
  54. * @details Apply a zig-zag cleaning pattern
  55. *
  56. * @param start point_t defining the starting point
  57. * @param end point_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 point_t &start, const point_t &end, const uint8_t &strokes, const uint8_t &objects) {
  62. const float diffx = end.x - start.x, diffy = end.y - start.y;
  63. if (!diffx || !diffy) return;
  64. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  65. const float ix = current_position[X_AXIS], iy = current_position[Y_AXIS], iz = current_position[Z_AXIS];
  66. #endif
  67. do_blocking_move_to(start.x, start.y, start.z);
  68. const uint8_t zigs = objects << 1;
  69. const bool horiz = ABS(diffx) >= ABS(diffy); // Do a horizontal wipe?
  70. const float P = (horiz ? diffx : diffy) / zigs; // Period of each zig / zag
  71. const point_t *side;
  72. for (uint8_t j = 0; j < strokes; j++) {
  73. for (int8_t i = 0; i < zigs; i++) {
  74. side = (i & 1) ? &end : &start;
  75. if (horiz)
  76. do_blocking_move_to_xy(start.x + i * P, side->y);
  77. else
  78. do_blocking_move_to_xy(side->x, start.y + i * P);
  79. }
  80. for (int8_t i = zigs; i >= 0; i--) {
  81. side = (i & 1) ? &end : &start;
  82. if (horiz)
  83. do_blocking_move_to_xy(start.x + i * P, side->y);
  84. else
  85. do_blocking_move_to_xy(side->x, start.y + i * P);
  86. }
  87. }
  88. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  89. do_blocking_move_to(ix, iy, iz);
  90. #endif
  91. }
  92. /**
  93. * @brief Circular clean pattern
  94. * @details Apply a circular cleaning pattern
  95. *
  96. * @param start point_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 point_t &start, const point_t &middle, const uint8_t &strokes, const float &radius) {
  101. if (strokes == 0) return;
  102. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  103. const float ix = current_position[X_AXIS], iy = current_position[Y_AXIS], iz = current_position[Z_AXIS];
  104. #endif
  105. do_blocking_move_to(start.x, start.y, start.z);
  106. for (uint8_t s = 0; s < strokes; s++)
  107. for (uint8_t i = 0; i < NOZZLE_CLEAN_CIRCLE_FN; i++)
  108. do_blocking_move_to_xy(
  109. middle.x + sin((RADIANS(360) / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius,
  110. middle.y + cos((RADIANS(360) / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius
  111. );
  112. // Let's be safe
  113. do_blocking_move_to_xy(start.x, start.y);
  114. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  115. do_blocking_move_to(ix, iy, iz);
  116. #endif
  117. }
  118. /**
  119. * @brief Clean the nozzle
  120. * @details Starts the selected clean procedure pattern
  121. *
  122. * @param pattern one of the available patterns
  123. * @param argument depends on the cleaning pattern
  124. */
  125. void Nozzle::clean(const uint8_t &pattern, const uint8_t &strokes, const float &radius, const uint8_t &objects/*=0*/) {
  126. switch (pattern) {
  127. case 1:
  128. zigzag(NOZZLE_CLEAN_START_POINT, NOZZLE_CLEAN_END_POINT, strokes, objects);
  129. break;
  130. case 2:
  131. circle(NOZZLE_CLEAN_START_POINT, NOZZLE_CLEAN_CIRCLE_MIDDLE, strokes, radius);
  132. break;
  133. default:
  134. stroke(NOZZLE_CLEAN_START_POINT, NOZZLE_CLEAN_END_POINT, strokes);
  135. }
  136. }
  137. #endif // NOZZLE_CLEAN_FEATURE
  138. #if ENABLED(NOZZLE_PARK_FEATURE)
  139. void Nozzle::park(const uint8_t z_action, const point_t &park /*= NOZZLE_PARK_POINT*/) {
  140. const float fr_xy = NOZZLE_PARK_XY_FEEDRATE;
  141. const float fr_z = NOZZLE_PARK_Z_FEEDRATE;
  142. switch (z_action) {
  143. case 1: // Go to Z-park height
  144. do_blocking_move_to_z(park.z, fr_z);
  145. break;
  146. case 2: // Raise by Z-park height
  147. do_blocking_move_to_z(MIN(current_position[Z_AXIS] + park.z, Z_MAX_POS), fr_z);
  148. break;
  149. default: // Raise to at least the Z-park height
  150. do_blocking_move_to_z(MAX(park.z, current_position[Z_AXIS]), fr_z);
  151. }
  152. do_blocking_move_to_xy(park.x, park.y, fr_xy);
  153. report_current_position();
  154. }
  155. #endif // NOZZLE_PARK_FEATURE
  156. #endif // NOZZLE_CLEAN_FEATURE || NOZZLE_PARK_FEATURE