Commit Graph

805 Commits (bfc953f52d99ce269cada9a444bfeaf03d49d214)

Author SHA1 Message Date
D.R.racer d80a58cfdb Fix unit tests 2022-06-20 17:03:40 +02:00
D.R.racer 5a636529ca "Printer in Charge" mode: report buttons into the printer for processing
Sets the UI module into a mode when the printer is in charge of processing the buttons (from all sources).
That means the MMU will detect its buttons but it will not react upon them.
This mode is important for error recovery when the printer needs to do some stuff before the MMU (like preheating the nozzle).
2022-06-20 17:03:40 +02:00
D.R.racer 2874dd3bc9 Make sure the selector never moves if FINDA is pressed
It looks we have some kind of leak when filament sensor state is not completely coherent with FINDA state.
This is yet to be discovered and fixed with some unit tests.
2022-06-20 14:20:31 +02:00
D.R.racer d2ba215580 Increment MMU error count with every new error ocurred 2022-06-20 13:54:07 +02:00
D.R.racer cecb659564 Reject LoadFilament if filament state > AtPulley
If the MMU receives a command LoadFilament with a slot number SL we reject
the command to avoid moving the selector (effectively cutting the piece of filament present in FINDA).

That includes the scenario when the selector is standing at the very same slot SL, because the filament could be held by the printer (i.e. loaded in the nozzle).

There is one special case though - same slot AND filament load state == InSelector (it MUST NOT be anywhere farther)
2022-06-20 13:53:35 +02:00
Yuri D'Elia f8080bc73b Avoid runtime floats in Pulley::PlanMove
Using U_mm inside a compilation unit will force the compiler to generate
a runtime copy of the function, and we don't want that.

But there seems also to be an optimization problem with gcc <= 7.x where
even when declaring an inline function constexpr, if called enough
times, the compiler will choose _not_ to evaluate the function at
compile time and thus avoid our compile-time float->integer
conversions...

For this reason, split the body of the function in two parts: the actual
function that uses AxisUnits at runtime for calling motion.PlanMove, and
a wrapper that forces the conversion. By marking this function as
always_inline, the body is correctly evaluated at compile time at each
call site.
2022-06-18 09:07:03 +02:00
D.R.racer de8a2f35ae Fix setup/FINDA init state
It turned out FINDA needs running timer to perform BlockingInit() correctly.
Therefore setup() was split into setup() (no IRQ) and setup2() (IRQ enabled).

Then, finally, the check for FINDA state became reliable upon start of the FW.
2022-06-14 07:32:08 +02:00
D.R.racer 7ae9c9019c Clear EEPROM filament state upon start when FINDA is off
Complement to PR#176
2022-06-14 07:32:08 +02:00
D.R.racer b4f9924013 Improve robustness of unit tests 2022-06-14 07:31:51 +02:00
D.R.racer 750e83c5e9 Tune debounce timeout of buttons 2022-06-14 07:31:51 +02:00
D.R.racer fbb46e5951 Distinguish fast and slow feed stage
Originally, only FeedingToBondtech was reported to the printer.
With PR#173 we have this operation separated into a fast and a slow stage (for MK3S with the chimney).
It looks like the printer could benefit from knowing if the MMU is still pushing fast
or when it entered the slow stage (to prevent ramming hard the Bondtech gears)

Along with this new state being reported, we also introduce a new ErrorCode::FSENSOR_TOO_EARLY
which basically means that the fsensor triggered in the fast feeding stage.
2022-05-23 07:41:54 +02:00
D.R.racer d830a92fee Distinguish between fast and slow FeedToBondtech stage 2022-05-23 07:34:46 +02:00
Yuri D'Elia ed4c1712f7 motion: Update tests to check for correct acceleration
- Check rates using the reported acceleration instead of deriving the
  value from the slope.
- Simplify the tolerances when checking (use 10% for single-axis,
  20% with multiple due to quantization)
- Check a broader range of values
2022-05-21 15:13:49 +02:00
Yuri D'Elia ea3b8e5c85 pulse_gen: Fix acceleration_rate block calculations
The acceleration_rate should really by a premultiplication by 1<<24 so
that the division in Step() (while calculating the acc_step_rate) can be
computed again with a right shift.

This was incorrectly changed to F_CPU, which was close enough but would
cause the acceleration to be always slighly slower than expected.

Fix the ratio, but keep the multiplication in fixed-point to avoid a
float conversion.
2022-05-21 15:13:49 +02:00
D.R.racer e99e7441e1 Add unit tests for unlimited load 2022-05-13 12:54:23 +02:00
D.R.racer 6b06fed4b1 Perform a re-check (LoadFilamentLimited) after successful LoadFilament
- [] Unit tests of unlimited LoadFilament need to be introduced as the complexity of this scenario is increasing

.
2022-05-13 12:54:23 +02:00
D.R.racer c5aea89cac Report FINDA/EEPROM disrepancy to the printer 2022-05-13 08:17:28 +02:00
D.R.racer e9aae8570a Try to recover FINDA pressed + no EEPROM record at start 2022-05-13 08:17:28 +02:00
Yuri D'Elia f1d938b57f motion: Test for underflow as well 2022-05-11 08:48:53 +02:00
Yuri D'Elia 3fbdf8bb2b motion: PlanMove() correctly also when overflowing Position()
Correctly compute both the number of steps and direction when
under/overflowing the current position by performing a relative move.

This makes a repeated PlanMove() _always_ perform the move correcly,
even when the upper-level code might require to handle the overflow
itself for measurement.

