Commit Graph

531 Commits (2ab3b96542e540ae607b4bfe695ad5718c9aa6b2)

Author SHA1 Message Date
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
D.R.racer 16dc129b49 Set real slot positions for the Idler and Selector
Extracted from the previous FW, may need some tuning based on units selected
for each of these axes (degrees, millimeters) - waiting for an update
of the motion implementation.

Updated starting conditions of the unit tests to reflect the global configuration.

MMU-58
2021-08-02 10:52:18 +02:00
D.R.racer ef96d998a3 Link top level error reporting to TMC2130 error flags 2021-08-02 07:45:45 +02:00
D.R.racer 7029b1b03d Reformat config.h after rebase 2021-08-02 07:45:45 +02:00
D.R.racer d94ad8b90e Merge coil errors, fix bit masks 2021-08-02 07:45:45 +02:00
D.R.racer f7c3d0b479 Fix axis bit masks 2021-08-02 07:45:45 +02:00
D.R.racer 751ee46450 Add bit masks for error codes for the TMC drivers
+ add common error handling for idler and selector
+ improve error handling in command_base
+ rename ERR1xxxx errors to ERRxxxx (remove the '1')
2021-08-02 07:45:45 +02:00
D.R.racer df2c1ba7fe Add prototype of unified handling of HW errors in the logic layer 2021-08-02 07:45:45 +02:00
D.R.racer f5df642eb5 Improve error codes
- Distinguish among FINDA on/off failuje
- The same applies to newly introduced Filament sensor errors
- Add TMC init error
- Add a communication error ID - to be used on the printer
2021-08-02 07:45:45 +02:00
Yuri D'Elia 7dcd4975e1 Allow units to be scaled by an unitless quantity
This allows Unit<> and AxisUnit<> to be scaled with a fraction as
expected, promoting the scaler to the same unit:

  0.2_mm * 10 => 2_mm (mm*f => mm)

Multiplication type is commutative:

  10 * 0.2_mm => 2_mm (f*mm => mm)

Division isn't:

  0.2_mm / 10 => 0.02_mm (mm*1/f => mm)
  10 / 0.2_mm => error (illegal type conversion)
2021-08-02 07:41:26 +02:00
D.R.racer fae7dead93 20 bits for coostep thr 2021-07-29 10:01:33 +02:00
D.R.racer b61836dd57 Remove shifting in config for TMC + add compile-time checks 2021-07-29 10:01:33 +02:00
D.R.racer a8147be803 Fix unit tests + rebase onto main + extract TMC parameters into config 2021-07-29 10:01:33 +02:00
Alex Voinea aca2cb7e79 tmc: Error flags 2021-07-29 10:01:33 +02:00
Alex Voinea 8577852b09 tmc2130: Stallguard and Isr 2021-07-29 10:01:33 +02:00
D.R.racer 3d1880c006 Make tests compile
Introduces a nasty hack to forcefully write into the constexpr SPI descriptor's registers
(which is the correct way in ASM, but kind of cumbersome in C++ now)
2021-07-29 10:01:33 +02:00
Alex Voinea 364f1bcb0d tmc2130: error handling stack overflow fix 2021-07-29 10:01:33 +02:00
Alex Voinea d071a6abf6 TMC pin map 2021-07-29 10:01:33 +02:00
Alex Voinea 2cdc3bfbc4 tmc2130: report error during init 2021-07-29 10:01:33 +02:00
Alex Voinea 3f20ff88ee Reorder functions 2021-07-29 10:01:33 +02:00
Alex Voinea b97aefcb5c tmc2130: More functions 2021-07-29 10:01:33 +02:00
Alex Voinea 129a89cf07 Fix stall detection polarity 2021-07-29 10:01:33 +02:00
Alex Voinea 5f83667b22 Finish init sequence 2021-07-29 10:01:33 +02:00
Alex Voinea e9046eed42 tmc2130: More init 2021-07-29 10:01:33 +02:00
Alex Voinea 1022603f9d tmc2130: Initial spi communication 2021-07-29 10:01:33 +02:00
Alex Voinea e2ba71fc03 tmc2130: Define the SPI bus for the tmc drivers 2021-07-29 10:01:33 +02:00
Alex Voinea d484685e02 tmc2130: Registers 2021-07-29 10:01:33 +02:00
DRracer 151a672f56
Merge pull request #71 from wavexx/motion_units
Motion units
2021-07-27 06:34:32 +02:00
D.R.racer 7f39f07679 Avoid repeated Enable/Disable on an axis if already in desired state 2021-07-27 06:25:01 +02:00
Yuri D'Elia 1abc8713bb Fix ejectLength typo 2021-07-26 11:22:40 +02:00
DRracer dc36afb82c
Merge branch 'main' into motion_units 2021-07-26 09:35:13 +02:00
D.R.racer 8a1df52d79 Add support for reporting MMU errors via S3 msg 2021-07-26 09:34:40 +02:00
D.R.racer 6af65bc4c8 Rename ISR -> Isr to avoid clash with AVR libc ISR #define 2021-07-26 09:34:24 +02:00
D.R.racer 1f7a84a623 Support CR XOR LF in protocol's line ending implementation
Please note Windows CRLF sequence is not supported,
but a separate CR xor a separate LF works now.

