Commit Graph

649 Commits (f4388b8d2079731438b686b725991fdd64b7b3f7)

Author SHA1 Message Date
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
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 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 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
D.R.racer d0ae94d655 Remove "moving away from front end" as it homes without it
after tuning of constants by @leptun in the previous commits
2022-02-17 08:21:15 +01:00
Alex Voinea 1b5936a8f6 Fix idler axis length (eyeballed it, we should find the real value) 2022-02-17 08:21:15 +01:00
Alex Voinea 26d2c9f2ca Fix SG_thrs and tcoolthrs parameters 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 e338eb9f4c Add missing pulley.Step() to main 2022-02-17 08:21:15 +01:00
D.R.racer 6b53db7610 Rebase onto main 2022-02-17 08:21:15 +01:00
D.R.racer a408651e62 CurrentPositionPulley_mm->CurrentPosition_mm and use it in debug prints 2022-02-17 08:21:15 +01:00
D.R.racer ee3c43b12c One more mp->mpu (in a commented piece of code) 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 53d285280d Avoid runtime conversions of floats in UnloadToFinda
Introduce axisUnitToTruncatedUnit to convert from an AxisUnit (now
conveniently returned from Motion::CurPosition) to a physical unit *but*
directly into a truncated integer type, avoiding conversions to long
double types at runtime.

The related function truncatedUnit perform the same truncation of a
constant unit, so that the result of axisUnitToTruncatedUnit and
truncatedUnit(unit) result in the same type for clarity.

Both functions accept a pre-multiplier, which is applied at compile
time for constant values when optimizations are enabled.
2022-02-01 07:00:53 +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 5af7d9a10f motion: correctly reset residuals of a stopping axes
Fixes the motion stutters generally happening as more than a single
axis are active and one completes in the middle of the motion.

Do not generate a spourious interval as one axis exits the queue. This
short interval didn't account for the minimal stepping quantum,
potentially causing a timer overflow.
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
Yuri D'Elia 2e32204d17 motion: Improve legibility of motion::SetPosition 2022-01-31 14:38:37 +01:00
D.R.racer 5ba8ba9646 Longer unload distance for FSensor OFF check
It's been too tight before causing unload errors unnecessarily.
We can play with this parameter more in the future.
2022-01-19 17:08:35 +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 8a6d962bd4 Separate load/unload speeds + faster
Slower loading speed is necessary for precise detection
of filament sensor trigger and starting rotation of the E-motor.
Experimentally it turned out speeds above 80mm/s tend to cause timing issues
(sometimes one can hear a crack as MMU' or the printer's drive gears
slip while pushing the filament).

Such a timing issue then causes blobs in purge towers.

On the other hand - 80mm/s for the fast part of filament load
seems not only absolutely reliable, but also very quiet.
120mm/s for unload is much louder (we may slow it down later)
2022-01-19 17:08:35 +01:00
D.R.racer 7cdb63f07a Make Idler::Engage not obey the position of filament
fixes UnloadFilament startup - it wasn't waiting for the Idler to engage
before moving the 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 21390cefe1 Add Homing/Stalled error codes for Pulley, Idler, Selector 2022-01-18 09:43:18 +01:00
Alex Voinea fd6c0bcc23 Symmetrical latch signal 2021-12-01 09:07:08 +01:00
Alex Voinea f509dc8346 Adjust latch pulse length 2021-12-01 09:07:08 +01:00
Alex Voinea d399a024bb SHR16 correct signal timing 2021-12-01 09:07:08 +01:00
D.R.racer 662e05b813 Turn off other LEDs when appropriate
Solves an interesting tiny issue introduced in the previous commits.
When we start with the filament in selector, the corresponding LED
is set to ON. However, all of the logic state machines only operated
on the LED pair of the active slot -> the starting LED may have been
left ON in some edge cases.

