Rewrite the logic behind the "chunking"/error count behind the PAT9125.
Basic idea: check the _direction_ of movement returned by the optical
sensor and compare it to the direction of the stepper. To avoid doing
this continuosly (and because the optical sensor doesn't necessarily
have the accuracy to track small distances), do so in chunks.
Each time a chunk doesn't match the expected direction, increase the
error count.
Several improvements were done to the previous code:
- Increase the chunk window: this ensures that a filament with
poor response returns an usable direction, while also moving the
average return values from the sensor in the middle of the 12 bits
available for maximum effectiveness.
- Since the returned values are more reliable, reduce the error count
(1.25mm*4 = ~5mm before runout detection)
- Track _both_ positive and negative movement, although only trigger
errors during extrusion (necessary due to several assumptions made
in the mmu/unloading code)
- Do not reset the counters for each block: accumulate distances
correctly, allowing detection of any block lenght.
When the error count is cleared, the cumulative deltas as well as the
segment lenght which is kept inside the stepper isr need to be reset.
Introduce a helper function fsensor_reset_err_cnt to clear all the
required variables in one place which can be used in most cases
(the only exceptions being quality measument).
Introduce a new function st_reset_fsensor to also clear the segment
lenght within the isr.
- Hide all prototypes related to PAT9125 to force all callers
to check for the proper sensor, since the handling differences
are substantial
- Remove unneeded lenght accounting from the stepper isr as as
consequence.
- Keep detailed soft failure counts for the MK3 on the "last print
failures" status screen, but fix build on variants without a PAT9125
by fixing the lcd stats function.
To maintain an accurate step count (which is required for correct
position recovery), any call to plan_set_position&co needs to be done
synchronously and from a halted state.
However, G92 E* is currently special-cased to skip the sync (likely to
avoid the associated performance cost), causing an incorrect E step
count and position to be set. This breaks absolute position recovery,
miscalculation of the LA factor and possibly other weird issues.
We rewrite the handling of G92 to always sync but still special-case the
frequent "G92 E0" for performance by using a free bit in the block flags.
To avoid a sync, we relay the request for reset first to the planner
which clears its internal state and then relays the request to the final
stepper isr.
Do not store the block e_D ratio, store directly the computed
compression factor so that we can recompute the advance steps
quickly and update them in sync with the acceleration rates.
The pressure state is already reset implicitly at the end of each block,
meaning an extruder switch will never have to reset the internal state
anyway.
We clear the internal backpressure in the following conditions:
- when switching to a non-LA block
- when quickStop is called
- when the scheduler is idling (losing pressure)
- Move direction checks out of fsensor: fsensor_counter is now
always in the same direction as e_steps
- Check the filament chunk after e_steps have been physically done,
using the real e_step count so far
Timing functions (millis, micros and delay) replaced in whole source, defined in Marlin.h.
This commit enables original implementation (SYSTEM_TIMER_2 undefined)
Verified with passed complete wizard process.