diff options
| author | Jacob Palecki <[email protected]> | 2020-09-20 23:16:15 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-09-20 23:16:15 -0700 |
| commit | 2a756dfb08b4f8c0870173ad4e0393cdeef33c94 (patch) | |
| tree | 575d676af12a67db93b7ff7557ac029f27a58b8c | |
| parent | Merge branch 'GUI' into Unsure (diff) | |
| download | rawaccel-2a756dfb08b4f8c0870173ad4e0393cdeef33c94.tar.xz rawaccel-2a756dfb08b4f8c0870173ad4e0393cdeef33c94.zip | |
Attempt to get separate x/y working
| -rw-r--r-- | grapher/Models/AccelGUIFactory.cs | 11 | ||||
| -rw-r--r-- | grapher/Models/Calculations/AccelCalculator.cs | 46 | ||||
| -rw-r--r-- | grapher/Models/Calculations/AccelChartData.cs | 24 | ||||
| -rw-r--r-- | grapher/Models/Calculations/AccelData.cs | 38 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartState/XYOneGraphState.cs | 8 |
5 files changed, 109 insertions, 18 deletions
diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 526e399..eb30864 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -89,6 +89,10 @@ namespace grapher.Models Label optionSetYTitle, Label mouseLabel) { + var accelCalculator = new AccelCalculator( + new Field(dpiTextBox.TextBox, form, Constants.DefaultDPI), + new Field(pollRateTextBox.TextBox, form, Constants.DefaultPollRate)); + var accelCharts = new AccelCharts( form, new ChartXY(accelerationChart, accelerationChartY, Constants.SensitivityChartTitle), @@ -96,7 +100,8 @@ namespace grapher.Models new ChartXY(gainChart, gainChartY, Constants.GainChartTitle), showVelocityGainToolStripMenuItem, showLastMouseMoveMenuItem, - writeButton); + writeButton, + accelCalculator); var sensitivity = new OptionXY( sensitivityBoxX, @@ -276,10 +281,6 @@ namespace grapher.Models lockXYLabel, accelCharts); - var accelCalculator = new AccelCalculator( - new Field(dpiTextBox.TextBox, form, Constants.DefaultDPI), - new Field(pollRateTextBox.TextBox, form, Constants.DefaultPollRate)); - var settings = new SettingsManager( activeAccel, accelCalculator.DPI, diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs index ff1088b..35fee2d 100644 --- a/grapher/Models/Calculations/AccelCalculator.cs +++ b/grapher/Models/Calculations/AccelCalculator.cs @@ -96,9 +96,8 @@ namespace grapher.Models.Calculations public void CalculateCombinedDiffSens(AccelData data, ManagedAccel accel, DriverSettings settings, ICollection<MagnitudeData> magnitudeData) { - double lastInputMagnitudeX = 0; + double lastInputMagnitude = 0; double lastOutputMagnitudeX = 0; - double lastInputMagnitudeY = 0; double lastOutputMagnitudeY = 0; Sensitivity = GetSens(ref settings); @@ -116,13 +115,54 @@ namespace grapher.Models.Calculations data.Combined.AccelPoints.Add(magnitudeDatum.magnitude, ratio); } - var xRatio = magnitudeDatum.x > 0 ? output.Item1 / magnitudeDatum.x : settings.sensitivity.x * ratio; + var xRatio = settings.sensitivity.x * ratio; + var yRatio = settings.sensitivity.y * ratio; if (!data.X.AccelPoints.ContainsKey(magnitudeDatum.magnitude)) { + data.X.AccelPoints.Add(magnitudeDatum.magnitude, xRatio); + } + if (!data.Y.AccelPoints.ContainsKey(magnitudeDatum.magnitude)) + { + data.Y.AccelPoints.Add(magnitudeDatum.magnitude, yRatio); } + + var xOut = xRatio * magnitudeDatum.magnitude; + var yOut = yRatio * magnitudeDatum.magnitude; + + var inDiff = magnitudeDatum.magnitude - lastInputMagnitude; + var xOutDiff = xOut - lastOutputMagnitudeX; + var yOutDiff = yOut - lastOutputMagnitudeY; + var xSlope = inDiff > 0 ? xOutDiff / inDiff : settings.sensitivity.x; + var ySlope = inDiff > 0 ? yOutDiff / inDiff : settings.sensitivity.y; + + if (!data.X.VelocityPoints.ContainsKey(magnitudeDatum.magnitude)) + { + data.X.VelocityPoints.Add(magnitudeDatum.magnitude, xOut); + } + + if (!data.Y.VelocityPoints.ContainsKey(magnitudeDatum.magnitude)) + { + data.Y.VelocityPoints.Add(magnitudeDatum.magnitude, yOut); + } + + if (!data.X.GainPoints.ContainsKey(magnitudeDatum.magnitude)) + { + data.X.GainPoints.Add(magnitudeDatum.magnitude, xSlope); + } + + if (!data.Y.GainPoints.ContainsKey(magnitudeDatum.magnitude)) + { + data.Y.GainPoints.Add(magnitudeDatum.magnitude, ySlope); + } + + lastInputMagnitude = magnitudeDatum.magnitude; + lastOutputMagnitudeX = xOutDiff; + lastOutputMagnitudeY = yOutDiff; } + + data.Combined.OrderedVelocityPointsList.AddRange(data.Combined.VelocityPoints.Values.ToList()); } public ReadOnlyCollection<MagnitudeData> GetMagnitudes() diff --git a/grapher/Models/Calculations/AccelChartData.cs b/grapher/Models/Calculations/AccelChartData.cs index 8c0c8ea..c943643 100644 --- a/grapher/Models/Calculations/AccelChartData.cs +++ b/grapher/Models/Calculations/AccelChartData.cs @@ -52,12 +52,7 @@ namespace grapher.Models.Calculations } else { - var velIdx = OrderedVelocityPointsList.BinarySearch(outVelocityValue); - - if (velIdx < 0) - { - velIdx = ~velIdx; - } + var velIdx = GetVelocityIndex(outVelocityValue); velIdx = Math.Min(velIdx, VelocityPoints.Count - 1); values = (VelocityPoints.ElementAt(velIdx).Key, AccelPoints.ElementAt(velIdx).Value, GainPoints.ElementAt(velIdx).Value); @@ -66,6 +61,23 @@ namespace grapher.Models.Calculations } } + public (double, double, double) ValuesAtIndex(int index) + { + return (VelocityPoints.ElementAt(index).Value, AccelPoints.ElementAt(index).Value, GainPoints.ElementAt(index).Value); + } + + public int GetVelocityIndex(double outVelocityValue) + { + var velIdx = OrderedVelocityPointsList.BinarySearch(outVelocityValue); + + if (velIdx < 0) + { + velIdx = ~velIdx; + } + + return velIdx; + } + #endregion Methods } } diff --git a/grapher/Models/Calculations/AccelData.cs b/grapher/Models/Calculations/AccelData.cs index 057a53b..894774b 100644 --- a/grapher/Models/Calculations/AccelData.cs +++ b/grapher/Models/Calculations/AccelData.cs @@ -1,5 +1,6 @@ using grapher.Models.Charts; using System; +using System.Collections.Generic; namespace grapher.Models.Calculations { @@ -37,6 +38,8 @@ namespace grapher.Models.Calculations private EstimatedPoints EstimatedY { get; } + private Dictionary<double, (double, double, double, double, double, double, double)> OutVelocityToPoints { get; } + #endregion Properties #region Methods @@ -50,10 +53,10 @@ namespace grapher.Models.Calculations public void CalculateDots(int x, int y, double timeInMs) { - var magnitude = AccelCalculator.Velocity(x, y, timeInMs); + var outVelocity = AccelCalculator.Velocity(x, y, timeInMs); - (var inCombVel, var combSens, var combGain) = Combined.FindPointValuesFromOut(magnitude); - Estimated.Velocity.Set(inCombVel, magnitude); + (var inCombVel, var combSens, var combGain) = Combined.FindPointValuesFromOut(outVelocity); + Estimated.Velocity.Set(inCombVel, outVelocity); Estimated.Sensitivity.Set(inCombVel, combSens); Estimated.Gain.Set(inCombVel, combGain); } @@ -74,6 +77,35 @@ namespace grapher.Models.Calculations EstimatedY.Gain.Set(inYVelocity, yGain); } + public void CalculateDotsCombinedDiffSens(int x, int y, double timeInMs) + { + var outVelocity = AccelCalculator.Velocity(x, y, timeInMs); + + if (OutVelocityToPoints.TryGetValue(outVelocity, out var points)) + { + EstimatedX.Sensitivity.Set(points.Item1, points.Item2); + EstimatedX.Velocity.Set(points.Item1, points.Item3); + EstimatedX.Gain.Set(points.Item1, points.Item4); + EstimatedY.Sensitivity.Set(points.Item1, points.Item5); + EstimatedY.Velocity.Set(points.Item1, points.Item6); + EstimatedY.Gain.Set(points.Item1, points.Item7); + } + else + { + var index = Combined.GetVelocityIndex(outVelocity); + var inVelocity = Combined.VelocityPoints[index]; + var xPoints = X.FindPointValuesFromOut(outVelocity); + var yPoints = Y.FindPointValuesFromOut(outVelocity); + OutVelocityToPoints.Add(outVelocity, (inVelocity, xPoints.Item1, xPoints.Item2, xPoints.Item3, yPoints.Item1, yPoints.Item2, yPoints.Item3)); + EstimatedX.Sensitivity.Set(inVelocity, xPoints.Item1); + EstimatedX.Velocity.Set(inVelocity, xPoints.Item2); + EstimatedX.Gain.Set(inVelocity, xPoints.Item3); + EstimatedY.Sensitivity.Set(inVelocity, yPoints.Item1); + EstimatedY.Velocity.Set(inVelocity, yPoints.Item2); + EstimatedY.Gain.Set(inVelocity, yPoints.Item3); + } + } + #endregion Methods } } diff --git a/grapher/Models/Charts/ChartState/XYOneGraphState.cs b/grapher/Models/Charts/ChartState/XYOneGraphState.cs index bc9a88d..c1153c1 100644 --- a/grapher/Models/Charts/ChartState/XYOneGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYOneGraphState.cs @@ -1,4 +1,5 @@ using grapher.Models.Calculations; +using grapher.Models.Serialized; namespace grapher.Models.Charts.ChartState { @@ -27,7 +28,7 @@ namespace grapher.Models.Charts.ChartState public override void MakeDots(int x, int y, double timeInMs) { - Data.CalculateDotsXY(x, y, timeInMs); + Data.CalculateDotsCombinedDiffSens(x, y, timeInMs); } public override void Bind() @@ -36,5 +37,10 @@ namespace grapher.Models.Charts.ChartState VelocityChart.BindXY(Data.X.VelocityPoints, Data.Y.VelocityPoints); GainChart.BindXY(Data.X.GainPoints, Data.Y.GainPoints); } + + public override void Calculate(ManagedAccel accel, DriverSettings settings) + { + Calculator.CalculateCombinedDiffSens(Data, accel, settings, Calculator.MagnitudesCombined); + } } } |