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.h 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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. #ifndef __NOZZLE_H__
  23. #define __NOZZLE_H__
  24. #include "Marlin.h"
  25. #include "point_t.h"
  26. /**
  27. * @brief Nozzle class
  28. *
  29. * @todo: Do not ignore the end.z value and allow XYZ movements
  30. */
  31. class Nozzle {
  32. private:
  33. /**
  34. * @brief Stroke clean pattern
  35. * @details Wipes the nozzle back and forth in a linear movement
  36. *
  37. * @param start point_t defining the starting point
  38. * @param end point_t defining the ending point
  39. * @param strokes number of strokes to execute
  40. */
  41. static void stroke(
  42. __attribute__((unused)) point_t const &start,
  43. __attribute__((unused)) point_t const &end,
  44. __attribute__((unused)) uint8_t const &strokes
  45. ) __attribute__((optimize ("Os"))) {
  46. #if ENABLED(NOZZLE_CLEAN_FEATURE)
  47. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  48. // Store the current coords
  49. point_t const initial = {
  50. current_position[X_AXIS],
  51. current_position[Y_AXIS],
  52. current_position[Z_AXIS],
  53. current_position[E_AXIS]
  54. };
  55. #endif // NOZZLE_CLEAN_GOBACK
  56. // Move to the starting point
  57. do_blocking_move_to_xy(start.x, start.y);
  58. do_blocking_move_to_z(start.z);
  59. // Start the stroke pattern
  60. for (uint8_t i = 0; i < (strokes >>1); i++) {
  61. do_blocking_move_to_xy(end.x, end.y);
  62. do_blocking_move_to_xy(start.x, start.y);
  63. }
  64. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  65. // Move the nozzle to the initial point
  66. do_blocking_move_to(initial.x, initial.y, initial.z);
  67. #endif // NOZZLE_CLEAN_GOBACK
  68. #endif // NOZZLE_CLEAN_FEATURE
  69. }
  70. /**
  71. * @brief Zig-zag clean pattern
  72. * @details Apply a zig-zag cleanning pattern
  73. *
  74. * @param start point_t defining the starting point
  75. * @param end point_t defining the ending point
  76. * @param strokes number of strokes to execute
  77. * @param objects number of objects to create
  78. */
  79. static void zigzag(
  80. __attribute__((unused)) point_t const &start,
  81. __attribute__((unused)) point_t const &end,
  82. __attribute__((unused)) uint8_t const &strokes,
  83. __attribute__((unused)) uint8_t const &objects
  84. ) __attribute__((optimize ("Os"))) {
  85. #if ENABLED(NOZZLE_CLEAN_FEATURE)
  86. float A = fabs(end.y - start.y); // [twice the] Amplitude
  87. float P = fabs(end.x - start.x) / (objects << 1); // Period
  88. // Don't allow impossible triangles
  89. if (A <= 0.0f || P <= 0.0f ) return;
  90. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  91. // Store the current coords
  92. point_t const initial = {
  93. current_position[X_AXIS],
  94. current_position[Y_AXIS],
  95. current_position[Z_AXIS],
  96. current_position[E_AXIS]
  97. };
  98. #endif // NOZZLE_CLEAN_GOBACK
  99. for (uint8_t j = 0; j < strokes; j++) {
  100. for (uint8_t i = 0; i < (objects << 1); i++) {
  101. float const x = start.x + i * P;
  102. float const y = start.y + (A/P) * (P - fabs(fmod((i*P), (2*P)) - P));
  103. do_blocking_move_to_xy(x, y);
  104. if (i == 0) do_blocking_move_to_z(start.z);
  105. }
  106. for (int i = (objects << 1); i > -1; i--) {
  107. float const x = start.x + i * P;
  108. float const y = start.y + (A/P) * (P - fabs(fmod((i*P), (2*P)) - P));
  109. do_blocking_move_to_xy(x, y);
  110. }
  111. }
  112. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  113. // Move the nozzle to the initial point
  114. do_blocking_move_to_z(initial.z);
  115. do_blocking_move_to_xy(initial.x, initial.y);
  116. #endif // NOZZLE_CLEAN_GOBACK
  117. #endif // NOZZLE_CLEAN_FEATURE
  118. }
  119. public:
  120. /**
  121. * @brief Clean the nozzle
  122. * @details Starts the selected clean procedure pattern
  123. *
  124. * @param pattern one of the available patterns
  125. * @param argument depends on the cleaning pattern
  126. */
  127. static void clean(
  128. __attribute__((unused)) uint8_t const &pattern,
  129. __attribute__((unused)) uint8_t const &strokes,
  130. __attribute__((unused)) uint8_t const &objects = 0
  131. ) __attribute__((optimize ("Os"))) {
  132. #if ENABLED(NOZZLE_CLEAN_FEATURE)
  133. #if ENABLED(DELTA)
  134. if (current_position[Z_AXIS] > delta_clip_start_height)
  135. do_blocking_move_to_z(delta_clip_start_height);
  136. #endif
  137. switch (pattern) {
  138. case 1:
  139. Nozzle::zigzag(
  140. NOZZLE_CLEAN_START_POINT,
  141. NOZZLE_CLEAN_END_POINT, strokes, objects);
  142. break;
  143. default:
  144. Nozzle::stroke(
  145. NOZZLE_CLEAN_START_POINT,
  146. NOZZLE_CLEAN_END_POINT, strokes);
  147. }
  148. #endif // NOZZLE_CLEAN_FEATURE
  149. }
  150. static void park(
  151. __attribute__((unused)) uint8_t const &z_action
  152. ) __attribute__((optimize ("Os"))) {
  153. #if ENABLED(NOZZLE_PARK_FEATURE)
  154. float const z = current_position[Z_AXIS];
  155. point_t const park = NOZZLE_PARK_POINT;
  156. switch(z_action) {
  157. case 1: // force Z-park height
  158. do_blocking_move_to_z(park.z);
  159. break;
  160. case 2: // Raise by Z-park height
  161. do_blocking_move_to_z(
  162. (z + park.z > Z_MAX_POS) ? Z_MAX_POS : z + park.z);
  163. break;
  164. default: // Raise to Z-park height if lower
  165. if (current_position[Z_AXIS] < park.z)
  166. do_blocking_move_to_z(park.z);
  167. }
  168. do_blocking_move_to_xy(park.x, park.y);
  169. #endif // NOZZLE_PARK_FEATURE
  170. }
  171. };
  172. #endif