Now, this is resolved by clearing all other LEDs except for the active
slot where appropriate.
2021-11-25 13:04:22 +01:00
D.R.racer f2f82c620a Set green LED at start when filament loaded + set Idler as idle at start 2021-11-25 13:04:22 +01:00
D.R.racer e064a6c2f5 Introduce H0 command to invoke Idler+Selector homing seq. if safe 2021-11-25 13:04:22 +01:00
D.R.racer 9bf2b401e4 Avoid homing the idler at start when printing 2021-11-25 13:04:22 +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 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 afab309d27 Extract common Dis/Engaging of idler in Error states into base class 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 bfa710525b Discard all remaining planned blocks with AbortPlannedMoves
Previously it looked like only the active block has been discarded
which worked most of the time, since we only planned single moves.
But with introduction of PlanLongMove in one of the last commits
this is not true anymore.
2021-11-17 08:48:59 +01:00
D.R.racer 62e12102fd Check for FSensor OFF after unloaded to FINDA
we may discuss when to check for the FSensor state and why,
but this approach seemed to me like the least invasive method
of just checking the fsensor state and reporting an error in case
it didn't switch off.
2021-11-17 08:48:59 +01:00
D.R.racer 2a1539b65b Fix Right button handling for Load/Unload 2021-11-17 08:48:59 +01:00
Yuri D'Elia b6a676e093 AVR: Do not use __builtin_abs() for long types
In AVR __builtin_abs() breaks for non-base types.

Provide a generic function and use an overload when it is safe to use
instead.

