From f3740b21ad9c08d23368826d1de9eed9a89d9a11 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Sun, 2 Aug 2020 14:03:55 -0700 Subject: Move logic out of forms class into accelgui class --- grapher/Form1.cs | 161 ++++++++++++++++--------------------------------------- 1 file changed, 46 insertions(+), 115 deletions(-) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 3807d2a..1cbd6c9 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -55,16 +55,9 @@ namespace grapher public partial class RawAcceleration : Form { - public struct MagnitudeData - { - public double magnitude; - public int x; - public int y; - } #region Constructor - public static ReadOnlyCollection Magnitudes = GetMagnitudes(); public RawAcceleration() { @@ -90,39 +83,51 @@ namespace grapher IntPtr args_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(args)); Marshal.StructureToPtr(args, args_ptr, false); - ManagedAcceleration = new ManagedAccel(args_ptr); + var managedAcceleration = new ManagedAccel(args_ptr); Marshal.FreeHGlobal(args_ptr); - Sensitivity = new OptionXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1, sensitivityLabel, "Sensitivity"); - Rotation = new Option(rotationBox, this, 0, rotationLabel, "Rotation"); - Weight = new OptionXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1, weightLabel, "Weight"); - Cap = new OptionXY(capBoxX, capBoxY, capXYLock, this, 0, capLabel, "Cap"); - Offset = new Option(offsetBox, this, 0, offsetLabel, "Offset"); + var sensitivity = new OptionXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1, sensitivityLabel, "Sensitivity"); + var rotation = new Option(rotationBox, this, 0, rotationLabel, "Rotation"); + var weight = new OptionXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1, weightLabel, "Weight"); + var cap = new OptionXY(capBoxX, capBoxY, capXYLock, this, 0, capLabel, "Cap"); + var offset = new Option(offsetBox, this, 0, offsetLabel, "Offset"); // The name and layout of these options is handled by AccelerationOptions object. - Acceleration = new Option(new Field(accelerationBox, this, 0), constantOneLabel); - LimitOrExponent = new Option(new Field(limitBox, this, 2), constantTwoLabel); - Midpoint = new Option(new Field(midpointBox, this, 0), constantThreeLabel); + var acceleration = new Option(new Field(accelerationBox, this, 0), constantOneLabel); + var limitOrExponent = new Option(new Field(limitBox, this, 2), constantTwoLabel); + var midpoint = new Option(new Field(midpointBox, this, 0), constantThreeLabel); - AccelerationOptions = new AccelOptions( + var accelerationOptions = new AccelOptions( accelTypeDrop, new Option[] { - Offset, - Acceleration, - LimitOrExponent, - Midpoint, + offset, + acceleration, + limitOrExponent, + midpoint, }, new OptionXY[] { - Weight, - Cap, + weight, + cap, }, writeButton); - UpdateGraph(); - + AccelGUI = new AccelGUI( + this, + AccelerationChart, + managedAcceleration, + accelerationOptions, + sensitivity, + rotation, + weight, + cap, + offset, + acceleration, + limitOrExponent, + midpoint); + this.AccelerationChart.ChartAreas[0].AxisX.RoundAxisValues(); this.AccelerationChart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; @@ -147,108 +152,34 @@ namespace grapher #region Properties - public ManagedAccel ManagedAcceleration { get; set; } - - private AccelOptions AccelerationOptions { get; set; } - - private OptionXY Sensitivity { get; set; } - - private Option Rotation { get; set; } - - private OptionXY Weight { get; set; } - - private OptionXY Cap { get; set; } - - private Option Offset { get; set; } - - private Option Acceleration { get; set; } - - private Option LimitOrExponent { get; set; } - - private Option Midpoint { get; set; } + public AccelGUI AccelGUI { get; } #endregion Properties #region Methods - public static ReadOnlyCollection GetMagnitudes() - { - var magnitudes = new List(); - for (int i = 0; i < 100; i++) - { - for (int j = 0; j <= i; j++) - { - MagnitudeData magnitudeData; - magnitudeData.magnitude = Magnitude(i, j); - magnitudeData.x = i; - magnitudeData.y = j; - magnitudes.Add(magnitudeData); - } - } - - magnitudes.Sort((m1, m2) => m1.magnitude.CompareTo(m2.magnitude)); - - return magnitudes.AsReadOnly(); - } - - public static double Magnitude(int x, int y) - { - return Math.Sqrt(x * x + y * y); - } - - public static double Magnitude(double x, double y) - { - return Math.Sqrt(x * x + y * y); - } - private void Form1_Load(object sender, EventArgs e) { } - private void UpdateGraph() - { - var orderedPoints = new SortedDictionary(); - - foreach (var magnitudeData in Magnitudes) - { - var output = ManagedAcceleration.Accelerate(magnitudeData.x, magnitudeData.y, 1); - - var outMagnitude = Magnitude(output.Item1, output.Item2); - var ratio = magnitudeData.magnitude > 0 ? outMagnitude / magnitudeData.magnitude : Sensitivity.Fields.X; - - if (!orderedPoints.ContainsKey(magnitudeData.magnitude)) - { - orderedPoints.Add(magnitudeData.magnitude, ratio); - } - } - - var series = this.AccelerationChart.Series.FirstOrDefault(); - series.Points.Clear(); - - foreach (var point in orderedPoints) - { - series.Points.AddXY(point.Key, point.Value); - } - } - private void writeButton_Click(object sender, EventArgs e) { - ManagedAcceleration.UpdateAccel( - AccelerationOptions.AccelerationIndex, - Rotation.Field.Data, - Sensitivity.Fields.X, - Sensitivity.Fields.Y, - Weight.Fields.X, - Weight.Fields.Y, - Cap.Fields.X, - Cap.Fields.Y, - Offset.Field.Data, - Acceleration.Field.Data, - LimitOrExponent.Field.Data, - Midpoint.Field.Data); - ManagedAcceleration.WriteToDriver(); - UpdateGraph(); + AccelGUI.ManagedAcceleration.UpdateAccel( + AccelGUI.AccelerationOptions.AccelerationIndex, + AccelGUI.Rotation.Field.Data, + AccelGUI.Sensitivity.Fields.X, + AccelGUI.Sensitivity.Fields.Y, + AccelGUI.Weight.Fields.X, + AccelGUI.Weight.Fields.Y, + AccelGUI.Cap.Fields.X, + AccelGUI.Cap.Fields.Y, + AccelGUI.Offset.Field.Data, + AccelGUI.Acceleration.Field.Data, + AccelGUI.LimitOrExponent.Field.Data, + AccelGUI.Midpoint.Field.Data); + AccelGUI.ManagedAcceleration.WriteToDriver(); + AccelGUI.UpdateGraph(); } #endregion Methods -- cgit v1.2.3 From 529f18bd6ddbcd182fd03a13e3c07dc10162f036 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Sun, 2 Aug 2020 15:54:47 -0700 Subject: Add velocity graph --- grapher/Form1.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 1cbd6c9..50d6476 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -117,6 +117,7 @@ namespace grapher AccelGUI = new AccelGUI( this, AccelerationChart, + VelocityChart, managedAcceleration, accelerationOptions, sensitivity, @@ -146,6 +147,26 @@ namespace grapher this.AccelerationChart.ChartAreas[0].CursorX.IsUserEnabled = true; this.AccelerationChart.ChartAreas[0].CursorY.IsUserEnabled = true; + + this.VelocityChart.ChartAreas[0].AxisX.RoundAxisValues(); + + this.VelocityChart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; + this.VelocityChart.ChartAreas[0].AxisY.ScaleView.Zoomable = true; + + this.VelocityChart.ChartAreas[0].AxisY.ScaleView.MinSize = 0.01; + this.VelocityChart.ChartAreas[0].AxisY.ScaleView.SmallScrollSize = 0.001; + + this.VelocityChart.ChartAreas[0].CursorY.Interval = 0.001; + + this.VelocityChart.ChartAreas[0].CursorX.AutoScroll = true; + this.VelocityChart.ChartAreas[0].CursorY.AutoScroll = true; + + this.VelocityChart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; + this.VelocityChart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; + + this.VelocityChart.ChartAreas[0].CursorX.IsUserEnabled = true; + this.VelocityChart.ChartAreas[0].CursorY.IsUserEnabled = true; + } #endregion Constructor -- cgit v1.2.3 From 26b8727a8de23f829dbd95d9ec5a7f2713da7eb7 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Sun, 2 Aug 2020 18:20:29 -0700 Subject: Add gain and velocity graphs --- grapher/Form1.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 50d6476..fb841e9 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -118,6 +118,7 @@ namespace grapher this, AccelerationChart, VelocityChart, + GainChart, managedAcceleration, accelerationOptions, sensitivity, @@ -148,6 +149,7 @@ namespace grapher this.AccelerationChart.ChartAreas[0].CursorX.IsUserEnabled = true; this.AccelerationChart.ChartAreas[0].CursorY.IsUserEnabled = true; + this.VelocityChart.ChartAreas[0].AxisX.RoundAxisValues(); this.VelocityChart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; @@ -167,6 +169,25 @@ namespace grapher this.VelocityChart.ChartAreas[0].CursorX.IsUserEnabled = true; this.VelocityChart.ChartAreas[0].CursorY.IsUserEnabled = true; + + this.GainChart.ChartAreas[0].AxisX.RoundAxisValues(); + + this.GainChart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; + this.GainChart.ChartAreas[0].AxisY.ScaleView.Zoomable = true; + + this.GainChart.ChartAreas[0].AxisY.ScaleView.MinSize = 0.01; + this.GainChart.ChartAreas[0].AxisY.ScaleView.SmallScrollSize = 0.001; + + this.GainChart.ChartAreas[0].CursorY.Interval = 0.001; + + this.GainChart.ChartAreas[0].CursorX.AutoScroll = true; + this.GainChart.ChartAreas[0].CursorY.AutoScroll = true; + + this.GainChart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; + this.GainChart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; + + this.GainChart.ChartAreas[0].CursorX.IsUserEnabled = true; + this.GainChart.ChartAreas[0].CursorY.IsUserEnabled = true; } #endregion Constructor -- cgit v1.2.3 From dba84307479550135db0bccce9554da09c74aa74 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Mon, 3 Aug 2020 13:20:17 -0700 Subject: Add tool menu to enable\disable charts --- grapher/Form1.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index fb841e9..7fa6928 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -116,9 +116,12 @@ namespace grapher AccelGUI = new AccelGUI( this, - AccelerationChart, - VelocityChart, - GainChart, + new AccelCharts( + this, + AccelerationChart, + VelocityChart, + GainChart, + showVelocityGainToolStripMenuItem), managedAcceleration, accelerationOptions, sensitivity, -- cgit v1.2.3 From 4e63da9daa1a3869caef1ac6c45c598aaf5a4b6e Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Mon, 3 Aug 2020 14:07:21 -0700 Subject: Start work on reading from driver --- grapher/Form1.cs | 1 - 1 file changed, 1 deletion(-) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 7fa6928..4edb9e3 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -223,7 +223,6 @@ namespace grapher AccelGUI.Acceleration.Field.Data, AccelGUI.LimitOrExponent.Field.Data, AccelGUI.Midpoint.Field.Data); - AccelGUI.ManagedAcceleration.WriteToDriver(); AccelGUI.UpdateGraph(); } -- cgit v1.2.3 From c0b8b46f84eda91d01ce2eead3777c31be96bd60 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Tue, 4 Aug 2020 15:08:48 -0700 Subject: Data rebind for faster graph update --- grapher/Form1.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 4edb9e3..237a25d 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -131,7 +131,8 @@ namespace grapher offset, acceleration, limitOrExponent, - midpoint); + midpoint, + writeButton); this.AccelerationChart.ChartAreas[0].AxisX.RoundAxisValues(); -- cgit v1.2.3