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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. /**
  23. * feature/pause.cpp - Pause feature support functions
  24. * This may be combined with related G-codes if features are consolidated.
  25. */
  26. #include "../inc/MarlinConfig.h"
  27. #if ENABLED(ADVANCED_PAUSE_FEATURE) || ENABLED(PARK_HEAD_ON_PAUSE)
  28. #include "../Marlin.h"
  29. #include "../gcode/gcode.h"
  30. #include "../module/motion.h"
  31. #include "../module/planner.h"
  32. #include "../module/stepper.h"
  33. #include "../module/printcounter.h"
  34. #include "../module/temperature.h"
  35. #if ENABLED(FILAMENT_RUNOUT_SENSOR)
  36. #include "../feature/runout.h"
  37. #endif
  38. #if ENABLED(ULTIPANEL)
  39. #include "../lcd/ultralcd.h"
  40. #endif
  41. #include "../libs/buzzer.h"
  42. // private:
  43. static float resume_position[XYZE];
  44. #if ENABLED(SDSUPPORT)
  45. #include "../sd/cardreader.h"
  46. static bool sd_print_paused = false;
  47. #endif
  48. #if HAS_BUZZER
  49. static void filament_change_beep(const int8_t max_beep_count, const bool init=false) {
  50. static millis_t next_buzz = 0;
  51. static int8_t runout_beep = 0;
  52. if (init) next_buzz = runout_beep = 0;
  53. const millis_t ms = millis();
  54. if (ELAPSED(ms, next_buzz)) {
  55. if (max_beep_count < 0 || runout_beep < max_beep_count + 5) { // Only beep as long as we're supposed to
  56. next_buzz = ms + ((max_beep_count < 0 || runout_beep < max_beep_count) ? 2500 : 400);
  57. BUZZ(300, 2000);
  58. runout_beep++;
  59. }
  60. }
  61. }
  62. #endif
  63. static void ensure_safe_temperature() {
  64. bool heaters_heating = true;
  65. wait_for_heatup = true; // M108 will clear this
  66. while (wait_for_heatup && heaters_heating) {
  67. idle();
  68. heaters_heating = false;
  69. HOTEND_LOOP() {
  70. if (thermalManager.degTargetHotend(e) && abs(thermalManager.degHotend(e) - thermalManager.degTargetHotend(e)) > TEMP_HYSTERESIS) {
  71. heaters_heating = true;
  72. #if ENABLED(ULTIPANEL)
  73. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_WAIT_FOR_NOZZLES_TO_HEAT);
  74. #endif
  75. break;
  76. }
  77. }
  78. }
  79. }
  80. // public:
  81. bool move_away_flag = false;
  82. #if IS_KINEMATIC
  83. #define RUNPLAN(RATE_MM_S) planner.buffer_line_kinematic(destination, RATE_MM_S, active_extruder)
  84. #else
  85. #define RUNPLAN(RATE_MM_S) line_to_destination(RATE_MM_S)
  86. #endif
  87. bool pause_print(const float &retract, const float &z_lift, const float &x_pos, const float &y_pos,
  88. const float &unload_length/*=0*/ , const int8_t max_beep_count/*=0*/, const bool show_lcd/*=false*/
  89. ) {
  90. if (move_away_flag) return false; // already paused
  91. if (!DEBUGGING(DRYRUN) && (unload_length != 0 || retract != 0)) {
  92. #if ENABLED(PREVENT_COLD_EXTRUSION)
  93. if (!thermalManager.allow_cold_extrude &&
  94. thermalManager.degTargetHotend(active_extruder) < thermalManager.extrude_min_temp) {
  95. SERIAL_ERROR_START();
  96. SERIAL_ERRORLNPGM(MSG_TOO_COLD_FOR_M600);
  97. return false;
  98. }
  99. #endif
  100. ensure_safe_temperature(); // wait for extruder to heat up before unloading
  101. }
  102. // Indicate that the printer is paused
  103. move_away_flag = true;
  104. // Pause the print job and timer
  105. #if ENABLED(SDSUPPORT)
  106. if (IS_SD_PRINTING) {
  107. card.pauseSDPrint();
  108. sd_print_paused = true;
  109. }
  110. #endif
  111. print_job_timer.pause();
  112. // Show initial message and wait for synchronize steppers
  113. if (show_lcd) {
  114. #if ENABLED(ULTIPANEL)
  115. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INIT);
  116. #endif
  117. }
  118. // Save current position
  119. stepper.synchronize();
  120. COPY(resume_position, current_position);
  121. if (retract) {
  122. // Initial retract before move to filament change position
  123. set_destination_to_current();
  124. destination[E_AXIS] += retract;
  125. RUNPLAN(PAUSE_PARK_RETRACT_FEEDRATE);
  126. stepper.synchronize();
  127. }
  128. // Lift Z axis
  129. if (z_lift > 0)
  130. do_blocking_move_to_z(current_position[Z_AXIS] + z_lift, PAUSE_PARK_Z_FEEDRATE);
  131. // Move XY axes to filament exchange position
  132. do_blocking_move_to_xy(x_pos, y_pos, PAUSE_PARK_XY_FEEDRATE);
  133. if (unload_length != 0) {
  134. if (show_lcd) {
  135. #if ENABLED(ULTIPANEL)
  136. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_UNLOAD);
  137. idle();
  138. #endif
  139. }
  140. // Unload filament
  141. set_destination_to_current();
  142. destination[E_AXIS] += unload_length;
  143. RUNPLAN(FILAMENT_CHANGE_UNLOAD_FEEDRATE);
  144. stepper.synchronize();
  145. }
  146. if (show_lcd) {
  147. #if ENABLED(ULTIPANEL)
  148. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INSERT);
  149. #endif
  150. }
  151. #if HAS_BUZZER
  152. filament_change_beep(max_beep_count, true);
  153. #endif
  154. idle();
  155. // Disable extruders steppers for manual filament changing (only on boards that have separate ENABLE_PINS)
  156. #if E0_ENABLE_PIN != X_ENABLE_PIN && E1_ENABLE_PIN != Y_ENABLE_PIN
  157. disable_e_steppers();
  158. safe_delay(100);
  159. #endif
  160. // Start the heater idle timers
  161. const millis_t nozzle_timeout = (millis_t)(PAUSE_PARK_NOZZLE_TIMEOUT) * 1000UL;
  162. HOTEND_LOOP()
  163. thermalManager.start_heater_idle_timer(e, nozzle_timeout);
  164. return true;
  165. }
  166. void wait_for_filament_reload(const int8_t max_beep_count/*=0*/) {
  167. bool nozzle_timed_out = false;
  168. // Wait for filament insert by user and press button
  169. KEEPALIVE_STATE(PAUSED_FOR_USER);
  170. wait_for_user = true; // LCD click or M108 will clear this
  171. while (wait_for_user) {
  172. #if HAS_BUZZER
  173. filament_change_beep(max_beep_count);
  174. #endif
  175. // If the nozzle has timed out, wait for the user to press the button to re-heat the nozzle, then
  176. // re-heat the nozzle, re-show the insert screen, restart the idle timers, and start over
  177. if (!nozzle_timed_out)
  178. HOTEND_LOOP()
  179. nozzle_timed_out |= thermalManager.is_heater_idle(e);
  180. if (nozzle_timed_out) {
  181. #if ENABLED(ULTIPANEL)
  182. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_CLICK_TO_HEAT_NOZZLE);
  183. #endif
  184. // Wait for LCD click or M108
  185. while (wait_for_user) idle(true);
  186. // Re-enable the heaters if they timed out
  187. HOTEND_LOOP() thermalManager.reset_heater_idle_timer(e);
  188. // Wait for the heaters to reach the target temperatures
  189. ensure_safe_temperature();
  190. #if ENABLED(ULTIPANEL)
  191. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INSERT);
  192. #endif
  193. // Start the heater idle timers
  194. const millis_t nozzle_timeout = (millis_t)(PAUSE_PARK_NOZZLE_TIMEOUT) * 1000UL;
  195. HOTEND_LOOP()
  196. thermalManager.start_heater_idle_timer(e, nozzle_timeout);
  197. wait_for_user = true; /* Wait for user to load filament */
  198. nozzle_timed_out = false;
  199. #if HAS_BUZZER
  200. filament_change_beep(max_beep_count, true);
  201. #endif
  202. }
  203. idle(true);
  204. }
  205. KEEPALIVE_STATE(IN_HANDLER);
  206. }
  207. void resume_print(const float &load_length/*=0*/, const float &initial_extrude_length/*=0*/, const int8_t max_beep_count/*=0*/) {
  208. bool nozzle_timed_out = false;
  209. if (!move_away_flag) return;
  210. // Re-enable the heaters if they timed out
  211. HOTEND_LOOP() {
  212. nozzle_timed_out |= thermalManager.is_heater_idle(e);
  213. thermalManager.reset_heater_idle_timer(e);
  214. }
  215. if (nozzle_timed_out) ensure_safe_temperature();
  216. #if HAS_BUZZER
  217. filament_change_beep(max_beep_count, true);
  218. #endif
  219. set_destination_to_current();
  220. if (load_length != 0) {
  221. #if ENABLED(ULTIPANEL)
  222. // Show "insert filament"
  223. if (nozzle_timed_out)
  224. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INSERT);
  225. #endif
  226. KEEPALIVE_STATE(PAUSED_FOR_USER);
  227. wait_for_user = true; // LCD click or M108 will clear this
  228. while (wait_for_user && nozzle_timed_out) {
  229. #if HAS_BUZZER
  230. filament_change_beep(max_beep_count);
  231. #endif
  232. idle(true);
  233. }
  234. KEEPALIVE_STATE(IN_HANDLER);
  235. #if ENABLED(ULTIPANEL)
  236. // Show "load" message
  237. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_LOAD);
  238. #endif
  239. // Load filament
  240. destination[E_AXIS] += load_length;
  241. RUNPLAN(FILAMENT_CHANGE_LOAD_FEEDRATE);
  242. stepper.synchronize();
  243. }
  244. #if ENABLED(ULTIPANEL) && ADVANCED_PAUSE_EXTRUDE_LENGTH > 0
  245. float extrude_length = initial_extrude_length;
  246. do {
  247. if (extrude_length > 0) {
  248. // "Wait for filament extrude"
  249. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_EXTRUDE);
  250. // Extrude filament to get into hotend
  251. destination[E_AXIS] += extrude_length;
  252. RUNPLAN(ADVANCED_PAUSE_EXTRUDE_FEEDRATE);
  253. stepper.synchronize();
  254. }
  255. // Show "Extrude More" / "Resume" menu and wait for reply
  256. KEEPALIVE_STATE(PAUSED_FOR_USER);
  257. wait_for_user = false;
  258. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_OPTION);
  259. while (advanced_pause_menu_response == ADVANCED_PAUSE_RESPONSE_WAIT_FOR) idle(true);
  260. KEEPALIVE_STATE(IN_HANDLER);
  261. extrude_length = ADVANCED_PAUSE_EXTRUDE_LENGTH;
  262. // Keep looping if "Extrude More" was selected
  263. } while (advanced_pause_menu_response == ADVANCED_PAUSE_RESPONSE_EXTRUDE_MORE);
  264. #endif
  265. #if ENABLED(ULTIPANEL)
  266. // "Wait for print to resume"
  267. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_RESUME);
  268. #endif
  269. // Set extruder to saved position
  270. destination[E_AXIS] = current_position[E_AXIS] = resume_position[E_AXIS];
  271. planner.set_e_position_mm(current_position[E_AXIS]);
  272. // Move XY to starting position, then Z
  273. do_blocking_move_to_xy(resume_position[X_AXIS], resume_position[Y_AXIS], PAUSE_PARK_XY_FEEDRATE);
  274. do_blocking_move_to_z(resume_position[Z_AXIS], PAUSE_PARK_Z_FEEDRATE);
  275. #if ENABLED(FILAMENT_RUNOUT_SENSOR)
  276. filament_ran_out = false;
  277. #endif
  278. #if ENABLED(ULTIPANEL)
  279. // Show status screen
  280. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_STATUS);
  281. #endif
  282. #if ENABLED(SDSUPPORT)
  283. if (sd_print_paused) {
  284. card.startFileprint();
  285. sd_print_paused = false;
  286. }
  287. #endif
  288. move_away_flag = false;
  289. }
  290. #endif // ADVANCED_PAUSE_FEATURE || PARK_HEAD_ON_PAUSE