This fixes the underlying step count calculation in PlanMove, thus
removing the need for the PlanLongMove work-around.
2021-11-11 07:41:48 +01:00
D.R.racer 2d81332626 Fix typo - selector homing condition 2021-11-03 10:37:51 +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 2640e9d899 Fix inverted condition (kudos to @leptun) 2021-11-03 10:13:03 +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 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 6294e39746 Avoid repeated writes into the shift register
May reduce flickering of LEDs on some boards
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 04348b2d86 Make all SHR16 public functions "thread-safe" 2021-10-21 10:17:10 +02:00
D.R.racer 19dcfcef79 Revert selector's config back after testing on real HW 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 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
Alex Voinea 7380cb740a Pulley SG increased 2021-10-21 07:55:41 +02:00
Alex Voinea 99c05b79d0 Adjust SG filtering threshold 2021-10-21 07:55:41 +02:00
Alex Voinea a87b981a3d Homing initial 2021-10-21 07:55:41 +02:00
D.R.racer 0fbcb9dac2 Tag all source files with @file for doxygen 2021-10-18 17:59:46 +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 8eb6240541 Add HAL AVR EEPROM implementation 2021-10-18 16:29:54 +02:00
D.R.racer abe2567c84 Fixes for loading filament into nozzle
Slower speed once we reach the fsensor + avoid grind while disengaging the Idler
while the printer is already pulling the filament.
2021-10-18 07:29:13 +02:00
Alex Voinea 9dc2ccc337 Revert accidental include 2021-10-14 14:27:56 +02:00
Alex Voinea 438ced6b96 Revert accidental commit 2021-10-14 14:27:56 +02:00
D.R.racer 9994d05d7f Reformat usb_cdc.cpp 2021-10-14 14:27:56 +02:00
D.R.racer d35bcd258a Refactor after rebase onto main 2021-10-14 14:27:56 +02:00
Alex Voinea 78af22e6c3 Dual bank test. Seemed to work for me. Don't care if it's placebo 2021-10-14 14:27:56 +02:00
Alex Voinea 538d4c8ef6 Remove useless debug info 2021-10-14 14:27:56 +02:00
Alex Voinea 3391b04ec7 update usb debug 2021-10-14 14:27:56 +02:00
Alex Voinea ea7d44a611 debug USB stream 2021-10-14 14:27:56 +02:00
Alex Voinea 362d012eff USB cdc stdout stream 2021-10-14 14:27:56 +02:00
3d-gussner 63aead0ab8 Update eject to use FilamentLoadState NotLoaded 2021-10-12 18:11:05 +02:00
3d-gussner fb97e519aa Feed slowly if FilamentLoadState is unknown 2021-10-12 18:11:05 +02:00
D.R.racer 206923598b Fix error codes formatting 2021-10-12 18:11:05 +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
Alex Voinea 94e6d1403e (Hopefully) Fir shr16 timing issues
Should also hopefully fix the random behavior of the DIR pins. When I was testing a really slow timing, the steppers seemed to want to not go in the right direction. That was fixed with the critical section. The 1us delay might be overkill, but I'm not the one that added a 100nF capacitor on the LATCH line (basically chip select). This might be part of the randomness that happened and why some board behaved better than others (stronger GPIO outputs)
2021-10-12 18:11:05 +02:00
Alex Voinea 34442469a3 More extreme speeds. They reveal errors in the motion planner 2021-10-12 18:11:05 +02:00
Alex Voinea 6e50d902d2 Steppers should be disabled on startup 2021-10-12 18:11:05 +02:00
Alex Voinea ef997a6352 Update cuttingEdgeRetract 2021-10-12 18:11:05 +02:00
Alex Voinea 0a1290102c Actually fix retract filament from finda 2021-10-12 18:11:05 +02:00
Alex Voinea 6071257973 Fix unloading state machine 2021-10-12 18:11:05 +02:00
3d-gussner 221f40c7a1 Fix issue that all tool changes after first one fail to change to planned slot
Update Filament Load state
2021-10-12 18:11:05 +02:00
3d-gussner 33b467f1bc Add debug to retract from finda 2021-10-12 18:11:05 +02:00
3d-gussner 62116b1283 Update debug 2021-10-12 18:11:05 +02:00
3d-gussner d9134b16fc Update Filament Load state order 2021-10-12 18:11:05 +02:00
3d-gussner 82f2e8ec54 fix some debug output 2021-10-12 18:11:05 +02:00
3d-gussner f9561e6cf7 Remove double operations
- feed to finda engages the idler so no need to do that before
- retract from finda disengages the idler, again avoid double operation
LEDs set mostly by feed to finda and retract from finda
2021-10-12 18:11:05 +02:00
3d-gussner 5cfb0887d0 Disengage Idler after retracted from FINDA
Add some dbg_logic output
2021-10-12 18:11:05 +02:00
3d-gussner b752c5c4e7 Set FilamentLoaded state to InSelector if FINDA triggers 2021-10-12 18:11:05 +02:00
3d-gussner fa50462929 Add InFSensor state 2021-10-12 18:11:05 +02:00
3d-gussner 67657329d1 Correct debug messages for state 2021-10-12 18:11:05 +02:00
3d-gussner f99adae31e Use config.h 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
3d-gussner 28c8e09bcf Use config.h to define DEBUGS 2021-10-12 18:11:05 +02:00
3d-gussner dbf26d13ac Make search for error codes easier 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 b13214b7f5 Fix debug sprintf variant 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 f18ff63cf7 Fix PROGMEM addressing in debug.h
I hate when the compiler doesn't check something what it normally does:
`pgm_read_byte` is more than happy with a parameter (*str), which reads
an address at a location where *str points to - which is obviously not the intent.
2021-10-12 18:11:05 +02:00
D.R.racer 236a40c6ef Use dbg_logic logging
and improve the variadic version used to print formatted
text at some spots in previous commits
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 505930c576 Explain better final Idler state in FeedToFinda and FeedToBondtech 2021-10-12 18:11:05 +02:00
D.R.racer e0d1fe3b73 Extract common ErrDisengagingIdler state's implementation 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 5eedeb0968 Remove redundant ::Color and ::Mode for LED colors and modes
makes the code shorter and more readable, no identifier clashes revealed
2021-10-12 18:11:05 +02:00
D.R.racer 53b329941f Keep constants start with lowercase letter
and remove a few warnings from the build
2021-10-12 18:11:05 +02:00
D.R.racer ac1f13672a Fix format config.h 2021-10-12 18:11:05 +02:00
3d-gussner 0bead533df clang-format 2021-10-12 18:11:05 +02:00
3d-gussner 15adeaa180 Add DEBUG_LOGIC 2021-10-12 18:11:05 +02:00
3d-gussner b8259ac555 Fix some LED status 2021-10-12 18:11:05 +02:00
3d-gussner b1f50d8789 Use constants 2021-10-12 18:11:05 +02:00
3d-gussner 645d0b55ed Use constants 2021-10-12 18:11:05 +02:00
3d-gussner c0938e41d5 Use constants 2021-10-12 18:11:05 +02:00
3d-gussner ddcf24af43 Use constants 2021-10-12 18:11:05 +02:00
3d-gussner 5c44cf9ee0 Add UnloadingToFinda 2021-10-12 18:11:05 +02:00
3d-gussner afe732d3ff Use constants 2021-10-12 18:11:05 +02:00
3d-gussner 64bd2bb894 Use constants 2021-10-12 18:11:05 +02:00
3d-gussner 2f2f4d7be3 Add some distances and put axis settings together 2021-10-12 18:11:05 +02:00
D.R.racer 1a5cd52d58 Fix some doxygen comments 2021-09-29 13:28:34 +02:00
D.R.racer 1402fb3dd6 Add 'F' and 'f' decoding + unit tests where necessary 2021-09-29 13:28:34 +02:00
D.R.racer 4900dd0222 Change FilamentSensor msg code from 'F' to 'f'
to avoid clash with Filament Type msg (which is not handled yet)
2021-09-29 13:28:34 +02:00
D.R.racer e277ca75ee Support F0 in response decoder 2021-09-29 13:28:34 +02:00
D.R.racer dc3f5764a6 Add filament sensor status reporting from printer into MMU 2021-09-29 13:28:34 +02:00
D.R.racer e59e7e3884 Make protocol decoder tolerant to leading whitespace 2021-09-29 13:28:34 +02:00
D.R.racer ee353cd98c Report "Reset finished" after MMU FW start
kudos to @leptun for this original and actually a very clean idea.

