c#插料工作线程
private void InsertPinRun()// 插料工作线程
{
CGraphDiscs Graph = null;//需要插料的石墨盘工位
//CBuffPlat BuffPlat = null;//可以取料的缓冲平台
bool result = false;
RobotPoint TakPoint = new RobotPoint();
RobotPoint DstPoint = new RobotPoint();
RobotPoint TakPoint_Up = new RobotPoint();
RobotPoint DstPoint_Up = new RobotPoint();
//STA.Insert = 0;
//OPCServer.SetValue("缓冲平台1夹引脚B", 1);
while (true)
{
switch (STA.Insert)
{
case 0://空闲状态
if (label_woksta_Insert.Text != "0空闲状态") this.Invoke(new Action(() => { label_woksta_Insert.Text = "0空闲状态"; }));
if (STA.CCD == 0 && STA.Insert == 0 && STA.Taker == 0)
{
button_Stop.Tag = false;
}
break;
case 1://由视觉处理线程启动,视觉处理完成后,启动插料。
if (label_woksta_Insert.Text != "1暂停") this.Invoke(new Action(() => { label_woksta_Insert.Text = "1暂停"; }));
break;
case 2://等待石墨盘视觉处理完成。
if (label_woksta_Insert.Text != "2等待石墨盘视觉处理完成!") this.Invoke(new Action(() => { label_woksta_Insert.Text = "2等待石墨盘视觉处理完成!"; }));
if (GraphDiscs1.status == CGraphDiscs.GRAPHDISCS_STATUS.CCDProcessed)
{
Graph = GraphDiscs1;
STA.Insert = 3;
}
else if (GraphDiscs2.status == CGraphDiscs.GRAPHDISCS_STATUS.CCDProcessed)
{
Graph = GraphDiscs2;
STA.Insert = 3;
}
break;
case 3://移动石墨盘到插料的位置
if (label_woksta_Insert.Text != "3移动石墨盘到插料的位置") this.Invoke(new Action(() => { label_woksta_Insert.Text = "3移动石墨盘到插料的位置"; }));
// Graph.AbsMove(CGraphDiscs.Pos.Work);
// Take4LocationIndex = Graph.InsertLocationIndex;
if (Graph.ID == GraphDiscs1.ID)
GraphDiscs1.AbsMove_G1_Work();
else
GraphDiscs2.AbsMove_G2_Work();
STA.Insert = 4;
break;
case 4://
if (label_woksta_Insert.Text != "4等待石墨盘移动到位") this.Invoke(new Action(() => { label_woksta_Insert.Text = "4等待石墨盘移动到位"; }));
if (Graph == GraphDiscs1)
{
if (Graph.AbsMove_G1_Work() == true)
{
STA.Insert = 5;
}
}
else
{
if (Graph.AbsMove_G2_Work() == true)
{
STA.Insert = 5;
}
}
if (RobotCtrl.IsDingLiaoA_Down == true && RobotCtrl.IsDingLiaoB_Down == true) //两个顶料机构都在下方
{
// if (OPCServer.GetValue("振动盘有料传感器1") == 1 && OPCServer.GetValue("振动盘有料传感器2") == 1 && OPCServer.GetValue("振动盘有料传感器3") == 1)
// Thread.Sleep(500);
if (RobotCtrl.IsYouLiao37 == true && RobotCtrl.IsYouLiao21 == true && RobotCtrl.IsYouLiao22 == true && RobotCtrl.IsYouLiao23 == true)
// if (RobotCtrl.IsYouLiao21 == true)
{
// Thread.Sleep(300);
// OPCServer.SetValue("顶料机构", 1);//DI21 is good
RobotCtrl.DingLiao1(true);
if (RobotCtrl.IsDingLiaoA_Up == false)
{
STA.Insert = 4;
if (label_woksta_Insert.Text != "A顶料气缸上升失败") this.Invoke(new Action(() => { label_woksta_Insert.Text = "A顶料气缸上升失败"; }));
Thread.Sleep(200);
}
if (Take4LocationIndex == 20 || Take4LocationIndex == 21 || Take4LocationIndex == 13 ||
Take4LocationIndex == 14 || Take4LocationIndex == 15 || Take4LocationIndex == 16 ||
Take4LocationIndex == 17 || Take4LocationIndex == 18 || Take4LocationIndex == 19)
{
Thread.Sleep(30);
RobotCtrl.DingLiao2(true);
if (RobotCtrl.IsDingLiaoB_Up == false)
{
STA.Insert = 4;
if (label_woksta_Insert.Text != "B顶料气缸上升失败") this.Invoke(new Action(() => { label_woksta_Insert.Text = "B顶料气缸上升失败"; }));
Thread.Sleep(200);
}
}
}
}
break;
case 5://初始化取料点、插料点坐标
if (label_woksta_Insert.Text != "5初始化取料点、插料点坐标") this.Invoke(new Action(() => { label_woksta_Insert.Text = "5初始化取料点、插料点坐标"; }));
TakPoint = RobotCtrl.TakePoint;//取料点坐标
if (Graph.InsertLocationIndex < CGraphDiscs.Single_Insert_Total_Count)//刘林(2019.1.10)
{
DstPoint = Graph.A[Graph.InsertLocationIndex];//刘林(2019.1.10):将索引值清零
}
else if (Graph.InsertLocationIndex >= CGraphDiscs.Single_Insert_Total_Count)//刘林(2019.1.10)索引值大于25后,插右边的石墨盘
{
DstPoint = Graph.B[Graph.InsertLocationIndex - CGraphDiscs.Single_Insert_Total_Count];//刘林(2019.1.10):将索引值清零
}
TakPoint_Up = TakPoint;//取料点坐标上方
TakPoint_Up.SetZ = 0;
DstPoint_Up = DstPoint;//插料点坐标上方
DstPoint_Up.SetZ = 0;
RobotCtrl.Clamp(false);
STA.Insert = 6;
break;
case 6://移动到取料位置上方
if (label_woksta_Insert.Text != "6移动到取料位置上方") this.Invoke(new Action(() => { label_woksta_Insert.Text = "6移动到取料位置上方"; }));
Thread.Sleep(100);
result = RobotCtrl.MoveToPoint(TakPoint_Up);
if (result)
{
STA.Insert = 7;
}
break;
case 7://移动到取料位置
if (label_woksta_Insert.Text != "7等待顶料机构顶料") this.Invoke(new Action(() => { label_woksta_Insert.Text = "7等待顶料机构顶料"; }));
// Thread.Sleep(500);
// if (OPCServer.GetValue("顶料机构顶起") == 1)//等待顶料机构顶上来
Thread.Sleep(100);
if (RobotCtrl.IsDingLiaoA_Up == true)
{ //1ji
if (Graph.InsertLocationIndex == 20 || Graph.InsertLocationIndex == 12 || Graph.InsertLocationIndex == 13 ||
Graph.InsertLocationIndex == 14 || Graph.InsertLocationIndex == 15 || Graph.InsertLocationIndex == 16 ||
Graph.InsertLocationIndex == 17 || Graph.InsertLocationIndex == 18 || Graph.InsertLocationIndex == 19||
Graph.InsertLocationIndex == 20 + 25 || Graph.InsertLocationIndex == 12 + 25 || Graph.InsertLocationIndex == 13 + 25 ||
Graph.InsertLocationIndex == 14 + 25 || Graph.InsertLocationIndex == 15 + 25 || Graph.InsertLocationIndex == 16 + 25 ||
Graph.InsertLocationIndex == 17 + 25 || Graph.InsertLocationIndex == 18 + 25 || Graph.InsertLocationIndex == 19 + 25)
{ //2ji
Thread.Sleep(50);
if (RobotCtrl.IsDingLiaoB_Up == true)
{
TimeOutCount = 0;
RobotCtrl.LightOn(1);
result = RobotCtrl.MoveToPoint(TakPoint);
if (result)
{
STA.Insert = 8;
break;
}
}
else
{
if (label_woksta_Insert.Text != "B顶料气缸上升失败") this.Invoke(new Action(() => { label_woksta_Insert.Text = "B顶料气缸上升失败"; }));
// Thread.Sleep(500);
if (TimeOutCount < 100)
{
// Thread.Sleep(200);
TimeOutCount++;
if (TimeOutCount == 50)
{
RobotCtrl.LightOn(0);
RobotCtrl.BeepOn();
Thread.Sleep(100);
}
}
STA.Insert = 4;
break;
}
} //2ji
// Thread.Sleep(200);
TimeOutCount = 0;
RobotCtrl.LightOn(1);
result = RobotCtrl.MoveToPoint(TakPoint);
if (result)
{
STA.Insert = 8;
}
} //1ji
else
{ //1ji else
if (label_woksta_Insert.Text != "A顶料气缸上升失败") this.Invoke(new Action(() => { label_woksta_Insert.Text = "A顶料气缸上升失败"; }));
// Thread.Sleep(500);
if (TimeOutCount < 100)
{
// Thread.Sleep(200);
TimeOutCount++;
if (TimeOutCount == 50)
{
RobotCtrl.LightOn(0);
RobotCtrl.BeepOn();
Thread.Sleep(100);
}
}
STA.Insert = 4;
} //1ji else
break;
case 8://取料气缸夹紧
if (label_woksta_Insert.Text != "8取料气缸夹紧") this.Invoke(new Action(() => { label_woksta_Insert.Text = "8取料气缸夹紧"; }));
RobotCtrl.Clamp(true);
STA.Insert = 10;
break;
case 10://Z轴移动到上方
if (label_woksta_Insert.Text != "10等到气缸夹紧到位") this.Invoke(new Action(() => { label_woksta_Insert.Text = "10等到气缸夹紧到位"; }));
try
{
Thread.Sleep(10);
if (RobotCtrl.IsClamp == true)
{
Thread.Sleep(10);
if (label_woksta_Insert.Text != "提料") this.Invoke(new Action(() => { label_woksta_Insert.Text = "提料"; }));
result = RobotCtrl.MoveToPoint(TakPoint_Up);
if (result)
{
bool ret;
// OPCServer.SetValue("缓冲平台1夹引脚B", 0);//取料气缸下降
RobotCtrl.DingLiao2(false);
RobotCtrl.DingLiao1(false);
STA.Insert = 11;
}
}
}
catch (Exception e)
{
}
break;
case 11://移动到放料位置上方
if (label_woksta_Insert.Text != "11移动到插料位置上方") this.Invoke(new Action(() => { label_woksta_Insert.Text = "11移动到插料位置上方"; }));
Thread.Sleep(10);
result = RobotCtrl.MoveToPoint(DstPoint_Up);
if (result)
{
STA.Insert = 12;
}
break;
case 12://移动到放料位置
if (label_woksta_Insert.Text != "12插料…") this.Invoke(new Action(() => { label_woksta_Insert.Text = "12插料…"; }));
result = RobotCtrl.MoveToPoint(DstPoint, 30);//移动到插料位置,速度为20%
if (result)
{
STA.Insert = 13;
}
break;
case 13://放料
if (label_woksta_Insert.Text != "13张开气缸") this.Invoke(new Action(() => { label_woksta_Insert.Text = "13张开气缸"; }));
RobotCtrl.Clamp(false);//张开夹爪
STA.Insert = 14;
break;
case 14://
if (label_woksta_Insert.Text != "14等待张开气缸完成") this.Invoke(new Action(() => { label_woksta_Insert.Text = "14等待张开气缸完成"; }));
try
{
Thread.Sleep(10);
if (RobotCtrl.IsClamp == false)//等待夹爪张开
{
// Thread.Sleep(300);
// //OPCServer.SetValue("顶料机构", 1);
// if (RobotCtrl.IsYouLiao21 == true && RobotCtrl.IsYouLiao22 == true && RobotCtrl.IsYouLiao23 == true && RobotCtrl.IsYouLiao37 == true) //new added判断顶4个还是3个
// {
// if (Graph.InsertLocationIndex == 11 || Graph.InsertLocationIndex == 12 || Graph.InsertLocationIndex == 13 ||
// Graph.InsertLocationIndex == 14 || Graph.InsertLocationIndex == 15 || Graph.InsertLocationIndex == 16 ||
// Graph.InsertLocationIndex == 17 || Graph.InsertLocationIndex == 18 || Graph.InsertLocationIndex == 19 ||
// Graph.InsertLocationIndex == 11 + 25 || Graph.InsertLocationIndex == 12 + 25 || Graph.InsertLocationIndex == 13 + 25 ||
// Graph.InsertLocationIndex == 14 + 25 || Graph.InsertLocationIndex == 15 + 25 || Graph.InsertLocationIndex == 16 + 25 ||
// Graph.InsertLocationIndex == 17 + 25 || Graph.InsertLocationIndex == 18 + 25 || Graph.InsertLocationIndex == 19 + 25)
// {
// RobotCtrl.DingLiao1(true);
// RobotCtrl.DingLiao2(true);
// }
// else
// {
// RobotCtrl.DingLiao1(true);
// }
// }
// else
// {
// RobotCtrl.DingLiao2(false);
// RobotCtrl.DingLiao1(false); //new added
// }
STA.Insert = 15;
}
}
catch (Exception e)
{
}
break;
case 15://Z轴移动上方
if (label_woksta_Insert.Text != "15Z轴移回上方") this.Invoke(new Action(() => { label_woksta_Insert.Text = "15Z轴移回上方"; }));
result = RobotCtrl.MoveZAbs(CRobotCtrl.Z_Top);
if (result)
{
STA.Insert = 16;
}
break;
case 16://已经插完一组引脚
if (label_woksta_Insert.Text != "16一组引脚插料完成") this.Invoke(new Action(() => { label_woksta_Insert.Text = "16一组引脚插料完成"; }));
//Graph.PINCount += 3;
{
Graph.InsertLocationIndex++;
Take4LocationIndex++; //new 0330
if (Take4LocationIndex > 25) //new 0330
Take4LocationIndex = 1; //new 0330
}
if (Graph.InsertLocationIndex >= CGraphDiscs.All_Insert_Total_Count)//刘林(2019.1.10):判断一个工位的石墨盘是否全部插满
{
Graph.status = CGraphDiscs.GRAPHDISCS_STATUS.InsertComplet;
// Graph.AbsMove(CGraphDiscs.Pos.Complet);
if (Graph == GraphDiscs1)
{
Graph.AbsMove_G1_Complete();
}
else
{
Graph.AbsMove_G2_Complete();
}
STA.Insert = 2;
if (Graph.ID == 1)
{
this.Invoke(new Action(() => { button_Sta1_Start.Enabled = true; }));
// OPCServer.SetValue("Q2_0", 0);//关闭启动按钮灯arduino
}
else
{
this.Invoke(new Action(() => { button_Sta2_Start.Enabled = true; }));
// OPCServer.SetValue("Q2_1", 0);//关闭启动按钮灯arduino
}
}
else
{
STA.Insert = 4;
}
#region//统计生产数据
this.ProductPinCount = this.ProductPinCount + 3;
this.Invoke(new Action(() => { label_ProductPinCount.Text = this.ProductPinCount.ToString(); }));
this.Invoke(new Action(() => { label_ProductProCount.Text = (int)(this.ProductPinCount / 4) + ""; }));
if (this.ProductPinCount % (CGraphDiscs.PIN_Total_Count_168 / 2) == 0)
{
this.ProductModelCount++;
this.Invoke(new Action(() => { this.label_ProductModelCount.Text = this.ProductModelCount.ToString(); }));
string data = this.ProductPinCount + "\r\n" + this.ProductProCount + "\r\n" + this.ProductModelCount;
try
{
File.WriteAllText(Application.StartupPath + "//ProductCount.txt", data, Encoding.UTF8);
}
catch (Exception e)
{
this.label_ProductModelCount.Text = "写数据异常!";
}
}
#endregion
break;
}
//------------------new added----------------
//if (RobotCtrl.IsDingLiaoA_Down != true && RobotCtrl.IsDingLiaoB_Down != true)
//{
// // if (opcServer.GetValue("振动盘有料传感器1") == 1 && opcServer.GetValue("振动盘有料传感器2") == 1 && opcServer.GetValue("振动盘有料传感器3") == 1)
// //if ((robot.IsYouLiao20 == true) && (robot.IsYouLiao22 == true) )//&& (robot.IsYouLiao21 == true) && (robot.IsYouLiao23 == true))
// if (RobotCtrl.IsYouLiao21 == true)
// {
// // opcServer.SetValue("顶料机构", 1);
// RobotCtrl.DingLiao1(true);
// RobotCtrl.DingLiao2(true);
// }
//}
//else//顶料机构在上方
//{
// // if (opcServer.GetValue("振动盘有料传感器1") != 1 && opcServer.GetValue("振动盘有料传感器2") != 1 && opcServer.GetValue("振动盘有料传感器3") != 1)
// //if ((robot.IsYouLiao20 != true) && (robot.IsYouLiao22 != true))// && (robot.IsYouLiao21 != true) && (robot.IsYouLiao23 != true))
// if (RobotCtrl.IsYouLiao21 != true)
// {
// // opcServer.SetValue("顶料机构", 0);
// RobotCtrl.DingLiao2(false);
// RobotCtrl.DingLiao1(false);
// }
//}
----------------------------------------------------
Application.DoEvents();
if (Convert.ToBoolean(button_Stop.Tag) == true)
{
STA.Insert = 0;
}
if (Convert.ToBoolean(button_Pause.Tag) == true && STA.Insert != 1)//暂停功能
{
STA_Pause.Insert = STA.Insert;
STA.Insert = 1;
}
//if (RobotCtrl.GetRobotState(CRobotCtrl.RobotState.SERVO) == "0") //tangscott
//{
// this.button_Stop_Click(new object(), new EventArgs());
// RobotCtrl.LightOn(0);
// RobotCtrl.BeepOn();
//}
}
}