diff --git a/DroneSimulator/FormMain.Designer.cs b/DroneSimulator/FormMain.Designer.cs index aa7351c..200f2b1 100644 --- a/DroneSimulator/FormMain.Designer.cs +++ b/DroneSimulator/FormMain.Designer.cs @@ -56,6 +56,7 @@ tabPage_Model = new TabPage(); panel_Menu_Model = new Panel(); groupBox1 = new GroupBox(); + checkBox_Model_Range_Real = new CheckBox(); label55 = new Label(); numericUpDown_Range_Laten = new NumericUpDown(); label56 = new Label(); @@ -70,6 +71,7 @@ label46 = new Label(); label47 = new Label(); groupBox_OF = new GroupBox(); + checkBox_Model_OF_Real = new CheckBox(); label40 = new Label(); numericUpDown_OF_Lens = new NumericUpDown(); label39 = new Label(); @@ -91,6 +93,7 @@ label14 = new Label(); label15 = new Label(); groupBox_Barometer = new GroupBox(); + checkBox_Model_Bar_Real = new CheckBox(); label30 = new Label(); numericUpDown_Bar_Laten = new NumericUpDown(); label29 = new Label(); @@ -105,6 +108,7 @@ label5 = new Label(); label7 = new Label(); groupBox_GPS = new GroupBox(); + checkBox_Model_Pos_Real = new CheckBox(); label2 = new Label(); numericUpDown_Pos_Laten = new NumericUpDown(); label4 = new Label(); @@ -122,6 +126,7 @@ numericUpDown_Mag_Freq = new NumericUpDown(); label22 = new Label(); groupBox_Gyr = new GroupBox(); + checkBox_Model_Gyr_Real = new CheckBox(); label51 = new Label(); numericUpDown_Gyr_Laten = new NumericUpDown(); label52 = new Label(); @@ -138,6 +143,7 @@ numericUpDown_Gyr_Freq = new NumericUpDown(); label21 = new Label(); groupBox_Acc = new GroupBox(); + checkBox_Model_Acc_Real = new CheckBox(); label49 = new Label(); numericUpDown_Acc_Laten = new NumericUpDown(); label50 = new Label(); @@ -150,9 +156,6 @@ label23 = new Label(); numericUpDown_Acc_Freq = new NumericUpDown(); label20 = new Label(); - groupBox2 = new GroupBox(); - radioButton1 = new RadioButton(); - radioButton_Real = new RadioButton(); tabPage_Area = new TabPage(); groupBox4 = new GroupBox(); numericUpDown_Area_Wind_RotResist = new NumericUpDown(); @@ -233,7 +236,6 @@ ((System.ComponentModel.ISupportInitialize)numericUpDown_Acc_Scale_Rigth).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDown_Acc_Noise).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDown_Acc_Freq).BeginInit(); - groupBox2.SuspendLayout(); tabPage_Area.SuspendLayout(); groupBox4.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)numericUpDown_Area_Wind_RotResist).BeginInit(); @@ -516,7 +518,6 @@ panel_Menu_Model.Controls.Add(groupBox_Mag); panel_Menu_Model.Controls.Add(groupBox_Gyr); panel_Menu_Model.Controls.Add(groupBox_Acc); - panel_Menu_Model.Controls.Add(groupBox2); panel_Menu_Model.Dock = DockStyle.Fill; panel_Menu_Model.Location = new Point(3, 3); panel_Menu_Model.Name = "panel_Menu_Model"; @@ -525,6 +526,7 @@ // // groupBox1 // + groupBox1.Controls.Add(checkBox_Model_Range_Real); groupBox1.Controls.Add(label55); groupBox1.Controls.Add(numericUpDown_Range_Laten); groupBox1.Controls.Add(label56); @@ -539,13 +541,25 @@ groupBox1.Controls.Add(label46); groupBox1.Controls.Add(label47); groupBox1.Dock = DockStyle.Top; - groupBox1.Location = new Point(0, 732); + groupBox1.Location = new Point(0, 688); groupBox1.Name = "groupBox1"; groupBox1.Size = new Size(204, 133); groupBox1.TabIndex = 8; groupBox1.TabStop = false; groupBox1.Text = "Range"; // + // checkBox_Model_Range_Real + // + checkBox_Model_Range_Real.AutoSize = true; + checkBox_Model_Range_Real.Location = new Point(156, 20); + checkBox_Model_Range_Real.Name = "checkBox_Model_Range_Real"; + checkBox_Model_Range_Real.Size = new Size(48, 19); + checkBox_Model_Range_Real.TabIndex = 41; + checkBox_Model_Range_Real.Tag = "#en"; + checkBox_Model_Range_Real.Text = "Real"; + checkBox_Model_Range_Real.UseVisualStyleBackColor = true; + checkBox_Model_Range_Real.CheckedChanged += numericUpDown_Range_Update; + // // label55 // label55.AutoSize = true; @@ -681,6 +695,7 @@ // // groupBox_OF // + groupBox_OF.Controls.Add(checkBox_Model_OF_Real); groupBox_OF.Controls.Add(label40); groupBox_OF.Controls.Add(numericUpDown_OF_Lens); groupBox_OF.Controls.Add(label39); @@ -702,13 +717,25 @@ groupBox_OF.Controls.Add(label14); groupBox_OF.Controls.Add(label15); groupBox_OF.Dock = DockStyle.Top; - groupBox_OF.Location = new Point(0, 563); + groupBox_OF.Location = new Point(0, 519); groupBox_OF.Name = "groupBox_OF"; groupBox_OF.Size = new Size(204, 169); groupBox_OF.TabIndex = 4; groupBox_OF.TabStop = false; groupBox_OF.Text = "Optical flow"; // + // checkBox_Model_OF_Real + // + checkBox_Model_OF_Real.AutoSize = true; + checkBox_Model_OF_Real.Location = new Point(156, 78); + checkBox_Model_OF_Real.Name = "checkBox_Model_OF_Real"; + checkBox_Model_OF_Real.Size = new Size(48, 19); + checkBox_Model_OF_Real.TabIndex = 40; + checkBox_Model_OF_Real.Tag = "#en"; + checkBox_Model_OF_Real.Text = "Real"; + checkBox_Model_OF_Real.UseVisualStyleBackColor = true; + checkBox_Model_OF_Real.CheckedChanged += numericUpDown_OF_Update; + // // label40 // label40.AutoSize = true; @@ -916,6 +943,7 @@ // // groupBox_Barometer // + groupBox_Barometer.Controls.Add(checkBox_Model_Bar_Real); groupBox_Barometer.Controls.Add(label30); groupBox_Barometer.Controls.Add(numericUpDown_Bar_Laten); groupBox_Barometer.Controls.Add(label29); @@ -930,7 +958,7 @@ groupBox_Barometer.Controls.Add(label5); groupBox_Barometer.Controls.Add(label7); groupBox_Barometer.Dock = DockStyle.Top; - groupBox_Barometer.Location = new Point(0, 433); + groupBox_Barometer.Location = new Point(0, 389); groupBox_Barometer.Name = "groupBox_Barometer"; groupBox_Barometer.Size = new Size(204, 130); groupBox_Barometer.TabIndex = 3; @@ -938,6 +966,18 @@ groupBox_Barometer.Tag = "#barometer"; groupBox_Barometer.Text = "Barometer"; // + // checkBox_Model_Bar_Real + // + checkBox_Model_Bar_Real.AutoSize = true; + checkBox_Model_Bar_Real.Location = new Point(157, 43); + checkBox_Model_Bar_Real.Name = "checkBox_Model_Bar_Real"; + checkBox_Model_Bar_Real.Size = new Size(48, 19); + checkBox_Model_Bar_Real.TabIndex = 39; + checkBox_Model_Bar_Real.Tag = "#en"; + checkBox_Model_Bar_Real.Text = "Real"; + checkBox_Model_Bar_Real.UseVisualStyleBackColor = true; + checkBox_Model_Bar_Real.CheckedChanged += numericUpDown_Bar_Update; + // // label30 // label30.AutoSize = true; @@ -1072,6 +1112,7 @@ // // groupBox_GPS // + groupBox_GPS.Controls.Add(checkBox_Model_Pos_Real); groupBox_GPS.Controls.Add(label2); groupBox_GPS.Controls.Add(numericUpDown_Pos_Laten); groupBox_GPS.Controls.Add(label4); @@ -1083,13 +1124,25 @@ groupBox_GPS.Controls.Add(label48); groupBox_GPS.Controls.Add(checkBox_Pos_Enable); groupBox_GPS.Dock = DockStyle.Top; - groupBox_GPS.Location = new Point(0, 327); + groupBox_GPS.Location = new Point(0, 283); groupBox_GPS.Name = "groupBox_GPS"; groupBox_GPS.Size = new Size(204, 106); groupBox_GPS.TabIndex = 2; groupBox_GPS.TabStop = false; groupBox_GPS.Text = "Position"; // + // checkBox_Model_Pos_Real + // + checkBox_Model_Pos_Real.AutoSize = true; + checkBox_Model_Pos_Real.Location = new Point(156, 15); + checkBox_Model_Pos_Real.Name = "checkBox_Model_Pos_Real"; + checkBox_Model_Pos_Real.Size = new Size(48, 19); + checkBox_Model_Pos_Real.TabIndex = 38; + checkBox_Model_Pos_Real.Tag = "#en"; + checkBox_Model_Pos_Real.Text = "Real"; + checkBox_Model_Pos_Real.UseVisualStyleBackColor = true; + checkBox_Model_Pos_Real.CheckedChanged += numericUpDown_Pos_Update; + // // label2 // label2.AutoSize = true; @@ -1204,7 +1257,7 @@ groupBox_Mag.Controls.Add(label22); groupBox_Mag.Dock = DockStyle.Top; groupBox_Mag.Enabled = false; - groupBox_Mag.Location = new Point(0, 276); + groupBox_Mag.Location = new Point(0, 232); groupBox_Mag.Name = "groupBox_Mag"; groupBox_Mag.Size = new Size(204, 51); groupBox_Mag.TabIndex = 5; @@ -1258,6 +1311,7 @@ // // groupBox_Gyr // + groupBox_Gyr.Controls.Add(checkBox_Model_Gyr_Real); groupBox_Gyr.Controls.Add(label51); groupBox_Gyr.Controls.Add(numericUpDown_Gyr_Laten); groupBox_Gyr.Controls.Add(label52); @@ -1274,13 +1328,25 @@ groupBox_Gyr.Controls.Add(numericUpDown_Gyr_Freq); groupBox_Gyr.Controls.Add(label21); groupBox_Gyr.Dock = DockStyle.Top; - groupBox_Gyr.Location = new Point(0, 154); + groupBox_Gyr.Location = new Point(0, 110); groupBox_Gyr.Name = "groupBox_Gyr"; groupBox_Gyr.Size = new Size(204, 122); groupBox_Gyr.TabIndex = 7; groupBox_Gyr.TabStop = false; groupBox_Gyr.Text = "Gyroscope"; // + // checkBox_Model_Gyr_Real + // + checkBox_Model_Gyr_Real.AutoSize = true; + checkBox_Model_Gyr_Real.Location = new Point(153, 101); + checkBox_Model_Gyr_Real.Name = "checkBox_Model_Gyr_Real"; + checkBox_Model_Gyr_Real.Size = new Size(48, 19); + checkBox_Model_Gyr_Real.TabIndex = 37; + checkBox_Model_Gyr_Real.Tag = "#en"; + checkBox_Model_Gyr_Real.Text = "Real"; + checkBox_Model_Gyr_Real.UseVisualStyleBackColor = true; + checkBox_Model_Gyr_Real.CheckedChanged += numericUpDown_Gyr_Update; + // // label51 // label51.AutoSize = true; @@ -1438,6 +1504,7 @@ // // groupBox_Acc // + groupBox_Acc.Controls.Add(checkBox_Model_Acc_Real); groupBox_Acc.Controls.Add(label49); groupBox_Acc.Controls.Add(numericUpDown_Acc_Laten); groupBox_Acc.Controls.Add(label50); @@ -1451,13 +1518,25 @@ groupBox_Acc.Controls.Add(numericUpDown_Acc_Freq); groupBox_Acc.Controls.Add(label20); groupBox_Acc.Dock = DockStyle.Top; - groupBox_Acc.Location = new Point(0, 44); + groupBox_Acc.Location = new Point(0, 0); groupBox_Acc.Name = "groupBox_Acc"; groupBox_Acc.Size = new Size(204, 110); groupBox_Acc.TabIndex = 6; groupBox_Acc.TabStop = false; groupBox_Acc.Text = "Accelerometer"; // + // checkBox_Model_Acc_Real + // + checkBox_Model_Acc_Real.AutoSize = true; + checkBox_Model_Acc_Real.Location = new Point(156, 91); + checkBox_Model_Acc_Real.Name = "checkBox_Model_Acc_Real"; + checkBox_Model_Acc_Real.Size = new Size(48, 19); + checkBox_Model_Acc_Real.TabIndex = 36; + checkBox_Model_Acc_Real.Tag = "#en"; + checkBox_Model_Acc_Real.Text = "Real"; + checkBox_Model_Acc_Real.UseVisualStyleBackColor = true; + checkBox_Model_Acc_Real.CheckedChanged += numericUpDown_Acc_Update; + // // label49 // label49.AutoSize = true; @@ -1582,42 +1661,6 @@ label20.TabIndex = 2; label20.Text = "Freq:"; // - // groupBox2 - // - groupBox2.Controls.Add(radioButton1); - groupBox2.Controls.Add(radioButton_Real); - groupBox2.Dock = DockStyle.Top; - groupBox2.Location = new Point(0, 0); - groupBox2.Name = "groupBox2"; - groupBox2.Size = new Size(204, 44); - groupBox2.TabIndex = 9; - groupBox2.TabStop = false; - groupBox2.Text = "Mode"; - // - // radioButton1 - // - radioButton1.AutoSize = true; - radioButton1.Checked = true; - radioButton1.Location = new Point(9, 19); - radioButton1.Name = "radioButton1"; - radioButton1.Size = new Size(50, 19); - radioButton1.TabIndex = 2; - radioButton1.TabStop = true; - radioButton1.Text = "Ideal"; - radioButton1.UseVisualStyleBackColor = true; - radioButton1.CheckedChanged += checkBox_Mode_Real_CheckedChanged; - // - // radioButton_Real - // - radioButton_Real.AutoSize = true; - radioButton_Real.Location = new Point(150, 19); - radioButton_Real.Name = "radioButton_Real"; - radioButton_Real.Size = new Size(47, 19); - radioButton_Real.TabIndex = 1; - radioButton_Real.Text = "Real"; - radioButton_Real.UseVisualStyleBackColor = true; - radioButton_Real.CheckedChanged += checkBox_Mode_Real_CheckedChanged; - // // tabPage_Area // tabPage_Area.Controls.Add(groupBox4); @@ -2007,8 +2050,6 @@ ((System.ComponentModel.ISupportInitialize)numericUpDown_Acc_Scale_Rigth).EndInit(); ((System.ComponentModel.ISupportInitialize)numericUpDown_Acc_Noise).EndInit(); ((System.ComponentModel.ISupportInitialize)numericUpDown_Acc_Freq).EndInit(); - groupBox2.ResumeLayout(false); - groupBox2.PerformLayout(); tabPage_Area.ResumeLayout(false); groupBox4.ResumeLayout(false); groupBox4.PerformLayout(); @@ -2151,14 +2192,11 @@ private Label label55; private NumericUpDown numericUpDown_Range_Laten; private Label label56; - private GroupBox groupBox2; private ListBox listBox_Drones; private Label label39; private NumericUpDown numericUpDown_OF_Wait; private Label label40; private NumericUpDown numericUpDown_OF_Lens; - private RadioButton radioButton1; - private RadioButton radioButton_Real; private GroupBox groupBox3; private CheckBox checkBox_Area_Freeze_X; private CheckBox checkBox_Area_Freeze_Z; @@ -2181,5 +2219,11 @@ private Label label64; private NumericUpDown numericUpDown_Area_Wind_RotResist; private Label label65; + private CheckBox checkBox_Model_Gyr_Real; + private CheckBox checkBox_Model_Acc_Real; + private CheckBox checkBox_Model_Range_Real; + private CheckBox checkBox_Model_OF_Real; + private CheckBox checkBox_Model_Bar_Real; + private CheckBox checkBox_Model_Pos_Real; } } diff --git a/DroneSimulator/FormMain.cs b/DroneSimulator/FormMain.cs index 7475bdc..9fb1d9d 100644 --- a/DroneSimulator/FormMain.cs +++ b/DroneSimulator/FormMain.cs @@ -23,7 +23,6 @@ namespace DroneSimulator { InitializeComponent(); - RealMode.RealSimulation = radioButton_Real.Checked; numericUpDown_Acc_Update(null, null); numericUpDown_Gyr_Update(null, null); numericUpDown_Pos_Update(null, null); @@ -226,6 +225,8 @@ namespace DroneSimulator private void numericUpDown_Bar_Update(object sender, EventArgs e) { + RealMode.Barometer.RealSimulation = checkBox_Model_Bar_Real.Checked; + try { RealMode.Barometer.Pressure = uint.Parse(textBox_Bar_Pressure.Text); } catch { @@ -233,20 +234,16 @@ namespace DroneSimulator MessageBox.Show("Pressure invalid format", "Barometer error", MessageBoxButtons.OK, MessageBoxIcon.Error); } - RealMode.Barometer.Freq = (uint)numericUpDown_Bar_Freq.Value; RealMode.Barometer.Noise = (float)numericUpDown_Bar_Noise.Value; RealMode.Barometer.Lateness = (float)numericUpDown_Bar_Laten.Value; RealMode.Barometer.Enable = checkBox_Bar_Enable.Checked; } - private void checkBox_Mode_Real_CheckedChanged(object sender, EventArgs e) - { - RealMode.RealSimulation = radioButton_Real.Checked; - } - private void numericUpDown_Acc_Update(object sender, EventArgs e) { + RealMode.Accelerometer.RealSimulation=checkBox_Model_Acc_Real.Checked; + RealMode.Accelerometer.Freq = (uint)numericUpDown_Acc_Freq.Value; RealMode.Accelerometer.Noise = (float)numericUpDown_Acc_Noise.Value; RealMode.Accelerometer.Lateness = (float)numericUpDown_Acc_Laten.Value; @@ -257,6 +254,8 @@ namespace DroneSimulator private void numericUpDown_Gyr_Update(object sender, EventArgs e) { + RealMode.Gyroscope.RealSimulation = checkBox_Model_Gyr_Real.Checked; + RealMode.Gyroscope.Freq = (uint)numericUpDown_Gyr_Freq.Value; RealMode.Gyroscope.Noise = (float)numericUpDown_Gyr_Noise.Value; RealMode.Gyroscope.Lateness = (float)numericUpDown_Gyr_Laten.Value; @@ -268,6 +267,8 @@ namespace DroneSimulator private void numericUpDown_Pos_Update(object sender, EventArgs e) { + RealMode.Position.RealSimulation = checkBox_Model_Pos_Real.Checked; + RealMode.Position.Freq = (uint)numericUpDown_Pos_Freq.Value; RealMode.Position.Noise = (float)numericUpDown_Pos_Noise.Value; RealMode.Position.Lateness = (float)numericUpDown_Pos_Laten.Value; @@ -276,6 +277,8 @@ namespace DroneSimulator private void numericUpDown_Range_Update(object sender, EventArgs e) { + RealMode.Range.RealSimulation = checkBox_Model_Range_Real.Checked; + RealMode.Range.Freq = (uint)numericUpDown_Range_Freq.Value; RealMode.Range.Noise = (float)numericUpDown_Range_Noise.Value; RealMode.Range.Lateness = (float)numericUpDown_Range_Laten.Value; @@ -286,6 +289,8 @@ namespace DroneSimulator private void numericUpDown_OF_Update(object sender, EventArgs e) { + RealMode.OpticalFlow.RealSimulation = checkBox_Model_OF_Real.Checked; + RealMode.OpticalFlow.Freq = (uint)numericUpDown_OF_Freq.Value; RealMode.OpticalFlow.Noise = (float)numericUpDown_OF_Noise.Value; RealMode.OpticalFlow.Lateness = (float)numericUpDown_OF_Laten.Value; diff --git a/DroneSimulator/RealMode.cs b/DroneSimulator/RealMode.cs index f9c2c47..ce26081 100644 --- a/DroneSimulator/RealMode.cs +++ b/DroneSimulator/RealMode.cs @@ -10,7 +10,7 @@ namespace DroneSimulator { internal class RealMode { - public static bool RealSimulation; + internal class Accelerometer { @@ -19,6 +19,7 @@ namespace DroneSimulator public static float ScaleLeft; public static float ScaleRight; public static float Lateness; + public static bool RealSimulation; private uint last = 0; @@ -81,6 +82,7 @@ namespace DroneSimulator public static float Noise; public static Vector3 Shift; public static float Lateness; + public static bool RealSimulation; private uint last = 0; @@ -145,6 +147,7 @@ namespace DroneSimulator public static uint Freq; public static float Noise; public static float Lateness; + public static bool RealSimulation; private uint last = 0; @@ -159,6 +162,12 @@ namespace DroneSimulator public void Update(Vector3 value, uint time) { + if (!Enable) + { + result = Vector3.NaN; + return; + } + if (!RealSimulation) { result = value; @@ -166,12 +175,6 @@ namespace DroneSimulator return; } - if (!Enable) - { - result = Vector3.NaN; - return; - } - int noise = (int)(Noise * 1000); value.X += ((float)rand.Next(-noise, noise)) / 1000; value.Y += ((float)rand.Next(-noise, noise)) / 1000; @@ -207,6 +210,7 @@ namespace DroneSimulator public static uint Freq; public static float Noise; public static float Lateness; + public static bool RealSimulation; private uint last = 0; @@ -223,6 +227,12 @@ namespace DroneSimulator { value = Pressure - value; + if (!Enable) + { + result = float.NaN; + return; + } + if (!RealSimulation) { result = value; @@ -230,12 +240,6 @@ namespace DroneSimulator return; } - if (!Enable) - { - result = float.NaN; - return; - } - int noise = (int)(Noise * 1000); value += ((float)rand.Next(-noise, noise)) / 1000; @@ -272,6 +276,7 @@ namespace DroneSimulator public static float Error; public static uint Wait; public static float Lens; + public static bool RealSimulation; private uint last = 0; @@ -287,6 +292,12 @@ namespace DroneSimulator public Vector2 result; public void Update(Vector2 value, float Range, uint time) { + if (!Enable) + { + result = Vector2.NaN; + return; + } + if (!RealSimulation) { result = value; @@ -294,12 +305,6 @@ namespace DroneSimulator return; } - if (!Enable) - { - result = Vector2.NaN; - return; - } - value *= Lens; if (rand.Next(0, 1000) < (Error * 10)) @@ -350,6 +355,7 @@ namespace DroneSimulator public static uint Freq; public static float Noise; public static float Lateness; + public static bool RealSimulation; private uint last = 0; @@ -364,6 +370,12 @@ namespace DroneSimulator public void Update(float value, uint time) { + if (!Enable) + { + result = float.NaN; + return; + } + if (!RealSimulation) { result = value; @@ -371,13 +383,7 @@ namespace DroneSimulator return; } - if (!Enable) - { - result = float.NaN; - return; - } - - if (value > MaxHeight) value = -1; + if (value > MaxHeight) value = MaxHeight; else { int noise = (int)(Noise * 1000);