diff options
| author | Jacob Palecki <[email protected]> | 2020-08-02 18:20:29 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-08-02 18:20:29 -0700 |
| commit | 26b8727a8de23f829dbd95d9ec5a7f2713da7eb7 (patch) | |
| tree | cb39d2c783e9a7bf7b64dfb7f7573b11b64f1069 | |
| parent | Add velocity graph (diff) | |
| download | rawaccel-26b8727a8de23f829dbd95d9ec5a7f2713da7eb7.tar.xz rawaccel-26b8727a8de23f829dbd95d9ec5a7f2713da7eb7.zip | |
Add gain and velocity graphs
| -rw-r--r-- | grapher/AccelGUI.cs | 31 | ||||
| -rw-r--r-- | grapher/Form1.Designer.cs | 31 | ||||
| -rw-r--r-- | grapher/Form1.cs | 21 |
3 files changed, 80 insertions, 3 deletions
diff --git a/grapher/AccelGUI.cs b/grapher/AccelGUI.cs index 9acb38e..48fad7e 100644 --- a/grapher/AccelGUI.cs +++ b/grapher/AccelGUI.cs @@ -26,6 +26,7 @@ namespace grapher RawAcceleration accelForm, Chart accelerationChart, Chart velocityChart, + Chart gainChart, ManagedAccel managedAccel, AccelOptions accelOptions, OptionXY sensitivity, @@ -40,6 +41,7 @@ namespace grapher AccelForm = accelForm; AccelChart = accelerationChart; VelocityChart = velocityChart; + GainChart = gainChart; ManagedAcceleration = managedAccel; AccelerationOptions = accelOptions; Sensitivity = sensitivity; @@ -64,6 +66,8 @@ namespace grapher public Chart VelocityChart { get; } + public Chart GainChart { get; } + public ManagedAccel ManagedAcceleration { get; } public AccelOptions AccelerationOptions { get; } @@ -122,8 +126,12 @@ namespace grapher public void UpdateGraph() { - var orderedAccelPoints = new SortedDictionary<double, double>(); - var orderedVelocityPoints = new SortedDictionary<double, double>(); + var orderedAccelPoints = new SortedDictionary<double, double>(); + var orderedVelocityPoints = new SortedDictionary<double, double>(); + var orderedGainPoints = new SortedDictionary<double, double>(); + + double lastInputMagnitude = 0; + double lastOutputMagnitude = 0; foreach (var magnitudeData in Magnitudes) { @@ -132,6 +140,12 @@ namespace grapher var outMagnitude = Magnitude(output.Item1, output.Item2); var ratio = magnitudeData.magnitude > 0 ? outMagnitude / magnitudeData.magnitude : Sensitivity.Fields.X; + var inDiff = magnitudeData.magnitude - lastInputMagnitude; + var outDiff = outMagnitude - lastOutputMagnitude; + var slope = inDiff > 0 ? outDiff / inDiff : Sensitivity.Fields.X; + lastInputMagnitude = magnitudeData.magnitude; + lastOutputMagnitude = outMagnitude; + if (!orderedAccelPoints.ContainsKey(magnitudeData.magnitude)) { orderedAccelPoints.Add(magnitudeData.magnitude, ratio); @@ -141,6 +155,11 @@ namespace grapher { orderedVelocityPoints.Add(magnitudeData.magnitude, outMagnitude); } + + if (!orderedGainPoints.ContainsKey(magnitudeData.magnitude)) + { + orderedGainPoints.Add(magnitudeData.magnitude, slope); + } } var accelSeries = AccelChart.Series.FirstOrDefault(); @@ -158,6 +177,14 @@ namespace grapher { velSeries.Points.AddXY(point.Key, point.Value); } + + var gainSeries = GainChart.Series.FirstOrDefault(); + gainSeries.Points.Clear(); + + foreach (var point in orderedGainPoints) + { + gainSeries.Points.AddXY(point.Key, point.Value); + } } diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index 11b84f9..f7e674d 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -36,6 +36,9 @@ namespace grapher System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea3 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend3 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.accelTypeDrop = new System.Windows.Forms.ComboBox(); this.sensitivityBoxX = new System.Windows.Forms.TextBox(); @@ -63,8 +66,10 @@ namespace grapher this.weightXYLock = new System.Windows.Forms.CheckBox(); this.LockXYLabel = new System.Windows.Forms.Label(); this.VelocityChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.GainChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); ((System.ComponentModel.ISupportInitialize)(this.AccelerationChart)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.VelocityChart)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.GainChart)).BeginInit(); this.SuspendLayout(); // // AccelerationChart @@ -304,6 +309,8 @@ namespace grapher // // VelocityChart // + chartArea2.AxisX.Title = "Speed (count/ms)"; + chartArea2.AxisY.Title = "Output Speed (counts/ms)"; chartArea2.Name = "ChartArea1"; this.VelocityChart.ChartAreas.Add(chartArea2); legend2.Name = "Legend1"; @@ -319,11 +326,31 @@ namespace grapher this.VelocityChart.TabIndex = 28; this.VelocityChart.Text = "chart1"; // + // GainChart + // + chartArea3.AxisX.Title = "Speed (counts/ms)"; + chartArea3.AxisY.Title = "Slope of Velocity Chart"; + chartArea3.Name = "ChartArea1"; + this.GainChart.ChartAreas.Add(chartArea3); + legend3.Name = "Legend1"; + this.GainChart.Legends.Add(legend3); + this.GainChart.Location = new System.Drawing.Point(242, 625); + this.GainChart.Name = "GainChart"; + series3.ChartArea = "ChartArea1"; + series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series3.Legend = "Legend1"; + series3.Name = "Velocity Gain"; + this.GainChart.Series.Add(series3); + this.GainChart.Size = new System.Drawing.Size(721, 300); + this.GainChart.TabIndex = 29; + this.GainChart.Text = "chart1"; + // // RawAcceleration // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(963, 621); + this.ClientSize = new System.Drawing.Size(963, 925); + this.Controls.Add(this.GainChart); this.Controls.Add(this.VelocityChart); this.Controls.Add(this.LockXYLabel); this.Controls.Add(this.weightXYLock); @@ -356,6 +383,7 @@ namespace grapher this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.AccelerationChart)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.VelocityChart)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.GainChart)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -390,6 +418,7 @@ namespace grapher private System.Windows.Forms.CheckBox weightXYLock; private System.Windows.Forms.Label LockXYLabel; private System.Windows.Forms.DataVisualization.Charting.Chart VelocityChart; + private System.Windows.Forms.DataVisualization.Charting.Chart GainChart; } } 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 |