My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

pause.cpp 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. #include "../libs/nozzle.h"
  43. // private:
  44. static float resume_position[XYZE];
  45. #if ENABLED(SDSUPPORT)
  46. #include "../sd/cardreader.h"
  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. void do_pause_e_move(const float &length, const float fr) {
  81. current_position[E_AXIS] += length / planner.e_factor[active_extruder];
  82. set_destination_from_current();
  83. #if IS_KINEMATIC
  84. planner.buffer_line_kinematic(destination, fr, active_extruder);
  85. #else
  86. buffer_line_to_destination(fr);
  87. #endif
  88. stepper.synchronize();
  89. }
  90. // public:
  91. uint8_t did_pause_print = 0;
  92. bool pause_print(const float &retract, const point_t &park_point, const float &unload_length/*=0*/,
  93. const int8_t max_beep_count/*=0*/, const bool show_lcd/*=false*/
  94. ) {
  95. if (did_pause_print) return false; // already paused
  96. #ifdef ACTION_ON_PAUSE
  97. SERIAL_ECHOLNPGM("//action:" ACTION_ON_PAUSE);
  98. #endif
  99. if (!DEBUGGING(DRYRUN) && unload_length != 0) {
  100. #if ENABLED(PREVENT_COLD_EXTRUSION)
  101. if (!thermalManager.allow_cold_extrude &&
  102. thermalManager.degTargetHotend(active_extruder) < thermalManager.extrude_min_temp) {
  103. SERIAL_ERROR_START();
  104. SERIAL_ERRORLNPGM(MSG_TOO_COLD_FOR_M600);
  105. return false;
  106. }
  107. #endif
  108. ensure_safe_temperature(); // wait for extruder to heat up before unloading
  109. }
  110. // Indicate that the printer is paused
  111. ++did_pause_print;
  112. // Pause the print job and timer
  113. #if ENABLED(SDSUPPORT)
  114. if (IS_SD_PRINTING) {
  115. card.pauseSDPrint();
  116. ++did_pause_print;
  117. }
  118. #endif
  119. print_job_timer.pause();
  120. // Show initial message and wait for synchronize steppers
  121. if (show_lcd) {
  122. #if ENABLED(ULTIPANEL)
  123. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INIT);
  124. #endif
  125. }
  126. stepper.synchronize();
  127. COPY(resume_position, current_position); // Save current position for later
  128. // Initial retract before move to filament change position
  129. if (retract && !thermalManager.tooColdToExtrude(active_extruder))
  130. do_pause_e_move(retract, PAUSE_PARK_RETRACT_FEEDRATE);
  131. // Park the nozzle by moving up by z_lift and then moving to (x_pos, y_pos)
  132. Nozzle::park(2, park_point);
  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. do_pause_e_move(unload_length, FILAMENT_CHANGE_UNLOAD_FEEDRATE);
  142. }
  143. if (show_lcd) {
  144. #if ENABLED(ULTIPANEL)
  145. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INSERT);
  146. #endif
  147. }
  148. #if HAS_BUZZER
  149. filament_change_beep(max_beep_count, true);
  150. #endif
  151. idle();
  152. // Disable extruders steppers for manual filament changing (only on boards that have separate ENABLE_PINS)
  153. #if E0_ENABLE_PIN != X_ENABLE_PIN && E1_ENABLE_PIN != Y_ENABLE_PIN
  154. disable_e_steppers();
  155. safe_delay(100);
  156. #endif
  157. // Start the heater idle timers
  158. const millis_t nozzle_timeout = (millis_t)(PAUSE_PARK_NOZZLE_TIMEOUT) * 1000UL;
  159. HOTEND_LOOP()
  160. thermalManager.start_heater_idle_timer(e, nozzle_timeout);
  161. return true;
  162. }
  163. void wait_for_filament_reload(const int8_t max_beep_count/*=0*/) {
  164. bool nozzle_timed_out = false;
  165. // Wait for filament insert by user and press button
  166. KEEPALIVE_STATE(PAUSED_FOR_USER);
  167. wait_for_user = true; // LCD click or M108 will clear this
  168. while (wait_for_user) {
  169. #if HAS_BUZZER
  170. filament_change_beep(max_beep_count);
  171. #endif
  172. // If the nozzle has timed out, wait for the user to press the button to re-heat the nozzle, then
  173. // re-heat the nozzle, re-show the insert screen, restart the idle timers, and start over
  174. if (!nozzle_timed_out)
  175. HOTEND_LOOP()
  176. nozzle_timed_out |= thermalManager.is_heater_idle(e);
  177. if (nozzle_timed_out) {
  178. #if ENABLED(ULTIPANEL)
  179. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_CLICK_TO_HEAT_NOZZLE);
  180. #endif
  181. // Wait for LCD click or M108
  182. while (wait_for_user) idle(true);
  183. // Re-enable the heaters if they timed out
  184. HOTEND_LOOP() thermalManager.reset_heater_idle_timer(e);
  185. // Wait for the heaters to reach the target temperatures
  186. ensure_safe_temperature();
  187. #if ENABLED(ULTIPANEL)
  188. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INSERT);
  189. #endif
  190. // Start the heater idle timers
  191. const millis_t nozzle_timeout = (millis_t)(PAUSE_PARK_NOZZLE_TIMEOUT) * 1000UL;
  192. HOTEND_LOOP()
  193. thermalManager.start_heater_idle_timer(e, nozzle_timeout);
  194. wait_for_user = true; /* Wait for user to load filament */
  195. nozzle_timed_out = false;
  196. #if HAS_BUZZER
  197. filament_change_beep(max_beep_count, true);
  198. #endif
  199. }
  200. idle(true);
  201. }
  202. KEEPALIVE_STATE(IN_HANDLER);
  203. }
  204. void resume_print(const float &load_length/*=0*/, const float &initial_extrude_length/*=0*/, const int8_t max_beep_count/*=0*/) {
  205. bool nozzle_timed_out = false;
  206. if (!did_pause_print) return;
  207. // Re-enable the heaters if they timed out
  208. HOTEND_LOOP() {
  209. nozzle_timed_out |= thermalManager.is_heater_idle(e);
  210. thermalManager.reset_heater_idle_timer(e);
  211. }
  212. if (nozzle_timed_out) ensure_safe_temperature();
  213. #if HAS_BUZZER
  214. filament_change_beep(max_beep_count, true);
  215. #endif
  216. if (load_length != 0) {
  217. #if ENABLED(ULTIPANEL)
  218. // Show "insert filament"
  219. if (nozzle_timed_out)
  220. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INSERT);
  221. #endif
  222. KEEPALIVE_STATE(PAUSED_FOR_USER);
  223. wait_for_user = true; // LCD click or M108 will clear this
  224. while (wait_for_user && nozzle_timed_out) {
  225. #if HAS_BUZZER
  226. filament_change_beep(max_beep_count);
  227. #endif
  228. idle(true);
  229. }
  230. KEEPALIVE_STATE(IN_HANDLER);
  231. #if ENABLED(ULTIPANEL)
  232. // Show "load" message
  233. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_LOAD);
  234. #endif
  235. // Load filament
  236. do_pause_e_move(load_length, FILAMENT_CHANGE_LOAD_FEEDRATE);
  237. }
  238. #if ENABLED(ULTIPANEL) && ADVANCED_PAUSE_EXTRUDE_LENGTH > 0
  239. if (!thermalManager.tooColdToExtrude(active_extruder)) {
  240. float extrude_length = initial_extrude_length;
  241. do {
  242. if (extrude_length > 0) {
  243. // "Wait for filament extrude"
  244. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_EXTRUDE);
  245. // Extrude filament to get into hotend
  246. do_pause_e_move(extrude_length, ADVANCED_PAUSE_EXTRUDE_FEEDRATE);
  247. }
  248. // Show "Extrude More" / "Resume" menu and wait for reply
  249. KEEPALIVE_STATE(PAUSED_FOR_USER);
  250. wait_for_user = false;
  251. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_OPTION);
  252. while (advanced_pause_menu_response == ADVANCED_PAUSE_RESPONSE_WAIT_FOR) idle(true);
  253. KEEPALIVE_STATE(IN_HANDLER);
  254. extrude_length = ADVANCED_PAUSE_EXTRUDE_LENGTH;
  255. // Keep looping if "Extrude More" was selected
  256. } while (advanced_pause_menu_response == ADVANCED_PAUSE_RESPONSE_EXTRUDE_MORE);
  257. }
  258. #endif
  259. #if ENABLED(ULTIPANEL)
  260. // "Wait for print to resume"
  261. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_RESUME);
  262. #endif
  263. // Set extruder to saved position
  264. planner.set_e_position_mm((current_position[E_AXIS] = resume_position[E_AXIS]));
  265. // Move XY to starting position, then Z
  266. do_blocking_move_to_xy(resume_position[X_AXIS], resume_position[Y_AXIS], NOZZLE_PARK_XY_FEEDRATE);
  267. do_blocking_move_to_z(resume_position[Z_AXIS], NOZZLE_PARK_Z_FEEDRATE);
  268. #if ENABLED(FILAMENT_RUNOUT_SENSOR)
  269. filament_ran_out = false;
  270. #endif
  271. #if ENABLED(ULTIPANEL)
  272. // Show pause status screen
  273. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_STATUS);
  274. #endif
  275. #ifdef ACTION_ON_RESUME
  276. SERIAL_ECHOLNPGM("//action:" ACTION_ON_RESUME);
  277. #endif
  278. --did_pause_print;
  279. #if ENABLED(SDSUPPORT)
  280. if (did_pause_print) {
  281. card.startFileprint();
  282. --did_pause_print;
  283. }
  284. #endif
  285. }
  286. #endif // ADVANCED_PAUSE_FEATURE || PARK_HEAD_ON_PAUSE