This is a workaround for stupid terminals for debugging purposes,
and it is not necessary for the protocol to work on its own.
It may be removed in the future.
2021-07-26 09:34:02 +02:00
Alex Voinea b109a520c2 buttons: Fix comment 2021-07-26 06:49:05 +02:00
Yuri D'Elia 5928ade6be Improve motion::unitToAxisUnit template parameter names 2021-07-26 01:28:29 +02:00
Yuri D'Elia 051bce9098 Nicely format doxygen documentation 2021-07-25 23:50:01 +02:00
Yuri D'Elia d955897829 Convert config::selectorSlotPositions to physical units 2021-07-25 23:13:28 +02:00
Yuri D'Elia 6daf7fd060 Convert config::idlerSlotPositions to physical units 2021-07-25 22:39:18 +02:00
Yuri D'Elia b133c8b975 Simplify and enhance unit conversion
- Move unit/step conversion to modules/axisunit.h
- Unify motion::unitToAxisUnit<> and motion::unitToSteps<>,
  making conversion in other modules just as easy as motion.
- Improve the documentation
2021-07-25 22:25:48 +02:00
Yuri D'Elia 187858d228 Move config/unit.h to unit.h and it's own namespace 2021-07-25 22:14:56 +02:00
Yuri D'Elia 49275b2cb2 Update eject_steps with the new unit API for demonstration 2021-07-25 17:25:37 +02:00
Yuri D'Elia 402a2b91ce Define Motion::PlanMove/PlanMoveTo as constexpr 2021-07-25 17:08:15 +02:00
Yuri D'Elia 888cdf7cd5 Introduce compile-time axis unit type checks and conversions
Introduces:

- config::Unit: base class for physical quantities
- motion::AxisUnit: type-checked steps type

"config/unit.h" defines basic physical quantities, which are not
normally used elsewhere besides config.h.

"modules/axisunit.h" extends the modules::motion namespace with
Axis-aware units, with one type per axis per unit.

P_pos_t defines step positions for the pulley, I_pos_t for the idler,
etc. These are defined through the literar operators which are
similarly named and automatically convert a physical quantity to an
AxisUnit at compile time:

P_pos_t pulley_pos = 10.0_P_mm;

Besides type-checking, AxisUnit are otherwise identical to raw step
counts and are intended to be used along with the updated Motion API.

PlanMove/PlanMoveTo has been extended to support moves using these units
or physical quantities. Again, conversion is performed at compile time.
2021-07-25 16:39:54 +02:00
Yuri D'Elia 5e04d4ccaf Add getters/setters for Jerk in Motion/PulseGen
This allows us to make tests that expect jerk to be the same across two
axes, even if they're statically configured differently.
2021-07-25 01:24:40 +02:00
Yuri D'Elia 606b22a9ad Make Motion::Acceleration const 2021-07-25 01:17:25 +02:00
D.R.racer 777c830ac0 Add error handling and reporting documentation
and fix links from the main.dox page
2021-07-21 14:50:23 +02:00
D.R.racer 9d2f8b2b39 Fix indentation once again
please use the pre-commit script to solve indentation
2021-07-19 06:25:09 +02:00
D.R.racer 0744009955 Fix FW build - define (empty) TMC2130::Init 2021-07-14 09:00:40 +02:00
DRracer 52e3c3375a
Merge pull request #47 from wavexx/motion_wip
WIP: Motion API
2021-07-14 08:26:49 +02:00
Yuri D'Elia 4160d019be Motion: implement InitAxis 2021-07-13 20:44:09 +02:00
Yuri D'Elia 8f0732a0cc Motion: initial StallGuard support
Add the code in the right position to sample StallGuard and set/reset
the trigger flag.
2021-07-13 20:36:43 +02:00
Yuri D'Elia eec95d6fb7 Motion: add assertions for stepTimerQuantum 2021-07-13 19:40:00 +02:00
Yuri D'Elia 324fb92fd5 Motion: implement timer multiplexing 2021-07-13 19:21:13 +02:00
D.R.racer c81072d1d5 Add sending of response messages 2021-07-13 17:53:31 +02:00
Yuri D'Elia d0581bf494 Motion: Add more methods and tests
- Add SetPosition/CurPosition (not only) for testing
- Implement some real tests
2021-07-13 17:43:50 +02:00
Yuri D'Elia 18ced44341 Merge remote-tracking branch 'upstream/main' into motion_wip 2021-07-13 15:31:31 +02:00
Yuri D'Elia d9d769721f hal/cpu: reformat 2021-07-13 15:24:43 +02:00
Yuri D'Elia c7459df05e PulseGen: improve comments. 2021-07-13 15:10:47 +02:00
Yuri D'Elia fcb1b0c85d cmath.h: convert AVR min/max/abs into templates
At least for min/max this will ensure types for both arguments are the
same.

