Before PR #2591 LA was automatically capped during cruising or
deceleration. However we now rely on reaching the current pressure state
exactly to stop. When dual/quad stepping inside the eISR we might incur
in oscillating behavior if we do not handle it correctly.
This might be the cause behind #2757
This now changes e_step_loops to be a phase-local variable, so we now
reset it each phase too (instead of per-segment).
When switching to a new trapezoid step with the right pressure, cancel
any pending eISR right away.
Similarly do not schedule another eISR if the pressure will be reached
by the end of the eISR.
This was done in the past to preserve the current LA_phase. This is not
needed anymore, since it will be reset at each trapezoid step when LA
is re-initialized.
There used to be a single stage where an extruder reversal could occur,
but since PR #2591 reversals can happen up to two times per trapezoid.
Reset LA_phase when ADV_INIT is set, since it is re-inizialized only
when needed a few lines afterward. This improves performance by avoiding
to check the phase continuosly to the end of the trapezoid.
Likewise, always set ADV_INIT during the first cruising step, also to
force a LA_phase reset.
Move la10c_reset into finishAndDisableStepper, which is called in both
via lcd_print_stop() and indirectly via M84, saving some space.
M84 is checked-for to determine a complete file, so it's a superior
candidate to G80 (which some people avoid due to MBL issues).
Handle uniformly compression & decompression at any stage of the
trapezoid.
Compared to before, this now enables LA compression also in the cruising
step (handling the converse of a chained wipe), as well as decompression
during acceleration.
Both of these can happen as a result of jerk moves, but are incredibly
rare. This is mostly needed to allow rapid decompression directly at the
acceleration step during travels between a retraction&deretraction.
We also check for the pressure level in a single place, reducing code
size as well as disabling LA earlier when not needed for the rest of the
block.
LA assumes all the nozzle pressure is released at the end of each
extrusion, which makes calculating the required pressure advance during
travels and retracts not normally necessary.
This is not always true in our planner, since the E axis is explicitly
ignored when not in use, but also due to E-jerk allowing a non-linear
jump in speed. And since the compression factor is currently tied by XYZ
axes and not independently calculated, this can result in a wrong
estimation of final pressure in several conditions.
To avoid overburdening the planner, change the underlying assumptions
about backpressure:
1) Pressure is no longer lost when LA is disabled: if a retract is
followed by an unretract of the same length, the pressure will be likely
maintained entirely. This also holds true during travels, as long as the
retract length can overcome all the backpressure (which is the case in
all but the most noodly materials)
2) Pressure is released as soon as possible during travels: we now
enable LA also during travels, but under the sole condition of undoing
excess pressure.
We do that by checking for backpressure at the start of any segment
without an acceleration phase that doesn't have any E-steps (a result
which can happen due to the above). If pressure is not nominal, we run
the extruder in reverse at maximum jerk as long as the segment allows
us, since proper acceleration would be prohibitive at this stage. As the
pressure difference resulting by the above is still _very_ low, any wipe
or short travel will be able to equalize the nozzle pressure *before*
extrusion is resumed, avoiding ooze.
In the current code we initialize the LA state on-demand already at the
right step, which makes keeping track of the tick position no longer
necessary.
Make the advance ISR almost stateless by removing the last vestiges of
the original implementation and introduce a single target pressure. This
will be needed later in order to trigger the LA isr inside the cruising
phase.
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