Commit Graph

255 Commits (db2125e67ad6ea3cff321826460d394934e70962)

Author SHA1 Message Date
D.R.racer ada4ed3dda Workaround INVALID_TOOL error codes
May meed some more work to recover gracefully, not sure if it is just a unit test "issue" or a deeper problem in the state machines.
2022-12-28 12:15:47 +01:00
D.R.racer a52f833223 Fix and tune CutFilament + unit tests
Several issues addressed in this PR:
- CutFilament tuning + error recovery
- introduce register 0x1d (cut filament selector iRun current level)
- optimize setting iRun and iHold currents in the FW
- CutFilament unit test fixed
2022-12-28 12:15:47 +01:00
D.R.racer 98daf765af Separate NoCommand and StartUp (new state machine)
The reasons for this change are:
- NoCommand is used during the lifetime of the firmware as a fallback in case an unknown command is received (simplifies command handling code). It must remain not doing anything.
- StartUp became a complex infrastructure which needs to "live" until an error is fixed (if any). That requires a "standard" StateInner() function which waits for the user to resolve the error.

Unit tests renamed as well.
2022-12-27 12:41:29 +01:00
Guðni Már Gilbert 8f212a5cb3 Add unit tests 2022-12-27 12:41:29 +01:00
D.R.racer 3988a9aff0 Improve logging in unit tests' helpers.ipp
Based on work from @gudnimg: https://github.com/gudnimg/Prusa-Firmware-MMU-Private/tree/MMU-206
2022-12-20 10:35:59 +01:00
D.R.racer 3e9410c4f9 Fix: make sure VerifyEnvironmentState checks filamentLoaded reliably
... and improve unit tests
2022-12-20 06:32:51 +01:00
D.R.racer c0189d81af Distinguish among different error states when recovering ToolChange
Some errors need specific recovery, it seems it is no longer possible to "just" retry.
2022-11-18 22:42:05 +01:00
D.R.racer c8c39f7b69 Make sure ToolChange moves Selector to desired slot
and verify correct behaviour in unit tests - especially when Selector's start position is at a different slot.
2022-11-18 22:29:01 +01:00
D.R.racer 08f777b5cb Introduce FINDA_FLICKERS error code
Intended for scenarios when FINDA used to be OFF but accidentally became ON without a reason.
The user is obliged to inspect FINDA and tune its switching.
2022-11-17 07:32:38 +01:00
D.R.racer 3f09ba0c16 Unit tests: selector refused to move in ToolChange
Revealed all kinds of subtle issues (which is great). All have been fixed in this commit.
2022-11-17 07:32:38 +01:00
D.R.racer c74d418016 Invalidate Idler+Selector homing flags when Retry from ToolChange Error
If FSENSOR_DIDNT_SWITCH_ON was caused by misaligned Idler, rehoming it may fix the issue when auto retrying -> no user intervention.
So first invalidate homing flags as the user may have moved the Idler or Selector accidentally.

Beware: we may run into issues when FINDA or FSensor do not work correctly. Selector may rely on the presumed filament position and actually cut it accidentally when trying to rehome.
It is yet to be seen if something like this can actually happen.

MMU-191
2022-11-15 17:42:12 +01:00
D.R.racer 299a31b765 Generate exactly 1 userInput event when button pressed (and held)
This PR is a different solution to what @gudnimg found in PR#233 / PFW-1404.

The benefit of this approach is the fact, that the button press event is generated when the button is pressed and not after it has been released.

The downside is obvious:
CPUFLASH: +28B
RAM: +1B
2022-11-15 07:19:20 +01:00
Guðni Már Gilbert 0e625dc551 circular_buffer: implement reset()
reset() discards any data in the buffer (head == tail)

