PFW-1504 Add precision error
This fixes an issue where sometimes not all 20 pixels are rendered. It is better to render 1 too many pixels (sometimes), rather than rendering too few. Change in memory: Flash: +18 bytes SRAM: 0 bytes
This commit is contained in:
parent
f2157c6f1d
commit
9865d4a38a
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue