diff options
| author | JacobPalecki <[email protected]> | 2021-01-20 20:13:33 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-01-20 20:13:33 -0800 |
| commit | 5b6479013c8f35df933dd57c680063f4db1e4028 (patch) | |
| tree | 60dd7c67a0f163457da2519b42553382a39a591b /grapher/Models/Calculations/Data | |
| parent | show custom dialog on bad input (#63) (diff) | |
| parent | Guard against bad anisotropy args (diff) | |
| download | rawaccel-5b6479013c8f35df933dd57c680063f4db1e4028.tar.xz rawaccel-5b6479013c8f35df933dd57c680063f4db1e4028.zip | |
Merge pull request #65 from JacobPalecki/Directional
Directionality Features + Graph Fidelity
Diffstat (limited to 'grapher/Models/Calculations/Data')
4 files changed, 218 insertions, 0 deletions
diff --git a/grapher/Models/Calculations/Data/AccelDataCombined.cs b/grapher/Models/Calculations/Data/AccelDataCombined.cs new file mode 100644 index 0000000..8efb9ac --- /dev/null +++ b/grapher/Models/Calculations/Data/AccelDataCombined.cs @@ -0,0 +1,49 @@ +using grapher.Models.Charts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Models.Calculations.Data +{ + public class AccelDataCombined : IAccelData + { + public AccelDataCombined(EstimatedPoints points, AccelCalculator calculator) + { + X = new AccelChartData(); + Points = points; + Calculator = calculator; + } + + public AccelChartData X { get; } + + public AccelChartData Y { get => X; } + + private EstimatedPoints Points { get; } + + private AccelCalculator Calculator { get; } + + public void CalculateDots(double x, double y, double timeInMs) + { + var outVelocity = AccelCalculator.Velocity(x, y, timeInMs); + + (var inCombVel, var combSens, var combGain) = X.FindPointValuesFromOut(outVelocity); + Points.Velocity.Set(inCombVel, outVelocity); + Points.Sensitivity.Set(inCombVel, combSens); + Points.Gain.Set(inCombVel, combGain); + + } + + public void Clear() + { + X.Clear(); + } + + public void CreateGraphData(ManagedAccel accel, DriverSettings settings) + { + Clear(); + Calculator.Calculate(X, accel, settings.sensitivity.x, Calculator.SimulatedInputCombined); + } + } +} diff --git a/grapher/Models/Calculations/Data/AccelDataXYComponential.cs b/grapher/Models/Calculations/Data/AccelDataXYComponential.cs new file mode 100644 index 0000000..6231eb3 --- /dev/null +++ b/grapher/Models/Calculations/Data/AccelDataXYComponential.cs @@ -0,0 +1,64 @@ +using grapher.Models.Charts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Models.Calculations.Data +{ + public class AccelDataXYComponential : IAccelData + { + public AccelDataXYComponential( + EstimatedPoints xPoints, + EstimatedPoints yPoints, + AccelCalculator calculator) + { + X = new AccelChartData(); + Y = new AccelChartData(); + XPoints = xPoints; + YPoints = yPoints; + Calculator = calculator; + } + + public AccelChartData X { get; } + + public AccelChartData Y { get; } + + private EstimatedPoints XPoints { get; } + + private EstimatedPoints YPoints { get; } + + private AccelCalculator Calculator { get; } + + public void CalculateDots(double x, double y, double timeInMs) + { + var outX = Math.Abs(x) / timeInMs; + var outY = Math.Abs(y) / timeInMs; + + (var inXVelocity, var xSensitivity, var xGain) = X.FindPointValuesFromOut(outX); + XPoints.Velocity.Set(inXVelocity, outX); + XPoints.Sensitivity.Set(inXVelocity, xSensitivity); + XPoints.Gain.Set(inXVelocity, xGain); + + (var inYVelocity, var ySensitivity, var yGain) = Y.FindPointValuesFromOut(outY); + YPoints.Velocity.Set(inYVelocity, outY); + YPoints.Sensitivity.Set(inYVelocity, ySensitivity); + YPoints.Gain.Set(inYVelocity, yGain); + + } + + public void Clear() + { + X.Clear(); + Y.Clear(); + } + + public void CreateGraphData(ManagedAccel accel, DriverSettings settings) + { + Clear(); + Calculator.Calculate(X, accel, settings.sensitivity.x, Calculator.SimulatedInputX); + Calculator.Calculate(Y, accel, settings.sensitivity.y, Calculator.SimulatedInputY); + } + } +} diff --git a/grapher/Models/Calculations/Data/AccelDataXYDirectional.cs b/grapher/Models/Calculations/Data/AccelDataXYDirectional.cs new file mode 100644 index 0000000..8bd889d --- /dev/null +++ b/grapher/Models/Calculations/Data/AccelDataXYDirectional.cs @@ -0,0 +1,84 @@ +using grapher.Models.Charts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Models.Calculations.Data +{ + public class AccelDataXYDirectional : IAccelData + { + public AccelDataXYDirectional( + EstimatedPoints xPoints, + EstimatedPoints yPoints, + AccelCalculator calculator) + { + XPoints = xPoints; + YPoints = yPoints; + Calculator = calculator; + AngleToData = new AccelChartData[Constants.AngleDivisions]; + FillAngleData(); + } + + public AccelChartData X { get => AngleToData[0]; } + + public AccelChartData Y { get => AngleToData[Constants.AngleDivisions-1]; } + + public double SensitivityMax { get => X.MaxAccel; } + + public double SensitivityMin { get => X.MinAccel; } + + public double GainMax { get => X.MaxGain; } + + public double GainMin { get => X.MinGain; } + + private AccelChartData[] AngleToData { get; } + + private EstimatedPoints XPoints { get; } + + private EstimatedPoints YPoints { get; } + + private AccelCalculator Calculator { get; } + + public void CalculateDots(double x, double y, double timeInMs) + { + var outVelocity = AccelCalculator.Velocity(x, y, timeInMs); + var outAngle = Math.Atan2(Math.Abs(y),Math.Abs(x)); + var nearestAngleDivision = AccelCalculator.NearestAngleDivision(outAngle); + var data = AngleToData[nearestAngleDivision]; + var index = data.GetVelocityIndex(outVelocity); + var inVelocity = data.VelocityPoints.ElementAt(index).Key; + var xPoints = X.ValuesAtIndex(index); + var yPoints = Y.ValuesAtIndex(index); + XPoints.Sensitivity.Set(inVelocity, xPoints.Item1); + XPoints.Velocity.Set(inVelocity, xPoints.Item2); + XPoints.Gain.Set(inVelocity, xPoints.Item3); + YPoints.Sensitivity.Set(inVelocity, yPoints.Item1); + YPoints.Velocity.Set(inVelocity, yPoints.Item2); + YPoints.Gain.Set(inVelocity, yPoints.Item3); + } + + public void Clear() + { + foreach (var data in AngleToData) + { + data.Clear(); + } + } + + public void CreateGraphData(ManagedAccel accel, DriverSettings settings) + { + Clear(); + Calculator.CalculateDirectional(AngleToData, accel, settings, Calculator.SimulatedDirectionalInput); + } + + private void FillAngleData() + { + for(int i=0; i < Constants.AngleDivisions; i++) + { + AngleToData[i] = new AccelChartData(); + } + } + } +} diff --git a/grapher/Models/Calculations/Data/IAccelData.cs b/grapher/Models/Calculations/Data/IAccelData.cs new file mode 100644 index 0000000..576e6df --- /dev/null +++ b/grapher/Models/Calculations/Data/IAccelData.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Models.Calculations.Data +{ + public interface IAccelData + { + void CalculateDots(double x, double y, double timeInMs); + + void CreateGraphData(ManagedAccel accel, DriverSettings settings); + + void Clear(); + + AccelChartData X { get; } + + AccelChartData Y { get; } + } +} |