diff options
| -rw-r--r-- | grapher/Models/Calculations/AccelCalculator.cs | 73 | ||||
| -rw-r--r-- | grapher/Models/Calculations/Data/AccelDataCombined.cs | 49 | ||||
| -rw-r--r-- | grapher/Models/Calculations/Data/AccelDataXYComponential.cs | 64 | ||||
| -rw-r--r-- | grapher/Models/Calculations/Data/AccelDataXYDirectional.cs | 77 | ||||
| -rw-r--r-- | grapher/Models/Calculations/Data/IAccelData.cs | 21 | ||||
| -rw-r--r-- | grapher/Models/Charts/AccelCharts.cs | 4 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartState/ChartState.cs | 5 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartState/ChartStateManager.cs | 11 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartState/CombinedState.cs | 20 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartState/XYOneGraphState.cs | 8 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartState/XYTwoGraphState.cs | 11 | ||||
| -rw-r--r-- | grapher/grapher.csproj | 4 |
12 files changed, 322 insertions, 25 deletions
diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs index 2c32753..f59a0fa 100644 --- a/grapher/Models/Calculations/AccelCalculator.cs +++ b/grapher/Models/Calculations/AccelCalculator.cs @@ -14,12 +14,24 @@ namespace grapher.Models.Calculations { public double velocity; public double time; + public double angle; public int x; public int y; } #endregion Structs + #region Static + + public static double[] SlowMovements = + { + 0,0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8, 3.0, 3.333, 3.666, 4.0, 4.333, 4.666, + }; + + public IEnumerable<double> Angles = GetAngles(); + + #endregion static + #region Constructors public AccelCalculator(Field dpi, Field pollRate) @@ -58,6 +70,14 @@ namespace grapher.Models.Calculations #region Methods + public static IEnumerable<double> GetAngles() + { + for(int i=0; i<19; i++) + { + yield return (i / 18) * (Math.PI / 2); + } + } + public void Calculate(AccelChartData data, ManagedAccel accel, double starter, ICollection<SimulatedMouseInput> simulatedInputData) { double lastInputMagnitude = 0; @@ -316,6 +336,7 @@ namespace grapher.Models.Calculations mouseInputData.y = j; mouseInputData.time = MeasurementTime; mouseInputData.velocity = Velocity(i, j, mouseInputData.time); + mouseInputData.angle = Math.Atan2(j,i); magnitudes.Add(mouseInputData); } } @@ -336,6 +357,7 @@ namespace grapher.Models.Calculations mouseInputData.y = 0; mouseInputData.time = MeasurementTime; mouseInputData.velocity = Velocity(i, 0, mouseInputData.time); + mouseInputData.angle = 0; magnitudes.Add(mouseInputData); } @@ -353,12 +375,63 @@ namespace grapher.Models.Calculations mouseInputData.y = i; mouseInputData.time = MeasurementTime; mouseInputData.velocity = Velocity(0, i, mouseInputData.time); + mouseInputData.angle = Math.PI / 2; magnitudes.Add(mouseInputData); } return magnitudes.AsReadOnly(); } + public ReadOnlyCollection<SimulatedMouseInput> GetSimulatedInputXY() + { + var magnitudes = new List<SimulatedMouseInput>(); + + foreach (var slowMoveMagnitude in SlowMovements) + { + foreach (var slowAngle in Angles) + { + var slowMoveX = slowMoveMagnitude * Math.Cos(slowAngle); + var slowMoveY = slowMoveMagnitude * Math.Sin(slowAngle); + var ceilX = (int)Math.Ceiling(slowMoveX); + var ceilY = (int)Math.Ceiling(slowMoveY); + var magnitude = Magnitude(slowMoveX, slowMoveY); + var ceilMagnitude = Magnitude(ceilX, ceilY); + var timeFactor = ceilMagnitude / magnitude; + + SimulatedMouseInput mouseInputData; + mouseInputData.x = ceilX; + mouseInputData.y = ceilY; + mouseInputData.time = timeFactor; + mouseInputData.velocity = Velocity(ceilX, ceilY, timeFactor); + mouseInputData.angle = slowAngle; + magnitudes.Add(mouseInputData); + } + } + + for (int magnitude = 5; magnitude < XYMaxVelocity; magnitude+=Increment) + { + foreach (var angle in Angles) + { + var slowMoveX = magnitude * Math.Cos(angle); + var slowMoveY = magnitude * Math.Sin(angle); + var ceilX = (int)Math.Ceiling(slowMoveX); + var ceilY = (int)Math.Ceiling(slowMoveY); + var ceilMagnitude = Magnitude(ceilX, ceilY); + var timeFactor = ceilMagnitude / magnitude; + + SimulatedMouseInput mouseInputData; + mouseInputData.x =ceilX; + mouseInputData.y = ceilY; + mouseInputData.time = MeasurementTime; + mouseInputData.velocity = Velocity(ceilX, ceilY, mouseInputData.time); + mouseInputData.angle = angle; + magnitudes.Add(mouseInputData); + } + } + + return magnitudes.AsReadOnly(); + } + public static double Magnitude(int x, int y) { return Math.Sqrt(x * x + y * y); 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..ffa353f --- /dev/null +++ b/grapher/Models/Calculations/Data/AccelDataXYDirectional.cs @@ -0,0 +1,77 @@ +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) + { + 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 xStripped, var yStripped) = AccelCalculator.StripSens(x, y, settings.sensitivity.x, settings.sensitivity.y); + var outVelocity = AccelCalculator.Velocity(xStripped, yStripped, timeInMs); + + if (OutVelocityToPoints.TryGetValue(outVelocity, out var points)) + { + XPoints.Sensitivity.Set(points.Item1, points.Item2); + XPoints.Velocity.Set(points.Item1, points.Item3); + XPoints.Gain.Set(points.Item1, points.Item4); + YPoints.Sensitivity.Set(points.Item1, points.Item5); + YPoints.Velocity.Set(points.Item1, points.Item6); + YPoints.Gain.Set(points.Item1, points.Item7); + } + else + { + var index = Combined.GetVelocityIndex(outVelocity); + var inVelocity = Combined.VelocityPoints.ElementAt(index).Key; + var xPoints = X.ValuesAtIndex(index); + var yPoints = Y.ValuesAtIndex(index); + 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); + } + + } + + public void Clear() + { + X.Clear(); + Y.Clear(); + } + + public void CreateGraphData(ManagedAccel accel, DriverSettings settings) + { + Clear(); + } + + } +} 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; } + } +} diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs index ea1345f..b9f7a8b 100644 --- a/grapher/Models/Charts/AccelCharts.cs +++ b/grapher/Models/Charts/AccelCharts.cs @@ -1,4 +1,5 @@ using grapher.Models.Calculations; +using grapher.Models.Calculations.Data; using grapher.Models.Charts; using grapher.Models.Charts.ChartState; using grapher.Models.Serialized; @@ -26,7 +27,6 @@ namespace grapher var estimatedX = new EstimatedPoints(); var estimatedY = new EstimatedPoints(); SetupCharts(sensitivityChart, velocityChart, gainChart, estimated, estimatedX, estimatedY); - var accelData = new AccelData(estimated, estimatedX, estimatedY); ChartStateManager = new ChartStateManager(sensitivityChart, velocityChart, gainChart, accelData, accelCalculator); ContainingForm = form; @@ -56,7 +56,7 @@ namespace grapher private Button WriteButton { get; } - public AccelData AccelData + public IAccelData AccelData { get { diff --git a/grapher/Models/Charts/ChartState/ChartState.cs b/grapher/Models/Charts/ChartState/ChartState.cs index 269d269..2a0325c 100644 --- a/grapher/Models/Charts/ChartState/ChartState.cs +++ b/grapher/Models/Charts/ChartState/ChartState.cs @@ -1,4 +1,5 @@ using grapher.Models.Calculations; +using grapher.Models.Calculations.Data; using grapher.Models.Serialized; using System; using System.Collections.Generic; @@ -15,13 +16,11 @@ namespace grapher.Models.Charts.ChartState ChartXY sensitivityChart, ChartXY velocityChart, ChartXY gainChart, - AccelData accelData, AccelCalculator calculator) { SensitivityChart = sensitivityChart; VelocityChart = velocityChart; GainChart = gainChart; - Data = accelData; Calculator = calculator; TwoDotsPerGraph = false; } @@ -32,7 +31,7 @@ namespace grapher.Models.Charts.ChartState public ChartXY GainChart { get; } - public AccelData Data { get; } + public IAccelData Data { get; protected set; } public AccelCalculator Calculator { get; } diff --git a/grapher/Models/Charts/ChartState/ChartStateManager.cs b/grapher/Models/Charts/ChartState/ChartStateManager.cs index ff4fe54..9ed54e1 100644 --- a/grapher/Models/Charts/ChartState/ChartStateManager.cs +++ b/grapher/Models/Charts/ChartState/ChartStateManager.cs @@ -14,21 +14,24 @@ namespace grapher.Models.Charts.ChartState ChartXY sensitivityChart, ChartXY velocityChart, ChartXY gainChat, - AccelData accelData, - AccelCalculator accelCalculator) + AccelCalculator accelCalculator, + EstimatedPoints combined, + EstimatedPoints xPoints, + EstimatedPoints yPoints) { CombinedState = new CombinedState( sensitivityChart, velocityChart, gainChat, - accelData, + combined, accelCalculator); XYOneGraphState = new XYOneGraphState( sensitivityChart, velocityChart, gainChat, - accelData, + xPoints, + yPoints, accelCalculator); XYTwoGraphState = new XYTwoGraphState( diff --git a/grapher/Models/Charts/ChartState/CombinedState.cs b/grapher/Models/Charts/ChartState/CombinedState.cs index 9eadb87..7275d16 100644 --- a/grapher/Models/Charts/ChartState/CombinedState.cs +++ b/grapher/Models/Charts/ChartState/CombinedState.cs @@ -1,4 +1,5 @@ using grapher.Models.Calculations; +using grapher.Models.Calculations.Data; using grapher.Models.Serialized; namespace grapher.Models.Charts.ChartState @@ -9,15 +10,16 @@ namespace grapher.Models.Charts.ChartState ChartXY sensitivityChart, ChartXY velocityChart, ChartXY gainChart, - AccelData accelData, + EstimatedPoints points, AccelCalculator accelCalculator) : base( sensitivityChart, velocityChart, gainChart, - accelData, accelCalculator) - { } + { + Data = new AccelDataCombined(points, accelCalculator); + } public override void Activate() { @@ -37,16 +39,16 @@ namespace grapher.Models.Charts.ChartState public override void Bind() { - SensitivityChart.Bind(Data.Combined.AccelPoints); - VelocityChart.Bind(Data.Combined.VelocityPoints); - GainChart.Bind(Data.Combined.GainPoints); - SensitivityChart.SetMinMax(Data.Combined.MinAccel, Data.Combined.MaxAccel); - GainChart.SetMinMax(Data.Combined.MinGain, Data.Combined.MaxGain); + SensitivityChart.Bind(Data.X.AccelPoints); + VelocityChart.Bind(Data.X.VelocityPoints); + GainChart.Bind(Data.X.GainPoints); + SensitivityChart.SetMinMax(Data.X.MinAccel, Data.X.MaxAccel); + GainChart.SetMinMax(Data.X.MinGain, Data.X.MaxGain); } public override void Calculate(ManagedAccel accel, DriverSettings settings) { - Calculator.Calculate(Data.Combined, accel, settings.sensitivity.x, Calculator.SimulatedInputCombined); + Calculator.Calculate(Data.X, accel, settings.sensitivity.x, Calculator.SimulatedInputCombined); } } } diff --git a/grapher/Models/Charts/ChartState/XYOneGraphState.cs b/grapher/Models/Charts/ChartState/XYOneGraphState.cs index 4a755b6..14d8850 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.Calculations.Data; using grapher.Models.Serialized; namespace grapher.Models.Charts.ChartState @@ -9,15 +10,16 @@ namespace grapher.Models.Charts.ChartState ChartXY sensitivityChart, ChartXY velocityChart, ChartXY gainChart, - AccelData accelData, + EstimatedPoints xPoints, + EstimatedPoints yPoints, AccelCalculator accelCalculator) : base( sensitivityChart, velocityChart, gainChart, - accelData, accelCalculator) { + Data = new AccelDataXYDirectional(xPoints, yPoints, accelCalculator); TwoDotsPerGraph = true; } @@ -30,7 +32,7 @@ namespace grapher.Models.Charts.ChartState public override void MakeDots(double x, double y, double timeInMs) { - Data.CalculateDotsCombinedDiffSens(x, y, timeInMs, Settings); + Data.CalculateDots(x, y, timeInMs); } public override void Bind() diff --git a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs index 732ea3c..7dc2810 100644 --- a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs @@ -1,4 +1,5 @@ using grapher.Models.Calculations; +using grapher.Models.Calculations.Data; using grapher.Models.Serialized; using System; @@ -10,15 +11,17 @@ namespace grapher.Models.Charts.ChartState ChartXY sensitivityChart, ChartXY velocityChart, ChartXY gainChart, - AccelData accelData, + EstimatedPoints xPoints, + EstimatedPoints yPoints, AccelCalculator accelCalculator) : base( sensitivityChart, velocityChart, gainChart, - accelData, accelCalculator) - { } + { + Data = new AccelDataXYComponential(xPoints, yPoints, accelCalculator); + } public override DriverSettings Settings { get; set; } @@ -35,7 +38,7 @@ namespace grapher.Models.Charts.ChartState public override void MakeDots(double x, double y, double timeInMs) { - Data.CalculateDotsXY(x, y, timeInMs); + Data.CalculateDots(x, y, timeInMs); } public override void Bind() diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index 140d521..0216b8b 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -84,6 +84,10 @@ <Compile Include="Models\Calculations\AccelCalculator.cs" /> <Compile Include="Models\Calculations\AccelChartData.cs" /> <Compile Include="Models\Calculations\AccelData.cs" /> + <Compile Include="Models\Calculations\Data\AccelDataCombined.cs" /> + <Compile Include="Models\Calculations\Data\AccelDataXYComponential.cs" /> + <Compile Include="Models\Calculations\Data\AccelDataXYDirectional.cs" /> + <Compile Include="Models\Calculations\Data\IAccelData.cs" /> <Compile Include="Models\Charts\AccelCharts.cs" /> <Compile Include="Models\AccelGUI.cs" /> <Compile Include="Models\Charts\ChartState\ChartState.cs" /> |