Commit Graph

294 Commits (cbada468be9304ec877198963e3c4555e244db1b)

Author SHA1 Message Date
Guðni Már Gilbert cbada468be
Merge 3e68bb41e3 into 48d4d920be 2025-12-02 10:11:37 +01:00
D.R.racer b2dd038814 LEDs: unify common app-logic behavior into functions
In the entire code base, we basically use 4 LED scenarios:
- all off
- active slot green on
- active slot green blinking
- active slot red blinking

Compacting this behaviour into 4 functions saves in total ~140B - which is huge.
It's not an entirely clean solution, LEDs should not know anything about globals::ActiveSlot, but the savings are more important.
Ideally, such an optimization could have been done by the compiler.
2025-12-01 10:48:28 +01:00
D.R.racer f4388b8d20 ToolChange: don't disengage Idler after unload, but engage next slot immediately 2025-12-01 10:48:28 +01:00
Guðni Már Gilbert b6bdd55def pulley: HomeBack state is never used
Also remove unused FinishHomingAndPlanMoveToParkPos.
2025-12-01 08:52:47 +01:00
Guðni Már Gilbert 3e68bb41e3 idler/selector: simplify init
The homing is always invalidated in all cases. Let's simply invalidate
the homing only in the init method. The state machine's Ready state then
decides when it is OK to perform the homing move.

We shouldn't need to guess the axis's position, and should assume its not correct. Currently the init methods are only called during the boot up sequence.

Change in memory:
Flash: -126 bytes
SRAM: 0 bytes
2025-11-30 09:43:18 +00:00
Alex Voinea 5e50516fe7 Use single banks for CDC 2025-10-30 07:45:38 +01:00
Alex Voinea 454619bfd4 USB manual PLL control 2025-10-30 07:45:38 +01:00
Guðni Már Gilbert f240bb24d1 idler: adjust distance threshold
Before, the axis limits had an error of 25° so 225° would actually be measured as 250°.

Now after fixing axisUnitToTruncatedUnit to return a more accurate value, the new values are lower. Adjust the distances by 20° to offset previous error.
2025-10-30 07:43:35 +01:00
Guðni Már Gilbert 4e4e2df739 Improve accuracy in axisUnitToTruncatedUnit
When converting 800mm/s2, it would be truncated to 795mm/s2 for the pulley. This is due to cutting out significant decimal digits.

Instead let's multiply in floating point, this needs quite a bit of resources. So to optimise against this, multiply with the recoprical. Then the cost is not more than 20 bytes.

Testing:
M707 A0x0e; Read Pulley Acceleration (default at boot up is 800mm/s2)
M708 A0x0e X790 ; Set Pulley Acceleration to 790mm/s2
M707 A0x0e; Read Pulley Acceleration (should be 790mm/s2)

The results before this commit:

M707 A0x0e -> returns 805
M708 A0x0e X790 ; Set Pulley Acceleration to 790mm/s2
M707 A0x0e; returns 795

After this commit:

M707 A0x0e -> returns 799
M708 A0x0e X790 ; Set Pulley Acceleration to 790mm/s2
M707 A0x0e; returns 789

NOTE:
axisUnitToTruncatedUnit is used in Idler homing, selector homing, and pulley positioning. I am not sure yet how this improvement will affect those areas.
2025-10-30 07:43:35 +01:00
Guðni Már Gilbert dc68b70cff idler: reduce duplicate code
Change in memory:
Flash: 54 bytes
SRAM: 0 bytes
2025-01-02 11:30:35 +01:00
Guðni Már Gilbert 4ab07d627a optimisation: compare uint16_t against uint16_t
AxisDistance returns uint16_t type and is currently compared with long double axis length. The axis lengths fit easily into uint16_t:

selectorLimits.lenght = 75
idlerLimits.lenght = 225

Change in memory:
Flash: -122 bytes
SRAM: 0 bytes
2024-12-24 13:44:55 +00:00
Guðni Már Gilbert 0a205e41ff optimisation: set enum types explictly to uint8_t
This commit produces the same savings as the compiler options -fshort-enums. Except by setting the types manually we save also 2 bytes of SRAM.

