From d0e7c2c20821d2d96e3c8e18f116b55cacfe0252 Mon Sep 17 00:00:00 2001 From: FBN <62633887+fBn0523@users.noreply.github.com> Date: Fri, 16 Sep 2022 07:02:08 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20More=20automatic=20MMU2=20load?= =?UTF-8?q?=20(#24750)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/feature/mmu/mmu2.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/Marlin/src/feature/mmu/mmu2.cpp b/Marlin/src/feature/mmu/mmu2.cpp index a4718b53d9..c3bc2114b9 100644 --- a/Marlin/src/feature/mmu/mmu2.cpp +++ b/Marlin/src/feature/mmu/mmu2.cpp @@ -585,7 +585,7 @@ static void mmu2_not_responding() { command(MMU_CMD_T0 + index); manage_response(true, true); mmu_continue_loading(); - command(MMU_CMD_C0); + //command(MMU_CMD_C0); extruder = index; active_extruder = 0; @@ -653,13 +653,33 @@ static void mmu2_not_responding() { } void MMU2::mmu_continue_loading() { + // Try to load the filament a limited number of times for (uint8_t i = 0; i < MMU_LOADING_ATTEMPTS_NR; i++) { - DEBUG_ECHOLNPGM("Additional load attempt #", i); - if (FILAMENT_PRESENT()) break; + DEBUG_ECHOLNPGM("Load attempt #", i + 1); + + // Done as soon as filament is present + bool fil_present = FILAMENT_PRESENT(); + if (fil_present) break; + + // Attempt to load the filament, 1mm at a time, for 3s command(MMU_CMD_C0); + stepper.enable_extruder(); + const millis_t expire_ms = millis() + 3000; + do { + current_position.e += 1; + line_to_current_position(MMU_LOAD_FEEDRATE); + planner.synchronize(); + // When (T0 rx->ok) load is ready, but in fact it did not load + // successfully or an overload created pressure in the extruder. + // Send (C0) to load more and move E_AXIS a little to release pressure. + if ((fil_present = FILAMENT_PRESENT())) MMU2_COMMAND("A"); + } while (!fil_present && PENDING(millis(), expire_ms)); + stepper.disable_extruder(); manage_response(true, true); } - if (!FILAMENT_PRESENT()) { + + // Was the filament still missing in the last check? + if (!fil_present) { DEBUG_ECHOLNPGM("Filament never reached sensor, runout"); filament_runout(); } @@ -682,7 +702,7 @@ static void mmu2_not_responding() { command(MMU_CMD_T0 + index); manage_response(true, true); command(MMU_CMD_C0); - extruder = index; //filament change is finished + extruder = index; // Filament change is finished active_extruder = 0; stepper.enable_extruder(); SERIAL_ECHO_MSG(STR_ACTIVE_EXTRUDER, extruder);