Commit Graph

134 Commits

Author SHA1 Message Date
Yuri D'Elia
feafc5e5ab Alternative schedule for LA ticks
Remove most of the original complexity from advance_spread.

Instead of accumulating time to be scheduled, plan ahead of time each
eISR tick using the next main interval + an accumulator (eISR_Err),
which keeps everything much simpler.

The distribution of the advance ticks is now using the real LA
frequency, which leaves a bit more time between the last LA tick and
the main stepper isr.

We take advantage of the accumulator to force a LA tick right after the
first main tick, which removes a +/- 1 scheduling error at higher step
rates.

When decompressing, we force 2 steps instead, so that the direction
reversal happens immediately (first tick zeros esteps, second inverts
the sign), removing another +/- 1 error at higher step rates.
2020-07-29 19:14:48 +02:00
Yuri D'Elia
c54474f2db Guard against planning/numerical errors in short segments
Turns out for high-res curved models the numerical error and the
SLOWDOWN handling in the planner can cause enough variance in the
calculated pressure to trigger LA to continuosly, making matters worse.

Clamp LA again, but only during extrusion, so that the runaway error is
limited by the current segment length.
2020-07-16 18:54:00 +02:00
Yuri D'Elia
fb5f09da6d Fix incorrect precedence for retraction phase
The logic was inverted, causing the fastest isr to always retract
instead of counter-balance the acceleration properly.
2020-07-16 18:53:53 +02:00
Yuri D'Elia
c08f37da96 Use nominal rate for phase calculations
The local interval calculated by advance_spread() might oscillate too
much in narrow intervals.
2020-07-12 17:15:47 +02:00
Yuri D'Elia
f1efce7e52 Handle LA termination with double/quad stepping properly
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).
2020-06-23 16:51:54 +02:00
Yuri D'Elia
50a09824fd Avoid scheduling useless eISR ticks
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.
2020-06-23 15:24:16 +02:00
Yuri D'Elia
173aa2deba Fix bogus timer check preventing fast LA steps to be scheduled
Simplify and fix the broken timer check when scheduling advance ticks.
This dates back to the original LA15 PR, an old bug...
2020-06-22 00:54:50 +02:00
Yuri D'Elia
51a539608c Reset LA_phase at each trapezoid stage
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.
2020-06-22 00:19:47 +02:00
Yuri D'Elia
5082f2a36e Move reset LA state from G80 to M84
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).
2020-04-29 22:51:23 +02:00
Yuri D'Elia
ae4abdf11f Unify LA for all trapezoid steps
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.
2020-04-12 01:28:34 +02:00
Yuri D'Elia
02a36c498c Release excess pressure within cruising blocks
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.
2020-04-09 00:46:57 +02:00
Yuri D'Elia
919386c957 Remove several globals by using a single target pressure
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.
2020-04-09 00:46:57 +02:00
Yuri D'Elia
9ec0ac9c64 Always reset e_steps between blocks
If e_steps are scheduled, but not ticked, they're just lost.
Only carry over the pressure state.
2020-04-09 00:46:57 +02:00
Yuri D'Elia
e84f82a675 Rewrite filament sensor PAT9125 error handling
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.
2020-02-06 14:37:46 +01:00
Yuri D'Elia
5c4235b886 Correctly reset the PAT9125 filament counters
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.
2020-02-05 16:21:27 +01:00
Yuri D'Elia
6fbd632c84 Isolate all PAT9125-specific code, fix build on !MK3 variants
- 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.
2020-02-05 16:20:12 +01:00
Yuri D'Elia
bab756699f Fix incorrect usage of plan_set_e_position() in G92 E*
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.
2020-01-14 20:24:14 +01:00
Yuri D'Elia
5122f79a39 Merge remote-tracking branch 'upstream/MK3' into MK3_LA15 2019-12-04 17:27:23 +01:00
Marek Bel
219a5e0625 Initialize EEPROM_SILENT in one place both for MK3 and MK25 printers and make it more clear. 2019-10-03 21:25:52 +02:00
leptun
444daceca3 Move define as requested 2019-09-12 13:39:04 +03:00
leptun
78708903e8 Also update eeprom value 2019-09-12 07:16:31 +03:00
leptun
90e5f14309 Fix compile error on MK3 2019-08-30 13:02:00 +03:00
leptun
56c949b9af Fix typo 2019-08-30 12:14:43 +03:00
leptun
d8d0069f97 Fix MK2.x Default stepper power out of sync 2019-08-30 12:12:29 +03:00
Yuri D'Elia
18b8dc89e5 Merge remote-tracking branch 'upstream/MK3' into MK3_LA15 2019-08-04 17:06:34 +02:00
Yuri D'Elia
1435e4a68d Use the computed direction in fsensor_st_block_begin 2019-08-04 16:53:48 +02:00
DRracer
8b806f692e
Merge pull request #1664 from MRprusa3d/PFW-811
"disable_z()" for Delta PSU
2019-07-16 16:46:34 +02:00
Yuri D'Elia
b6bcb901f3 Correct initialization of eISR_Err
Further tweak the initial term to improve the linearity of the resulting
speed after BW filtering.
2019-06-27 13:21:39 +02:00
Yuri D'Elia
2e073527fb Also avoid E direction inversions while coasting 2019-06-19 14:28:04 +02:00
Yuri D'Elia
4b3af0d2df Respect minimum direction change delay 2019-06-19 13:22:44 +02:00
Yuri D'Elia
0239f4bce1 Update/compute advance steps inside calculate_trapezoid_for_block
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.
2019-06-05 20:25:26 +02:00
Yuri D'Elia
048628083a Remove clear_current_adv_vars()
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)
2019-06-05 20:25:19 +02:00
Yuri D'Elia
7d33089d9a Remove use_advance_lead
The per-step state is kept implicitly using nextAdvanceISR,
while the current pressure is decoupled anyway.
2019-06-05 20:25:12 +02:00
Yuri D'Elia
cda9ed4a1d Reset LA state more carefully during stop conditions 2019-06-04 16:22:40 +02:00
Yuri D'Elia
1bed8cfa94 Don't call fsensor_st_next_block repeatedly during the last step
Rely on st_block_begin to perform a single call instead of calling
block_chunk for each advance tick in the last step
2019-06-04 16:22:33 +02:00
Yuri D'Elia
c50b1c0351 Rework the filament counter logic
- 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
2019-06-01 22:08:00 +02:00
Yuri D'Elia
47d2562510 Typos 2019-05-26 21:06:29 +02:00
Yuri D'Elia
823f7b069c Fix filament sensor direction again 2019-05-26 21:06:22 +02:00
Yuri D'Elia
9d834925c0 Recalculate LA_phase correctly 2019-05-26 17:06:21 +02:00
Yuri D'Elia
3abb2188df Fixup initial error by defect 2019-05-26 16:59:45 +02:00
Yuri D'Elia
20694aeabc Save 316 bytes by avoiding advance_spread copies 2019-05-26 16:41:56 +02:00
Yuri D'Elia
a28fb65bb2 Optimize advance_spread further 2019-05-26 16:41:50 +02:00
Yuri D'Elia
6f6cef65b5 Revert "Correctly handle direction for the filament sensor"
This reverts commit aae03ad83e.
2019-05-26 16:41:37 +02:00
Yuri D'Elia
bddc3e84ab Use WRITE_NC directly in the isr 2019-05-25 21:52:06 +02:00
Yuri D'Elia
aae03ad83e Correctly handle direction for the filament sensor 2019-05-25 21:51:59 +02:00
Yuri D'Elia
935a798236 Speedup advance_spread for common divisors 2019-05-25 21:51:52 +02:00
Yuri D'Elia
fa7ecfc38e Check for serial roughtly in the middle of the stepper isr 2019-05-25 18:41:28 +02:00
Yuri D'Elia
282b502393 Improve the distribution of the advance steps 2019-05-24 17:08:32 +02:00
Yuri D'Elia
aae5cce28f Use the nominal frequency to merge ticks 2019-05-24 17:08:32 +02:00
Yuri D'Elia
c6dbcc494f Typo 2019-05-24 17:08:32 +02:00