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.

clean_nozzle.h 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 __CLEAN_NOZZLE_H__
  23. #define __CLEAN_NOZZLE_H__
  24. #include "Marlin.h"
  25. #include "point_t.h"
  26. /**
  27. * @brief CleanNozzle class
  28. *
  29. * @todo: Do not ignore the end.z value and allow XYZ movements
  30. * @todo: Currently this feature needs AUTO_BED_LEVELING_FEATURE to be active
  31. * due to the do_blocking_move_to*() functions.
  32. */
  33. class CleanNozzle {
  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. // Move to the starting point
  46. do_blocking_move_to_xy(start.x, start.y);
  47. do_blocking_move_to_z(start.z);
  48. // Start the stroke pattern
  49. for (uint8_t i = 0; i < (strokes >>1); i++) {
  50. do_blocking_move_to_xy(end.x, end.y);
  51. do_blocking_move_to_xy(start.x, start.y);
  52. }
  53. }
  54. /**
  55. * @brief Zig-zag clean pattern
  56. * @details Apply a zig-zag cleanning pattern
  57. *
  58. * @param start point_t defining the starting point
  59. * @param end point_t defining the ending point
  60. * @param triangles number of triangles to execute
  61. */
  62. static void zigzag(point_t const &start, point_t const &end, uint8_t const &triangles)
  63. __attribute__ ((optimize ("Os"))) {
  64. // Move to the starting point
  65. do_blocking_move_to_xy(start.x, start.y);
  66. do_blocking_move_to_z(start.z);
  67. // Calculate the triangle side
  68. float const a = fabs(end.x - start.x) / triangles;
  69. // Don't allow the sides (a, b) to be smaller than 5mm
  70. if (a < 5 || fabs(end.y - start.y) < 5) return;
  71. // Start the zig-zag pattern
  72. for (uint8_t i = 0; i < triangles; i++) {
  73. float const x = start.x + (a * (i + 1));
  74. do_blocking_move_to_xy(x, end.y);
  75. do_blocking_move_to_y(start.y);
  76. }
  77. }
  78. public:
  79. /**
  80. * @brief Clean the nozzle
  81. * @details Starts the selected clean procedure pattern
  82. *
  83. * @param pattern one of the available patterns
  84. * @param argument depends on the cleaning pattern
  85. */
  86. static void start(uint8_t const &pattern, uint8_t const &argument)
  87. __attribute__ ((optimize ("Os"))) {
  88. switch (pattern) {
  89. case 1:
  90. CleanNozzle::zigzag(
  91. CLEAN_NOZZLE_START_PT,
  92. CLEAN_NOZZLE_END_PT, argument);
  93. break;
  94. default:
  95. CleanNozzle::stroke(
  96. CLEAN_NOZZLE_START_PT,
  97. CLEAN_NOZZLE_END_PT, argument);
  98. }
  99. }
  100. };
  101. #endif