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.
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
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.
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.
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
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
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.
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.
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.
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
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
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.