This should be a little bit closer to the <cmath> definition that
simply overloads these functions instead.
2021-07-13 01:08:33 +02:00
Yuri D'Elia 98845008aa Rename Motion::CurrentPos to Position()
This matches PulseGen::Position() and avoids confusion around the term
"current": Position() returns the head position in the queue, not the
"live" axis position.

We have PulseGen::CurPosition() now for this purpose, although we don't
expose it to Motion yet.
2021-07-13 01:03:03 +02:00
Yuri D'Elia 9bb1bf4a53 PulseGen: typos in comments 2021-07-13 00:54:03 +02:00
Yuri D'Elia 16e7f62aee PulseGen: introduce CurPosition() for testing
CurPosition() returns the live axis position, which in this
implementation is inherently expensive to compute.

This shouldn't be required for the MMU, but it /will/ come in handy to
check for the axis position/s in Motion tests.
2021-07-13 00:48:44 +02:00
Alex Voinea edf0804fd8 Fix Buttons ADC range 2021-07-12 16:55:37 +02:00
Alex Voinea d44de216a9 Fix ADC channels 2021-07-12 16:55:37 +02:00
Alex Voinea 4281e89e5d HAL adc 2021-07-12 16:55:37 +02:00
Yuri D'Elia be9296281f Make Read/Write/Toggle pin functional for testing
Make ReadPin return the last value set by WritePin for proper testing.

Add a slow-path to TogglePin that goes through a read-write cycle. This
is useful both for testing and for platforms that don't have an
efficient toggle like AVR.
2021-07-12 11:25:04 +02:00
Yuri D'Elia 151f030318 Fix return value of gpio::ReadPin
The cast to Level is incorrect, since the expression returns either 0 or
a positive value if the pin is set. The value is directly assigned to
the underlying uint8_t, meaning that Level::high won't match for levels
greater than 0.

Return a boolean and cast that to Level instead.
2021-07-12 11:25:04 +02:00
Yuri D'Elia 787c73ecff Merge remote-tracking branch 'upstream/main' into motion_wip 2021-07-12 10:25:06 +02:00
Yuri D'Elia 9b0dd2d633 Motion: fix new Step() prototype 2021-07-12 09:58:53 +02:00
Alan Dragomirecký 09819cb1aa Split the main CMakeLists.txt into more files within subdirectories 2021-07-12 09:09:21 +02:00
Yuri D'Elia b3f3f0538e Shim <limits> on AVR
Instead of adding #ifdefs for missing headers, create a shim that can be
included everywhere.

"limits.h" includes a bare-bone implementation of numeric_limits (to be
extended as needed).
2021-07-12 09:02:05 +02:00
Yuri D'Elia e53a91d563 Implement more methods in Motion, remove Motion::Full()
Motion::Full() (without a specific axis) is counter-productive.

When planning new moves the axis needs to be known beforehand, so it
might be as well be given to Full() to check the proper queue.
2021-07-11 22:07:23 +02:00
Yuri D'Elia 7337e97765 Rename Motion::DisableAxis to Disable
Implement Motion::SetEnabled (for symmetry with TMC2130::SetEnabled).

Rename DisableAxis to Disable and use the new SetEnabled. This makes the
member names more consistent.
2021-07-11 21:38:01 +02:00
Yuri D'Elia 066aab7adc Move cpuFrequencyDivider to config::stepTimerFrequencyDivider 2021-07-11 21:17:08 +02:00
Yuri D'Elia b01a819644 Make Read/Write/Toggle pin functional for testing
Make ReadPin return the last value set by WritePin for proper testing.

