diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index ad6a28ba1..7e604f738 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -245,7 +245,17 @@ bool MMU2::VerifyFilamentEnteredPTFE() { // If the filament sensor reads 0 at any moment, then report FAILURE const float delta_mm = MMU2_CHECK_FILAMENT_PRESENCE_EXTRUSION_LENGTH - logic.ExtraLoadDistance(); - const float length_step_mm = 2 * (delta_mm) / (LCD_WIDTH + 1); + + // Allow some error in each pixel step. It is better to render too many pixels + // rather than too few. Note that 0.25mm is not enough but 0.50mm seems to work + // 0.50mm gives 1 digit precision + static constexpr float float_precision = 0.50; // mm + + // The total length is twice delta_mm. Divide that length by number of pixels + // available to get length per pixel. + // Finally subtract the step length by the precision set above to allow some + // error introduced by CPU execution delays + const float length_step_mm = ( (2 * delta_mm) / LCD_WIDTH) - float_precision; float last_position = stepper_get_machine_position_E_mm(); TryLoadUnloadProgressbarInit(); @@ -274,8 +284,10 @@ bool MMU2::VerifyFilamentEnteredPTFE() { fsensorStateLCD |= (WhereIsFilament() == FilamentState::NOT_PRESENT); fsensorState |= fsensorStateLCD; // No need to do the above comparison twice, just bitwise OR - if ((fabs(stepper_get_machine_position_E_mm() - last_position)) > length_step_mm) { - last_position = stepper_get_machine_position_E_mm(); // Reset + // Fetch the position once, to ensure last_position will be correct + float current_mm = stepper_get_machine_position_E_mm(); + if (fabs(current_mm - last_position) > length_step_mm) { + last_position = current_mm; if (pixel > (LCD_WIDTH - 1)) pixel = LCD_WIDTH - 1; TryLoadUnloadProgressbar(pixel++, fsensorStateLCD); fsensorStateLCD = 0; // Clear temporary bit