/// <summary> /// Думаем, что центр scan1 - это X2,Y2. Нужно вернуть X1,Y1. /// </summary> /// <returns>Возвращает массив int[3]: X,Y,error: координаты настоящего центра scan1 и квадрат расстояния от него до реального симуляционного центра scan1</returns> public int[] getRealCoords4() { Console.WriteLine("crosslinkig " + X0 + "," + Y0 + ";" + X1 + "," + Y1 + ";" + X2 + "," + Y2); double minsum = 100000000; int limXY = 20; double summ; double min; int optX = 0, optY = 0; int C = (Parameters.getD_scan() + Parameters.getR_scan()) / 2; List <int[]> errorZone = pieErrorZoneSearch(0, 0, X2 - X0, Y2 - Y0); // Console.WriteLine("errorZone.Count "+ errorZone.Count); int numberOfMinPoints = 0; //количество точек с одинаковыми минимальными значениями функционала ошибки //TODO for (int k = 0; k < errorZone.Count; k++) { PixelMap map01 = new PixelMap(Parameters.getD_scan1() + Parameters.getR_scan(), Parameters.getD_scan1() + Parameters.getR_scan(), 0, 0, 0); List <int[]> irrelevantPoints0 = new List <int[]>(); List <int[]> irrelevantPoints1 = new List <int[]>(); int X = errorZone[k][0]; int Y = errorZone[k][1]; for (int i = 0; i < scan0.xyScan.Count; i++) { map01[scan0.xyScan[i][0] + C, scan0.xyScan[i][1] + C] = new Pixel(Parameters.wallColor); } for (int i = 0; i < scan1.xyScan.Count; i++) { map01[scan1.xyScan[i][0] + X + C, scan1.xyScan[i][1] + Y + C] = new Pixel(Parameters.wallColor); } int y1 = new int(); int x1 = new int(); bool flagR; //Будет true, если на текущем угле сканирования видно препятствие, иначе false и радиус от текущего угла будет равен нулю bool flagRepeated; //Будет true, если точка уже сохранена в списке скана int rPhi = -1; for (int i = 0; i < Parameters.getN_phi(); i++) { //---------------------------------------scan1 flagR = false; for (ushort r = 1; r < Parameters.getR_scan() + 1; r++) { x1 = (int)Math.Round(r * Math.Cos(i * Parameters.getScan_step())); y1 = (int)Math.Round(r * Math.Sin(i * Parameters.getScan_step())); if (map01[x1 + X + C, y1 + Y + C].Color == Parameters.wallColor) { rPhi = r; flagR = true; break; } } if (!flagR) { rPhi = 0; } if (rPhi == -1) { Console.WriteLine("Scanning problems r == -1 on scan1, angle: " + i * Parameters.getScan_step() / Math.PI * 180); } if (scan1.rByPhi[i] != rPhi) { flagRepeated = false; for (int j = 0; j < irrelevantPoints1.Count; j++) { if ((irrelevantPoints1[j][0] == x1) && (irrelevantPoints1[j][1] == y1)) { flagRepeated = true; } } if (!flagRepeated) { irrelevantPoints1.Add(new int[2] { x1, y1 }); } } //---------------------------------------scan0 flagR = false; for (ushort r = 1; r < Parameters.getR_scan() + 1; r++) { x1 = (int)Math.Round(r * Math.Cos(i * Parameters.getScan_step())); y1 = (int)Math.Round(r * Math.Sin(i * Parameters.getScan_step())); if (map01[x1 + C, y1 + C].Color == Parameters.wallColor) { rPhi = r; flagR = true; break; } } if (!flagR) { rPhi = 0; } if (rPhi == -1) { Console.WriteLine("Scanning problems r == -1 on scan0, angle: " + i * Parameters.getScan_step() / Math.PI * 180); } if (scan0.rByPhi[i] != rPhi) { flagRepeated = false; for (int j = 0; j < irrelevantPoints0.Count; j++) { if ((irrelevantPoints0[j][0] == x1) && (irrelevantPoints0[j][1] == y1)) { flagRepeated = true; } } if (!flagRepeated) { irrelevantPoints0.Add(new int[2] { x1, y1 }); } } } summ = 0; for (int i = 0; i < irrelevantPoints1.Count; i++) { min = 1000000; for (int j = 0; j < scan1.xyScan.Count; j++) { if (min > Parameters.getSquaredDistance(irrelevantPoints1[i][0], irrelevantPoints1[i][1], scan1.xyScan[j][0], scan1.xyScan[j][1])) { min = Parameters.getSquaredDistance(irrelevantPoints1[i][0], irrelevantPoints1[i][1], scan1.xyScan[j][0], scan1.xyScan[j][1]); } } summ += min; } for (int i = 0; i < irrelevantPoints0.Count; i++) { min = 1000000; for (int j = 0; j < scan0.xyScan.Count; j++) { if (min > Parameters.getSquaredDistance(irrelevantPoints0[i][0], irrelevantPoints0[i][1], scan0.xyScan[j][0], scan0.xyScan[j][1])) { min = Parameters.getSquaredDistance(irrelevantPoints0[i][0], irrelevantPoints0[i][1], scan0.xyScan[j][0], scan0.xyScan[j][1]); } } summ += min; } if (minsum > summ) { minsum = summ; optX = X; optY = Y; numberOfMinPoints = 0; //TODO } if (summ == minsum) //TODO { numberOfMinPoints++; } } int errorSquredDistance = Parameters.getSquaredDistance(X1, Y1, X0 + optX, Y0 + optY); //квадрат раастояния от реального положения до предсказанного // // Console.WriteLine("opts "+optX+","+optY); if (errorSquredDistance != 0) //TODO { Console.WriteLine("Don't match--------------------------------------"); } return(new int[5] { X0 + optX, Y0 + optY, errorSquredDistance, errorZone.Count(), numberOfMinPoints }); //TODO }
/// <summary> /// Требуемый метод для поддержки конструктора — не изменяйте /// содержимое этого метода с помощью редактора кода. /// </summary> private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); this.panel1 = new System.Windows.Forms.Panel(); this.panel3 = new System.Windows.Forms.Panel(); this.label8 = new System.Windows.Forms.Label(); this.numericUpDown4sgm_psi = new System.Windows.Forms.NumericUpDown(); this.numericUpDown5scan_noise = new System.Windows.Forms.NumericUpDown(); this.numericUpDown6n_phi = new System.Windows.Forms.NumericUpDown(); this.numericUpDown3sgm_lmax = new System.Windows.Forms.NumericUpDown(); this.numericUpDown2r_robot = new System.Windows.Forms.NumericUpDown(); this.numericUpDown1r_scan = new System.Windows.Forms.NumericUpDown(); this.label7 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.button2 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.button1 = new System.Windows.Forms.Button(); this.radioButton3 = new System.Windows.Forms.RadioButton(); this.radioButton2 = new System.Windows.Forms.RadioButton(); this.radioButton1 = new System.Windows.Forms.RadioButton(); this.panel2 = new System.Windows.Forms.Panel(); this.panel1.SuspendLayout(); this.panel3.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4sgm_psi)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown5scan_noise)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown6n_phi)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3sgm_lmax)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2r_robot)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1r_scan)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // // panel1 // this.panel1.BackColor = System.Drawing.SystemColors.GradientActiveCaption; this.panel1.Controls.Add(this.panel3); this.panel1.Controls.Add(this.label1); this.panel1.Controls.Add(this.pictureBox1); this.panel1.Controls.Add(this.button1); this.panel1.Controls.Add(this.radioButton3); this.panel1.Controls.Add(this.radioButton2); this.panel1.Controls.Add(this.radioButton1); resources.ApplyResources(this.panel1, "panel1"); this.panel1.Name = "panel1"; // // panel3 // this.panel3.BackColor = System.Drawing.SystemColors.ScrollBar; this.panel3.Controls.Add(this.label8); this.panel3.Controls.Add(this.numericUpDown4sgm_psi); this.panel3.Controls.Add(this.numericUpDown5scan_noise); this.panel3.Controls.Add(this.numericUpDown6n_phi); this.panel3.Controls.Add(this.numericUpDown3sgm_lmax); this.panel3.Controls.Add(this.numericUpDown2r_robot); this.panel3.Controls.Add(this.numericUpDown1r_scan); this.panel3.Controls.Add(this.label7); this.panel3.Controls.Add(this.label6); this.panel3.Controls.Add(this.label5); this.panel3.Controls.Add(this.label4); this.panel3.Controls.Add(this.label3); this.panel3.Controls.Add(this.label2); this.panel3.Controls.Add(this.button2); resources.ApplyResources(this.panel3, "panel3"); this.panel3.Name = "panel3"; // // label8 // resources.ApplyResources(this.label8, "label8"); this.label8.BackColor = System.Drawing.SystemColors.InactiveCaption; this.label8.Name = "label8"; // // numericUpDown6n_phi // resources.ApplyResources(this.numericUpDown6n_phi, "numericUpDown6n_phi"); this.numericUpDown6n_phi.Name = "numericUpDown6n_phi"; this.numericUpDown6n_phi.Maximum = 500; this.numericUpDown6n_phi.Minimum = 10; this.numericUpDown6n_phi.Value = Parameters.getN_phi(); // // numericUpDown2r_robot // resources.ApplyResources(this.numericUpDown2r_robot, "numericUpDown2r_robot"); this.numericUpDown2r_robot.Name = "numericUpDown2r_robot"; this.numericUpDown2r_robot.Maximum = 100; this.numericUpDown2r_robot.Minimum = 0; this.numericUpDown2r_robot.Value = Parameters.getR_robot(); // // numericUpDown1r_scan // resources.ApplyResources(this.numericUpDown1r_scan, "numericUpDown1r_scan"); this.numericUpDown1r_scan.Name = "numericUpDown1r_scan"; this.numericUpDown1r_scan.Maximum = 300; this.numericUpDown1r_scan.Minimum = 0; this.numericUpDown1r_scan.Value = Parameters.getR_scan(); // // numericUpDown4sgm_psi // resources.ApplyResources(this.numericUpDown4sgm_psi, "numericUpDown4sgm_psi"); this.numericUpDown4sgm_psi.Name = "numericUpDown4sgm_psi"; this.numericUpDown4sgm_psi.Maximum = 300; this.numericUpDown4sgm_psi.Minimum = 0; this.numericUpDown4sgm_psi.Value = Parameters.getSgm_psi_deg(); // // numericUpDown5scan_noise // resources.ApplyResources(this.numericUpDown5scan_noise, "numericUpDown5scan_noise"); this.numericUpDown5scan_noise.Name = "numericUpDown5scan_noise"; this.numericUpDown5scan_noise.Maximum = 3; this.numericUpDown5scan_noise.Minimum = 0; this.numericUpDown5scan_noise.Value = Environment.getR_scanNoiseMode(); // // numericUpDown3sgm_lmax // resources.ApplyResources(this.numericUpDown3sgm_lmax, "numericUpDown3sgm_lmax"); this.numericUpDown3sgm_lmax.Name = "numericUpDown3sgm_lmax"; this.numericUpDown3sgm_lmax.Maximum = 50; this.numericUpDown3sgm_lmax.Minimum = 0; this.numericUpDown3sgm_lmax.Value = Parameters.getSgm_lmax(); // // label7 // resources.ApplyResources(this.label7, "label7"); this.label7.Name = "label7"; // // label6 // resources.ApplyResources(this.label6, "label6"); this.label6.Name = "label6"; // // label5 // resources.ApplyResources(this.label5, "label5"); this.label5.Name = "label5"; // // label4 // resources.ApplyResources(this.label4, "label4"); this.label4.Name = "label4"; // // label3 // resources.ApplyResources(this.label3, "label3"); this.label3.Name = "label3"; // // label2 // resources.ApplyResources(this.label2, "label2"); this.label2.Name = "label2"; // // button2 // resources.ApplyResources(this.button2, "button2"); this.button2.Name = "button2"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // label1 // resources.ApplyResources(this.label1, "label1"); this.label1.Name = "label1"; // // pictureBox1 // this.pictureBox1.BackColor = System.Drawing.SystemColors.ControlDark; resources.ApplyResources(this.pictureBox1, "pictureBox1"); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.TabStop = false; // // button1 // resources.ApplyResources(this.button1, "button1"); this.button1.BackColor = System.Drawing.SystemColors.ControlLight; this.button1.Name = "button1"; this.button1.UseVisualStyleBackColor = false; // // radioButton3 // resources.ApplyResources(this.radioButton3, "radioButton3"); this.radioButton3.Name = "radioButton3"; this.radioButton3.TabStop = true; this.radioButton3.UseVisualStyleBackColor = true; radioButton3.CheckedChanged += radioButton3_CheckedChanged; // // radioButton2 // resources.ApplyResources(this.radioButton2, "radioButton2"); this.radioButton2.Name = "radioButton2"; this.radioButton2.TabStop = true; this.radioButton2.UseVisualStyleBackColor = true; radioButton2.CheckedChanged += radioButton2_CheckedChanged; // // radioButton1 // resources.ApplyResources(this.radioButton1, "radioButton1"); this.radioButton1.Name = "radioButton1"; this.radioButton1.TabStop = true; this.radioButton1.UseVisualStyleBackColor = true; radioButton1.Checked = true; radioButton1.CheckedChanged += radioButton1_CheckedChanged; // // panel2 // resources.ApplyResources(this.panel2, "panel2"); this.panel2.Name = "panel2"; // // MainForm // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.BackColor = System.Drawing.SystemColors.ActiveCaption; resources.ApplyResources(this, "$this"); this.Controls.Add(this.panel1); this.Controls.Add(this.panel2); this.Name = "MainForm"; this.WindowState = System.Windows.Forms.FormWindowState.Maximized; this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); this.panel3.ResumeLayout(false); this.panel3.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4sgm_psi)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown5scan_noise)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown6n_phi)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3sgm_lmax)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2r_robot)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1r_scan)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); }
/// <summary> /// Возвращает скан с точной карты в заданных координатах /// </summary> /// <param name="X"></param> /// <param name="Y"></param> /// <param name="scanColor">цвет скана для отрисовки</param> /// <returns></returns> public Scan getScan(int X, int Y, Color scanColor) { Scan scan = new Scan(); int y = new int(); int x = new int(); bool flagR; //Будет true, если на текущем угле сканирования видно препятствие, иначе false и радиус от текущего угла будет равен нулю bool flagRepeated; //Будет true, если точка уже сохранена в списке скана Random rand = new Random(System.DateTime.Now.Millisecond); // Stopwatch stopwatch = Stopwatch.StartNew(); for (int i = 0; i < Parameters.getN_phi(); i++) { flagR = false; for (ushort r = 1; r < Parameters.getR_scan1(); r++) { x = (int)Math.Round(r * Math.Cos(i * Parameters.getScan_step())); y = (int)Math.Round(r * Math.Sin(i * Parameters.getScan_step())); if (preciseMap[x + X, y + Y].Color == Parameters.wallColor) { scan.rByPhi[i] = r; flagRepeated = false; for (int j = 0; j < scan.xyScan.Count; j++) { if ((scan.xyScan[j][0] == x) && (scan.xyScan[j][1] == y)) { flagRepeated = true; } } if (!flagRepeated) { switch (r_scanNoiseMode) { case 1: r = rNoising1(ref r, ref rand); break; case 2: r = rNoising2(ref r, ref rand); break; case 3: r = rNoising3(ref r, ref rand); break; } x = (int)Math.Round(r * Math.Cos(i * Parameters.getScan_step())); y = (int)Math.Round(r * Math.Sin(i * Parameters.getScan_step())); scan.xyScan.Add(new int[2] { x, y }); } scan.scanBmp[x + Parameters.getR_scan(), y + Parameters.getR_scan()] = new Pixel(scanColor); flagR = true; break; } } if (!flagR) { scan.rByPhi[i] = 0; } } // stopwatch.Stop(); // Console.WriteLine("Time wasted: "+stopwatch.ElapsedMilliseconds); return(scan); }