From 05c7094a93c7d29eb8ac05247110995574a7b963 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 16 Sep 2020 01:20:23 -0700 Subject: Unsure if I will use this --- grapher/Models/AccelGUI.cs | 2 +- grapher/Models/Charts/AccelCharts.cs | 196 +++++++++------------ grapher/Models/Charts/ChartState/ChartState.cs | 86 +++++++++ .../Models/Charts/ChartState/ChartStateManager.cs | 68 +++++++ grapher/Models/Charts/ChartState/CombinedState.cs | 38 ++++ .../Models/Charts/ChartState/XYOneGraphState.cs | 20 +++ .../Models/Charts/ChartState/XYTwoGraphState.cs | 38 ++++ grapher/Models/Options/ApplyOptions.cs | 2 +- 8 files changed, 332 insertions(+), 118 deletions(-) create mode 100644 grapher/Models/Charts/ChartState/ChartState.cs create mode 100644 grapher/Models/Charts/ChartState/ChartStateManager.cs create mode 100644 grapher/Models/Charts/ChartState/CombinedState.cs create mode 100644 grapher/Models/Charts/ChartState/XYOneGraphState.cs create mode 100644 grapher/Models/Charts/ChartState/XYTwoGraphState.cs (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 3acb943..59aab2f 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -128,7 +128,7 @@ namespace grapher private void SetupWriteButton() { - WriteButton.Top = AccelCharts.SensitivityChart.Top + AccelCharts.SensitivityChart.Height - Constants.WriteButtonVerticalOffset; + WriteButton.Top = AccelCharts.Top + AccelCharts.TopChartHeight - Constants.WriteButtonVerticalOffset; SetWriteButtonDefault(); } diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs index 3f228c3..f255d79 100644 --- a/grapher/Models/Charts/AccelCharts.cs +++ b/grapher/Models/Charts/AccelCharts.cs @@ -1,5 +1,6 @@ using grapher.Models.Calculations; using grapher.Models.Charts; +using grapher.Models.Charts.ChartState; using grapher.Models.Serialized; using System; using System.Drawing; @@ -20,31 +21,21 @@ namespace grapher ToolStripMenuItem enableLastMouseMove, Button writeButton) { - Estimated = new EstimatedPoints(); - EstimatedX = new EstimatedPoints(); - EstimatedY = new EstimatedPoints(); - AccelData = new AccelData(Estimated, EstimatedX, EstimatedY); + var estimated = new EstimatedPoints(); + 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); - ContaingForm = form; - SensitivityChart = sensitivityChart; - VelocityChart = velocityChart; - GainChart = gainChart; + ContainingForm = form; EnableVelocityAndGain = enableVelocityAndGain; EnableLastValue = enableLastMouseMove; WriteButton = writeButton; - SensitivityChart.SetPointBinds(Estimated.Sensitivity, EstimatedX.Sensitivity, EstimatedY.Sensitivity); - VelocityChart.SetPointBinds(Estimated.Velocity, EstimatedX.Velocity, EstimatedY.Velocity); - GainChart.SetPointBinds(Estimated.Gain, EstimatedX.Gain, EstimatedY.Gain); - SensitivityChart.SetTop(0); - VelocityChart.SetHeight(SensitivityChart.Height); - VelocityChart.SetTop(SensitivityChart.Height + Constants.ChartSeparationVertical); - GainChart.SetHeight(SensitivityChart.Height); - GainChart.SetTop(VelocityChart.Top + VelocityChart.Height + Constants.ChartSeparationVertical); - - Rectangle screenRectangle = ContaingForm.RectangleToScreen(ContaingForm.ClientRectangle); - FormBorderHeight = screenRectangle.Top - ContaingForm.Top; + Rectangle screenRectangle = ContainingForm.RectangleToScreen(ContainingForm.ClientRectangle); + FormBorderHeight = screenRectangle.Top - ContainingForm.Top; EnableVelocityAndGain.Click += new System.EventHandler(OnEnableClick); EnableVelocityAndGain.CheckedChanged += new System.EventHandler(OnEnableVelocityGainCheckStateChange); @@ -52,22 +43,15 @@ namespace grapher EnableLastValue.CheckedChanged += new System.EventHandler(OnEnableLastMouseMoveCheckStateChange); HideVelocityAndGain(); - SensitivityChart.Show(); - Combined = false; - ShowCombined(); + ChartState = ChartStateManager.InitialState(); + ChartState.Activate(); } #endregion Constructors #region Properties - public Form ContaingForm { get; } - - public ChartXY SensitivityChart { get; } - - public ChartXY VelocityChart { get; } - - public ChartXY GainChart { get; } + public Form ContainingForm { get; } public ToolStripMenuItem EnableVelocityAndGain { get; } @@ -75,90 +59,109 @@ namespace grapher private Button WriteButton { get; } - public AccelData AccelData { get; } - - private EstimatedPoints Estimated { get; } + public AccelData AccelData + { + get + { + return ChartState.AccelData; + } + } - private EstimatedPoints EstimatedX { get; } + public int Left + { + get + { + return ChartState.SensitivityChart.Left; + } + } - private EstimatedPoints EstimatedY { get; } + public int Top + { + get + { + return ChartState.SensitivityChart.Top; + } + } - private bool Combined { get; set; } + public int TopChartHeight + { + get + { + return ChartState.SensitivityChart.Height; + } + } private int FormBorderHeight { get; } + private ChartState ChartState { get; set; } + + private ChartStateManager ChartStateManager { get; } + #endregion Properties #region Methods public void MakeDots(int x, int y, double timeInMs) { - if (Combined) - { - AccelData.CalculateDots(x, y, timeInMs); - } - else - { - AccelData.CalculateDotsXY(x, y, timeInMs); - } + ChartState.MakeDots(x, y, timeInMs); } public void DrawLastMovement() { if (EnableLastValue.Checked) { - SensitivityChart.DrawLastMovementValue(); - VelocityChart.DrawLastMovementValue(); - GainChart.DrawLastMovementValue(); + ChartState.DrawLastMovement(); } } public void Bind() { - if (Combined) - { - SensitivityChart.Bind(AccelData.Combined.AccelPoints); - VelocityChart.Bind(AccelData.Combined.VelocityPoints); - GainChart.Bind(AccelData.Combined.GainPoints); - } - else - { - SensitivityChart.BindXY(AccelData.X.AccelPoints, AccelData.Y.AccelPoints); - VelocityChart.BindXY(AccelData.X.VelocityPoints, AccelData.Y.VelocityPoints); - GainChart.BindXY(AccelData.X.GainPoints, AccelData.Y.GainPoints); - } + ChartState.Bind(); } public void ShowActive(DriverSettings driverSettings) { - if (driverSettings.combineMagnitudes) - { - ShowCombined(); - } - else - { - ShowXandYSeparate(); - } + ChartState = ChartStateManager.DetermineState(driverSettings); + ChartState.Activate(); + UpdateFormWidth(); + Bind(); } public void SetWidened() { - SensitivityChart.SetWidened(); - VelocityChart.SetWidened(); - GainChart.SetWidened(); + ChartState.SetWidened(); UpdateFormWidth(); AlignWriteButton(); } public void SetNarrowed() { - SensitivityChart.SetNarrowed(); - VelocityChart.SetNarrowed(); - GainChart.SetNarrowed(); + ChartState.SetNarrowed(); UpdateFormWidth(); AlignWriteButton(); } + private static void SetupCharts( + ChartXY sensitivityChart, + ChartXY velocityChart, + ChartXY gainChart, + EstimatedPoints estimated, + EstimatedPoints estimatedX, + EstimatedPoints estimatedY) + { + sensitivityChart.SetPointBinds(estimated.Sensitivity, estimatedX.Sensitivity, estimatedY.Sensitivity); + velocityChart.SetPointBinds(estimated.Velocity, estimatedX.Velocity, estimatedY.Velocity); + gainChart.SetPointBinds(estimated.Gain, estimatedX.Gain, estimatedY.Gain); + + sensitivityChart.SetTop(0); + velocityChart.SetHeight(sensitivityChart.Height); + velocityChart.SetTop(sensitivityChart.Height + Constants.ChartSeparationVertical); + gainChart.SetHeight(sensitivityChart.Height); + gainChart.SetTop(velocityChart.Top + velocityChart.Height + Constants.ChartSeparationVertical); + + sensitivityChart.Show(); + } + private void OnEnableClick(object sender, EventArgs e) { EnableVelocityAndGain.Checked = !EnableVelocityAndGain.Checked; @@ -180,67 +183,28 @@ namespace grapher { if (!EnableLastValue.Checked) { - SensitivityChart.ClearLastValue(); - VelocityChart.ClearLastValue(); - GainChart.ClearLastValue(); + ChartState.ClearLastValue(); } } private void ShowVelocityAndGain() { - VelocityChart.Show(); - GainChart.Show(); - ContaingForm.Height = SensitivityChart.Height + - Constants.ChartSeparationVertical + - VelocityChart.Height + - Constants.ChartSeparationVertical + - GainChart.Height + - FormBorderHeight; + ChartState.ShowVelocityAndGain(ContainingForm, FormBorderHeight); } private void HideVelocityAndGain() { - VelocityChart.Hide(); - GainChart.Hide(); - ContaingForm.Height = SensitivityChart.Height + FormBorderHeight; - } - - private void ShowXandYSeparate() - { - if (Combined) - { - Combined = false; - - SensitivityChart.SetSeparate(); - VelocityChart.SetSeparate(); - GainChart.SetSeparate(); - UpdateFormWidth(); - Bind(); - } - } - - private void ShowCombined() - { - if (!Combined) - { - Combined = true; - - SensitivityChart.SetCombined(); - VelocityChart.SetCombined(); - GainChart.SetCombined(); - UpdateFormWidth(); - Bind(); - } + ChartState.HideVelocityAndGain(ContainingForm, FormBorderHeight); } private void UpdateFormWidth() { - ContaingForm.Width = SensitivityChart.Left + SensitivityChart.Width; + ContainingForm.Width = ChartState.SensitivityChart.Left + ChartState.SensitivityChart.Width; } private void AlignWriteButton() { - WriteButton.Left = SensitivityChart.Left / 2 - WriteButton.Width / 2; + WriteButton.Left = ChartState.SensitivityChart.Left / 2 - WriteButton.Width / 2; } #endregion Methods diff --git a/grapher/Models/Charts/ChartState/ChartState.cs b/grapher/Models/Charts/ChartState/ChartState.cs new file mode 100644 index 0000000..b450357 --- /dev/null +++ b/grapher/Models/Charts/ChartState/ChartState.cs @@ -0,0 +1,86 @@ +using grapher.Models.Calculations; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Charts.ChartState +{ + public abstract class ChartState + { + public ChartState( + ChartXY sensitivityChart, + ChartXY velocityChart, + ChartXY gainChart, + AccelData accelData) + { + SensitivityChart = sensitivityChart; + VelocityChart = velocityChart; + GainChart = gainChart; + AccelData = accelData; + } + + public ChartXY SensitivityChart { get; } + + public ChartXY VelocityChart { get; } + + public ChartXY GainChart { get; } + + public AccelData AccelData { get; } + + public abstract void MakeDots(int x, int y, double timeInMs); + + public abstract void Bind(); + + public abstract void Activate(); + + public void DrawLastMovement() + { + SensitivityChart.DrawLastMovementValue(); + VelocityChart.DrawLastMovementValue(); + GainChart.DrawLastMovementValue(); + } + + public void SetWidened() + { + SensitivityChart.SetWidened(); + VelocityChart.SetWidened(); + GainChart.SetWidened(); + } + + public void SetNarrowed() + { + SensitivityChart.SetNarrowed(); + VelocityChart.SetNarrowed(); + GainChart.SetNarrowed(); + } + + public void ClearLastValue() + { + SensitivityChart.ClearLastValue(); + VelocityChart.ClearLastValue(); + GainChart.ClearLastValue(); + } + + public void ShowVelocityAndGain(Form form, int borderHeight) + { + VelocityChart.Show(); + GainChart.Show(); + form.Height = SensitivityChart.Height + + Constants.ChartSeparationVertical + + VelocityChart.Height + + Constants.ChartSeparationVertical + + GainChart.Height + + borderHeight; + } + + public void HideVelocityAndGain(Form form, int borderHeight) + { + VelocityChart.Hide(); + GainChart.Hide(); + form.Height = SensitivityChart.Height + borderHeight; + } + } +} diff --git a/grapher/Models/Charts/ChartState/ChartStateManager.cs b/grapher/Models/Charts/ChartState/ChartStateManager.cs new file mode 100644 index 0000000..27d0836 --- /dev/null +++ b/grapher/Models/Charts/ChartState/ChartStateManager.cs @@ -0,0 +1,68 @@ +using grapher.Models.Calculations; +using grapher.Models.Serialized; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Models.Charts.ChartState +{ + public class ChartStateManager + { + public ChartStateManager( + ChartXY sensitivityChart, + ChartXY velocityChart, + ChartXY gainChat, + AccelData accelData) + { + CombinedState = new CombinedState( + sensitivityChart, + velocityChart, + gainChat, + accelData); + + XYOneGraphState = new XYOneGraphState( + sensitivityChart, + velocityChart, + gainChat, + accelData); + + XYTwoGraphState = new XYTwoGraphState( + sensitivityChart, + velocityChart, + gainChat, + accelData); + } + + private CombinedState CombinedState { get; } + + private XYOneGraphState XYOneGraphState { get; } + + private XYTwoGraphState XYTwoGraphState { get; } + + public ChartState DetermineState(DriverSettings settings) + { + if (settings.combineMagnitudes) + { + if (settings.sensitivity.x != settings.sensitivity.y) + { + return XYOneGraphState; + } + else + { + return CombinedState; + } + } + else + { + return XYTwoGraphState; + } + } + + public ChartState InitialState() + { + return CombinedState; + } + } +} diff --git a/grapher/Models/Charts/ChartState/CombinedState.cs b/grapher/Models/Charts/ChartState/CombinedState.cs new file mode 100644 index 0000000..bc8c720 --- /dev/null +++ b/grapher/Models/Charts/ChartState/CombinedState.cs @@ -0,0 +1,38 @@ +using grapher.Models.Calculations; + +namespace grapher.Models.Charts.ChartState +{ + public class CombinedState : ChartState + { + public CombinedState( + ChartXY sensitivityChart, + ChartXY velocityChart, + ChartXY gainChart, + AccelData accelData) + : base( + sensitivityChart, + velocityChart, + gainChart, + accelData) + { } + + public override void Activate() + { + SensitivityChart.SetCombined(); + VelocityChart.SetCombined(); + GainChart.SetCombined(); + } + + public override void MakeDots(int x, int y, double timeInMs) + { + AccelData.CalculateDots(x, y, timeInMs); + } + + public override void Bind() + { + SensitivityChart.Bind(AccelData.Combined.AccelPoints); + VelocityChart.Bind(AccelData.Combined.VelocityPoints); + GainChart.Bind(AccelData.Combined.GainPoints); + } + } +} diff --git a/grapher/Models/Charts/ChartState/XYOneGraphState.cs b/grapher/Models/Charts/ChartState/XYOneGraphState.cs new file mode 100644 index 0000000..58276e4 --- /dev/null +++ b/grapher/Models/Charts/ChartState/XYOneGraphState.cs @@ -0,0 +1,20 @@ +using grapher.Models.Calculations; + +namespace grapher.Models.Charts.ChartState +{ + public class XYOneGraphState : ChartState + { + public XYOneGraphState( + ChartXY sensitivityChart, + ChartXY velocityChart, + ChartXY gainChart, + AccelData accelData) + : base( + sensitivityChart, + velocityChart, + gainChart, + accelData) + { } + + } +} diff --git a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs new file mode 100644 index 0000000..f37af08 --- /dev/null +++ b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs @@ -0,0 +1,38 @@ +using grapher.Models.Calculations; + +namespace grapher.Models.Charts.ChartState +{ + public class XYTwoGraphState : ChartState + { + public XYTwoGraphState( + ChartXY sensitivityChart, + ChartXY velocityChart, + ChartXY gainChart, + AccelData accelData) + : base( + sensitivityChart, + velocityChart, + gainChart, + accelData) + { } + + public override void Activate() + { + SensitivityChart.SetSeparate(); + VelocityChart.SetSeparate(); + GainChart.SetSeparate(); + } + + public override void MakeDots(int x, int y, double timeInMs) + { + AccelData.CalculateDotsXY(x, y, timeInMs); + } + + public override void Bind() + { + SensitivityChart.BindXY(AccelData.X.AccelPoints, AccelData.Y.AccelPoints); + VelocityChart.BindXY(AccelData.X.VelocityPoints, AccelData.Y.VelocityPoints); + GainChart.BindXY(AccelData.X.GainPoints, AccelData.Y.GainPoints); + } + } +} diff --git a/grapher/Models/Options/ApplyOptions.cs b/grapher/Models/Options/ApplyOptions.cs index 241fe50..6ec9d31 100644 --- a/grapher/Models/Options/ApplyOptions.cs +++ b/grapher/Models/Options/ApplyOptions.cs @@ -227,7 +227,7 @@ namespace grapher.Models.Options private void SetActiveTitlesWhole() { OptionSetX.ActiveValuesTitle.Left = OptionSetX.Options.Left + OptionSetX.Options.Width; - LockXYLabel.Width = (AccelCharts.SensitivityChart.Left - OptionSetX.ActiveValuesTitle.Left) / 2; + LockXYLabel.Width = (AccelCharts.Left - OptionSetX.ActiveValuesTitle.Left) / 2; OptionSetX.ActiveValuesTitle.Width = LockXYLabel.Width; LockXYLabel.Left = OptionSetX.ActiveValuesTitle.Left + OptionSetX.ActiveValuesTitle.Width; Sensitivity.Fields.LockCheckBox.Left = LockXYLabel.Left + LockXYLabel.Width / 2 - Sensitivity.Fields.LockCheckBox.Width / 2; -- cgit v1.2.3 From 5beedd6d1aca73adaae6556ded584d3f454509b0 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 17 Sep 2020 01:29:18 -0700 Subject: Much progress --- grapher/Models/Calculations/AccelCalculator.cs | 57 +++++++++++++++++++++- grapher/Models/Charts/AccelCharts.cs | 2 +- grapher/Models/Charts/ChartState/ChartState.cs | 3 ++ .../Models/Charts/ChartState/ChartStateManager.cs | 12 +++-- .../Models/Charts/ChartState/XYOneGraphState.cs | 18 +++++++ .../Models/Charts/ChartState/XYTwoGraphState.cs | 32 +++++++++++- 6 files changed, 117 insertions(+), 7 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs index 4627732..9bbbd26 100644 --- a/grapher/Models/Calculations/AccelCalculator.cs +++ b/grapher/Models/Calculations/AccelCalculator.cs @@ -49,6 +49,10 @@ namespace grapher.Models.Calculations private double MeasurementTime { get; set; } + private (double, double) RotationVector { get; set; } + + private (double, double) Sensitivity { get; set; } + #endregion Fields #region Methods @@ -59,19 +63,44 @@ namespace grapher.Models.Calculations data.Clear(); - Calculate(data.Combined, accel, settings.sensitivity.x, MagnitudesCombined); + Calculate(data.Combined, accel, settings.sensitivity.x, MagnitudesCombined, true, settings); Calculate(data.X, accel, settings.sensitivity.x, MagnitudesX); Calculate(data.Y, accel, settings.sensitivity.y, MagnitudesY); } - public void Calculate(AccelChartData data, ManagedAccel accel, double starter, ICollection magnitudeData) + public void Calculate(AccelChartData data, ManagedAccel accel, double starter, ICollection magnitudeData, bool strip = false, DriverSettings settings = null) { double lastInputMagnitude = 0; double lastOutputMagnitude = 0; + bool stripSens = strip && ShouldStripSens(ref settings); + bool stripRot = strip && ShouldStripRot(ref settings); + + if(stripSens) + { + Sensitivity = GetSens(ref settings); + } + + if (stripRot) + { + RotationVector = GetRotVector(ref settings); + } + foreach (var magnitudeDatum in magnitudeData) { var output = accel.Accelerate(magnitudeDatum.x, magnitudeDatum.y, MeasurementTime); + var outputX = output.Item1; + var outputY = output.Item2; + + if (stripSens) + { + (outputX, outputY) = StripThisSens(outputX, outputY); + } + + if (stripRot) + { + (outputX, outputY) = StripThisRot(outputX, outputY); + } var outMagnitude = Magnitude(output.Item1, output.Item2); var ratio = magnitudeDatum.magnitude > 0 ? outMagnitude / magnitudeDatum.magnitude : starter; @@ -174,6 +203,30 @@ namespace grapher.Models.Calculations return Magnitude(x, y) / time; } + public static bool ShouldStripSens(ref DriverSettings settings) => + settings.sensitivity.x != settings.sensitivity.y; + + public static bool ShouldStripRot(ref DriverSettings settings) => + settings.rotation > 0; + + public static (double, double) GetSens(ref DriverSettings settings) => + (settings.sensitivity.x, settings.sensitivity.y); + + public static (double, double) GetRotVector(ref DriverSettings settings) => + (Math.Cos(settings.rotation), Math.Sin(settings.rotation)); + + public static (double, double) StripSens(double outputX, double outputY, double sensitivityX, double sensitivityY) => + (outputX / sensitivityX, outputY / sensitivityY); + + public (double, double) StripRot(double outputX, double outputY, double rotX, double rotY) => + (outputX * rotX + outputY * rotY, outputX * rotY - outputY * rotX); + + public (double, double) StripThisSens(double outputX, double outputY) => + StripSens(outputX, outputY, Sensitivity.Item1, Sensitivity.Item2); + + public (double, double) StripThisRot(double outputX, double outputY) => + StripRot(outputX, outputY, RotationVector.Item1, RotationVector.Item2); + public void ScaleByMouseSettings() { var dpiPollFactor = DPI.Data / PollRate.Data; diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs index f255d79..844afe1 100644 --- a/grapher/Models/Charts/AccelCharts.cs +++ b/grapher/Models/Charts/AccelCharts.cs @@ -42,9 +42,9 @@ namespace grapher EnableLastValue.CheckedChanged += new System.EventHandler(OnEnableLastMouseMoveCheckStateChange); - HideVelocityAndGain(); ChartState = ChartStateManager.InitialState(); ChartState.Activate(); + HideVelocityAndGain(); } #endregion Constructors diff --git a/grapher/Models/Charts/ChartState/ChartState.cs b/grapher/Models/Charts/ChartState/ChartState.cs index b450357..cc334ac 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.Serialized; using System; using System.Collections.Generic; using System.Linq; @@ -30,6 +31,8 @@ namespace grapher.Models.Charts.ChartState public AccelData AccelData { get; } + public virtual DriverSettings Settings { get; set; } + public abstract void MakeDots(int x, int y, double timeInMs); public abstract void Bind(); diff --git a/grapher/Models/Charts/ChartState/ChartStateManager.cs b/grapher/Models/Charts/ChartState/ChartStateManager.cs index 27d0836..b64b1a2 100644 --- a/grapher/Models/Charts/ChartState/ChartStateManager.cs +++ b/grapher/Models/Charts/ChartState/ChartStateManager.cs @@ -41,23 +41,29 @@ namespace grapher.Models.Charts.ChartState private XYTwoGraphState XYTwoGraphState { get; } + public ChartState DetermineState(DriverSettings settings) { + ChartState chartState; + if (settings.combineMagnitudes) { if (settings.sensitivity.x != settings.sensitivity.y) { - return XYOneGraphState; + chartState = XYOneGraphState; } else { - return CombinedState; + chartState = CombinedState; } } else { - return XYTwoGraphState; + chartState = XYTwoGraphState; } + + chartState.Settings = settings; + return chartState; } public ChartState InitialState() diff --git a/grapher/Models/Charts/ChartState/XYOneGraphState.cs b/grapher/Models/Charts/ChartState/XYOneGraphState.cs index 58276e4..3ed5c5b 100644 --- a/grapher/Models/Charts/ChartState/XYOneGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYOneGraphState.cs @@ -16,5 +16,23 @@ namespace grapher.Models.Charts.ChartState accelData) { } + public override void Activate() + { + SensitivityChart.SetSeparate(); + VelocityChart.SetSeparate(); + GainChart.SetSeparate(); + } + + public override void MakeDots(int x, int y, double timeInMs) + { + AccelData.CalculateDotsXY(x, y, timeInMs); + } + + public override void Bind() + { + SensitivityChart.BindXY(AccelData.X.AccelPoints, AccelData.Y.AccelPoints); + VelocityChart.BindXY(AccelData.X.VelocityPoints, AccelData.Y.VelocityPoints); + GainChart.BindXY(AccelData.X.GainPoints, AccelData.Y.GainPoints); + } } } diff --git a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs index f37af08..b54832c 100644 --- a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs @@ -1,9 +1,13 @@ using grapher.Models.Calculations; +using grapher.Models.Serialized; +using System; namespace grapher.Models.Charts.ChartState { public class XYTwoGraphState : ChartState { + private DriverSettings _settings; + public XYTwoGraphState( ChartXY sensitivityChart, ChartXY velocityChart, @@ -16,6 +20,24 @@ namespace grapher.Models.Charts.ChartState accelData) { } + public override DriverSettings Settings + { + get { return _settings; } + set + { + _settings = value; + ShouldStripSens = AccelCalculator.ShouldStripSens(ref value); + if (ShouldStripSens) + { + Sensitivity = AccelCalculator.GetSens(ref value); + } + } + } + + private bool ShouldStripSens { get; set; } + + private (double, double) Sensitivity { get; set; } + public override void Activate() { SensitivityChart.SetSeparate(); @@ -25,7 +47,15 @@ namespace grapher.Models.Charts.ChartState public override void MakeDots(int x, int y, double timeInMs) { - AccelData.CalculateDotsXY(x, y, timeInMs); + double xCalc = x; + double yCalc = y; + + if (ShouldStripSens) + { + (xCalc, yCalc) = AccelCalculator.StripSens(xCalc, yCalc, Sensitivity.Item1, Sensitivity.Item2); + } + + AccelData.CalculateDotsXY((int)Math.Round(xCalc), (int)Math.Round(yCalc), timeInMs); } public override void Bind() -- cgit v1.2.3 From df173decac3ac5e1043b53961f1512bb88b85136 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 17 Sep 2020 20:26:15 -0700 Subject: Further work --- grapher/Models/Calculations/AccelCalculator.cs | 5 ----- grapher/Models/Charts/AccelCharts.cs | 7 ++++--- grapher/Models/Charts/ChartState/ChartState.cs | 12 +++++++++--- grapher/Models/Charts/ChartState/ChartStateManager.cs | 12 ++++++++---- grapher/Models/Charts/ChartState/CombinedState.cs | 14 ++++++++------ grapher/Models/Charts/ChartState/XYOneGraphState.cs | 14 ++++++++------ grapher/Models/Charts/ChartState/XYTwoGraphState.cs | 14 ++++++++------ 7 files changed, 45 insertions(+), 33 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs index 9bbbd26..9807ddf 100644 --- a/grapher/Models/Calculations/AccelCalculator.cs +++ b/grapher/Models/Calculations/AccelCalculator.cs @@ -97,11 +97,6 @@ namespace grapher.Models.Calculations (outputX, outputY) = StripThisSens(outputX, outputY); } - if (stripRot) - { - (outputX, outputY) = StripThisRot(outputX, outputY); - } - var outMagnitude = Magnitude(output.Item1, output.Item2); var ratio = magnitudeDatum.magnitude > 0 ? outMagnitude / magnitudeDatum.magnitude : starter; diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs index 844afe1..a5f004d 100644 --- a/grapher/Models/Charts/AccelCharts.cs +++ b/grapher/Models/Charts/AccelCharts.cs @@ -19,14 +19,15 @@ namespace grapher ChartXY gainChart, ToolStripMenuItem enableVelocityAndGain, ToolStripMenuItem enableLastMouseMove, - Button writeButton) + Button writeButton, + AccelCalculator accelCalculator) { var estimated = new EstimatedPoints(); 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); + ChartStateManager = new ChartStateManager(sensitivityChart, velocityChart, gainChart, accelData, accelCalculator); ContainingForm = form; EnableVelocityAndGain = enableVelocityAndGain; @@ -63,7 +64,7 @@ namespace grapher { get { - return ChartState.AccelData; + return ChartState.Data; } } diff --git a/grapher/Models/Charts/ChartState/ChartState.cs b/grapher/Models/Charts/ChartState/ChartState.cs index cc334ac..99f44ff 100644 --- a/grapher/Models/Charts/ChartState/ChartState.cs +++ b/grapher/Models/Charts/ChartState/ChartState.cs @@ -15,12 +15,14 @@ namespace grapher.Models.Charts.ChartState ChartXY sensitivityChart, ChartXY velocityChart, ChartXY gainChart, - AccelData accelData) + AccelData accelData, + AccelCalculator calculator) { SensitivityChart = sensitivityChart; VelocityChart = velocityChart; GainChart = gainChart; - AccelData = accelData; + Data = accelData; + Calculator = calculator; } public ChartXY SensitivityChart { get; } @@ -29,7 +31,9 @@ namespace grapher.Models.Charts.ChartState public ChartXY GainChart { get; } - public AccelData AccelData { get; } + public AccelData Data { get; } + + public AccelCalculator Calculator { get; } public virtual DriverSettings Settings { get; set; } @@ -39,6 +43,8 @@ namespace grapher.Models.Charts.ChartState public abstract void Activate(); + public abstract void Calculate(); + public void DrawLastMovement() { SensitivityChart.DrawLastMovementValue(); diff --git a/grapher/Models/Charts/ChartState/ChartStateManager.cs b/grapher/Models/Charts/ChartState/ChartStateManager.cs index b64b1a2..54d2e81 100644 --- a/grapher/Models/Charts/ChartState/ChartStateManager.cs +++ b/grapher/Models/Charts/ChartState/ChartStateManager.cs @@ -14,25 +14,29 @@ namespace grapher.Models.Charts.ChartState ChartXY sensitivityChart, ChartXY velocityChart, ChartXY gainChat, - AccelData accelData) + AccelData accelData, + AccelCalculator accelCalculator) { CombinedState = new CombinedState( sensitivityChart, velocityChart, gainChat, - accelData); + accelData, + accelCalculator); XYOneGraphState = new XYOneGraphState( sensitivityChart, velocityChart, gainChat, - accelData); + accelData, + accelCalculator); XYTwoGraphState = new XYTwoGraphState( sensitivityChart, velocityChart, gainChat, - accelData); + accelData, + accelCalculator); } private CombinedState CombinedState { get; } diff --git a/grapher/Models/Charts/ChartState/CombinedState.cs b/grapher/Models/Charts/ChartState/CombinedState.cs index bc8c720..d229a43 100644 --- a/grapher/Models/Charts/ChartState/CombinedState.cs +++ b/grapher/Models/Charts/ChartState/CombinedState.cs @@ -8,12 +8,14 @@ namespace grapher.Models.Charts.ChartState ChartXY sensitivityChart, ChartXY velocityChart, ChartXY gainChart, - AccelData accelData) + AccelData accelData, + AccelCalculator accelCalculator) : base( sensitivityChart, velocityChart, gainChart, - accelData) + accelData, + accelCalculator) { } public override void Activate() @@ -25,14 +27,14 @@ namespace grapher.Models.Charts.ChartState public override void MakeDots(int x, int y, double timeInMs) { - AccelData.CalculateDots(x, y, timeInMs); + Data.CalculateDots(x, y, timeInMs); } public override void Bind() { - SensitivityChart.Bind(AccelData.Combined.AccelPoints); - VelocityChart.Bind(AccelData.Combined.VelocityPoints); - GainChart.Bind(AccelData.Combined.GainPoints); + SensitivityChart.Bind(Data.Combined.AccelPoints); + VelocityChart.Bind(Data.Combined.VelocityPoints); + GainChart.Bind(Data.Combined.GainPoints); } } } diff --git a/grapher/Models/Charts/ChartState/XYOneGraphState.cs b/grapher/Models/Charts/ChartState/XYOneGraphState.cs index 3ed5c5b..bc9a88d 100644 --- a/grapher/Models/Charts/ChartState/XYOneGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYOneGraphState.cs @@ -8,12 +8,14 @@ namespace grapher.Models.Charts.ChartState ChartXY sensitivityChart, ChartXY velocityChart, ChartXY gainChart, - AccelData accelData) + AccelData accelData, + AccelCalculator accelCalculator) : base( sensitivityChart, velocityChart, gainChart, - accelData) + accelData, + accelCalculator) { } public override void Activate() @@ -25,14 +27,14 @@ namespace grapher.Models.Charts.ChartState public override void MakeDots(int x, int y, double timeInMs) { - AccelData.CalculateDotsXY(x, y, timeInMs); + Data.CalculateDotsXY(x, y, timeInMs); } public override void Bind() { - SensitivityChart.BindXY(AccelData.X.AccelPoints, AccelData.Y.AccelPoints); - VelocityChart.BindXY(AccelData.X.VelocityPoints, AccelData.Y.VelocityPoints); - GainChart.BindXY(AccelData.X.GainPoints, AccelData.Y.GainPoints); + SensitivityChart.BindXY(Data.X.AccelPoints, Data.Y.AccelPoints); + VelocityChart.BindXY(Data.X.VelocityPoints, Data.Y.VelocityPoints); + GainChart.BindXY(Data.X.GainPoints, Data.Y.GainPoints); } } } diff --git a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs index b54832c..8be88f0 100644 --- a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs @@ -12,12 +12,14 @@ namespace grapher.Models.Charts.ChartState ChartXY sensitivityChart, ChartXY velocityChart, ChartXY gainChart, - AccelData accelData) + AccelData accelData, + AccelCalculator accelCalculator) : base( sensitivityChart, velocityChart, gainChart, - accelData) + accelData, + accelCalculator) { } public override DriverSettings Settings @@ -55,14 +57,14 @@ namespace grapher.Models.Charts.ChartState (xCalc, yCalc) = AccelCalculator.StripSens(xCalc, yCalc, Sensitivity.Item1, Sensitivity.Item2); } - AccelData.CalculateDotsXY((int)Math.Round(xCalc), (int)Math.Round(yCalc), timeInMs); + Data.CalculateDotsXY((int)Math.Round(xCalc), (int)Math.Round(yCalc), timeInMs); } public override void Bind() { - SensitivityChart.BindXY(AccelData.X.AccelPoints, AccelData.Y.AccelPoints); - VelocityChart.BindXY(AccelData.X.VelocityPoints, AccelData.Y.VelocityPoints); - GainChart.BindXY(AccelData.X.GainPoints, AccelData.Y.GainPoints); + SensitivityChart.BindXY(Data.X.AccelPoints, Data.Y.AccelPoints); + VelocityChart.BindXY(Data.X.VelocityPoints, Data.Y.VelocityPoints); + GainChart.BindXY(Data.X.GainPoints, Data.Y.GainPoints); } } } -- cgit v1.2.3 From 1dd0c108b8948c50fd8f2b9c9055dbb8e7d47270 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 17 Sep 2020 23:51:47 -0700 Subject: Add y lines to graphes + further work --- grapher/Models/AccelGUI.cs | 3 +-- grapher/Models/Calculations/AccelCalculator.cs | 11 ----------- grapher/Models/Charts/AccelCharts.cs | 6 ++++++ grapher/Models/Charts/ChartState/ChartState.cs | 7 ++++++- grapher/Models/Charts/ChartState/CombinedState.cs | 6 ++++++ grapher/Models/Charts/ChartState/XYTwoGraphState.cs | 6 ++++++ 6 files changed, 25 insertions(+), 14 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 59aab2f..5567be3 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -102,8 +102,7 @@ namespace grapher public void UpdateGraph() { - AccelCalculator.Calculate( - AccelCharts.AccelData, + AccelCharts.Calculate( Settings.ActiveAccel, Settings.RawAccelSettings.AccelerationSettings); AccelCharts.Bind(); diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs index 9807ddf..ab1f346 100644 --- a/grapher/Models/Calculations/AccelCalculator.cs +++ b/grapher/Models/Calculations/AccelCalculator.cs @@ -57,17 +57,6 @@ namespace grapher.Models.Calculations #region Methods - public void Calculate(AccelData data, ManagedAccel accel, DriverSettings settings) - { - ScaleByMouseSettings(); - - data.Clear(); - - Calculate(data.Combined, accel, settings.sensitivity.x, MagnitudesCombined, true, settings); - Calculate(data.X, accel, settings.sensitivity.x, MagnitudesX); - Calculate(data.Y, accel, settings.sensitivity.y, MagnitudesY); - } - public void Calculate(AccelChartData data, ManagedAccel accel, double starter, ICollection magnitudeData, bool strip = false, DriverSettings settings = null) { double lastInputMagnitude = 0; diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs index a5f004d..657ae89 100644 --- a/grapher/Models/Charts/AccelCharts.cs +++ b/grapher/Models/Charts/AccelCharts.cs @@ -142,6 +142,12 @@ namespace grapher AlignWriteButton(); } + public void Calculate(ManagedAccel accel, DriverSettings settings) + { + ChartState.SetUpCalculate(settings); + ChartState.Calculate(accel, settings); + } + private static void SetupCharts( ChartXY sensitivityChart, ChartXY velocityChart, diff --git a/grapher/Models/Charts/ChartState/ChartState.cs b/grapher/Models/Charts/ChartState/ChartState.cs index 99f44ff..a219cc4 100644 --- a/grapher/Models/Charts/ChartState/ChartState.cs +++ b/grapher/Models/Charts/ChartState/ChartState.cs @@ -43,7 +43,12 @@ namespace grapher.Models.Charts.ChartState public abstract void Activate(); - public abstract void Calculate(); + public abstract void Calculate(ManagedAccel accel, DriverSettings settings); + public virtual void SetUpCalculate(DriverSettings settings) + { + Data.Clear(); + Calculator.ScaleByMouseSettings(); + } public void DrawLastMovement() { diff --git a/grapher/Models/Charts/ChartState/CombinedState.cs b/grapher/Models/Charts/ChartState/CombinedState.cs index d229a43..c788775 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.Serialized; namespace grapher.Models.Charts.ChartState { @@ -36,5 +37,10 @@ namespace grapher.Models.Charts.ChartState VelocityChart.Bind(Data.Combined.VelocityPoints); GainChart.Bind(Data.Combined.GainPoints); } + + public override void Calculate(ManagedAccel accel, DriverSettings settings) + { + Calculator.Calculate(Data.Combined, accel, settings.sensitivity.x, Calculator.MagnitudesCombined, true, settings); + } } } diff --git a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs index 8be88f0..69dc335 100644 --- a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs @@ -66,5 +66,11 @@ 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.Calculate(Data.X, accel, settings.sensitivity.x, Calculator.MagnitudesX); + Calculator.Calculate(Data.Y, accel, settings.sensitivity.y, Calculator.MagnitudesY); + } } } -- cgit v1.2.3 From 8f5c6c2a733812b19641789e34552afe9e601686 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Sat, 19 Sep 2020 19:27:37 -0700 Subject: further work --- grapher/Models/Calculations/AccelCalculator.cs | 54 ++++++++++++++--------- grapher/Models/Calculations/AccelData.cs | 4 +- grapher/Models/Charts/ChartState/CombinedState.cs | 2 +- 3 files changed, 35 insertions(+), 25 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs index ab1f346..ff1088b 100644 --- a/grapher/Models/Calculations/AccelCalculator.cs +++ b/grapher/Models/Calculations/AccelCalculator.cs @@ -57,35 +57,14 @@ namespace grapher.Models.Calculations #region Methods - public void Calculate(AccelChartData data, ManagedAccel accel, double starter, ICollection magnitudeData, bool strip = false, DriverSettings settings = null) + public void Calculate(AccelChartData data, ManagedAccel accel, double starter, ICollection magnitudeData) { double lastInputMagnitude = 0; double lastOutputMagnitude = 0; - bool stripSens = strip && ShouldStripSens(ref settings); - bool stripRot = strip && ShouldStripRot(ref settings); - - if(stripSens) - { - Sensitivity = GetSens(ref settings); - } - - if (stripRot) - { - RotationVector = GetRotVector(ref settings); - } - foreach (var magnitudeDatum in magnitudeData) { var output = accel.Accelerate(magnitudeDatum.x, magnitudeDatum.y, MeasurementTime); - var outputX = output.Item1; - var outputY = output.Item2; - - if (stripSens) - { - (outputX, outputY) = StripThisSens(outputX, outputY); - } - var outMagnitude = Magnitude(output.Item1, output.Item2); var ratio = magnitudeDatum.magnitude > 0 ? outMagnitude / magnitudeDatum.magnitude : starter; @@ -115,6 +94,37 @@ namespace grapher.Models.Calculations data.OrderedVelocityPointsList.AddRange(data.VelocityPoints.Values.ToList()); } + public void CalculateCombinedDiffSens(AccelData data, ManagedAccel accel, DriverSettings settings, ICollection magnitudeData) + { + double lastInputMagnitudeX = 0; + double lastOutputMagnitudeX = 0; + double lastInputMagnitudeY = 0; + double lastOutputMagnitudeY = 0; + + Sensitivity = GetSens(ref settings); + + foreach (var magnitudeDatum in magnitudeData) + { + var output = accel.Accelerate(magnitudeDatum.x, magnitudeDatum.y, MeasurementTime); + var outputWithoutSens = StripThisSens(output.Item1, output.Item2); + var magnitudeWithoutSens = Magnitude(outputWithoutSens.Item1, outputWithoutSens.Item2); + + var ratio = magnitudeDatum.magnitude > 0 ? magnitudeWithoutSens / magnitudeDatum.magnitude : 1; + + if (!data.Combined.AccelPoints.ContainsKey(magnitudeDatum.magnitude)) + { + data.Combined.AccelPoints.Add(magnitudeDatum.magnitude, ratio); + } + + var xRatio = magnitudeDatum.x > 0 ? output.Item1 / magnitudeDatum.x : settings.sensitivity.x * ratio; + + if (!data.X.AccelPoints.ContainsKey(magnitudeDatum.magnitude)) + { + + } + } + } + public ReadOnlyCollection GetMagnitudes() { var magnitudes = new List(); diff --git a/grapher/Models/Calculations/AccelData.cs b/grapher/Models/Calculations/AccelData.cs index eef4d01..057a53b 100644 --- a/grapher/Models/Calculations/AccelData.cs +++ b/grapher/Models/Calculations/AccelData.cs @@ -60,8 +60,8 @@ namespace grapher.Models.Calculations public void CalculateDotsXY(int x, int y, double timeInMs) { - var outX = Math.Abs(x); - var outY = Math.Abs(y); + var outX = Math.Abs(x) / timeInMs; + var outY = Math.Abs(y) / timeInMs; (var inXVelocity, var xSensitivity, var xGain) = X.FindPointValuesFromOut(outX); EstimatedX.Velocity.Set(inXVelocity, outX); diff --git a/grapher/Models/Charts/ChartState/CombinedState.cs b/grapher/Models/Charts/ChartState/CombinedState.cs index c788775..17cd68a 100644 --- a/grapher/Models/Charts/ChartState/CombinedState.cs +++ b/grapher/Models/Charts/ChartState/CombinedState.cs @@ -40,7 +40,7 @@ namespace grapher.Models.Charts.ChartState public override void Calculate(ManagedAccel accel, DriverSettings settings) { - Calculator.Calculate(Data.Combined, accel, settings.sensitivity.x, Calculator.MagnitudesCombined, true, settings); + Calculator.Calculate(Data.Combined, accel, settings.sensitivity.x, Calculator.MagnitudesCombined); } } } -- cgit v1.2.3 From 2a756dfb08b4f8c0870173ad4e0393cdeef33c94 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Sun, 20 Sep 2020 23:16:15 -0700 Subject: Attempt to get separate x/y working --- grapher/Models/AccelGUIFactory.cs | 11 +++--- grapher/Models/Calculations/AccelCalculator.cs | 46 ++++++++++++++++++++-- grapher/Models/Calculations/AccelChartData.cs | 24 ++++++++--- grapher/Models/Calculations/AccelData.cs | 38 ++++++++++++++++-- .../Models/Charts/ChartState/XYOneGraphState.cs | 8 +++- 5 files changed, 109 insertions(+), 18 deletions(-) (limited to 'grapher/Models') 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) { - 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 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 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); + } } } -- cgit v1.2.3 From ba642cd8c8e63ec3778fa17ecbcd7964074aaba1 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Mon, 21 Sep 2020 00:08:19 -0700 Subject: separate x/y mostly works --- grapher/Models/AccelGUI.cs | 2 +- grapher/Models/Calculations/AccelCalculator.cs | 8 +++---- grapher/Models/Calculations/AccelChartData.cs | 4 +++- grapher/Models/Calculations/AccelData.cs | 16 ++++++++----- grapher/Models/Charts/AccelCharts.cs | 1 + grapher/Models/Charts/ChartState/ChartState.cs | 10 ++++++--- .../Models/Charts/ChartState/XYOneGraphState.cs | 18 ++++++++------- grapher/Models/Charts/ChartXY.cs | 26 ++++++++++++++++++---- 8 files changed, 59 insertions(+), 26 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 5567be3..95d0c25 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -96,8 +96,8 @@ namespace grapher public void RefreshOnRead() { - UpdateGraph(); UpdateShownActiveValues(); + UpdateGraph(); } public void UpdateGraph() diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs index 35fee2d..a140c90 100644 --- a/grapher/Models/Calculations/AccelCalculator.cs +++ b/grapher/Models/Calculations/AccelCalculator.cs @@ -110,9 +110,9 @@ namespace grapher.Models.Calculations var ratio = magnitudeDatum.magnitude > 0 ? magnitudeWithoutSens / magnitudeDatum.magnitude : 1; - if (!data.Combined.AccelPoints.ContainsKey(magnitudeDatum.magnitude)) + if (!data.Combined.VelocityPoints.ContainsKey(magnitudeDatum.magnitude)) { - data.Combined.AccelPoints.Add(magnitudeDatum.magnitude, ratio); + data.Combined.VelocityPoints.Add(magnitudeDatum.magnitude, magnitudeWithoutSens); } var xRatio = settings.sensitivity.x * ratio; @@ -158,8 +158,8 @@ namespace grapher.Models.Calculations } lastInputMagnitude = magnitudeDatum.magnitude; - lastOutputMagnitudeX = xOutDiff; - lastOutputMagnitudeY = yOutDiff; + lastOutputMagnitudeX = xOut; + lastOutputMagnitudeY = yOut; } data.Combined.OrderedVelocityPointsList.AddRange(data.Combined.VelocityPoints.Values.ToList()); diff --git a/grapher/Models/Calculations/AccelChartData.cs b/grapher/Models/Calculations/AccelChartData.cs index c943643..907eb0e 100644 --- a/grapher/Models/Calculations/AccelChartData.cs +++ b/grapher/Models/Calculations/AccelChartData.cs @@ -63,7 +63,7 @@ namespace grapher.Models.Calculations public (double, double, double) ValuesAtIndex(int index) { - return (VelocityPoints.ElementAt(index).Value, AccelPoints.ElementAt(index).Value, GainPoints.ElementAt(index).Value); + return (AccelPoints.ElementAt(index).Value, VelocityPoints.ElementAt(index).Value, GainPoints.ElementAt(index).Value); } public int GetVelocityIndex(double outVelocityValue) @@ -75,6 +75,8 @@ namespace grapher.Models.Calculations velIdx = ~velIdx; } + velIdx = Math.Min(velIdx, VelocityPoints.Count - 1); + return velIdx; } diff --git a/grapher/Models/Calculations/AccelData.cs b/grapher/Models/Calculations/AccelData.cs index 894774b..0fe7a3c 100644 --- a/grapher/Models/Calculations/AccelData.cs +++ b/grapher/Models/Calculations/AccelData.cs @@ -1,6 +1,8 @@ using grapher.Models.Charts; +using grapher.Models.Serialized; using System; using System.Collections.Generic; +using System.Linq; namespace grapher.Models.Calculations { @@ -20,6 +22,8 @@ namespace grapher.Models.Calculations Estimated = combined; EstimatedX = x; EstimatedY = y; + + OutVelocityToPoints = new Dictionary(); } #endregion Constructors @@ -49,6 +53,7 @@ namespace grapher.Models.Calculations Combined.Clear(); X.Clear(); Y.Clear(); + OutVelocityToPoints.Clear(); } public void CalculateDots(int x, int y, double timeInMs) @@ -77,9 +82,10 @@ namespace grapher.Models.Calculations EstimatedY.Gain.Set(inYVelocity, yGain); } - public void CalculateDotsCombinedDiffSens(int x, int y, double timeInMs) + public void CalculateDotsCombinedDiffSens(int x, int y, double timeInMs, DriverSettings settings) { - var outVelocity = AccelCalculator.Velocity(x, y, 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)) { @@ -93,9 +99,9 @@ namespace grapher.Models.Calculations else { var index = Combined.GetVelocityIndex(outVelocity); - var inVelocity = Combined.VelocityPoints[index]; - var xPoints = X.FindPointValuesFromOut(outVelocity); - var yPoints = Y.FindPointValuesFromOut(outVelocity); + var inVelocity = Combined.VelocityPoints.ElementAt(index).Value; + 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); diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs index 657ae89..d22ab78 100644 --- a/grapher/Models/Charts/AccelCharts.cs +++ b/grapher/Models/Charts/AccelCharts.cs @@ -98,6 +98,7 @@ namespace grapher private ChartStateManager ChartStateManager { get; } + #endregion Properties #region Methods diff --git a/grapher/Models/Charts/ChartState/ChartState.cs b/grapher/Models/Charts/ChartState/ChartState.cs index a219cc4..ea67e83 100644 --- a/grapher/Models/Charts/ChartState/ChartState.cs +++ b/grapher/Models/Charts/ChartState/ChartState.cs @@ -23,6 +23,7 @@ namespace grapher.Models.Charts.ChartState GainChart = gainChart; Data = accelData; Calculator = calculator; + TwoDotsPerGraph = false; } public ChartXY SensitivityChart { get; } @@ -37,6 +38,8 @@ namespace grapher.Models.Charts.ChartState public virtual DriverSettings Settings { get; set; } + internal bool TwoDotsPerGraph { get; set; } + public abstract void MakeDots(int x, int y, double timeInMs); public abstract void Bind(); @@ -44,6 +47,7 @@ namespace grapher.Models.Charts.ChartState public abstract void Activate(); public abstract void Calculate(ManagedAccel accel, DriverSettings settings); + public virtual void SetUpCalculate(DriverSettings settings) { Data.Clear(); @@ -52,9 +56,9 @@ namespace grapher.Models.Charts.ChartState public void DrawLastMovement() { - SensitivityChart.DrawLastMovementValue(); - VelocityChart.DrawLastMovementValue(); - GainChart.DrawLastMovementValue(); + SensitivityChart.DrawLastMovementValue(TwoDotsPerGraph); + VelocityChart.DrawLastMovementValue(TwoDotsPerGraph); + GainChart.DrawLastMovementValue(TwoDotsPerGraph); } public void SetWidened() diff --git a/grapher/Models/Charts/ChartState/XYOneGraphState.cs b/grapher/Models/Charts/ChartState/XYOneGraphState.cs index c1153c1..bbc0c28 100644 --- a/grapher/Models/Charts/ChartState/XYOneGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYOneGraphState.cs @@ -17,25 +17,27 @@ namespace grapher.Models.Charts.ChartState gainChart, accelData, accelCalculator) - { } + { + TwoDotsPerGraph = true; + } public override void Activate() { - SensitivityChart.SetSeparate(); - VelocityChart.SetSeparate(); - GainChart.SetSeparate(); + SensitivityChart.SetCombined(); + VelocityChart.SetCombined(); + GainChart.SetCombined(); } public override void MakeDots(int x, int y, double timeInMs) { - Data.CalculateDotsCombinedDiffSens(x, y, timeInMs); + Data.CalculateDotsCombinedDiffSens(x, y, timeInMs, Settings); } public override void Bind() { - SensitivityChart.BindXY(Data.X.AccelPoints, Data.Y.AccelPoints); - VelocityChart.BindXY(Data.X.VelocityPoints, Data.Y.VelocityPoints); - GainChart.BindXY(Data.X.GainPoints, Data.Y.GainPoints); + SensitivityChart.BindXYCombined(Data.X.AccelPoints, Data.Y.AccelPoints); + VelocityChart.BindXYCombined(Data.X.VelocityPoints, Data.Y.VelocityPoints); + GainChart.BindXYCombined(Data.X.GainPoints, Data.Y.GainPoints); } public override void Calculate(ManagedAccel accel, DriverSettings settings) diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs index 1360409..fdd0258 100644 --- a/grapher/Models/Charts/ChartXY.cs +++ b/grapher/Models/Charts/ChartXY.cs @@ -117,12 +117,17 @@ namespace grapher chart.Titles[0].Font = new System.Drawing.Font(chart.Titles[0].Font.Name, 9.0f, System.Drawing.FontStyle.Italic); } - public static void DrawPoint(Chart chart, PointData point) + public static void DrawPoint(Chart chart, PointData pointOne, PointData pointTwo = null) { if (chart.Visible) { - point.Get(out var x, out var y); + pointOne.Get(out var x, out var y); chart.Series[1].Points.DataBindXY(x, y); + if (pointTwo != null) + { + pointTwo.Get(out x, out y); + chart.Series[3].Points.DataBindXY(x, y); + } chart.Update(); } } @@ -134,11 +139,18 @@ namespace grapher YPointData = y; } - public void DrawLastMovementValue() + public void DrawLastMovementValue(bool twoDotsPerGraph = false) { if(Combined) { - DrawPoint(ChartX, CombinedPointData); + if (twoDotsPerGraph) + { + DrawPoint(ChartX, XPointData, YPointData); + } + else + { + DrawPoint(ChartX, CombinedPointData); + } } else { @@ -164,6 +176,12 @@ namespace grapher ChartY.Series[0].Points.DataBindXY(dataY.Keys, dataY.Values); } + public void BindXYCombined(IDictionary dataX, IDictionary dataY) + { + ChartX.Series[0].Points.DataBindXY(dataX.Keys, dataX.Values); + ChartX.Series[2].Points.DataBindXY(dataY.Keys, dataY.Values); + } + public void SetCombined() { if (!Combined) -- cgit v1.2.3 From 99ad8686bb039dcf82115550dbf347d8695ee1f8 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Mon, 21 Sep 2020 12:41:16 -0700 Subject: x/y diff sens works --- grapher/Models/Calculations/AccelChartData.cs | 5 +++++ grapher/Models/Calculations/AccelData.cs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Calculations/AccelChartData.cs b/grapher/Models/Calculations/AccelChartData.cs index 907eb0e..fbf1944 100644 --- a/grapher/Models/Calculations/AccelChartData.cs +++ b/grapher/Models/Calculations/AccelChartData.cs @@ -66,6 +66,11 @@ namespace grapher.Models.Calculations return (AccelPoints.ElementAt(index).Value, VelocityPoints.ElementAt(index).Value, GainPoints.ElementAt(index).Value); } + public (double, double, double) ValuesAtInVelocity(double inVelocity) + { + return (AccelPoints[inVelocity], VelocityPoints[inVelocity], GainPoints[inVelocity]); + } + public int GetVelocityIndex(double outVelocityValue) { var velIdx = OrderedVelocityPointsList.BinarySearch(outVelocityValue); diff --git a/grapher/Models/Calculations/AccelData.cs b/grapher/Models/Calculations/AccelData.cs index 0fe7a3c..67d4f3f 100644 --- a/grapher/Models/Calculations/AccelData.cs +++ b/grapher/Models/Calculations/AccelData.cs @@ -99,7 +99,7 @@ namespace grapher.Models.Calculations else { var index = Combined.GetVelocityIndex(outVelocity); - var inVelocity = Combined.VelocityPoints.ElementAt(index).Value; + 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)); -- cgit v1.2.3