By default, the enum type is 2 bytes, with we can explictly set it to one byte when applicable to reduce code size.

Almost all the savings from from 'enum Mode' in leds.h.

Change in memory:
Flash: -116 bytes
SRAM: -2 bytes
2024-12-24 13:39:41 +00:00
D.R.racer 19a0cd3ebb Add cutLength register (0x23) 2023-11-03 14:19:27 +01:00
3d-gussner c90db080e5 Update to MMU3 2023-08-22 16:11:10 +02:00
D.R.racer fbda9faa2a Set maximum bowden length to 1m 2023-08-10 16:08:07 +02:00
D.R.racer 41f5d29083 Set correct default bowden length 2023-08-10 16:08:07 +02:00
D.R.racer 3a105cab4a Introduce bowden length RW register (no runtime autotune)
contains updated unit tests
2023-08-10 16:08:07 +02:00
Guðni Már Gilbert c096725674 modules: leds: Implement SetAllOff()
A helper function which turns of all LEDs
reduces code size :)

Change in memory:
Flash: -64 bytes
SRAM: 0 bytes
2023-05-02 07:32:27 +02:00
D.R.racer f07e206398 Hold/Resume Idler+Selector even after their homing errors
MMU-222
2023-03-14 18:14:02 +01:00
D.R.racer f0a633b4b6 Ignore Idler's SG signal from TMC when rolling over filaments 2023-03-14 17:58:11 +01:00
D.R.racer b97b7561c6 Ignoring the diag pin (stallguard) completely in specified range
This seems to greatly improve overall homing reliability of Idler on MMUs which couldn't home with inserted filaments at all.
The only downside is the fact, that we may actually "home" a blocked Idler correctly.
2023-03-14 17:58:11 +01:00
D.R.racer 95915cb080 Prototype adaptive Idler homing sg_thrs
Needs to be tweaked further to make it a production code.
But my primary concern now is the fact that it doesn't seem to help too much while homing over the too-tightened Idler cover.
2023-03-14 17:58:11 +01:00
D.R.racer 98ef2368a0 Rename CurrentVCC->CurrentBandgapVoltage
and tune surrounding comments
2023-03-08 15:14:36 +01:00
D.R.racer 314233b37f Add runtime VCC measurement as register
- extract logic of undervoltage handling into main.cpp
- fix unit tests
- bump version to 2.1.9 (new register)
2023-03-08 15:14:36 +01:00
Alex Voinea 23a9978980 VCC undervoltage check module 2023-03-08 15:14:36 +01:00
D.R.racer 8b55b25028 Allow cutting current >31
Needs reinitialization of the axis (Selector) because the TMC driver needs to set another register to double the current level.
2023-03-07 21:07:52 +01:00
D.R.racer 9b43b61939 Idler+Selector homing speeds: writeable registers 2023-03-02 19:54:50 +01:00
D.R.racer d2a2014b89 Cleanup HoldOn-Resume code in movables 2023-03-02 12:20:06 +01:00
D.R.racer ea41fd6b83 Update unit tests 2023-03-02 12:20:06 +01:00
D.R.racer d75119c8d6 Suspend all moves of Idler and Selector when entering an Error screen 2023-03-02 12:20:06 +01:00
D.R.racer 7e2375deee Introduce TMC2130 currents doxy group
and clean-up doxygen warnings a bit
2023-02-17 15:50:20 +01:00
D.R.racer 88a489e3cb Add runtime iHold <= iRun check
+ refactor TMC register compilation (saves 26B)
+ update currents registers range documentation
+ update currents even in MovableBase::InitMovementNoReinitAxis
2022-12-29 11:27:34 +01:00
D.R.racer 425f89c862 Optimization - save 30B 2022-12-29 11:27:34 +01:00
D.R.racer 0bca66aeb5 Allow runtime config/register motor/axis iRun current
This commit introduces a new set of registers 0x1e, 0x1f and 0x20 which allow reading and writing iRun current values for each axis/motor.
Please note the register contains raw TMC2130 iRun value which needs to be translated into mA to be understandable by people.
Translation table of iRun -> mA is present in tmc2130.cpp for now.
2022-12-29 11:27:34 +01:00
D.R.racer 9c9322d02f Remove old commented code 2022-12-29 09:01:27 +01:00
D.R.racer b16ac63c5d Compute vSense dynamically from iRun/iHold 2022-12-29 09:01:27 +01:00
D.R.racer 7e8ad83e25 Distinguish iRun<32
as per suggestion from @leptun
2022-12-28 12:15:47 +01:00
D.R.racer a52f833223 Fix and tune CutFilament + unit tests
Several issues addressed in this PR:
- CutFilament tuning + error recovery
- introduce register 0x1d (cut filament selector iRun current level)
- optimize setting iRun and iHold currents in the FW
- CutFilament unit test fixed
2022-12-28 12:15:47 +01:00
D.R.racer b6c3cba396 Refactor CheckFINDAvsEEPROM and setup2 2022-12-27 12:41:29 +01:00
Guðni Már Gilbert 35344f5a5e If Finda is not pressed, don't report Unload Manually error 2022-12-27 12:41:29 +01:00
Guðni Már Gilbert 4d38d1f620 PFW-1423 add Retry handling in NoCommand for init error 2022-12-27 12:41:29 +01:00
Guðni Már Gilbert 6a4ebdaee6 optimisation: inline functions to reduce size
Change in memory:
Flash: -394 bytes
SRAM: 0 bytes

