Some EEPROM allocations do not use the hole allocated space:
- EEPROM_FARM_NUMBER is only numeric 000-999 and only uses 2 bytes to store the Farm number BUT allocated 3 bytes. Added EEPROM_FREE_NR1 as free space that can be used
- EEPROM_CRASH_DET just changes 1 byte to save it status [on/off] but allocated 5 bytes. Added EEPROM_FREE_NR2 to EEPROM_FREE_NR5 as free space that can be used
Just after setting up the w2m matrix, call "clamp_to_software_endstops"
on the current_position (initially [0,0,0]) to move it to the effective
minimal position, which is usually [0,0,non-zero] due to MIN_Z and the
negative probe offset.
This is required to calculate correctly the first relative move:
planning X+10 would unexpectedly calculate a Z shift otherwise.
Tune the "soft" filament recheck to be more in-line with the latest
changes. Relax the thresholds so that a poorly tracking filament
that managed to trigger a recheck can still pass as long as /some/
motion is detected.
Hide the unused fsensor_oq_result() behind the FSENSOR_QUALITY define,
which is likely broken currently anyway.
Cleanup and simplify all the OQ defines.
When doing a PAT9125 "soft check", use two different speeds between
retraction and extrusion. This increases the chances that we can
track the surface.
Depending on the filament surface and moving speed, the PAT9125 sensor
can stop being able to track movement.
In such cases, instead of triggering false errors and/or relying on
previous states, read and use the exposure data off the sensor and
increase error counts only for poorly exposed images instead, which
is a good indicator of a far-away (or missing!) tracking surface.
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.
The filament sensor "chunk lenght" needs to be updated every time the
E axis resolution is changed in order to trigger at the same distance.
Introduce a new function fsensor_set_axis_steps_per_unit() and use
it consistent during init, in M92 and M350.
When upgrading K values of a LA1.0 print, also adjust E-jerk settings
(<2) if permissible according to current accell limits. The same is also
true when jerk is set mid-print via 'M205 E'.
Existing values are always restored when switching to another
compatibility mode.
TODO: Since this is stateful, we will need to save the current print
mode / acceleration and jerk in the eeprom for this to survive a power
panic (see prusa3d#2456).
When calculating the advance tick interval, be sure to check for integer
overflow. Very low step rates can result in values exceeding uint16_t
causing premature LA tick delivery.
An overflow resulting in zero would also block in an infinite loop
within advance_spread().
Even though such rates are worthless in terms of compensation and often
result in 0 extra ticks as well, do not disable LA for the block (as
doing so would reset the count for short segments) and do not check for
zero in multiple paces either.
Saturate the interval instead, delaying any further tick to the next
block.
M24 was always cleaning the last print failstats. But because M24 is
used to restore a print after power failure (by setting the seek
offset), it would also reset the stats incorrectly after resuming.
Check for the file index position and reset the stats only when a print
is started from the beginning of the file.
Apply the same logic to M32 and similarly handle the LA10->15 conversion
(do not re-apply the adjustment for a resumed print).
There is a chance that current_block can be NULL despite
the queue being non-empty. This can happen early after a block has been
queued, but before the isr has picked it up for processing, and/or when
the current block is at the last step and is being discarded.
Check for current_block directly to avoid this race.
Both during early init and in uvlo_tiny, display "POWER PANIC DETECTED"
if enough charge is left.
This is not worth doing in regular uvlo_, as we want to give full
priority to the X motor
If power has been lost during startup already a falling edge would be
skipped, causing the print to continue and lose its state without
being able to save again.
Check for a low line after arming the interrupt and simply wait
for reset.
Do not allow uvlo_tiny() to trigger before the previous print has
already been recovered.
A quick repeated power failure could cause uvlo_tiny to overwrite
the Z position before it has been correctly recovered.
enable/disable_z behave differently when PSU_Delta is defined.
During powerpanic and kill however we do *really* need to save energy
and poweroff the motors.
Rename enable/disable_z as poweron/poweroff_z and define some aliases so
that we can use the low-level function where needed.
Use 2 bytes to store extruder temperature during UVLO.
Re-use the storage of EEPROM_UVLO_TINY_Z_MICROSTEPS which has been freed
by previous changes.
Fixes#2303
- In both uvlo_ and uvlo_tiny, calculate Z usteps properly and adjust
the Z position to a true fullstep before disabling the motor. This
avoids shifs during recovery.
- In uvlo_tiny, instead of moving up indefinitely, adjust Z just
once using the smallest move possible (new def UVLO_TINY_Z_AXIS_SHIFT)
- Perform all the uvlo/recovery processing in physical coordinates
and MBL off: there should be no automatic Z movement!
- Disable heaters in both handlers to conserve more power.
- Add timing information to uvlo_tiny too.
- During recovery, to switch between physical and logical positioning
introduce a new "PRUSA MBL" gcode as most of the procedure is
enqueued, and no existing gcode was available.
There is frequently plenty of power left during a PP. Take advantage of
it by moving the extruder to either side of the axis to detach
completely the nozzle from the print.
Re-enable Z during this move to avoid losing the current step.
When the printer is connected to a USB host during a PP (and the host
does not lose power), the rambo can linger for longer, sometimes for
long enough to recover the print state. Drain some more power.
If the motors are off-phase, this is more likely to "bump" them to an
incorrect/reverse full-step, doing worse.
We need to ensure the motors are already positioned on a fullstep
during power panic instead.
Remove the PSU_DELTA exception: Z _always_ needs to be powered here.
Also clear the UVLO flag when using lcd_print_stop. This prevents an
aborted print which has been cancelled while unparking (just prior to
recover) to come back again at the next startup.
- Initially restore the last E position from the eeprom in any case, not
just when using absolute mode (although unnecessary: since it will be
reset later), fixing a possible unitialized position and crash during
recovery (thanks to @leptun)
- Remove useless extra calls to put the extruder in relative mode:
the extruder already starts in relative mode and is later switched to
absolute.
- Replace incorrect calls to STRINGIFY with sprintf_P
- Retract after pressure has been restored in uvlo_tiny, to be
consistent with a regular uvlo (remove the bogus double unretract
as a result).
- Set the real E position prior to the panic *after* the retraction,
using the now-fixed G92.
Do not process serial commands when re-enabling the global isr.
While printing via USB and a power panic is triggered, *any* extra
command should be ignored.
Abuse the "saved_printing" variable to inhibit serial processing.