Add a slow-path to TogglePin that goes through a read-write cycle. This
is useful both for testing and for platforms that don't have an
efficient toggle like AVR.
2021-07-11 20:25:52 +02:00
Yuri D'Elia 32e09afd4c Fix return value of gpio::ReadPin
The cast to Level is incorrect, since the expression returns either 0 or
a positive value if the pin is set. The value is directly assigned to
the underlying uint8_t, meaning that Level::high won't match for levels
greater than 0.

Return a boolean and cast that to Level instead.
2021-07-11 20:23:21 +02:00
Yuri D'Elia 1ff9b81630 Rename PulseGen::Move to PlanMoveTo
Make Motion and PulseGen intentionally very similar.
2021-07-07 16:59:40 +02:00
Yuri D'Elia be30314634 Motion: initialize axes in the same order as the enumeration 2021-07-07 16:59:40 +02:00
Yuri D'Elia 2875e61484 Motion: allow to query the buffer per-axis
We might want to schedule new moves while a single motor is moving.
Allow to do that by introducing per-axis query functions.

The main QueueEmpty() and Full() still function as before:

- Call QueueEmpty() to wait for all moves to finish.
- Use !Full() to know that a Plan() move will never be discarded.
2021-07-07 16:59:40 +02:00
Yuri D'Elia 94f11642e0 PulseGen: perform an extra queue check in Move()
Since scheduling a move on a block which is being executed will jolt the
motors, be extra-safe and perform an extra lower-level check before
committing even if the caller is responsible.

Return the status, which can be useful to build a simple busy loop.
2021-07-07 16:59:40 +02:00
Yuri D'Elia bd8ae62211 PulseGen: cleanup AxisData initialization 2021-07-07 16:59:40 +02:00
Yuri D'Elia d87db1ff76 Revised WIP for the Motion API
- Remove the combined PlanMove(a,b,c,rate) call. If we allow the units
  of the various motors to be changed at compile time, the unit of
  rate can vary between axes.
- Build PlanMove on top of the absolute PlanMoveTo.
- Add required stubs for TMC2130.
- Allow each axis mode to be set independently, since we have this
  feature for free anyway.
- Rework internals to use PulseGen data types and structs.
2021-07-07 16:59:39 +02:00
Yuri D'Elia d7874d5336 PulseGen: implement AbortPlannedMoves 2021-07-07 16:59:04 +02:00
Yuri D'Elia 44a263d334 PulseGen: move Step() to header for inlining 2021-07-07 16:59:04 +02:00
Yuri D'Elia 6f518f1ed2 PulseGen: complete implementation 2021-07-07 16:59:04 +02:00
Yuri D'Elia ed04bd02e2 PulseGen/speed_tables: cleanup constants 2021-07-07 16:59:04 +02:00
Yuri D'Elia 006dfd4abc PulseGen: remove all floating point calculations
Work in steps, steps/s, steps/s2 directly.
2021-07-07 16:59:04 +02:00
Yuri D'Elia cf5be5aade PulseGen: initial version of the ramp/pulse generator 2021-07-07 16:59:04 +02:00
Yuri D'Elia 7d2329cf85 Add src/cmath.h for <math.h> portability between platforms 2021-07-07 16:59:04 +02:00
Yuri D'Elia de88ed4c6b Add initial Axis configuration static structs 2021-07-07 16:59:04 +02:00
Yuri D'Elia ef7c776461 Update Motion for the new TMC2130/pins definitions 2021-07-07 16:59:04 +02:00
Yuri D'Elia 531f60ed27 Add modules::speed_table for acceleration lookup tables 2021-07-07 16:59:04 +02:00
Yuri D'Elia 1d6736cff6 Add modules::math for specialized math functions
Currently include reduced-precision 8x16 and 16x16 multiplication
functions used by the speed lookup tables.
2021-07-07 16:59:04 +02:00
Alan Dragomirecký 9448c04b36 Disable preprocessor code indentation 2021-07-07 16:33:03 +02:00
Yuri D'Elia f95c47638d CircularIndex: fight against type promotion in size checks
To generate optimal code, size itself needs to be of the same type as
the index to avoid promotion to the largest type.

In full(), wrap the subtraction explicity in another type cast to avoid
another automatic type promotion.
2021-07-06 12:51:56 +02:00
Yuri D'Elia f57a1c3b17 CircularIndex: add static checks for index/size limits
The empty/full distinction fails to work if size matches the number of
representable positions for the index type.

Add a static check to ensure this invariant is met where possible.
2021-07-06 12:51:56 +02:00
Yuri D'Elia 4362d77083 CircularIndex: alternate index management for full capacity
Comparing head/tail indexes cannot distinguish between empty/full cases,
so we end up wasting one item in the circular buffer. This also limits
the smallest and efficient size choice to be 4.

