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 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. * @todo: Currently this feature needs HAS_BED_PROBE to be active
  31. * due to the do_blocking_move_to*() functions.
  32. */
  33. class Nozzle {
  34. private:
  35. /**
  36. * @brief Stroke clean pattern
  37. * @details Wipes the nozzle back and forth in a linear movement
  38. *
  39. * @param start point_t defining the starting point
  40. * @param end point_t defining the ending point
  41. * @param strokes number of strokes to execute
  42. */
  43. static void stroke(point_t const &start, point_t const &end, uint8_t const &strokes)
  44. __attribute__ ((optimize ("Os"))) {
  45. #if ENABLED(NOZZLE_CLEAN_PARK)
  46. // Store the current coords
  47. point_t const initial = {
  48. current_position[X_AXIS],
  49. current_position[Y_AXIS],
  50. current_position[Z_AXIS],
  51. current_position[E_AXIS]
  52. };
  53. #endif
  54. // Move to the starting point
  55. do_blocking_move_to_xy(start.x, start.y);
  56. do_blocking_move_to_z(start.z);
  57. // Start the stroke pattern
  58. for (uint8_t i = 0; i < (strokes >>1); i++) {
  59. do_blocking_move_to_xy(end.x, end.y);
  60. do_blocking_move_to_xy(start.x, start.y);
  61. }
  62. #if ENABLED(NOZZLE_CLEAN_PARK)
  63. // Move the nozzle to the initial point
  64. do_blocking_move_to_z(initial.z);
  65. do_blocking_move_to_xy(initial.x, initial.y);
  66. #endif
  67. }
  68. /**
  69. * @brief Zig-zag clean pattern
  70. * @details Apply a zig-zag cleanning pattern
  71. *
  72. * @param start point_t defining the starting point
  73. * @param end point_t defining the ending point
  74. * @param strokes number of strokes to execute
  75. * @param objects number of objects to create
  76. */
  77. static void zigzag(point_t const &start,
  78. point_t const &end, uint8_t const &strokes, uint8_t const &objects)
  79. __attribute__ ((optimize ("Os"))) {
  80. float A = fabs(end.y - start.y); // [twice the] Amplitude
  81. float P = fabs(end.x - start.x) / (objects << 1); // Period
  82. // Don't allow impossible triangles
  83. if (A <= 0.0f || P <= 0.0f ) return;
  84. #if ENABLED(NOZZLE_CLEAN_PARK)
  85. // Store the current coords
  86. point_t const initial = {
  87. current_position[X_AXIS],
  88. current_position[Y_AXIS],
  89. current_position[Z_AXIS],
  90. current_position[E_AXIS]
  91. };
  92. #endif
  93. for (uint8_t j = 0; j < strokes; j++) {
  94. for (uint8_t i = 0; i < (objects << 1); i++) {
  95. float const x = start.x + i * P;
  96. float const y = start.y + (A/P) * (P - fabs(fmod((i*P), (2*P)) - P));
  97. do_blocking_move_to_xy(x, y);
  98. if (i == 0) do_blocking_move_to_z(start.z);
  99. }
  100. for (int i = (objects << 1); i > -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. }
  105. }
  106. #if ENABLED(NOZZLE_CLEAN_PARK)
  107. // Move the nozzle to the initial point
  108. do_blocking_move_to_z(initial.z);
  109. do_blocking_move_to_xy(initial.x, initial.y);
  110. #endif
  111. }
  112. public:
  113. /**
  114. * @brief Clean the nozzle
  115. * @details Starts the selected clean procedure pattern
  116. *
  117. * @param pattern one of the available patterns
  118. * @param argument depends on the cleaning pattern
  119. */
  120. static void clean(uint8_t const &pattern,
  121. uint8_t const &strokes, uint8_t const &objects = 0)
  122. __attribute__ ((optimize ("Os"))) {
  123. switch (pattern) {
  124. case 1:
  125. Nozzle::zigzag(
  126. NOZZLE_CLEAN_START_PT,
  127. NOZZLE_CLEAN_END_PT, strokes, objects);
  128. break;
  129. default:
  130. Nozzle::stroke(
  131. NOZZLE_CLEAN_START_PT,
  132. NOZZLE_CLEAN_END_PT, strokes);
  133. }
  134. }
  135. };
  136. #endif