For the start we report "Reset finished" which in fact corresponds with the MMU state pretty closely
and plays nicely even with the protocol implementation.
And, since the default startup command is the noCommand, which always returns "Finished"
the implementation is clean and straightforward - the response to the first Q0 messages
will look like "X0 F" until a command (T, L, U ...) has been issued.
2021-09-29 13:28:34 +02:00
D.R.racer 89dcafbcef Add internal protocol decoding reset 2021-09-29 13:28:34 +02:00
D.R.racer 8a5614844c Add more error codes for the printer's perspective 2021-09-29 13:28:34 +02:00
D.R.racer 43c953b7f1 Fix appending newline character in puts* methods 2021-09-27 11:15:20 +02:00
D.R.racer 304988fc6c Simple debug logging via USART1
Encapsulates the #define macros and AVR implementation of dumping strings
(RAM and PROGMEM) onto USART1.
2021-09-27 11:15:20 +02:00
D.R.racer c896031a62 Merge branch 'lufa-cmake' of github.com:DRracer/Prusa-Firmware-MMU-Private into lufa-cmake 2021-09-23 13:40:34 +02:00
D.R.racer 10e08021fb Another fix format 2021-09-23 13:40:15 +02:00
Alex Voinea 77e0f56142
Merge branch 'main' into lufa-cmake 2021-09-23 04:31:11 -07:00
Alex Voinea e35ae30470
Remove some debug code 2021-09-23 14:24:07 +03:00
D.R.racer cddc16dc2e Tune USB CDC class + doc 2021-09-23 13:14:28 +02:00
D.R.racer b6d630d1c9 Clean up the code + introduce USB CDC module
... and tune some more namespaces
2021-09-23 13:06:36 +02:00
3d-gussner d3d992da5b Cheange LED modes to be consistent. 2021-09-23 10:04:50 +02:00
Alex Voinea 4f6ea16515 Functional USB reset 2021-09-20 19:01:08 +02:00
Alex Voinea 9f0f7bc33b Fix limits.h naming conflict 2021-09-20 18:18:52 +02:00
Alex Voinea 6346dd3989 USB reset initial 2021-09-20 17:31:45 +02:00
Alex Voinea 29018671b5 Reduce verbosity 2021-09-20 17:31:45 +02:00
Alex Voinea a8b1725dfe Line encoding update 2021-09-20 17:31:45 +02:00
Alex Voinea 9611db9f53 Fix formatting and 🐑 2021-09-20 17:31:45 +02:00
Alex Voinea 895671aeb2 Fix descriptors 2021-09-20 17:31:45 +02:00
Alex Voinea 26fd53251b Checkpoint 2021-09-20 17:31:45 +02:00
3d-gussner c0b776375d Fix right button issue on some hardware
My MM-control-board v0.3 has following ADC readings in DEBUG_BUTTONS
- none = 1023
- left = 169
- mid = 91-92
- right = 0

