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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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_z(initial.z);
  67. do_blocking_move_to_xy(initial.x, initial.y);
  68. #endif // NOZZLE_CLEAN_GOBACK
  69. #endif // NOZZLE_CLEAN_FEATURE
  70. }
  71. /**
  72. * @brief Zig-zag clean pattern
  73. * @details Apply a zig-zag cleanning pattern
  74. *
  75. * @param start point_t defining the starting point
  76. * @param end point_t defining the ending point
  77. * @param strokes number of strokes to execute
  78. * @param objects number of objects to create
  79. */
  80. static void zigzag(
  81. __attribute__((unused)) point_t const &start,
  82. __attribute__((unused)) point_t const &end,
  83. __attribute__((unused)) uint8_t const &strokes,
  84. __attribute__((unused)) uint8_t const &objects
  85. ) __attribute__((optimize ("Os"))) {
  86. #if ENABLED(NOZZLE_CLEAN_FEATURE)
  87. float A = fabs(end.y - start.y); // [twice the] Amplitude
  88. float P = fabs(end.x - start.x) / (objects << 1); // Period
  89. // Don't allow impossible triangles
  90. if (A <= 0.0f || P <= 0.0f ) return;
  91. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  92. // Store the current coords
  93. point_t const initial = {
  94. current_position[X_AXIS],
  95. current_position[Y_AXIS],
  96. current_position[Z_AXIS],
  97. current_position[E_AXIS]
  98. };
  99. #endif // NOZZLE_CLEAN_GOBACK
  100. for (uint8_t j = 0; j < strokes; j++) {
  101. for (uint8_t i = 0; i < (objects << 1); i++) {
  102. float const x = start.x + i * P;
  103. float const y = start.y + (A/P) * (P - fabs(fmod((i*P), (2*P)) - P));
  104. do_blocking_move_to_xy(x, y);
  105. if (i == 0) do_blocking_move_to_z(start.z);
  106. }
  107. for (int i = (objects << 1); i > -1; i--) {
  108. float const x = start.x + i * P;
  109. float const y = start.y + (A/P) * (P - fabs(fmod((i*P), (2*P)) - P));
  110. do_blocking_move_to_xy(x, y);
  111. }
  112. }
  113. #if ENABLED(NOZZLE_CLEAN_GOBACK)
  114. // Move the nozzle to the initial point
  115. do_blocking_move_to_z(initial.z);
  116. do_blocking_move_to_xy(initial.x, initial.y);
  117. #endif // NOZZLE_CLEAN_GOBACK
  118. #endif // NOZZLE_CLEAN_FEATURE
  119. }
  120. public:
  121. /**
  122. * @brief Clean the nozzle
  123. * @details Starts the selected clean procedure pattern
  124. *
  125. * @param pattern one of the available patterns
  126. * @param argument depends on the cleaning pattern
  127. */
  128. static void clean(
  129. __attribute__((unused)) uint8_t const &pattern,
  130. __attribute__((unused)) uint8_t const &strokes,
  131. __attribute__((unused)) uint8_t const &objects = 0
  132. ) __attribute__((optimize ("Os"))) {
  133. #if ENABLED(NOZZLE_CLEAN_FEATURE)
  134. switch (pattern) {
  135. case 1:
  136. Nozzle::zigzag(
  137. NOZZLE_CLEAN_START_POINT,
  138. NOZZLE_CLEAN_END_POINT, strokes, objects);
  139. break;
  140. default:
  141. Nozzle::stroke(
  142. NOZZLE_CLEAN_START_POINT,
  143. NOZZLE_CLEAN_END_POINT, strokes);
  144. }
  145. #endif // NOZZLE_CLEAN_FEATURE
  146. }
  147. static void park(
  148. __attribute__((unused)) uint8_t const &z_action
  149. ) __attribute__((optimize ("Os"))) {
  150. #if ENABLED(NOZZLE_PARK_FEATURE)
  151. float const z = current_position[Z_AXIS];
  152. point_t const park = NOZZLE_PARK_POINT;
  153. switch(z_action) {
  154. case 1: // force Z-park height
  155. do_blocking_move_to_z(park.z);
  156. break;
  157. case 2: // Raise by Z-park height
  158. do_blocking_move_to_z(
  159. (z + park.z > Z_MAX_POS) ? Z_MAX_POS : z + park.z);
  160. break;
  161. default: // Raise to Z-park height if lower
  162. if (current_position[Z_AXIS] < park.z)
  163. do_blocking_move_to_z(park.z);
  164. }
  165. do_blocking_move_to_xy(park.x, park.y);
  166. #endif // NOZZLE_PARK_FEATURE
  167. }
  168. };
  169. #endif