MMU2 S Mode spins the BMG gears during C0 (#19429)

This commit is contained in:
Trocololo 2020-09-26 03:28:01 +02:00 committed by GitHub
parent 5cf2cf2be9
commit 88d7f4d7be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,6 +54,8 @@ MMU2 mmu2;
#define MMU_CMD_TIMEOUT 45000UL // 45s timeout for mmu commands (except P0) #define MMU_CMD_TIMEOUT 45000UL // 45s timeout for mmu commands (except P0)
#define MMU_P0_TIMEOUT 3000UL // Timeout for P0 command: 3seconds #define MMU_P0_TIMEOUT 3000UL // Timeout for P0 command: 3seconds
#define MMU2_COMMAND(S) tx_str_P(PSTR(S "\n"))
#if ENABLED(MMU_EXTRUDER_SENSOR) #if ENABLED(MMU_EXTRUDER_SENSOR)
uint8_t mmu_idl_sens = 0; uint8_t mmu_idl_sens = 0;
static bool mmu_loading_flag = false; static bool mmu_loading_flag = false;
@ -152,7 +154,7 @@ void MMU2::reset() {
safe_delay(20); safe_delay(20);
WRITE(MMU2_RST_PIN, HIGH); WRITE(MMU2_RST_PIN, HIGH);
#else #else
tx_str_P(PSTR("X0\n")); // Send soft reset MMU2_COMMAND("X0"); // Send soft reset
#endif #endif
} }
@ -175,9 +177,7 @@ void MMU2::mmu_loop() {
DEBUG_ECHOLNPGM("MMU => 'start'"); DEBUG_ECHOLNPGM("MMU => 'start'");
DEBUG_ECHOLNPGM("MMU <= 'S1'"); DEBUG_ECHOLNPGM("MMU <= 'S1'");
// send "read version" request MMU2_COMMAND("S1"); // Read Version
tx_str_P(PSTR("S1\n"));
state = -2; state = -2;
} }
else if (millis() > 3000000) { else if (millis() > 3000000) {
@ -192,7 +192,7 @@ void MMU2::mmu_loop() {
DEBUG_ECHOLNPAIR("MMU => ", version, "\nMMU <= 'S2'"); DEBUG_ECHOLNPAIR("MMU => ", version, "\nMMU <= 'S2'");
tx_str_P(PSTR("S2\n")); // read build number MMU2_COMMAND("S2"); // Read Build Number
state = -3; state = -3;
} }
break; break;
@ -208,13 +208,13 @@ void MMU2::mmu_loop() {
#if ENABLED(MMU2_MODE_12V) #if ENABLED(MMU2_MODE_12V)
DEBUG_ECHOLNPGM("MMU <= 'M1'"); DEBUG_ECHOLNPGM("MMU <= 'M1'");
tx_str_P(PSTR("M1\n")); // switch to stealth mode MMU2_COMMAND("M1"); // Stealth Mode
state = -5; state = -5;
#else #else
DEBUG_ECHOLNPGM("MMU <= 'P0'"); DEBUG_ECHOLNPGM("MMU <= 'P0'");
tx_str_P(PSTR("P0\n")); // read finda MMU2_COMMAND("P0"); // Read FINDA
state = -4; state = -4;
#endif #endif
} }
@ -228,7 +228,7 @@ void MMU2::mmu_loop() {
DEBUG_ECHOLNPGM("MMU <= 'P0'"); DEBUG_ECHOLNPGM("MMU <= 'P0'");
tx_str_P(PSTR("P0\n")); // read finda MMU2_COMMAND("P0"); // Read FINDA
state = -4; state = -4;
} }
break; break;
@ -266,14 +266,14 @@ void MMU2::mmu_loop() {
else if (cmd == MMU_CMD_C0) { else if (cmd == MMU_CMD_C0) {
// continue loading // continue loading
DEBUG_ECHOLNPGM("MMU <= 'C0'"); DEBUG_ECHOLNPGM("MMU <= 'C0'");
tx_str_P(PSTR("C0\n")); MMU2_COMMAND("C0");
state = 3; // wait for response state = 3; // wait for response
} }
else if (cmd == MMU_CMD_U0) { else if (cmd == MMU_CMD_U0) {
// unload current // unload current
DEBUG_ECHOLNPGM("MMU <= 'U0'"); DEBUG_ECHOLNPGM("MMU <= 'U0'");
tx_str_P(PSTR("U0\n")); MMU2_COMMAND("U0");
state = 3; // wait for response state = 3; // wait for response
} }
else if (WITHIN(cmd, MMU_CMD_E0, MMU_CMD_E4)) { else if (WITHIN(cmd, MMU_CMD_E0, MMU_CMD_E4)) {
@ -286,7 +286,7 @@ void MMU2::mmu_loop() {
else if (cmd == MMU_CMD_R0) { else if (cmd == MMU_CMD_R0) {
// recover after eject // recover after eject
DEBUG_ECHOLNPGM("MMU <= 'R0'"); DEBUG_ECHOLNPGM("MMU <= 'R0'");
tx_str_P(PSTR("R0\n")); MMU2_COMMAND("R0");
state = 3; // wait for response state = 3; // wait for response
} }
else if (WITHIN(cmd, MMU_CMD_F0, MMU_CMD_F4)) { else if (WITHIN(cmd, MMU_CMD_F0, MMU_CMD_F4)) {
@ -303,8 +303,7 @@ void MMU2::mmu_loop() {
cmd = MMU_CMD_NONE; cmd = MMU_CMD_NONE;
} }
else if (ELAPSED(millis(), prev_P0_request + 300)) { else if (ELAPSED(millis(), prev_P0_request + 300)) {
// read FINDA MMU2_COMMAND("P0"); // Read FINDA
tx_str_P(PSTR("P0\n"));
state = 2; // wait for response state = 2; // wait for response
} }
@ -332,20 +331,33 @@ void MMU2::mmu_loop() {
#if ENABLED(MMU_EXTRUDER_SENSOR) #if ENABLED(MMU_EXTRUDER_SENSOR)
if (mmu_idl_sens) { if (mmu_idl_sens) {
if (FILAMENT_PRESENT() && mmu_loading_flag) { if (FILAMENT_PRESENT() && mmu_loading_flag) {
DEBUG_ECHOLNPGM("MMU <= 'A'\n"); DEBUG_ECHOLNPGM("MMU <= 'A'");
tx_str_P(PSTR("A\n")); // send 'abort' request MMU2_COMMAND("A"); // send 'abort' request
mmu_idl_sens = 0; mmu_idl_sens = 0;
DEBUG_ECHOLNPGM("MMU IDLER_SENSOR = 0 - ABORT\n"); DEBUG_ECHOLNPGM("MMU IDLER_SENSOR = 0 - ABORT");
} }
} }
#endif #endif
if (rx_ok()) { if (rx_ok()) {
// response to C0 mmu command in PRUSA_MMU2_S_MODE
bool can_reset = true;
if (ENABLED(PRUSA_MMU2_S_MODE) && last_cmd == MMU_CMD_C0) {
if (!mmu2s_triggered) {
can_reset = false;
// MMU ok received but filament sensor not triggered, retrying...
DEBUG_ECHOLNPGM("MMU => 'ok' (filament not present in gears)");
DEBUG_ECHOLNPGM("MMU <= 'C0' (keep trying)");
MMU2_COMMAND("C0");
}
}
if (can_reset) {
DEBUG_ECHOLNPGM("MMU => 'ok'"); DEBUG_ECHOLNPGM("MMU => 'ok'");
ready = true; ready = true;
state = 1; state = 1;
last_cmd = MMU_CMD_NONE; last_cmd = MMU_CMD_NONE;
} }
}
else if (ELAPSED(millis(), prev_request + MMU_CMD_TIMEOUT)) { else if (ELAPSED(millis(), prev_request + MMU_CMD_TIMEOUT)) {
// resend request after timeout // resend request after timeout
if (last_cmd) { if (last_cmd) {
@ -862,10 +874,19 @@ void MMU2::filament_runout() {
void MMU2::check_filament() { void MMU2::check_filament() {
const bool present = FILAMENT_PRESENT(); const bool present = FILAMENT_PRESENT();
if (cmd == MMU_CMD_NONE && last_cmd == MMU_CMD_C0) {
if (present && !mmu2s_triggered) { if (present && !mmu2s_triggered) {
DEBUG_ECHOLNPGM("MMU <= 'A'"); DEBUG_ECHOLNPGM("MMU <= 'A'");
tx_str_P(PSTR("A\n")); tx_str_P(PSTR("A\n"));
} }
// Slowly spin the extruder during C0
else {
while (planner.movesplanned() < 3) {
current_position.e += 0.25;
line_to_current_position(MMM_TO_MMS(120));
}
}
}
mmu2s_triggered = present; mmu2s_triggered = present;
} }