优化料盘定位算法

master
lhiven 1 year ago
parent 4fab8f5302
commit 53fd323880

@ -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<int>() { 1, 16, 241 };
//step = EThreePointLocationFlowStep.到拍照位;
}
break;
}
@ -176,5 +138,81 @@ namespace Rs.MotionPlat.Flow.NormalFlow
{
return "ThreePointLocation-";
}
/// <summary>
/// 生成三点定位数据
/// </summary>
/// <param name="trayType"></param>
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++;
}
}
}
}
}
}

@ -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;

@ -100,6 +100,9 @@ namespace Rs.MotionPlat.Recipe
private void btnCreateMatrix_Click(object sender, EventArgs e)
{
btnCreateMatrix.Enabled = false;
btnThreePointLocation.Enabled = false;
List<string> executeSql = new List<string>();
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;
}
}

@ -369,31 +369,31 @@
<data name="&gt;&gt;btnThreePointLocation.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="button2.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<data name="btnCreateMatrix.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Right</value>
</data>
<data name="button2.Location" type="System.Drawing.Point, System.Drawing">
<data name="btnCreateMatrix.Location" type="System.Drawing.Point, System.Drawing">
<value>605, 101</value>
</data>
<data name="button2.Size" type="System.Drawing.Size, System.Drawing">
<data name="btnCreateMatrix.Size" type="System.Drawing.Size, System.Drawing">
<value>159, 52</value>
</data>
<data name="button2.TabIndex" type="System.Int32, mscorlib">
<data name="btnCreateMatrix.TabIndex" type="System.Int32, mscorlib">
<value>56</value>
</data>
<data name="button2.Text" xml:space="preserve">
<data name="btnCreateMatrix.Text" xml:space="preserve">
<value>生成矩阵</value>
</data>
<data name="&gt;&gt;button2.Name" xml:space="preserve">
<value>button2</value>
<data name="&gt;&gt;btnCreateMatrix.Name" xml:space="preserve">
<value>btnCreateMatrix</value>
</data>
<data name="&gt;&gt;button2.Type" xml:space="preserve">
<data name="&gt;&gt;btnCreateMatrix.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;button2.Parent" xml:space="preserve">
<data name="&gt;&gt;btnCreateMatrix.Parent" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="&gt;&gt;button2.ZOrder" xml:space="preserve">
<data name="&gt;&gt;btnCreateMatrix.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="btnSaveSlotOffsetDistY.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">

Loading…
Cancel
Save