As the comparison was larger than 0 MY MMU2 right button wasn't detected.
2021-09-20 17:22:49 +02:00
D.R.racer b9811e3c21 Fix indentation 2021-09-20 17:18:46 +02:00
Alex Voinea fbe8d3d6cd Simplify logic 2021-09-20 17:10:10 +02:00
Alex Voinea 89a2bdc7e4 Fix configuration compute() math 2021-09-20 17:10:10 +02:00
Alex Voinea 0e9802c4cd watchdog configuration 2021-09-20 17:10:10 +02:00
Alex Voinea e86def99f9 Add Disable and use the avrlibc wdt functions 2021-09-20 17:09:54 +02:00
Alex Voinea 954ef2fb8d Reset the board using the cpu hal instead of the watchdog hal
Also some naming changes
2021-09-20 17:09:54 +02:00
D.R.racer 4ba6c6e679 Add handling of the X0 message (restart the MMU) via Watchdog 2021-09-20 17:09:09 +02:00
D.R.racer a23ed5e1bf Add watchdog implementation + use it in main() 2021-09-20 17:09:09 +02:00
Alex Voinea d1fd815e0c Quick and dirty workaround 2021-09-20 16:36:44 +02:00
Alex Voinea 7fe6f6c9eb Simplify logic 2021-09-20 16:28:53 +02:00
Alex Voinea cf636ec095 Fix configuration compute() math 2021-09-20 16:28:53 +02:00
Alex Voinea 06b959bb66 watchdog configuration 2021-09-20 16:28:53 +02:00
Alex Voinea a433db5648 Add Disable and use the avrlibc wdt functions 2021-09-20 16:28:42 +02:00
Alex Voinea 56eee8dcfb Reset the board using the cpu hal instead of the watchdog hal
Also some naming changes
2021-09-20 16:28:42 +02:00
D.R.racer 3b46c35595 Add handling of the X0 message (restart the MMU) via Watchdog 2021-09-20 16:28:17 +02:00
D.R.racer 324ced6807 Add watchdog implementation + use it in main() 2021-09-20 16:28:17 +02:00
Alex Voinea 82a9eaae43 Fix selector noise. IRUN=31(VS=1), MRES=x8 2021-09-16 10:30:27 +02:00
Alex Voinea bec3f73864 Fix typo
typo
2021-09-16 10:30:27 +02:00
Alex Voinea 91f622fcdc Tighter TPWMTHRS at standstill 2021-09-16 10:30:27 +02:00
Alex Voinea e0babfa4ba Updated motor currents and added freewheeling 2021-09-16 10:30:27 +02:00
Yuri D'Elia ad096c9d14 Motion: make Motion::Step finally inline 2021-09-07 15:09:49 +02:00
Yuri D'Elia b7fcfa5cb5 Add tests for single and multi-axis AbortPlannedMoves()
This introduces a new #define UNITTEST_MOTION which is used to control
the testing scenario:

- Normal tests, we allow the stub to override the built-in definition.
- For motion tests, we stub the lower-level classes and test the
  effective implementation

We also repeat the prototype of the function, which IMHO is more
readable and more flexible: we need to use inline for the real
definition, which would require even more macros otherwise.
2021-09-07 15:09:49 +02:00
D.R.racer a6800d491d Leverage the capability of aborting a move on just one axis 2021-09-07 15:03:36 +02:00
D.R.racer b1b5b9db84 Set better planned moves for homing + abort moves at StallGuard 2021-09-07 15:03:36 +02:00
D.R.racer 52a6d57704 Remove Motion::Home completely 2021-09-07 15:03:36 +02:00
D.R.racer dea41738a5 Add homing capability to Idler and Selector
MMU-73
2021-09-07 15:03:36 +02:00
Yuri D'Elia d18032b729 Motion: allow to abort movement on a single axis
This can be useful for things like faster homing in the future and comes
at no expense.
2021-09-07 14:48:06 +02:00
D.R.racer a380a698d9 Remove unnecessary #include 2021-09-07 14:17:03 +02:00
D.R.racer 3646b8b1c0 Change M0/M1 into a command
That implies changing motor's mode from SpreadCycle into StealtMode (or vice versa)
requires a stand still MMU with no other command (i.e. motor moves) being performed.
This elegantly solves the synchronization problem of TMC2130 mode change, as it results
in severe jerking while a motor is moving.

