diff options
| author | Jacob Palecki <[email protected]> | 2021-01-20 00:30:50 -0800 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2021-01-20 00:30:50 -0800 |
| commit | 9c2be5743fb44e8a68084ac0bd15c02f6cce637a (patch) | |
| tree | c0b09b75f7974a50ae6959fe385c1ec768fc7c83 | |
| parent | further tweaks (diff) | |
| download | rawaccel-9c2be5743fb44e8a68084ac0bd15c02f6cce637a.tar.xz rawaccel-9c2be5743fb44e8a68084ac0bd15c02f6cce637a.zip | |
Final graph fidelity tweaks and fixes
| -rw-r--r-- | common/accel-motivity.hpp | 20 | ||||
| -rw-r--r-- | grapher/Constants/Constants.cs | 5 | ||||
| -rw-r--r-- | grapher/Models/Calculations/AccelCalculator.cs | 53 | ||||
| -rw-r--r-- | grapher/Models/Calculations/Data/AccelDataXYDirectional.cs | 2 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartXY.cs | 4 |
5 files changed, 50 insertions, 34 deletions
diff --git a/common/accel-motivity.hpp b/common/accel-motivity.hpp index f88320b..246cf37 100644 --- a/common/accel-motivity.hpp +++ b/common/accel-motivity.hpp @@ -55,28 +55,40 @@ namespace rawaccel { inline void fill(si_pair* lookup) const { double lookup_speed = 0; + double integral_interval = 0; double gain_integral_speed = 0; + double gain_integral_speed_prev = 0; double gain = 0; double intercept = 0; double output = 0; + double output_prev = 0; double x = -2; + double logarithm_interval = 0.01; + double integral_intervals_per_speed = 10; + double integral_interval_factor = pow(10, logarithm_interval) / integral_intervals_per_speed; + lookup[0] = {}; for (size_t i = 1; i < LUT_SIZE; i++) { - x += 0.01; + x += logarithm_interval; + // Each lookup speed will be 10^0.01 = 2.33% higher than the previous + // To get 10 integral intervals per speed, set interval to 0.233% lookup_speed = pow(10, x); + integral_interval = lookup_speed * integral_interval_factor; while (gain_integral_speed < lookup_speed) { - gain_integral_speed += 0.001; + output_prev = output; + gain_integral_speed_prev = gain_integral_speed; + gain_integral_speed += integral_interval; gain = operator()(gain_integral_speed); - output += gain * 0.001; + output += gain * integral_interval; } - intercept = output - gain * lookup_speed; + intercept = output_prev - gain_integral_speed_prev * gain; lookup[i] = { gain, intercept }; } diff --git a/grapher/Constants/Constants.cs b/grapher/Constants/Constants.cs index c76ac59..e31f62c 100644 --- a/grapher/Constants/Constants.cs +++ b/grapher/Constants/Constants.cs @@ -17,10 +17,7 @@ namespace grapher public const int Resolution = 100; /// <summary> Multiplied by DPI over poll rate to find rough max expected velocity. </summary> - public const double MaxMultiplier = 85; - - /// <summary> Ratio of max (X, Y) used in "by component" calulations to those used in "whole vector" calculations. </summary> - public const double XYToCombinedRatio = 1.4; + public const double MaxMultiplier = .05; /// <summary> Separation between X and Y active value labels, in pixels. </summary> public const int ActiveLabelXYSeparation = 2; diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs index ffe8444..733a3c0 100644 --- a/grapher/Models/Calculations/AccelCalculator.cs +++ b/grapher/Models/Calculations/AccelCalculator.cs @@ -56,9 +56,7 @@ namespace grapher.Models.Calculations public Field PollRate { get; private set; } - private double CombinedMaxVelocity { get; set; } - - private double XYMaxVelocity { get; set; } + private double MaxVelocity { get; set; } private int Increment { get; set; } @@ -114,7 +112,7 @@ namespace grapher.Models.Calculations var inDiff = Math.Round(simulatedInputDatum.velocity - lastInputMagnitude, 5); var outDiff = Math.Round(outMagnitude - lastOutputMagnitude, 5); - if (inDiff <= 0) + if (inDiff == 0) { continue; } @@ -137,7 +135,7 @@ namespace grapher.Models.Calculations var ratio = outMagnitude / simulatedInputDatum.velocity; var slope = inDiff > 0 ? outDiff / inDiff : starter; - + if (ratio > maxRatio) { maxRatio = ratio; @@ -190,7 +188,7 @@ namespace grapher.Models.Calculations data.MinGain = minSlope; } - public void CalculateCombinedDiffSens(AccelChartData[] dataByAngle, ManagedAccel accel, DriverSettings settings, IReadOnlyCollection<IReadOnlyCollection<SimulatedMouseInput>> simulatedInputData) + public void CalculateDirectional(AccelChartData[] dataByAngle, ManagedAccel accel, DriverSettings settings, IReadOnlyCollection<IReadOnlyCollection<SimulatedMouseInput>> simulatedInputData) { double maxRatio = 0.0; double minRatio = Double.MaxValue; @@ -221,8 +219,18 @@ namespace grapher.Models.Calculations var output = accel.Accelerate(simulatedInputDatum.x, simulatedInputDatum.y, simulatedInputDatum.time); var magnitude = Velocity(output.Item1, output.Item2, simulatedInputDatum.time); + var inDiff = Math.Round(simulatedInputDatum.velocity - lastInputMagnitude, 5); + var outDiff = Math.Round(magnitude - lastOutputMagnitude, 5); - var ratio = magnitude / simulatedInputDatum.velocity; + if (inDiff == 0) + { + continue; + } + + if (inDiff < 0 || outDiff < 0) + { + Console.WriteLine(string.Empty); + } if (!data.VelocityPoints.ContainsKey(simulatedInputDatum.velocity)) { @@ -240,26 +248,27 @@ namespace grapher.Models.Calculations logIndex++; } - if (ratio > maxRatio) + var ratio = magnitude / simulatedInputDatum.velocity; + var slope = inDiff > 0 ? outDiff / inDiff : settings.sensitivity.x; + + bool indexToMeasureExtrema = (angleIndex == 0) || (angleIndex == (Constants.AngleDivisions - 1)); + + if (indexToMeasureExtrema && (ratio > maxRatio)) { maxRatio = ratio; } - if (ratio < minRatio) + if (indexToMeasureExtrema && (ratio < minRatio)) { minRatio = ratio; } - var inDiff = simulatedInputDatum.velocity - lastInputMagnitude; - var outDiff = magnitude - lastOutputMagnitude; - var slope = inDiff > 0 ? outDiff / inDiff : settings.sensitivity.x; - - if (slope > maxSlope) + if (indexToMeasureExtrema && (slope > maxSlope)) { maxSlope = slope; } - if (slope < minSlope) + if (indexToMeasureExtrema && (slope < minSlope)) { minSlope = slope; } @@ -320,7 +329,7 @@ namespace grapher.Models.Calculations } - for (int i = 5; i < CombinedMaxVelocity; i+=Increment) + for (int i = 5; i < MaxVelocity; i+=Increment) { SimulatedMouseInput mouseInputData; mouseInputData.x = i; @@ -353,7 +362,7 @@ namespace grapher.Models.Calculations magnitudes.Add(mouseInputData); } - for (int i = 5; i < XYMaxVelocity; i+=Increment) + for (int i = 5; i < MaxVelocity; i+=Increment) { SimulatedMouseInput mouseInputData; mouseInputData.x = i; @@ -384,7 +393,7 @@ namespace grapher.Models.Calculations magnitudes.Add(mouseInputData); } - for (int i = 5; i < XYMaxVelocity; i+=Increment) + for (int i = 5; i < MaxVelocity; i+=Increment) { SimulatedMouseInput mouseInputData; mouseInputData.x = 0; @@ -424,7 +433,7 @@ namespace grapher.Models.Calculations magnitudes.Add(mouseInputData); } - for (int magnitude = 5; magnitude < XYMaxVelocity; magnitude+=Increment) + for (int magnitude = 5; magnitude < MaxVelocity; magnitude+=Increment) { var slowMoveX = Math.Round(magnitude * Math.Cos(angle), 4); var slowMoveY = Math.Round(magnitude * Math.Sin(angle), 4); @@ -495,12 +504,10 @@ namespace grapher.Models.Calculations public void ScaleByMouseSettings() { - var dpiPollFactor = DPI.Data / PollRate.Data; - CombinedMaxVelocity = dpiPollFactor * Constants.MaxMultiplier; - var ratio = CombinedMaxVelocity / Constants.Resolution; + MaxVelocity = DPI.Data * Constants.MaxMultiplier; + var ratio = MaxVelocity / Constants.Resolution; Increment = ratio > 1 ? (int) Math.Floor(ratio) : 1; MeasurementTime = Increment == 1 ? 1 / ratio : 1; - XYMaxVelocity = CombinedMaxVelocity * Constants.XYToCombinedRatio; SimulatedInputCombined = GetSimulatedInput(); SimulatedInputX = GetSimulatInputX(); SimulatedInputY = GetSimulatedInputY(); diff --git a/grapher/Models/Calculations/Data/AccelDataXYDirectional.cs b/grapher/Models/Calculations/Data/AccelDataXYDirectional.cs index ad54989..8bd889d 100644 --- a/grapher/Models/Calculations/Data/AccelDataXYDirectional.cs +++ b/grapher/Models/Calculations/Data/AccelDataXYDirectional.cs @@ -70,7 +70,7 @@ namespace grapher.Models.Calculations.Data public void CreateGraphData(ManagedAccel accel, DriverSettings settings) { Clear(); - Calculator.CalculateCombinedDiffSens(AngleToData, accel, settings, Calculator.SimulatedDirectionalInput); + Calculator.CalculateDirectional(AngleToData, accel, settings, Calculator.SimulatedDirectionalInput); } private void FillAngleData() diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs index 553ab3e..bd80ea2 100644 --- a/grapher/Models/Charts/ChartXY.cs +++ b/grapher/Models/Charts/ChartXY.cs @@ -244,8 +244,8 @@ namespace grapher ChartX.ChartAreas[0].AxisY.Maximum = maxX * (1 + VerticalMargin); VerifyRange(minY, maxY); - ChartX.ChartAreas[0].AxisY.Minimum = minY * (1 - VerticalMargin); - ChartX.ChartAreas[0].AxisY.Maximum = maxY * (1 + VerticalMargin); + ChartY.ChartAreas[0].AxisY.Minimum = minY * (1 - VerticalMargin); + ChartY.ChartAreas[0].AxisY.Maximum = maxY * (1 + VerticalMargin); } public void SetCombined() |