My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

pause.cpp 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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)
  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(FWRETRACT)
  36. #include "../feature/fwretract.h"
  37. #endif
  38. #if ENABLED(FILAMENT_RUNOUT_SENSOR)
  39. #include "../feature/runout.h"
  40. #endif
  41. #if ENABLED(ULTIPANEL)
  42. #include "../lcd/ultralcd.h"
  43. #endif
  44. #include "../libs/buzzer.h"
  45. #include "../libs/nozzle.h"
  46. #include "pause.h"
  47. // private:
  48. static float resume_position[XYZE];
  49. AdvancedPauseMenuResponse advanced_pause_menu_response;
  50. float filament_change_unload_length[EXTRUDERS],
  51. filament_change_load_length[EXTRUDERS];
  52. #if ENABLED(SDSUPPORT)
  53. #include "../sd/cardreader.h"
  54. #endif
  55. #if HAS_BUZZER
  56. static void filament_change_beep(const int8_t max_beep_count, const bool init=false) {
  57. static millis_t next_buzz = 0;
  58. static int8_t runout_beep = 0;
  59. if (init) next_buzz = runout_beep = 0;
  60. const millis_t ms = millis();
  61. if (ELAPSED(ms, next_buzz)) {
  62. if (max_beep_count < 0 || runout_beep < max_beep_count + 5) { // Only beep as long as we're supposed to
  63. next_buzz = ms + ((max_beep_count < 0 || runout_beep < max_beep_count) ? 1000 : 500);
  64. BUZZ(50, 880 - (runout_beep & 1) * 220);
  65. runout_beep++;
  66. }
  67. }
  68. }
  69. #endif
  70. /**
  71. * Ensure a safe temperature for extrusion
  72. *
  73. * - Fail if the TARGET temperature is too low
  74. * - Display LCD placard with temperature status
  75. * - Return when heating is done or aborted
  76. *
  77. * Returns 'true' if heating was completed, 'false' for abort
  78. */
  79. static bool ensure_safe_temperature(const AdvancedPauseMode mode=ADVANCED_PAUSE_MODE_PAUSE_PRINT) {
  80. #if ENABLED(PREVENT_COLD_EXTRUSION)
  81. if (!DEBUGGING(DRYRUN) && thermalManager.targetTooColdToExtrude(active_extruder)) {
  82. SERIAL_ERROR_START();
  83. SERIAL_ERRORLNPGM(MSG_HOTEND_TOO_COLD);
  84. return false;
  85. }
  86. #endif
  87. #if ENABLED(ULTIPANEL)
  88. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_WAIT_FOR_NOZZLES_TO_HEAT, mode);
  89. #else
  90. UNUSED(mode);
  91. #endif
  92. wait_for_heatup = true; // M108 will clear this
  93. while (wait_for_heatup && thermalManager.wait_for_heating(active_extruder)) idle();
  94. const bool status = wait_for_heatup;
  95. wait_for_heatup = false;
  96. return status;
  97. }
  98. static void do_pause_e_move(const float &length, const float &fr) {
  99. set_destination_from_current();
  100. destination[E_AXIS] += length / planner.e_factor[active_extruder];
  101. planner.buffer_line_kinematic(destination, fr, active_extruder);
  102. stepper.synchronize();
  103. set_current_from_destination();
  104. }
  105. /**
  106. * Load filament into the hotend
  107. *
  108. * - Fail if the a safe temperature was not reached
  109. * - If pausing for confirmation, wait for a click or M108
  110. * - Show "wait for load" placard
  111. * - Load and purge filament
  112. * - Show "Purge more" / "Continue" menu
  113. * - Return when "Continue" is selected
  114. *
  115. * Returns 'true' if load was completed, 'false' for abort
  116. */
  117. bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_length/*=0*/, const float &purge_length/*=0*/, const int8_t max_beep_count/*=0*/,
  118. const bool show_lcd/*=false*/, const bool pause_for_user/*=false*/,
  119. const AdvancedPauseMode mode/*=ADVANCED_PAUSE_MODE_PAUSE_PRINT*/
  120. ) {
  121. #if DISABLED(ULTIPANEL)
  122. UNUSED(show_lcd);
  123. #endif
  124. if (!ensure_safe_temperature(mode)) {
  125. #if ENABLED(ULTIPANEL)
  126. if (show_lcd) // Show status screen
  127. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_STATUS);
  128. #endif
  129. return false;
  130. }
  131. if (pause_for_user) {
  132. #if ENABLED(ULTIPANEL)
  133. if (show_lcd) // Show "insert filament"
  134. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INSERT, mode);
  135. #endif
  136. SERIAL_ECHO_START();
  137. SERIAL_ECHOLNPGM(MSG_FILAMENT_CHANGE_INSERT);
  138. #if HAS_BUZZER
  139. filament_change_beep(max_beep_count, true);
  140. #else
  141. UNUSED(max_beep_count);
  142. #endif
  143. KEEPALIVE_STATE(PAUSED_FOR_USER);
  144. wait_for_user = true; // LCD click or M108 will clear this
  145. while (wait_for_user) {
  146. #if HAS_BUZZER
  147. filament_change_beep(max_beep_count);
  148. #endif
  149. idle(true);
  150. }
  151. KEEPALIVE_STATE(IN_HANDLER);
  152. }
  153. #if ENABLED(ULTIPANEL)
  154. if (show_lcd) // Show "wait for load" message
  155. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_LOAD, mode);
  156. #endif
  157. // Slow Load filament
  158. if (slow_load_length) do_pause_e_move(slow_load_length, FILAMENT_CHANGE_SLOW_LOAD_FEEDRATE);
  159. // Fast Load Filament
  160. if (fast_load_length) {
  161. #if FILAMENT_CHANGE_FAST_LOAD_ACCEL > 0
  162. const float saved_acceleration = planner.retract_acceleration;
  163. planner.retract_acceleration = FILAMENT_CHANGE_FAST_LOAD_ACCEL;
  164. #endif
  165. do_pause_e_move(fast_load_length, FILAMENT_CHANGE_FAST_LOAD_FEEDRATE);
  166. #if FILAMENT_CHANGE_FAST_LOAD_ACCEL > 0
  167. planner.retract_acceleration = saved_acceleration;
  168. #endif
  169. }
  170. #if ENABLED(ADVANCED_PAUSE_CONTINUOUS_PURGE)
  171. #if ENABLED(ULTIPANEL)
  172. if (show_lcd)
  173. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_CONTINUOUS_PURGE);
  174. #endif
  175. wait_for_user = true;
  176. for (float purge_count = purge_length; purge_count > 0 && wait_for_user; --purge_count)
  177. do_pause_e_move(1, ADVANCED_PAUSE_PURGE_FEEDRATE);
  178. wait_for_user = false;
  179. #else
  180. do {
  181. if (purge_length > 0) {
  182. // "Wait for filament purge"
  183. #if ENABLED(ULTIPANEL)
  184. if (show_lcd)
  185. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_PURGE, mode);
  186. #endif
  187. // Extrude filament to get into hotend
  188. do_pause_e_move(purge_length, ADVANCED_PAUSE_PURGE_FEEDRATE);
  189. }
  190. // Show "Purge More" / "Resume" menu and wait for reply
  191. #if ENABLED(ULTIPANEL)
  192. if (show_lcd) {
  193. KEEPALIVE_STATE(PAUSED_FOR_USER);
  194. wait_for_user = false;
  195. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_OPTION, mode);
  196. while (advanced_pause_menu_response == ADVANCED_PAUSE_RESPONSE_WAIT_FOR) idle(true);
  197. KEEPALIVE_STATE(IN_HANDLER);
  198. }
  199. #endif
  200. // Keep looping if "Purge More" was selected
  201. } while (
  202. #if ENABLED(ULTIPANEL)
  203. show_lcd && advanced_pause_menu_response == ADVANCED_PAUSE_RESPONSE_EXTRUDE_MORE
  204. #else
  205. 0
  206. #endif
  207. );
  208. #endif
  209. return true;
  210. }
  211. /**
  212. * Unload filament from the hotend
  213. *
  214. * - Fail if the a safe temperature was not reached
  215. * - Show "wait for unload" placard
  216. * - Retract, pause, then unload filament
  217. * - Disable E stepper (on most machines)
  218. *
  219. * Returns 'true' if unload was completed, 'false' for abort
  220. */
  221. bool unload_filament(const float &unload_length, const bool show_lcd/*=false*/,
  222. const AdvancedPauseMode mode/*=ADVANCED_PAUSE_MODE_PAUSE_PRINT*/
  223. ) {
  224. if (!ensure_safe_temperature(mode)) {
  225. #if ENABLED(ULTIPANEL)
  226. if (show_lcd) // Show status screen
  227. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_STATUS);
  228. #endif
  229. return false;
  230. }
  231. #if DISABLED(ULTIPANEL)
  232. UNUSED(show_lcd);
  233. #else
  234. if (show_lcd)
  235. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_UNLOAD, mode);
  236. #endif
  237. // Retract filament
  238. do_pause_e_move(-FILAMENT_UNLOAD_RETRACT_LENGTH, PAUSE_PARK_RETRACT_FEEDRATE);
  239. // Wait for filament to cool
  240. safe_delay(FILAMENT_UNLOAD_DELAY);
  241. // Quickly purge
  242. do_pause_e_move(FILAMENT_UNLOAD_RETRACT_LENGTH + FILAMENT_UNLOAD_PURGE_LENGTH, planner.max_feedrate_mm_s[E_AXIS]);
  243. // Unload filament
  244. #if FILAMENT_CHANGE_UNLOAD_ACCEL > 0
  245. const float saved_acceleration = planner.retract_acceleration;
  246. planner.retract_acceleration = FILAMENT_CHANGE_UNLOAD_ACCEL;
  247. #endif
  248. do_pause_e_move(unload_length, FILAMENT_CHANGE_UNLOAD_FEEDRATE);
  249. #if FILAMENT_CHANGE_FAST_LOAD_ACCEL > 0
  250. planner.retract_acceleration = saved_acceleration;
  251. #endif
  252. // Disable extruders steppers for manual filament changing (only on boards that have separate ENABLE_PINS)
  253. #if E0_ENABLE_PIN != X_ENABLE_PIN && E1_ENABLE_PIN != Y_ENABLE_PIN
  254. disable_e_stepper(active_extruder);
  255. safe_delay(100);
  256. #endif
  257. return true;
  258. }
  259. // public:
  260. /**
  261. * Pause procedure
  262. *
  263. * - Abort if already paused
  264. * - Send host action for pause, if configured
  265. * - Abort if TARGET temperature is too low
  266. * - Display "wait for start of filament change" (if a length was specified)
  267. * - Initial retract, if current temperature is hot enough
  268. * - Park the nozzle at the given position
  269. * - Call unload_filament (if a length was specified)
  270. *
  271. * Returns 'true' if pause was completed, 'false' for abort
  272. */
  273. uint8_t did_pause_print = 0;
  274. bool pause_print(const float &retract, const point_t &park_point, const float &unload_length/*=0*/, const bool show_lcd/*=false*/) {
  275. if (did_pause_print) return false; // already paused
  276. #ifdef ACTION_ON_PAUSE
  277. SERIAL_ECHOLNPGM("//action:" ACTION_ON_PAUSE);
  278. #endif
  279. #if ENABLED(ULTIPANEL)
  280. if (show_lcd) // Show initial message
  281. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INIT);
  282. #endif
  283. if (!DEBUGGING(DRYRUN) && unload_length && thermalManager.targetTooColdToExtrude(active_extruder)) {
  284. SERIAL_ERROR_START();
  285. SERIAL_ERRORLNPGM(MSG_HOTEND_TOO_COLD);
  286. #if ENABLED(ULTIPANEL)
  287. if (show_lcd) { // Show status screen
  288. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_STATUS);
  289. LCD_MESSAGEPGM(MSG_M600_TOO_COLD);
  290. }
  291. #endif
  292. return false; // unable to reach safe temperature
  293. }
  294. // Indicate that the printer is paused
  295. ++did_pause_print;
  296. // Pause the print job and timer
  297. #if ENABLED(SDSUPPORT)
  298. if (card.sdprinting) {
  299. card.pauseSDPrint();
  300. ++did_pause_print; // Indicate SD pause also
  301. }
  302. #endif
  303. print_job_timer.pause();
  304. // Wait for synchronize steppers
  305. stepper.synchronize();
  306. // Save current position
  307. COPY(resume_position, current_position);
  308. // Initial retract before move to filament change position
  309. if (retract && thermalManager.hotEnoughToExtrude(active_extruder))
  310. do_pause_e_move(retract, PAUSE_PARK_RETRACT_FEEDRATE);
  311. #if ENABLED(NO_MOTION_BEFORE_HOMING)
  312. if (!axis_unhomed_error())
  313. #endif
  314. // Park the nozzle by moving up by z_lift and then moving to (x_pos, y_pos)
  315. Nozzle::park(2, park_point);
  316. // Unload the filament
  317. if (unload_length)
  318. unload_filament(unload_length, show_lcd);
  319. return true;
  320. }
  321. /**
  322. * - Show "Insert filament and press button to continue"
  323. * - Wait for a click before returning
  324. * - Heaters can time out, reheated before accepting a click
  325. *
  326. * Used by M125 and M600
  327. */
  328. void wait_for_filament_reload(const int8_t max_beep_count/*=0*/) {
  329. bool nozzle_timed_out = false;
  330. #if ENABLED(ULTIPANEL)
  331. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INSERT);
  332. #endif
  333. SERIAL_ECHO_START();
  334. SERIAL_ERRORLNPGM(MSG_FILAMENT_CHANGE_INSERT);
  335. #if HAS_BUZZER
  336. filament_change_beep(max_beep_count, true);
  337. #endif
  338. // Start the heater idle timers
  339. const millis_t nozzle_timeout = (millis_t)(PAUSE_PARK_NOZZLE_TIMEOUT) * 1000UL;
  340. HOTEND_LOOP()
  341. thermalManager.start_heater_idle_timer(e, nozzle_timeout);
  342. // Wait for filament insert by user and press button
  343. KEEPALIVE_STATE(PAUSED_FOR_USER);
  344. wait_for_user = true; // LCD click or M108 will clear this
  345. while (wait_for_user) {
  346. #if HAS_BUZZER
  347. filament_change_beep(max_beep_count);
  348. #endif
  349. // If the nozzle has timed out, wait for the user to press the button to re-heat the nozzle, then
  350. // re-heat the nozzle, re-show the insert screen, restart the idle timers, and start over
  351. if (!nozzle_timed_out)
  352. HOTEND_LOOP()
  353. nozzle_timed_out |= thermalManager.is_heater_idle(e);
  354. if (nozzle_timed_out) {
  355. #if ENABLED(ULTIPANEL)
  356. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_CLICK_TO_HEAT_NOZZLE);
  357. #endif
  358. SERIAL_ECHO_START();
  359. #if ENABLED(ULTIPANEL) && ENABLED(EMERGENCY_PARSER)
  360. SERIAL_ERRORLNPGM(MSG_FILAMENT_CHANGE_HEAT);
  361. #elif ENABLED(EMERGENCY_PARSER)
  362. SERIAL_ERRORLNPGM(MSG_FILAMENT_CHANGE_HEAT_M108);
  363. #else
  364. SERIAL_ERRORLNPGM(MSG_FILAMENT_CHANGE_HEAT_LCD);
  365. #endif
  366. // Wait for LCD click or M108
  367. while (wait_for_user) idle(true);
  368. // Re-enable the heaters if they timed out
  369. HOTEND_LOOP() thermalManager.reset_heater_idle_timer(e);
  370. // Wait for the heaters to reach the target temperatures
  371. ensure_safe_temperature();
  372. #if ENABLED(ULTIPANEL)
  373. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INSERT);
  374. #endif
  375. SERIAL_ECHO_START();
  376. #if ENABLED(ULTIPANEL) && ENABLED(EMERGENCY_PARSER)
  377. SERIAL_ERRORLNPGM(MSG_FILAMENT_CHANGE_INSERT);
  378. #elif ENABLED(EMERGENCY_PARSER)
  379. SERIAL_ERRORLNPGM(MSG_FILAMENT_CHANGE_INSERT_M108);
  380. #else
  381. SERIAL_ERRORLNPGM(MSG_FILAMENT_CHANGE_INSERT_LCD);
  382. #endif
  383. // Start the heater idle timers
  384. const millis_t nozzle_timeout = (millis_t)(PAUSE_PARK_NOZZLE_TIMEOUT) * 1000UL;
  385. HOTEND_LOOP()
  386. thermalManager.start_heater_idle_timer(e, nozzle_timeout);
  387. wait_for_user = true; // Wait for user to load filament
  388. nozzle_timed_out = false;
  389. #if HAS_BUZZER
  390. filament_change_beep(max_beep_count, true);
  391. #endif
  392. }
  393. idle(true);
  394. }
  395. KEEPALIVE_STATE(IN_HANDLER);
  396. }
  397. /**
  398. * Resume or Start print procedure
  399. *
  400. * - Abort if not paused
  401. * - Reset heater idle timers
  402. * - Load filament if specified, but only if:
  403. * - a nozzle timed out, or
  404. * - the nozzle is already heated.
  405. * - Display "wait for print to resume"
  406. * - Re-prime the nozzle...
  407. * - FWRETRACT: Recover/prime from the prior G10.
  408. * - !FWRETRACT: Retract by resume_position[E], if negative.
  409. * Not sure how this logic comes into use.
  410. * - Move the nozzle back to resume_position
  411. * - Sync the planner E to resume_position[E]
  412. * - Send host action for resume, if configured
  413. * - Resume the current SD print job, if any
  414. */
  415. void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_length/*=0*/, const float &purge_length/*=ADVANCED_PAUSE_PURGE_LENGTH*/, const int8_t max_beep_count/*=0*/) {
  416. if (!did_pause_print) return;
  417. // Re-enable the heaters if they timed out
  418. bool nozzle_timed_out = false;
  419. HOTEND_LOOP() {
  420. nozzle_timed_out |= thermalManager.is_heater_idle(e);
  421. thermalManager.reset_heater_idle_timer(e);
  422. }
  423. if (nozzle_timed_out || thermalManager.hotEnoughToExtrude(active_extruder)) {
  424. // Load the new filament
  425. load_filament(slow_load_length, fast_load_length, purge_length, max_beep_count, true, nozzle_timed_out);
  426. }
  427. #if ENABLED(ULTIPANEL)
  428. // "Wait for print to resume"
  429. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_RESUME);
  430. #endif
  431. // Intelligent resuming
  432. #if ENABLED(FWRETRACT)
  433. // If retracted before goto pause
  434. if (fwretract.retracted[active_extruder])
  435. do_pause_e_move(-fwretract.retract_length, fwretract.retract_feedrate_mm_s);
  436. #endif
  437. // If resume_position is negative
  438. if (resume_position[E_AXIS] < 0) do_pause_e_move(resume_position[E_AXIS], PAUSE_PARK_RETRACT_FEEDRATE);
  439. // Move XY to starting position, then Z
  440. do_blocking_move_to_xy(resume_position[X_AXIS], resume_position[Y_AXIS], NOZZLE_PARK_XY_FEEDRATE);
  441. // Set Z_AXIS to saved position
  442. do_blocking_move_to_z(resume_position[Z_AXIS], NOZZLE_PARK_Z_FEEDRATE);
  443. // Now all extrusion positions are resumed and ready to be confirmed
  444. // Set extruder to saved position
  445. planner.set_e_position_mm((destination[E_AXIS] = current_position[E_AXIS] = resume_position[E_AXIS]));
  446. #if ENABLED(FILAMENT_RUNOUT_SENSOR)
  447. runout.reset();
  448. #endif
  449. #if ENABLED(ULTIPANEL)
  450. // Show status screen
  451. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_STATUS);
  452. #endif
  453. #ifdef ACTION_ON_RESUME
  454. SERIAL_ECHOLNPGM("//action:" ACTION_ON_RESUME);
  455. #endif
  456. --did_pause_print;
  457. #if ENABLED(SDSUPPORT)
  458. if (did_pause_print) {
  459. card.startFileprint();
  460. --did_pause_print;
  461. }
  462. #endif
  463. }
  464. #endif // ADVANCED_PAUSE_FEATURE