From 53fd323880c02fb69da61066d8f63e8d565a57b9 Mon Sep 17 00:00:00 2001 From: lhiven <236881222@qq.com> Date: Sat, 25 May 2024 16:06:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=99=E7=9B=98=E5=AE=9A?= =?UTF-8?q?=E4=BD=8D=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Flow/NormalFlow/ThreePointLocationFlow.cs | 144 +++++++++++------- .../StockTrayLocationRecipe.Designer.cs | 18 +-- .../Recipe/StockTrayLocationRecipe.cs | 21 ++- .../Recipe/StockTrayLocationRecipe.resx | 20 +-- 4 files changed, 128 insertions(+), 75 deletions(-) diff --git a/Rs.DeweyTester/Flow/NormalFlow/ThreePointLocationFlow.cs b/Rs.DeweyTester/Flow/NormalFlow/ThreePointLocationFlow.cs index d9d822b..a333648 100644 --- a/Rs.DeweyTester/Flow/NormalFlow/ThreePointLocationFlow.cs +++ b/Rs.DeweyTester/Flow/NormalFlow/ThreePointLocationFlow.cs @@ -18,8 +18,7 @@ namespace Rs.MotionPlat.Flow.NormalFlow { 到拍照位, 等待到拍照位, - 通知相机拍照, - 处理拍照结果 + 相机拍照处理 } public class ThreePointLocationFlow { @@ -96,7 +95,7 @@ namespace Rs.MotionPlat.Flow.NormalFlow { logInfo = $"已运动到拍照位,cloadx:{Ops.GetCurPosition(AxisControl.LoadX)},cloady1:{Ops.GetCurPosition(AxisControl.LoadY1)},cloady2:{Ops.GetCurPosition(AxisControl.LoadY2)}"; MessageQueue.Instance.Insert(logInfo); - step = EThreePointLocationFlowStep.通知相机拍照; + step = EThreePointLocationFlowStep.相机拍照处理; } else { @@ -104,62 +103,25 @@ namespace Rs.MotionPlat.Flow.NormalFlow } } break; - case EThreePointLocationFlowStep.通知相机拍照: + case EThreePointLocationFlowStep.相机拍照处理: vr = VisionHelper.Grab(Vision.EVisionScene.TrayLocation); if(vr!=null && vr.Result) { vResult.Add(vr); - step = EThreePointLocationFlowStep.处理拍照结果; - } - break; - case EThreePointLocationFlowStep.处理拍照结果: - //在这里先打印拍照结果 - logInfo = JsonConvert.SerializeObject(vr); - MessageQueue.Instance.Insert(logInfo); - points.RemoveAt(0); - if(points.Count > 0) - { - step = EThreePointLocationFlowStep.到拍照位; - } - else - { - - string deleteSql = $"delete from trayrunpoints where recipeName='{GlobalVar.CurRecipe}' and trayname='{trayType}'"; - SqliteHelper db = new SqliteHelper(); - int rowAffectNum = db.ExecuteNonQuery(deleteSql); - - - double x1 = TrayPointManager.GetSlotPoint(trayType, 1).X + vResult[0].OffsetX; - double y1 = TrayPointManager.GetSlotPoint(trayType, 1).Y + vResult[0].OffsetY; - - double x2 = TrayPointManager.GetSlotPoint(trayType, 16).X + vResult[1].OffsetX; - double y2 = TrayPointManager.GetSlotPoint(trayType, 16).Y + vResult[1].OffsetY; - - double x3 = TrayPointManager.GetSlotPoint(trayType, 241).X + vResult[2].OffsetX; - double y3 = TrayPointManager.GetSlotPoint(trayType, 241).Y + vResult[2].OffsetY; - double bigSpaceX = (x2 - x1) / 15; - double smallSapceY = (y2 - y1) / 15; - - double bigSpaceY = (y3 - y1) / 15; - double smallSpaceX = (x3 - x1) / 15; - int index = 1; - for (int row = 1; row <= 16; row++) + //在这里先打印拍照结果 + logInfo = JsonConvert.SerializeObject(vr); + MessageQueue.Instance.Insert(logInfo); + points.RemoveAt(0); + if (points.Count > 0) { - for (int col = 1; col <= 16; col++) - { - double x = x1 + (col - 1) * bigSpaceX + (row - 1) * smallSpaceX; - double y = y1 + (row - 1) * bigSpaceY + (col - 1) * smallSapceY; - string insertSql = $"insert into trayrunpoints(trayid,recipename,trayname,slotindex,x,y) values(1,'{GlobalVar.CurRecipe}','{trayType}',{index},{x},{y})"; - rowAffectNum = db.ExecuteNonQuery(insertSql); - index++; - } - + step = EThreePointLocationFlowStep.到拍照位; + } + else + { + CalcTrayRunPoint(trayType); + TrayRunPointManager.LoadPoint(); + finished = true; } - TrayRunPointManager.LoadPoint(); - finished = true; - //Msg.ShowInfo("三点定位完成"); - //points = new List() { 1, 16, 241 }; - //step = EThreePointLocationFlowStep.到拍照位; } break; } @@ -176,5 +138,81 @@ namespace Rs.MotionPlat.Flow.NormalFlow { return "ThreePointLocation-"; } + + /// + /// 生成三点定位数据 + /// + /// + private void CalcTrayRunPoint(ETrayType trayType) + { + if(false) + { + string deleteSql = $"delete from trayrunpoints where recipeName='{GlobalVar.CurRecipe}' and trayname='{trayType}'"; + SqliteHelper db = new SqliteHelper(); + int rowAffectNum = db.ExecuteNonQuery(deleteSql); + + double x1 = TrayPointManager.GetSlotPoint(trayType, 1).X + vResult[0].OffsetX; + double y1 = TrayPointManager.GetSlotPoint(trayType, 1).Y + vResult[0].OffsetY; + + double x2 = TrayPointManager.GetSlotPoint(trayType, 16).X + vResult[1].OffsetX; + double y2 = TrayPointManager.GetSlotPoint(trayType, 16).Y + vResult[1].OffsetY; + + double x3 = TrayPointManager.GetSlotPoint(trayType, 241).X + vResult[2].OffsetX; + double y3 = TrayPointManager.GetSlotPoint(trayType, 241).Y + vResult[2].OffsetY; + double bigSpaceX = (x2 - x1) / 15; + double smallSapceY = (y2 - y1) / 15; + + double bigSpaceY = (y3 - y1) / 15; + double smallSpaceX = (x3 - x1) / 15; + int index = 1; + for (int row = 1; row <= 16; row++) + { + for (int col = 1; col <= 16; col++) + { + double x = x1 + (col - 1) * bigSpaceX + (row - 1) * smallSpaceX; + double y = y1 + (row - 1) * bigSpaceY + (col - 1) * smallSapceY; + string insertSql = $"insert into trayrunpoints(trayid,recipename,trayname,slotindex,x,y) values(1,'{GlobalVar.CurRecipe}','{trayType}',{index},{x},{y})"; + rowAffectNum = db.ExecuteNonQuery(insertSql); + index++; + } + + } + } + else + { + string deleteSql = $"delete from trayrunpoints where recipeName='{GlobalVar.CurRecipe}' and trayname='{trayType}'"; + SqliteHelper db = new SqliteHelper(); + int rowAffectNum = db.ExecuteNonQuery(deleteSql); + + double x1 = TrayPointManager.GetSlotPoint(trayType, 1).X + vResult[0].OffsetX; + double y1 = TrayPointManager.GetSlotPoint(trayType, 1).Y + vResult[0].OffsetY; + + double x2 = TrayPointManager.GetSlotPoint(trayType, 16).X + vResult[1].OffsetX; + double y2 = TrayPointManager.GetSlotPoint(trayType, 16).Y + vResult[1].OffsetY; + + double x3 = TrayPointManager.GetSlotPoint(trayType, 241).X + vResult[2].OffsetX; + double y3 = TrayPointManager.GetSlotPoint(trayType, 241).Y + vResult[2].OffsetY; + + double bigSpaceX = (x3 - x1) / 15; + double smallSpaceY = (y3 - y1) / 15; + + double bigSpaceY = (y2 - y1) / 15; + double smallSpaceX = (x2 - x1) / 15; + int index = 1; + for (int row = 1; row <= 16; row++) + { + for (int col = 1; col <= 16; col++) + { + double x = y1 + (row - 1) * bigSpaceY + (col - 1) * smallSpaceX; + double y = x1 + (col - 1) * bigSpaceX + (row - 1) * smallSpaceY; + + string insertSql = $"insert into trayrunpoints(trayid,recipename,trayname,slotindex,x,y) values(1,'{GlobalVar.CurRecipe}','{trayType}',{index},{x},{y})"; + rowAffectNum = db.ExecuteNonQuery(insertSql); + index++; + } + + } + } + } } } diff --git a/Rs.DeweyTester/Recipe/StockTrayLocationRecipe.Designer.cs b/Rs.DeweyTester/Recipe/StockTrayLocationRecipe.Designer.cs index e798763..f4509d1 100644 --- a/Rs.DeweyTester/Recipe/StockTrayLocationRecipe.Designer.cs +++ b/Rs.DeweyTester/Recipe/StockTrayLocationRecipe.Designer.cs @@ -71,7 +71,7 @@ this.panelEx3 = new Rs.Controls.PanelEx(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.btnThreePointLocation = new System.Windows.Forms.Button(); - this.button2 = new System.Windows.Forms.Button(); + this.btnCreateMatrix = new System.Windows.Forms.Button(); this.btnSaveSlotOffsetDistY = new System.Windows.Forms.Button(); this.btnTeachMarkY2 = new System.Windows.Forms.Button(); this.btnSaveSlotOffsetDistX = new System.Windows.Forms.Button(); @@ -312,7 +312,7 @@ // groupBox1 // this.groupBox1.Controls.Add(this.btnThreePointLocation); - this.groupBox1.Controls.Add(this.button2); + this.groupBox1.Controls.Add(this.btnCreateMatrix); this.groupBox1.Controls.Add(this.btnSaveSlotOffsetDistY); this.groupBox1.Controls.Add(this.btnTeachMarkY2); this.groupBox1.Controls.Add(this.btnSaveSlotOffsetDistX); @@ -340,13 +340,13 @@ this.btnThreePointLocation.UseVisualStyleBackColor = false; this.btnThreePointLocation.Click += new System.EventHandler(this.btnThreePointLocation_Click); // - // button2 + // btnCreateMatrix // - resources.ApplyResources(this.button2, "button2"); - this.button2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(56)))), ((int)(((byte)(56))))); - this.button2.Name = "button2"; - this.button2.UseVisualStyleBackColor = false; - this.button2.Click += new System.EventHandler(this.btnCreateMatrix_Click); + resources.ApplyResources(this.btnCreateMatrix, "btnCreateMatrix"); + this.btnCreateMatrix.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(56)))), ((int)(((byte)(56))))); + this.btnCreateMatrix.Name = "btnCreateMatrix"; + this.btnCreateMatrix.UseVisualStyleBackColor = false; + this.btnCreateMatrix.Click += new System.EventHandler(this.btnCreateMatrix_Click); // // btnSaveSlotOffsetDistY // @@ -770,7 +770,7 @@ private Controls.PanelEx panelEx4; private System.Windows.Forms.GroupBox groupBox2; private Controls.RsTray rsTray1; - private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button btnCreateMatrix; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.GroupBox groupBox4; private System.Windows.Forms.DataGridView dgvBasePoints; diff --git a/Rs.DeweyTester/Recipe/StockTrayLocationRecipe.cs b/Rs.DeweyTester/Recipe/StockTrayLocationRecipe.cs index c590fbe..db075a6 100644 --- a/Rs.DeweyTester/Recipe/StockTrayLocationRecipe.cs +++ b/Rs.DeweyTester/Recipe/StockTrayLocationRecipe.cs @@ -100,6 +100,9 @@ namespace Rs.MotionPlat.Recipe private void btnCreateMatrix_Click(object sender, EventArgs e) { + btnCreateMatrix.Enabled = false; + btnThreePointLocation.Enabled = false; + List executeSql = new List(); int rowEffect = 0; if (ObjectHelper.IsNotNullorEmpty(dt)) { @@ -124,17 +127,29 @@ namespace Rs.MotionPlat.Recipe } else if(rsTray1.SortDir== ESortDir.LeftBottomToTop) { - xRun = double.Parse(txtMarkX1.Text) + (j * double.Parse(txtSlotOffsetDistX.Text)); - yRun = double.Parse(txtMarkY2.Text) + (i * double.Parse(txtSlotOffsetDistY.Text)); + xRun = double.Parse(txtMarkX1.Text) + (i * double.Parse(txtSlotOffsetDistX.Text)); + yRun = double.Parse(txtMarkY2.Text) + (j * double.Parse(txtSlotOffsetDistY.Text)); } string insertRunSql = $"insert into TrayPoints(trayid,recipename,trayname,slotindex,x,y) values('{dt.Rows[0]["id"]}','{dt.Rows[0]["recipename"]}','{dt.Rows[0]["TrayName"]}',{index},{xRun},{yRun})"; - db.ExecuteNonQuery(insertRunSql); + executeSql.Add(insertRunSql); + index++; } } + if(executeSql!=null&&executeSql.Count>0) + { + string sql = string.Join(";", executeSql); + rowEffect = db.ExecuteNonQuery(sql); + if(rowEffect>0) + { + Msgbox.ShowDialog(EButtonType.Ok, $"{rowEffect} data updated!"); + } + } BindPoints(); TrayPointManager.LoadPoint(); + btnCreateMatrix.Enabled = true; + btnThreePointLocation.Enabled = true; } } diff --git a/Rs.DeweyTester/Recipe/StockTrayLocationRecipe.resx b/Rs.DeweyTester/Recipe/StockTrayLocationRecipe.resx index 9c4434f..e0be33c 100644 --- a/Rs.DeweyTester/Recipe/StockTrayLocationRecipe.resx +++ b/Rs.DeweyTester/Recipe/StockTrayLocationRecipe.resx @@ -369,31 +369,31 @@ 0 - + Bottom, Right - + 605, 101 - + 159, 52 - + 56 - + 生成矩阵 - - button2 + + btnCreateMatrix - + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + groupBox1 - + 1