Commit Graph

292 Commits (0e3d61bedca7375c599301201e40d4deba195634)

Author SHA1 Message Date
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
DRracer 794b0d0a81
Fix unit tests on windows (#213)
* Fix unit tests on windows

Based on PR#210 from @gudnimg

Cherry picked just the necessary changes + reformatted the corresponding CMakeLists.txt

* Change cd -> WORKING_DIRECTORY even for test coverage report

* Update CMakeLists.txt

* Add `BYPRODUCTS` arguments

Co-authored-by: D.R.racer <drracer@drracer.eu>
Co-authored-by: vintagepc <53943260+vintagepc@users.noreply.github.com>
2022-10-11 07:15:01 +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
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
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 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 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
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
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 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 7fbd3c9c7e Fix homing error recovery + add homing unit tests 2022-02-17 08:21:15 +01:00
D.R.racer 4d9d310f00 Fix unit tests 2022-02-17 08:21:15 +01:00
D.R.racer f9addb0d7a WIP: homing on both ends of axes
The principle has been implemented, but the TMC is not providing
the right data for some reason - homing doesn't work at all right now.

Also, after solving the physical homing, unit tests must be updated.
2022-02-17 08:21:15 +01:00
D.R.racer 0c9d59ba5a Fix processing of Home commands + unit tests 2022-02-17 08:21:15 +01:00
D.R.racer c5e5f57100 Rename mp (modules::pulley) namespace to mpu
clashed with the already used `modules::protocol` (mp)
2022-02-17 08:21:15 +01:00
D.R.racer b36e6b99a1 Add Pulley as a Movable module
This PR brings the following improvements:
- unifies the error handling of TMC and Homing/Stallguard errors on all motorized modules (Idler, Selector, Pulley)
- now we distinguish between Homing and TMC errors + we have a separate handling of these two kinds into CommandBase unified for all motorized modules
- adds unit tests to verify the function
- fixes SetFINDAStateAndDebounce (didn't obey the press parameter before)
2022-02-17 08:21:15 +01:00
Yuri D'Elia 86d5e87a09 motion: Implement Position/CurPosition returning AxisUnit
These come in handy to avoid manual casts and enforce types at runtime.
2022-02-01 07:00:53 +01:00
Yuri D'Elia e318a9f9c1 tests/motion:: ensure stepTimerQuantum is always respected
This catches motion stutters as fixed in
502f42b7be
2022-01-31 14:38:37 +01:00
Yuri D'Elia e7003133f5 tests/motion: Do not step in test_motion::ResetMotionSim
Calling stepUntilDone defeats the purpose of the following REQUIRE().
The test should always start from a clean state.
2022-01-31 14:38:37 +01:00
Yuri D'Elia cabf284882 motion: Remove motion.ResetAxesData
Use motion.SetPosition directly to minimize redundant code which is used
for unit tests only.
2022-01-31 14:38:37 +01:00
D.R.racer ea8dd7e365 Unload now rechecks the position of filament after recovery
This solves a number of issues - if FINDA or FSensor failed,
the unload was never "complete" - filament was stuck in the selector
blocking it from normal operation.

Now, after all errors have been resolved, filament is explicitly FED
into FINDA and then RETRACTED to Pulley.
2022-01-19 17:08:35 +01:00
D.R.racer 97b362f2b7 Join feedrates of Load-to-FINDA and Load-to-Nozzle
MMU-105
2022-01-19 17:08:35 +01:00
D.R.racer 6973dbff13 Introduce intelligent homing if Idler and Selector
Both movable components now perform homing sequences transparently
whenever the logic layer invalidates the homingValid flag.
That reflects the fact, that the user may have moved the Idler or Selector
while trying to resolve a HW issue with un/loading filament.

Basic rules:
- Idler gets rehomed immediately and then moves into the target slot position
- Selector rehomes once it is possible - i.e. when filament load state
  is AtPulley - then it immediately and spontanneously executes the homing
  sequence and then returns to the desired state

Motivation:
- resolve startup issues (EEPROM says we have filament, but FINDA is not triggered)
- resolve accidental moves of Idler and/or Selector while
  digging out stuck filament from the unit
2021-11-25 13:04:22 +01:00
D.R.racer 7d423df583 Swap buttons left<->right 2021-11-23 12:55:39 +01:00
D.R.racer 6f982e2505 Cleanup compiler warnings 2021-11-17 08:48:59 +01:00
D.R.racer 151adf810a Add ToolChange Error resolve Button2 unit tests 2021-11-17 08:48:59 +01:00
D.R.racer 515119edc8 Test ToolChange error recovery by button 0 and 1 2021-11-17 08:48:59 +01:00
D.R.racer 7fe9d7f329 Finish UnloadFilament unit test - error state resolved by user + checks 2021-11-17 08:48:59 +01:00
D.R.racer c2325b687a Unittests: set buttons more consistently 2021-11-17 08:48:59 +01:00
D.R.racer 872b2206ed Cleanup error recovery of LoadFilament
+ cover all paths with unit tests
2021-11-17 08:48:59 +01:00
D.R.racer 96397ec16b Improve error handling of ToolChange state machines
... and fix an edge case in LoadFilament
2021-11-17 08:48:59 +01:00
D.R.racer ffd8924d8c Fix start MMU with filament blocking the selector 2021-11-03 10:37:51 +01:00
D.R.racer fa4e687fdc Fix chopping negative move values in PlanLongMove
+ use PlanLongMove in UnloadToFinda
+ fix comment in unit test
2021-11-03 10:13:03 +01:00
D.R.racer c3aec0bf92 Fix pulse gen unit tests with the larger block buffer 2021-11-03 10:13:03 +01:00
D.R.racer 5f1e3e018e Workaround planning moves longer than 32K steps 2021-11-03 10:13:03 +01:00
D.R.racer 7f9fc78cf6 Improve motion's unit tests 2021-11-03 10:13:03 +01:00
D.R.racer 22522c253f Update code after rebase onto main 2021-10-21 15:16:29 +02:00
D.R.racer 9438253106 Avoid trying to unload filament when not loaded
however, it looks like the EEPROM is not updated correctly, needs more testing
2021-10-21 15:16:29 +02:00
D.R.racer 021c79ff10 Fix unit test Feed to Bondtech 2021-10-21 07:55:41 +02:00
D.R.racer 63509af294 Fix cut filament unit tests
still, this may need some more work in relation to PR #128
2021-10-21 07:55:41 +02:00
D.R.racer 3d2a76b6a0 Fix feed_to_finda unit test 2021-10-21 07:55:41 +02:00
D.R.racer ee247246ee Fix unit tests
- fix homing procedure for Idler and Selector
  (homing now ends with a move to the Parking position)
- fix unit tests' startup conditions with regard to necessary
  homing of Idler and Selector

TODO: still test_cut_filament fails for minor reasons
2021-10-21 07:55:41 +02:00
D.R.racer 5b9c6ec36e Fix (workaround) LED blink when millis overflow + unit test 2021-10-18 16:30:08 +02:00
D.R.racer e1af08b3d5 Fix unit tests
That includes:
- introduce pulley slow feedrate and fsensor-to-nozzle distance
  in config necessary for slowly feeding the filament from fsensor into the nozzle.
  (the constant is subject to extraction into some other config as it has to be used in the printer as well).
- update FeedToBondtech accordingly to perform a gentle push into the nozzle
  after fsensor detects the filament + update its unit tests.
- slight cleanup of LoadFilament + fix its unit tests
- add FeedingToNozzle progress code, as it might be interesting
  to inform the printer about this task in the future
- revert non-clean changes from RetractFromFinda - it should not disengage the idler
- revert incorrect + fix ToolChange
- clean-up UnloadFilament
2021-10-12 18:11:05 +02:00
3d-gussner abf875bda0 After Load Filament is compeleted the slot LED should be off 2021-10-12 18:11:05 +02:00
D.R.racer c26cc30185 Add finer filament loaded states and improve unit tests
We need to know better where the filament is, a simple "filament loaded true/false"
does not correspond to the reality.
2021-10-12 18:11:05 +02:00
D.R.racer 5af0125672 LoadFilament should not set filament loaded (surprisingly)
because of the change of semantics of LoadFilament operation.
LoadFilament pushes the filament into FINDA and then retracts it back just to keep the
filament ready to be grabbed by the idler and pulley and loaded into the printer's nozzle.

So the selector is not blocked by the filament -> filament NOT loaded
2021-10-12 18:11:05 +02:00
D.R.racer 5cf4a496e3 Introduce checking for enabled/disabled Pulley axis in unit tests 2021-10-12 18:11:05 +02:00
D.R.racer a13f3b8a2d Fix CutFilament unit tests 2021-10-12 18:11:05 +02:00
D.R.racer bbd14ed217 Fix ToolChange operation + unit tests 2021-10-12 18:11:05 +02:00
D.R.racer 6426295e32 Change the semantics of load filament
Load filament performs feed to FINDA and retract:
- engage idler
- feed normal to FINDA with config::feedToFinda distance until FINDA triggers
- retract normal and as soon FINDA un-triggers move back to PTFE config::cuttingEdgeToFindaMidpoint
- disengage the idler

That implied introducing another substate machine - RetractFromFinda, which does the opposite
of FeedToFinda while also checking for the FINDA switching off while retracting filament.

Still, ToolChange and CutFilament need fixing with this change
2021-10-12 18:11:05 +02:00
D.R.racer 01b2280ea6 Fix Feed To Bondtech unit tests (disengage idler after success) 2021-10-12 18:11:05 +02:00
D.R.racer 06e4cd900f Fix Feed To Bondtech tests tags 2021-10-12 18:11:05 +02:00
D.R.racer 1563559685 Fix startup conditions for Unload to FINDA state machine tests 2021-10-12 18:11:05 +02:00
D.R.racer 2ca951ceea Fix test_unload_filament
only green LED status was not correct after the latest changes
2021-10-12 18:11:05 +02:00
D.R.racer 1a6f49410c Fix test_failing_tmc 2021-10-12 18:11:05 +02:00
D.R.racer bb574603ba Reformat helpers.ipp - makes placing breakpoint easier 2021-10-12 18:11:05 +02:00
3d-gussner 0bead533df clang-format 2021-10-12 18:11:05 +02:00
3d-gussner 5f28dbf056 Fix unit test feed to finda 2021-10-12 18:11:05 +02:00
D.R.racer 1402fb3dd6 Add 'F' and 'f' decoding + unit tests where necessary 2021-09-29 13:28:34 +02:00