Improve dosing logic (now based on predicting time-till-completion); fix parameters initialization bug; various fixes - #2
Open
death-to-invaders wants to merge 1 commit into
Conversation
…fix parameters initialization bug; various fixes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Fixed the bug where parameters entered via the Web UI were saved to flash memory, but the global variables (which drive the dosing logic) were not initialized to these stored values after a reboot. As a result, the UI displayed the previously entered values while the old internal default values were actually being used for dosing.
Learned grind delay is now persistently stored in flash memory, whereas previously it was lost after a reboot.
Tiny change: The minimum allowed dose is now 6g (which is a perfectly acceptable target for my DF64 grinder, for example)
Added an additional safety layer: If the scale stops sending weight updates for more than 2000ms mid-grind (after the first gram is registered), it triggers an emergency abort. Previously, the grinder would blindly run for the full "Max run time (s)" duration in this scenario.
The 1.0g startup gate: Discards early weight updates until the scale reaches 1.0g, preventing slow motor startup dynamics from skewing the flow rate calculations. Additionally, rate processing now only occurs if the smartplug relay is switched on.
Bypassing filter on startup: The code now bypasses the exponential moving average (EMA) smoothing for the very first weight packet over 1.0g, establishing an instantaneous real-time flow baseline. Previously, there was a zero-bias skew on the first few samples.
The main change in dosing logic (Predictive Trajectory): The system now uses the current flow rate to predict exactly how many milliseconds it will take to hit the target weight (minus the mechanical overrun delay).
w_pred = w + rate * delay_sand stopped only if it was already above the target.w_predis expected to reach the target dose, and schedules the relay=off command for that precise moment in the future.