My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

nozzle.cpp 5.8KB

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