The change in protocol is minimal - M0/M1 first return `M0 A` (accepted) and another `Q0` then
returns `M0 F` (finished). The MK4 counterpart may ignore the additional report if necessary
as the mode change is done immediately (shortly after responding with `M0 A`)
2021-09-07 14:17:03 +02:00
D.R.racer 09f81f8b33 Leverage the ability of motion to SetMode to all know axes 2021-09-02 12:27:41 +02:00
D.R.racer 852ca37e8f Add stealtMode flag into the global storage hive
May be used elsewhere to return to the desired motors' mode e.g. after homing
(which requires switching to normal mode)
2021-09-02 12:27:41 +02:00
D.R.racer 1e6194a9b9 Add support for M0/M1 messages
... route the messages into modules::motion's SetMode of all axes.
2021-09-02 12:27:41 +02:00
D.R.racer 5a53acd802 Force Tool Change to load the filament if same slot but not loaded
MMU-63
2021-09-02 12:15:55 +02:00
Yuri D'Elia 6f3540a14d Fix Motion::SetMode(axis, mode) and introduce SetMode(mode)
Motion::SetMode(axis, mode) was incorrectly looping through all axes,
setting the same axis three times.

Fix this and introduce Motion::SetMode(mode) which actually loops
through all axes (see PR #110)
2021-09-02 12:04:59 +02:00
Yuri D'Elia e7cba346da Use relative paths for panic.h
Avoids adding the main directory as an include path
2021-09-02 12:00:59 +02:00
Yuri D'Elia ee8c80e5c4 Motion: Panic if queue is full
If the queue is full and a new move is queued, panic!

Introduce a new error code QUEUE_FULL to help diagnose situations where
the queue is handled improperly: likely one of the state machines not
waiting for the previous actions to finish.

PulseGen::PlanMove returns a boolean if the queue cannot be moved.
We could extend this to Motion::PlanMove, however all moves would then
have to check for this. Having a global check such as this ensures
we never ignore such situation.
2021-09-02 12:00:59 +02:00
D.R.racer ac78619b5b Cache TMC error flags inside movable_base class 2021-09-02 08:35:56 +02:00
D.R.racer 309d4704b7 Fix return value of TMC2130::Init 2021-09-02 08:35:56 +02:00
D.R.racer 161e46b09a Add unit tests for failing TMC
more stuff will follow as these situations seem to cause various issues
2021-09-02 08:35:56 +02:00
D.R.racer 1d884d9099 Make motion::QueueEmpty inline for non-UNITTEST builds 2021-09-02 08:35:56 +02:00
D.R.racer 712b67beb4 Add checking of TMC2130 error states for Idler and Selector
we shall think about the Pulley as well, it looks like it should get its
own class just like Idler and Selector as it behaves very similarly in terms
of stepping and error checking
2021-09-02 08:35:56 +02:00
D.R.racer ffe5bc2807 Make Idler and Selector only wait for their own axis
... and fix the unit tests for this
2021-09-02 08:35:56 +02:00
D.R.racer 5571e77809 Improve/fix some comments 2021-09-02 08:35:56 +02:00
D.R.racer 74629f0103 Fix reporting progress of running commands
The problem was the error state while running a command - we never used the RUNNING error state.
2021-09-02 08:35:56 +02:00
D.R.racer b4d4807971 Add globa Panic() function
The intent is to halt the firmware while retaining the reporting capabilities and blinking LEDs
2021-08-31 14:19:40 +02:00
D.R.racer dc3d8941f7 Fix formatting 2021-08-31 06:59:29 +02:00
3d-gussner 1c565ddc02 Update documentation 2021-08-31 06:59:29 +02:00
3d-gussner 59db864329 Clean up code findaADC.. 2021-08-31 06:59:29 +02:00
3d-gussner 003b2f6899 Change FINDA from ADC to digital
Fix rebase issues
2021-08-31 06:59:29 +02:00
D.R.racer 06c46b20a6 Turn off green LED after load/unload finished successfully
MMU-65
2021-08-30 17:34:46 +02:00
Yuri D'Elia e9e43f744d Correct pulley steps by experimentation
Test performed by moving 500mm of filament back&forth 5 times across 5
pulleys of a MMU2 unit.

The error with this factor is centered around +/- 1.5mm depending on the
pulley and tension on the idler.
2021-08-30 12:49:54 +02:00
Yuri D'Elia f77e426af1 Use the MK2 values for the Pulley 2021-08-30 12:49:54 +02:00
Yuri D'Elia a7d8953519 Fix stepsPerUnit for the Pulley
Also use the correct value multiplied by the current ustep resolution to
make the conversion obvious.
2021-08-30 12:49:54 +02:00
Yuri D'Elia bc36ea4566 PulseGen: fix speed types in functions
Type was incorrectly changed in the last commit while debugging
2021-08-30 12:49:34 +02:00
Yuri D'Elia 04631677cc Motion/PulseGen: implement move chaining and end-speed control
Allow to chain moves by adding one extra parameter to the PlanMove[to]
functions: ending speed.

A move will always be accelerated from the last speed towards end ending
speed. The following:

  PlanMove(100._mm, 50._mm_s, 50._mm_s);
  PlanMove(200._mm, 100._mm_s);

Will first move the axis 100mm, accelerating towards 50mm/s, then
accelerate again to 100mm/s. The move will for then decelerate towards a
full stop after reaching 300mm in total.

Acceleration can be changed for each segment, so that a custom
acceleration curve can be created:

  SetAcceleration(10._mm_s2);
  PlanMove(100._mm, 50._mm_s, 50._mm_s);
  SetAcceleration(100._mm_s2);
  PlanMove(100._mm, 50._mm_s, 50._mm_s);

The ending speed might not always be reached, depending on the current
acceleration settings. The new function "Rate()" will return the ending
feedrate of the last move, if necessary.

AbortPlannedMoves accepts a new "halt" parameter to control how moves
will be chanined when interrupting the current move. By default
(halt=true) the move is completely interrupted.

When halt=false is requested, a subsequent move will be chained starting
at the currently aborted velocity. This allows to chain moves in reponse
to events, for example to accelerate the pulley without stopping as soon
as the FINDA is triggered, it's sufficient to interrupt the current move
followed by a new one:

  PlanMove(maximum_loading_lenght, slow_feedrate);
  ... wait for PINDA trigger ...
  AbortPlannedMoves(true);
  PlanMove(bowden_lenght, fast_feedrate);

will seamlessy continue loading and transition to the fast feedrate.

Jerk control has been simplified. It now handles only the maximal
velocity change of the last segment, which doesn't require reverse
planning.
2021-08-30 12:49:34 +02:00
Yuri D'Elia d55e01bb58 Motion/PulseGen: allow to abort a move for chaining
Add a new parameter "halt" (default to true) to control the stopping
behavior:

- halt=true: no subsequent moves will be planned, motions stops abruptly
- half=false: a new move will be chained after the current one
2021-08-30 12:49:34 +02:00
Yuri D'Elia d18143dff2 PulseGen: store/return the last segment speed 2021-08-30 12:49:34 +02:00
Yuri D'Elia 60c83b0af2 Allow to set axis acceleration with AxisUnit and physical units 2021-08-30 12:49:34 +02:00
Yuri D'Elia 563c8192cd Update motor currents
Use the same values from the original FW as suggested by @leptun
2021-08-30 07:12:24 +02:00
Yuri D'Elia bcf818b8fd Silence motion::Isr() unused variable warning
Move motion.Step() directly inside the __AVR__ code, silencing an unused
variable warning.

Calling motion.Step() without getting or setting the timer is not useful
anyway.
2021-08-30 07:11:29 +02:00
Yuri D'Elia 9c3b31756e Optimize timer multiplexing and increase stepTimerQuantum
Avoid calling PulseGen::Step() on idle axes by checking for a non-zero
queue size (which is more efficient to compute).

Increase stepTimerQuantum to 128us to ensure acceleration can be
computed in realtime for 3 axes at the same time.

Fix the logic of the static assertion, which was flipped: we need to
create slices larger than the maximal step frequency in order to ensure
no axis is starved while moving.
2021-08-30 07:10:54 +02:00
Yuri D'Elia d23ed53f3c Also fix min/max outside of AVR by using the standard std::min/max 2021-08-30 07:07:19 +02:00
Yuri D'Elia b55c13dec2 Use operators for min/max
Turns out AVR doesn't have __builtin_min/max
2021-08-30 07:07:19 +02:00
Yuri D'Elia 1f2662518b Fix gpio::TogglePin on AVR
TogglePin was incorrectly using the PINx pin for toggling, causing the
current pins (in addition to the requested ones) to be toggled, causing
stepping havoc.
2021-08-30 07:06:28 +02:00
D.R.racer a58450acb6 Extract feedrates of Idler and Selector into config.h 2021-08-27 15:31:20 +02:00
Yuri D'Elia c7f3fae266 Implement an initial Motion ISR for AVR
This is a tentative/crude implementation of an Init and ISR for the MMU
in order to check the motion API.

We remove the "extern void Isr", declaring it "static inline" instead.
We need to inline the ISR here in order to avoid the function call.

Include the missing speed_table data in the executable. This bumps the
code size to ~60% of the flash.

Implemement motion::Init to setup the ISR and timers, and replace the
call in main from tmc::Init to motion::Init. Motion will init each
driver every time the axis is enabled, so there should be no need for
a global module initialization (we need SPI, but this is initialized
earlier on by it's own module anyway).

The timer is currently setup without any HAL or proper TIMER1 wrapper.
This is to be improved later.

The real MMU unit seems to slow down quite a bit during acceleration.
At this point we need to inline some methods in PulseGen to avoid
overhead, however this breaks the stubs.
2021-08-27 10:13:23 +02:00
Yuri D'Elia 288e74283d Introduce config::MRes and fix (real) axis units
The parameter config::AxisConfig::uSteps was supposed to be
microstepping resolution, but it's instead being used as the driver's
MRES directly.

To avoid a runtime conversion, rename the field to mRes and define a new
enum listing all the possible (and valid) microstepping resolutions.

This simplifies the code and makes clear the stepsPerUnit scale.

Assign correct stepsPerUnit to all axes as a result, including working
limits.
2021-08-25 09:16:56 +02:00
Yuri D'Elia f7f0df4afa Move hal/avr/tmc2130 into hal/ directly
There are no dependencies on AVR in TMC2130, so move into the main tree
2021-08-25 07:57:19 +02:00
Yuri D'Elia 0548c17078 Motion: test low-level enable changes via GPIO stub
This fixes the driver's enable/disable incorrectly setting the direction
bit instead.
2021-08-25 07:57:19 +02:00
Yuri D'Elia 9a93ebecfc Motion: add tests for the axis autoenable
Add Motion::Enabled() to get the current axis enablement status.
2021-08-25 07:57:19 +02:00
Alex Voinea fc2fce1230 Even more shr16 documentation 2021-08-23 08:18:47 +02:00
Alex Voinea 55ac3d5c32 Update documentation 2021-08-23 08:18:47 +02:00
Alex Voinea 2144a3f440 Swap led direction 2021-08-23 08:18:47 +02:00
Alex Voinea 8766642a21 Turn off all LEDs after Init 2021-08-23 08:18:47 +02:00
Yuri D'Elia a6780d2224 Correct motor pins 2021-08-23 08:16:15 +02:00
D.R.racer 492208d25a Improve documentation of the startup process 2021-08-12 11:08:09 +02:00
D.R.racer f0b8cc9895 Fix encoding of Query responses for high numbers of errors
+ improve unit tests directly for the enumerated errors in logic/error_codes.h
2021-08-12 10:55:27 +02:00
D.R.racer a982381728 Only start a new command if the previous one finished
... that means with or without an error
and remember the Command's request message - to identify the responses
2021-08-12 10:30:40 +02:00
D.R.racer ccefe32ba1 Reset the error code for reusal of logic state machines 2021-08-12 10:30:40 +02:00
D.R.racer 9ba116e06e Handle slot indices out of range correctly at top level
Besides Unload Filament, which only operates on active slot, all other
top level state machines check the validity of the command's parameter.
If the parameter is out of range for available slots, they return
ErrorCode::INVALID_TOOL now.
2021-08-12 10:30:40 +02:00
D.R.racer c14c79f3ac Do not blink the left LED on start 2021-08-11 10:33:32 +02:00
D.R.racer 2c94e76ca9 Allow configurable LED's blinking period 2021-08-04 11:40:02 +02:00
D.R.racer 2f5dff6c5b Introduce short namespace aliases
especially for modules
2021-08-04 11:03:56 +02:00
Alex Voinea 9232e55563 millis interrupt 2021-08-04 10:51:33 +02:00
D.R.racer 2062a604d8 Improve unit computation
based on #76 which added a possibility to perform arithmetic operations
on unit-based quantities
2021-08-02 10:52:18 +02:00
D.R.racer aa5995368d Update to latest main + fix unit tests
... in relation to the newly introduced stepping in physical units rather than in steps
2021-08-02 10:52:18 +02:00