Add tests for this condition by exposing the internal CurBlockShift() to
the motion unit tests.
2022-05-11 08:48:53 +02:00
Yuri D'Elia 1a2034f545 motion: Allow to get the motion controller for any axis 2022-05-11 08:48:53 +02:00
Yuri D'Elia db494722aa motion: Remove the TODO (tests are now complete) 2022-05-11 08:48:53 +02:00
Yuri D'Elia afead891d1 motion: Fix motion::triple_move step count limit
Do not assume any step can be merged while moving three axes at the same
time.

Use the worst case scenario involving indepedent parameters for each
axis.
2022-05-11 08:46:26 +02:00
D.R.racer f428075a4d Make LoadFilament retract even when stopped with a button
+ fix unrelated unit test of unload to finda which got broken in PR#160
2022-05-11 08:20:41 +02:00
D.R.racer 9c1204dad9 Rename idle_mode to application 2022-05-10 20:03:16 +02:00
D.R.racer 047c76870c Move idle_mode out from logic subdir 2022-05-10 20:03:16 +02:00
D.R.racer c3739eaaef Make unlimited LoadFilament as default 2022-05-10 20:03:16 +02:00
Yuri D'Elia 6b4ba322bb Fix usage of CurrentPositionPulley_mm in debug macros
Rename to the correct Pulley::CurrentPosition_mm
2022-05-10 20:03:16 +02:00
D.R.racer ff1a89d369 Detect successful end of logic::command + start idle countdown
This commit looks horribly complex, but the main idea is to have each of the logic::commands
report their terminal OK state in the same way. That allow for leveraging this very moment
to initiate the idle timeout.

Additionally, I wanted to hide the logic of idle mode detection, which resulted in moving the
top level logic from main.cpp into logic/idle_mode.cpp and a set of additional files to compile
in unit tests.
2022-05-10 20:03:16 +02:00
D.R.racer 1f061405f6 Fix MoveSelector operation build 2022-05-10 20:03:16 +02:00
D.R.racer bd95807b23 Make LoadFilament terminate completely OK when button pressed 2022-05-10 20:03:16 +02:00
D.R.racer 8ce029a28c Fix unit tests
- circular buffer can return its count of elements (even though a better solution may be implemeted later)
- stub_motion can handle multiple planned moves
- improved load/unload filament tests
2022-05-10 20:03:16 +02:00
D.R.racer 1d8c1e8f3f Introduce manual operation of MMU
This PR brings the option to move the selector directly using
buttons of the MMU - obviously while the MMU is idle and no
filament is stuck in the selector.

Left/Right buttons move the selector Left/Right.

Middle button performs a LoadFilament (into the MMU) on the active slot.

With this PR a change of LoadFilament behavior is also introduced.
Now, LoadFilament spins the Pulley for infinite time while waiting
for either FINDA trigger and/or a button pressed.
2022-05-10 20:03:16 +02:00
D.R.racer 13c12aac7f Repeated unload
Set default nr. of repeated unloads to 1
+ introduce a unit test for repeated unloads
2022-05-10 19:58:09 +02:00
Yuri D'Elia 6fdc1638fa Include <array> to build test_protocol on gcc 12 2022-05-10 18:03:40 +02:00
Alex Voinea c058949cbe Make idler less sensitive SGT=5 -> SGT=7 2022-05-09 12:23:22 +02:00
Yuri D'Elia fbb5843158 Guard critical sections in modules::motion
While motion queuing is safe, code that relies on the current block
needs to run with the isr disabled.

Protect AbortPlannedMoves and CurPosition from isr' interference by
using a RAII guard.
2022-05-02 12:33:37 +02:00
Alex Voinea 8f827d68c5 Add R0 and R1 to clobbers of mulU24X24toH16 just to be on the safe side 2022-05-02 12:30:56 +02:00
D.R.racer f2b65ebda2 Improve mulU8X16toH16 accordingly 2022-05-02 12:30:56 +02:00
D.R.racer aefa962cc3 Fix mulU24X24toH16
based on https://github.com/prusa3d/Prusa-Firmware/pull/3365
2022-05-02 12:30:56 +02:00
D.R.racer ca86797a9c Invalidate currentSlot while homing
makes calls to Slot() consistent and reliable
2022-02-21 18:38:04 +01:00
D.R.racer 8e8a17c34e Fix unit test UnloadFilament 2022-02-17 08:21:15 +01:00
D.R.racer b685ec4aff Fix waiting for homing of Selector after UnloadFilament 2022-02-17 08:21:15 +01:00
D.R.racer c95c6677b1 Add more unit tests for homing + fix the homing
It is a carpet-bombing-commit again, but solving the problem correctly required such an approach.
2022-02-17 08:21:15 +01:00
D.R.racer 684051abe8 Enlarge load distance from fsensor to drive gear
shall prevent printer load fails
2022-02-17 08:21:15 +01:00
D.R.racer bcba966a0e Fix repeated re-homing + add more unit tests for that scenario 2022-02-17 08:21:15 +01:00
D.R.racer f25f88b164 Extract buttonADCMaxValue into config
to be used later
2022-02-17 08:21:15 +01:00
D.R.racer 18891dbeaf Add ClearButtons into unit tests 2022-02-17 08:21:15 +01:00
D.R.racer 7e759fdb51 Rebase onto main: use axisUnitToTruncatedUnit 2022-02-17 08:21:15 +01:00
D.R.racer 7fbd3c9c7e Fix homing error recovery + add homing unit tests 2022-02-17 08:21:15 +01:00