If the circular buffer is large, there's no issue, however for the
motion planner the block size is significant, and I was planning to use
exactly a ring buffer of two: one busy block, plus one planned.

Modify the indexer to store the internal "index" (aka cursor) pointer to
be one extra bit deeper than the final index. Comparing the underlying
cursor allow to distinguish the empty/full case due to the extra bit,
while producing the final index requires simple masking.

This is just as efficient if the size is a power of two with
2-complement wrap-around logic, which is the optimized case. However
the implementation also works for non-power-of-two sizes.

Add tests for more failure cases in the CircularBuffer which is built on
top.

(tecnique described in the Art of Computer Programming by Knuth)
2021-07-06 12:51:56 +02:00
Yuri D'Elia 477539c791 Split CircularBuffer into CircularIndex+CircularBuffer
Allow the lower-level index to be used without an actual container by
splitting off the index management into CircularIndex.

Rebuild CircularBuffer using CircularIndex itself.
2021-07-06 12:51:56 +02:00
D.R.racer 43a423f299 Change buttons' ADC limits into an array
as proposed by @vintagePC

cleaned-up some of the unit tests by this change
2021-07-05 18:07:54 +02:00
D.R.racer 552fec9abf Parametrize Idler and Selector in common config.h 2021-07-05 18:07:54 +02:00
D.R.racer ccda84df80 Make buttons' ADC decision levels "inclusive"
especially because of the zero level, which is very likely to be a valid button0 level
2021-07-05 18:07:54 +02:00
D.R.racer b484eeacb6 Start using config.h
Added some constexpr vars for buttons, finda, fsensor and
applied them in the FW and unit tests accordingly.
2021-07-05 18:07:54 +02:00
Yuri D'Elia dd5c036d38 GPIO: reformat affected files 2021-07-05 15:20:11 +02:00
Yuri D'Elia 3ccfc3adfb GPIO: correctly stub known ports
- Use the correct port name in the #define
- Fully qualify all references
2021-07-05 15:20:11 +02:00
Yuri D'Elia 32b2ec7f8d Remove GPIOI 2021-07-05 15:20:11 +02:00
Yuri D'Elia 067deb7e55 Completely remove PIN macros 2021-07-05 15:20:11 +02:00
Yuri D'Elia 7c7aa95445 Mock GPIO when building tests
Add some conditional statements in gpio.h so that we can mock the GPIO
registers when building tests.
2021-07-05 15:20:11 +02:00
Yuri D'Elia 169665331e Change the pin definitions in order to be valid types
Remove the constructor from GPIO_pin so that we can use brace
initialization at compile time.

Rewrite the contents of pins.h to construct GPIO_pin types directly by
the use of a simple preprocessor macro.

Makes the code type-check and easier to read/extend.
2021-07-05 15:20:11 +02:00
Yuri D'Elia e9627ad0d4 TMC2130: Reformat 2021-07-05 13:34:08 +02:00
Yuri D'Elia f491072614 TMC2130: Make stepping methods static
To keep these methods efficient no member should be accessed away.
That's the reason MotorParams is passed explicitly for each.

Mark all stepping methods as static.
2021-07-05 13:34:08 +02:00
Yuri D'Elia 28c9e55a79 Add vSense to MotorCurrents 2021-07-05 13:34:08 +02:00
Yuri D'Elia c78ed77ccc Revise the TMC2130 interface for stepping
Change the TMC2130 class after starting to review the Motion API.
Move motor mode handling and stepping to this module.

Create a new MotorParams class for compile-time settings (currently
pins, direction, microstepping).

Keep other settings separate, so that we can pass constexpr expressions
while stepping and still get 1 instruction without overhead.
2021-07-05 13:34:08 +02:00
Yuri D'Elia ea8b335f8d progmem: fix for AVR
- Fix header name
- Rename pgm_read_word to read_word since pgm_read_word is a macro
  and cannot be scoped
2021-07-05 13:33:49 +02:00
Yuri D'Elia a9937b94e2 Add initial AVR PROGMEM abstraction in hal::progmem 2021-07-05 13:33:49 +02:00
D.R.racer 9efb127acb Explain and fix the LED states while cutting filament
now the test is correct including LEDs
2021-07-01 08:12:47 +02:00
D.R.racer 974c1ba6db Verify Cut filament state machine + update unit tests 2021-07-01 07:03:39 +02:00
vintagepc e2ec745286
Simple config header with example (#39)
Simple config header with example
2021-07-01 06:47:40 +02:00
Yuri D'Elia ab01413116 Call LED::Step() correctly 2021-06-30 12:39:03 +02:00