Change in memory:
Flash: -116 bytes
SRAM: 0 bytes
2022-10-25 07:21:33 +02:00
Yuri D'Elia 3567a3dcd5 motion: Also test for the simplest case of a single+unplanned move 2022-10-22 17:40:28 +02:00
Yuri D'Elia 7053755b0e motion: Add tests for unscheduled moves in AbortPlannedMoves
This catches the previously untested #228
2022-10-22 17:21:08 +02:00
Guðni Már Gilbert 353affb9f3 Optimise Catch2 V3 includes + fix a few cases of missing includes 2022-10-22 15:41:44 +02:00
Guðni Már Gilbert 45f70e004c Update CMake integration for Catch v3.1.0 2022-10-22 15:41:44 +02:00
Alex Voinea e2924c3506 Fix tests 2022-10-20 12:09:42 +02:00
Guðni Már Gilbert bf89030423 user input test: Register enum with Catch
Now when REQUIRE ( a == b ) fails we see the values of a and b.
2022-10-17 17:27:47 +02:00
Guðni Már Gilbert 63404f7970 Format 2022-10-12 06:41:59 +02:00
Guðni Már Gilbert 01ef1191b0 Fix test_motion_ramp on Windows
* 'python3' is not valid on Windows

* call the .py file with 'python' command to prevent BAD_COMMAND error
2022-10-12 06:41:59 +02:00
Alex Voinea 2ab3b96542 tests... 2022-10-11 07:13:42 +02:00
D.R.racer 4f1a301e0e Force fix formatting 2022-09-22 12:16:41 +02:00
D.R.racer 0fa8a3c278 Refactor original solution from @leptun
- rename stall*guard to StallGuard (match name with the vendor)
- separate TMC2130 module from EEPROM (they do not need to know about each other at all)
- separate SGTHRS settings from motion - moved to globals like all other "global" parameters
- improved EEPROM storage for SGTHRS
2022-09-22 12:16:41 +02:00
D.R.racer 48d5bbc19e Fix computation of CRC for Write requests (non-zero value2) 2022-09-08 11:39:10 +02:00
D.R.racer 9a5a6d9498 Fix computation of CRC
came out of unit tests of read/write registers functionality.
2022-09-07 15:44:08 +02:00
D.R.racer 89fc176955 Add basic unit test infrastructure for application + registers 2022-08-11 10:26:42 +02:00
vintagepc fdb2058d2b Fix test build 2022-08-11 10:26:42 +02:00
D.R.racer 39caece714 Add CRC to the protocol + unit tests 2022-08-11 10:26:42 +02:00
D.R.racer bf5c0f3f23 Allow result codes on a Finished Command state
Helpful for the printer to show, that a command has been cancelled (or anything else we can think of in the future).
MMU-146
2022-08-11 10:26:42 +02:00
D.R.racer ad0b26c5ec Fix unit tests 2022-08-11 10:26:42 +02:00
D.R.racer 53f87c8755 Introduce generic Read/Write register operations 2022-08-11 10:26:42 +02:00
D.R.racer 5dffd32025 Introduce Idler::PartiallyDisengage
This is to solve a potential problem while feeding to printer's drive gears - while disengaging the Idler, the Pulley was still rotating to avoid grinding the filament (printer is pulling it).
Other filaments could have moved a bit when the Idler's bearings ran over them while the Pulley was still rotating slowly -> the filament could have been moved into the Selector's path causing trouble (especially when not used in the print).
Therefore, the Idler disengages partially now - moves into an intermediate position between the slots.
Then, the Pulley is completely stopped and after that the Idler does a full disengage like before.
2022-08-02 07:28:10 +02:00
D.R.racer 4964e9a781 Fixup unit tests due to new homing behavior 2022-08-02 07:16:54 +02:00
D.R.racer 3c3e625f39 Unit test ErrDisengageIdler: make sure it never sets error while disengaging 2022-07-20 16:23:43 +02:00
D.R.racer 4e44447762 Change the unit tests to follow the new spec 2022-07-20 16:23:43 +02:00
D.R.racer 40e9e5df7c Fix unit tests 2022-06-20 17:03:40 +02:00
D.R.racer bc298ab114 Add unit test for empty event queue 2022-06-20 17:03:40 +02:00
D.R.racer b82ffe8db9 Add missing ResponseParamCode Button support + unit test 2022-06-20 17:03:40 +02:00
D.R.racer d80a58cfdb Fix unit tests 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 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
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 b4f9924013 Improve robustness of unit tests 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
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
D.R.racer e99e7441e1 Add unit tests for unlimited load 2022-05-13 12:54:23 +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 db494722aa motion: Remove the TODO (tests are now complete) 2022-05-11 08:48:53 +02:00