Breakdown:
|------------------------------------------------------------|
| Function name                            | Flash reduction |
|------------------------------------------| ----------------|
|CommandBase::FinishedOK                   | 182 bytes       |
|MovableBase::InitMovementNoReinitAxis     | 60 bytes        |
|TMC2130::CheckForErrors                   | 36 bytes        |
|Protocol::UInt16ToHex                     | 32 bytes        |
|AddErrorAxisBit                           | 24 bytes        |
|Application::CheckManualOperation         | 22 bytes        |
|CommandBase::GoToErrEngagingIdler         | 12 bytes        |
|Application::PlanCommand                  | 12 bytes        |
|Pulley::FinishHomingAndPlanMoveToParkPos  | 8 bytes         |
|Pulley::InitAxis                          | 4 bytes         |
|------------------------------------------------------------|
2022-11-19 11:55:46 +01:00
D.R.racer c8c39f7b69 Make sure ToolChange moves Selector to desired slot
and verify correct behaviour in unit tests - especially when Selector's start position is at a different slot.
2022-11-18 22:29:01 +01:00
Guðni Már Gilbert 2f6e364ad0 optimisation: compiler should not inline SetFilamentLoaded
Change in memory:
Flash: -130 bytes
SRAM: 0 bytes
2022-11-18 21:33:46 +01:00
D.R.racer 3f09ba0c16 Unit tests: selector refused to move in ToolChange
Revealed all kinds of subtle issues (which is great). All have been fixed in this commit.
2022-11-17 07:32:38 +01:00
D.R.racer 299a31b765 Generate exactly 1 userInput event when button pressed (and held)
This PR is a different solution to what @gudnimg found in PR#233 / PFW-1404.

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

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

Change in memory:
Flash: -116 bytes
SRAM: 0 bytes
2022-10-25 07:21:33 +02:00
Guðni Már Gilbert 7bbee87a08 Empty the entire block_index queue when planned moves are aborted 2022-10-22 14:10:31 +00:00
D.R.racer 2c6f2d7533 Only set new SGTHRS when planning a Homing move (not regular moves) 2022-10-20 12:09:42 +02:00
D.R.racer dc487c36b6 Remove Enable/Disable TMC when reiniting Movable axes
The previous commits by @leptun were correct but there has been one call to Disable axis (and TMC) hidden in `InitMovement`.
Therefore `InitMovement` has been split into 2 separate functions - one is there to allow the original full axis reinit, but the other `InitMovementNoReinitAxis` now only prepares a move without reiniting the TMC driver.

This approach seems to have the benefit of fixing the Idler creep over time.

The disadvantage is the fact, that setting StallGuard threshold is no longer called. We may need to add a special piece of code to handle/apply SGTHRS change at runtime like before.
2022-10-20 12:09:42 +02:00