You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1032 lines
54 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Rs.Controls;
using Rs.Framework;
using Rs.Motion;
using Rs.MotionPlat.Commom;
using Rs.MotionPlat.Entitys;
using Rs.MotionPlat.Flow.Common;
using Rs.MotionPlat.Flow.SafePosFlow;
using Rs.MotionPlat.Flow.SubFlow;
using Rs.MotionPlat.Vision;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Rs.MotionPlat.Flow
{
enum EGrrFlowStep
{
//开始排料前准备
,
//料仓取料
,
,
,
,
,
//等待到料仓取料位上方,
//到料仓取料位下方,
//等待到料仓取料位下方,
//料仓取料完成抬起,
//等待料仓取料完成抬起,
//料仓取料真空吸检测,
//治具换料
,
,
,
,
,
1,
1,
2,
2,
,
,
1,
1,
2,
2,
,
,
,
,
,
,
1,
1,
2,
2,
,
,
//料仓放料
,
,
,
,
,
,
,
}
public class GrrFlow
{
private Task mainTask;
private GrrFlow() { }
private static GrrFlow instance;
public static GrrFlow Instance
{
get
{
if (instance == null)
{
instance = new GrrFlow();
}
return instance;
}
}
private AlarmEntity alarmEntity;
Stopwatch timeout = new Stopwatch();
EGrrFlowStep flowStep = EGrrFlowStep.;
public event Action CleanDataEvent;
int scanNum = 0;
string logInfo = string.Empty;
string alarmInfo = string.Empty;
private bool stop = true;
private bool run = true;
TargetPosition targetPosition = new TargetPosition();
ErrorCode errCode = ErrorCode.Ok;
/// <summary>
/// 当前取料穴位
/// </summary>
TraySlot curTakeSlot = null;
/// <summary>
/// 当前取料穴位的点位
/// </summary>
SlotPoint curTakeSlotPoint = null;
//Nozzle curNozzle = null;
Nozzle curTakeNozzle = null;
Nozzle curDumpNozzle= null;
TestFixture curFixture = null;
//放料穴位
TraySlot curDumpSlot = null;
/// <summary>
/// 最后一次换料的治具编号
/// </summary>
private int lastFixtureIndex = 0;
/// <summary>
/// 已经取走的产品数量
/// </summary>
private int takedNum = 0;
//相机拍照结果
VisionResult vResult = new VisionResult();
ProductLocationResult vProductResult = new ProductLocationResult();
List<TestFixture> needGrrFixtureList = new List<TestFixture>();
/// <summary>
/// 测试完成的数量
/// </summary>
private int testFinishedNum = 0;
private void Reset()
{
curTakeSlot = null;
curTakeSlotPoint = null;
curTakeNozzle = null;
curDumpNozzle = null;
curFixture = null;
curDumpSlot = null;
lastFixtureIndex = 0;
takedNum = 0;
testFinishedNum = 0;
VirtualBarCode.Reset();
}
public void Init()
{
mainTask = new Task(Run);
mainTask.Start();
}
public void Deinit()
{
run = false;
}
private void Run()
{
while (run)
{
if (stop)
{
Thread.Sleep(10);
continue;
}
switch (flowStep)
{
case EGrrFlowStep.:
CleanDataEvent?.Invoke();
needGrrFixtureList.Clear();
needGrrFixtureList = TestFixtureManager.Instance.GetEnableFixtureList();
if(needGrrFixtureList != null)
{
string fixtureindex = string.Join(",", needGrrFixtureList.Select(f => f.Index));
MessageQueue.Instance.Insert($"GRR流程开始启用治具:{fixtureindex},产品数量:{GlobalVar.GrrProductNum},测试次数:{GlobalVar.GrrTestNum}");
int i = 0;
foreach (TestFixture testFixture in needGrrFixtureList)
{
if(i==0)
{
needGrrFixtureList[i].IsFirstFixture = true;
}
else
{
needGrrFixtureList[i].IsFirstFixture = false;
}
i++;
}
}
flowStep = EGrrFlowStep.;
break;
#region 料仓取料
case EGrrFlowStep.:
if (takedNum < GlobalVar.GrrProductNum)
{
//检测吸嘴有几个产品少于3个产品则需要从料仓上料
int idelNozzleNum = NozzleManager.GetIdleNozzleCount();
if (idelNozzleNum == 1 || takedNum == GlobalVar.GrrProductNum)//如果空闲的吸嘴只剩下1个或者取起来的数量等于要测试的产品数量时取治具换料
{
logInfo = GetClassName() + $"空闲吸嘴的数量为{idelNozzleNum},没有空闲的吸嘴了,去治具换料";
MessageQueue.Instance.Insert(logInfo);
flowStep = EGrrFlowStep.;
}
else
{
logInfo = GetClassName() + $"空闲吸嘴的数量为{idelNozzleNum},继续取料";
MessageQueue.Instance.Insert(logInfo);
flowStep = EGrrFlowStep.;
}
}
else
{
flowStep = EGrrFlowStep.;
}
break;
case EGrrFlowStep.:
curTakeSlot = GlobalTray.GrrTray.GetSlot(ESlotStatus.Have);
if (curTakeSlot != null)
{
curTakeSlotPoint = TrayRunPointManager.GetSlotPoint(ETrayType.Grr, curTakeSlot.Index);
if (curTakeSlotPoint != null)
{
targetPosition.X = curTakeSlotPoint.X;
targetPosition.Y1 = GlobalVar.StockSideY1;
targetPosition.Y2 = curTakeSlotPoint.Y;
//double curLoadX = Ops.GetCurPosition(AxisControl.LoadX);
//if(curLoadX-GlobalVar.FixtureSafePosX>50)
//{
// DischargeModuleGoSafePosFlow.Instance.GoSafePostion(ESafePosSide.PlaceToStock);
//}
if(GroupAxisMove.XY1Y2MovePos(targetPosition, GlobalVar.WholeSpeed, EGoWhichSide.StockSide))
{
AxisPosPrint.PrintXY1Y2TargetPos("轴loadx,loady1,loady2已停止运动,", targetPosition, GetClassName());
flowStep = EGrrFlowStep.;
}
}
}
else
{
//没有料了,判断是否需要换料
GlobalTray.GrabTray.ChangeStatus(ESlotStatus.Have);
}
break;
case EGrrFlowStep.:
if (Ops.IsStop("LoadX", "LoadY1", "LoadY2"))
{
AxisPosPrint.PrintXY1Y2CurrentPos("轴loadx,loady1,loady2已停止运动,",GetClassName());
if (AxisArrived.LoadXY1Y2IsArrived(targetPosition.X, targetPosition.Y1, targetPosition.Y2))
{
AxisPosPrint.PrintXY1Y2CurrentPos("已运动到料仓拍照位上方,", GetClassName());
flowStep = EGrrFlowStep.;
}
else
{
flowStep = EGrrFlowStep.;
}
}
break;
case EGrrFlowStep.:
UpCameraHelper.Grab();
string msg = VisionHelper.OneGrabOne();//.Grab(EVisionScene.SingleScanBarcode);
vProductResult.Parse(msg);
if((vProductResult != null && vProductResult.Result== EOneGrabSixteenResult.Ok) || GlobalVar.RunSpace)
{
flowStep = EGrrFlowStep.;
}
else if(vProductResult != null && vProductResult.Result == EOneGrabSixteenResult.LocationOkScanBarcodeFail)
{
GrrScanFailFrm scanFail = new GrrScanFailFrm((act,qrcode) => {
if(act==1)
{
vProductResult.SN = qrcode;
flowStep = EGrrFlowStep.;
}
});
scanFail.ShowDialog();
//vProductResult.SN = VirtualBarCode.Code;
}
else
{
alarmEntity = AlarmCollection.Get(AlarmConstID.);
Msgbox.ShowDialog(alarmEntity,EButtonType.Retry);
}
break;
case EGrrFlowStep.:
//获取空闲吸嘴
curTakeNozzle = NozzleManager.GetIdelNozzle();
if (curTakeNozzle != null)
{
StockTakeFlow.Instance.Take(ETrayType.Grr, curTakeSlot.Index, curTakeNozzle.NozzleIndex, EStockScanBarcodeMode.Single, vProductResult);
takedNum++;
if (NozzleManager.GetIdleNozzleCount() == 1 || takedNum == GlobalVar.GrrProductNum)
{
flowStep = EGrrFlowStep.;
}
else
{
flowStep = EGrrFlowStep.;
}
//targetPosition = NozzleManager.GetToTraySlot(ETrayType.Grr, curTakeSlot.Index, curTakeNozzle.NozzleIndex);
//if(curTakeNozzle != null)
//{
// targetPosition.X += vProductResult.OffsetX;
// targetPosition.Y2+= vProductResult.OffsetY;
// if (GroupAxisMove.XY1Y2MovePos(targetPosition, GlobalVar.WholeSpeed, EGoWhichSide.StockSide))
// {
// AxisPosPrint.PrintXY1Y2TargetPos("到料仓取料位上方,", targetPosition, GetClassName());
// flowStep = EGrrFlowStep.等待到料仓取料位上方;
// }
//}
}
break;
//case EGrrFlowStep.等待到料仓取料位上方:
// if (Ops.IsStop("LoadX", "LoadY1", "LoadY2") || GlobalVar.VirtualAxis)
// {
// AxisPosPrint.PrintXY1Y2CurrentPos("轴XY1Y2已停止运动,",GetClassName());
// if (AxisArrived.LoadXY1Y2IsArrived(targetPosition.X, targetPosition.Y1, targetPosition.Y2))
// {
// AxisPosPrint.PrintXY1Y2CurrentPos("已运动到等待到料仓取料位上方,", GetClassName());
// flowStep = EGrrFlowStep.到料仓取料位下方;
// }
// else
// {
// flowStep = EGrrFlowStep.到料仓取料位上方;
// }
// }
// break;
//case EGrrFlowStep.到料仓取料位下方:
// targetPosition.NozzleZ = NozzleManager.GetNozzleToTrayTakeProductPos(ETrayType.Grr, curTakeNozzle.NozzleIndex);
// errCode = AxisControl.GetAxis($"NozzleZ{curTakeNozzle.NozzleIndex}").MovePos(targetPosition.NozzleZ, GlobalVar.WholeSpeed);
// if (errCode == ErrorCode.Ok)
// {
// logInfo = $"{GetClassName()}到料仓取料位下方";
// MessageQueue.Instance.Insert(logInfo);
// flowStep = EGrrFlowStep.等待到料仓取料位下方;
// }
// break;
//case EGrrFlowStep.等待到料仓取料位下方:
// if (Ops.IsStop($"NozzleZ{curTakeNozzle.NozzleIndex}"))
// {
// logInfo = $"{GetClassName()}已运动到料仓取料位下方";
// MessageQueue.Instance.Insert(logInfo);
// if (GlobalVar.RunSpace)
// {
// flowStep = EGrrFlowStep.料仓取料完成抬起;
// }
// else
// {
// Ops.On($"吸料真空{curTakeNozzle.NozzleIndex}吸");
// Thread.Sleep(100);
// flowStep = EGrrFlowStep.料仓取料完成抬起;
// }
// }
// break;
//case EGrrFlowStep.料仓取料完成抬起:
// if(NozzleManager.GotoSafePos(curTakeNozzle.NozzleIndex))
// {
// logInfo = $"{GetClassName()}料仓取料完成抬起";
// MessageQueue.Instance.Insert(logInfo);
// flowStep = EGrrFlowStep.等待料仓取料完成抬起;
// }
// break;
//case EGrrFlowStep.等待料仓取料完成抬起:
// if (Ops.IsStop($"NozzleZ{curTakeNozzle.NozzleIndex}"))
// {
// logInfo = $"{GetClassName()}料仓取料完成已抬起";
// MessageQueue.Instance.Insert(logInfo);
// flowStep = EGrrFlowStep.料仓取料真空吸检测;
// }
// break;
//case EGrrFlowStep.料仓取料真空吸检测:
// if (Ops.IsOn($"吸料真空{curTakeNozzle.NozzleIndex}检测") || GlobalVar.RunSpace)
// {
// takedNum++;
// //curTakeNozzle.Product = new TestProduct() { SN = VirtualBarCode.Code, TestNum = 0 };
// if(GlobalVar.RunSpace)
// {
// curTakeNozzle.Product = new TestProduct() { SN = VirtualBarCode.Code, FromSlotIndex = curTakeSlot.Index };
// }
// else
// {
// curTakeNozzle.Product = new TestProduct() { SN = vProductResult.SN, FromSlotIndex = curTakeSlot.Index };
// }
// curTakeNozzle.Status = ENozzleStatus.ToTest;
// GlobalTray.NozzleTray.ChangeStatus(curTakeNozzle.NozzleIndex, ESlotStatus.Have);
// GlobalTray.GrrTray.ChangeStatus(curTakeSlot.Index, ESlotStatus.NotHave);
// logInfo = $"{GetClassName()}料仓{curTakeSlot.Index}号穴位取料完成真空检测OK,产品SN:{curTakeNozzle.Product.SN}被吸嘴{curTakeNozzle.NozzleIndex}取走";
// MessageQueue.Instance.Insert(logInfo);
// if (NozzleManager.GetIdleNozzleCount() == 1 || takedNum == GlobalVar.GrrProductNum)
// {
// flowStep = EGrrFlowStep.等待治具测试完成换料;
// }
// else
// {
// flowStep = EGrrFlowStep.判断是否需要从料仓取料;
// }
// }
// else
// {
// alarmEntity=AlarmCollection.Get(AlarmConstID.GRR取料失败报警);
// Msgbox.ShowDialog(alarmEntity, EButtonType.Retry);
// flowStep = EGrrFlowStep.到料仓取料位上方;
// }
// break;
#endregion
case EGrrFlowStep.:
curFixture = needGrrFixtureList[lastFixtureIndex];
if (curFixture.Status == ETestFixtureStatus.IDLE)
{
if (curFixture.Product == null)
{
if (NozzleManager.GetToTestNozzle() != null)
{
flowStep = EGrrFlowStep.;
}
else
{
GotoNextFixture();
}
}
else
{
if(!string.IsNullOrEmpty(curFixture.Product.Result))
{
//curFixture.AddTestRecordToProduct();
flowStep = EGrrFlowStep.;
}
}
}
break;
case EGrrFlowStep.:
//先找出要放的吸嘴
curTakeNozzle = NozzleManager.GetIdelNozzle();
if (curTakeNozzle != null)
{
FixtureTakeFlow.Instance.Take(curFixture.Index, curTakeNozzle.NozzleIndex);
//curTakeNozzle.Product = curFixture.Product;
//string testFixtures = string.Join(",", curTakeNozzle.Product.TestedFixtures);
//logInfo = $"{GetClassName()}取料完成真空检测OK吸嘴 {curTakeNozzle.NozzleIndex} 从治具 {curFixture.Index} 把产品SN {curFixture.Product.SN} 取出,测试治具:{testFixtures},测试次数:{curTakeNozzle.Product.TestNum}";
//MessageQueue.Instance.Insert(logInfo);
//curFixture.Clear();
//GlobalTray.NozzleTray.ChangeStatus(curTakeNozzle.NozzleIndex, ESlotStatus.Have);
if (GlobalVar.TestMode == "GRR")
{
if (curTakeNozzle.Product.TestNum >= GlobalVar.GrrTestNum * needGrrFixtureList.Count)
{
testFinishedNum++;
curTakeNozzle.Status = ENozzleStatus.ToUnload;
}
else
{
curTakeNozzle.Status = ENozzleStatus.ToTest;
}
if (NozzleManager.GetNozzlesByStatus(ENozzleStatus.ToUnload).Count == 3 || testFinishedNum == GlobalVar.GrrProductNum)
{
flowStep = EGrrFlowStep.;
}
else
{
if (NozzleManager.GetToTestNozzle(curTakeNozzle.NozzleIndex) != null)
{
flowStep = EGrrFlowStep.;
}
else
{
GotoNextFixture();
flowStep = EGrrFlowStep.;
}
}
}
else
{
curTakeNozzle.Status = ENozzleStatus.ToUnload;
if (NozzleManager.GetIdleNozzleCount() == 1 || TestFixtureManager.Instance.GetHasProuctFixtureCount() == 0)
{
flowStep = EGrrFlowStep.;
}
else
{
flowStep = EGrrFlowStep.;
}
}
//targetPosition = NozzleManager.GetNozzleToFixturePos(curFixture.Index, curTakeNozzle.NozzleIndex);
//targetPosition.X += curFixture.PlaceProductOffsetX;
//targetPosition.Y2+= curFixture.PlaceProductOffsetY;
////if(targetPosition.X-GlobalVar.FixtureSafePosX>50)
////{
//// DischargeModuleGoSafePosFlow.Instance.GoSafePostion(ESafePosSide.PlaceToFixture);
////}
//if(GroupAxisMove.XY1Y2MovePos(targetPosition, GlobalVar.WholeSpeed, EGoWhichSide.FixtureSide))
//{
// AxisPosPrint.PrintXY1Y2TargetPos("到治具取料位上方,", targetPosition, GetClassName());
// flowStep = EGrrFlowStep.等待到治具取料位上方;
//}
}
break;
//case EGrrFlowStep.等待到治具取料位上方:
// if (Ops.IsStop("LoadX", "LoadY1", "LoadY2"))
// {
// AxisPosPrint.PrintXY1Y2CurrentPos("轴loadx,loady1,loady2已停止运动,",GetClassName());
// if (AxisArrived.LoadXY1Y2IsArrived(targetPosition.X, targetPosition.Y1, targetPosition.Y2))
// {
// AxisPosPrint.PrintXY1Y2CurrentPos("已运动到治具取料位上方,", GetClassName());
// flowStep = EGrrFlowStep.到治具取料位下方1;
// }
// else
// {
// flowStep = EGrrFlowStep.到治具取料位上方;
// }
// }
// break;
//case EGrrFlowStep.到治具取料位下方1:
// targetPosition.NozzleZ = NozzleManager.GetFixtureTakeProductPos(curFixture.Index, curTakeNozzle.NozzleIndex);
// if(NozzleManager.Go(curTakeNozzle, targetPosition.NozzleZ, GlobalVar.WholeSpeed))
// {
// logInfo = $"{GetClassName()}到治具取料位下方1";
// MessageQueue.Instance.Insert(logInfo);
// flowStep = EGrrFlowStep.等待到治具取料位下方1;
// }
// break;
//case EGrrFlowStep.等待到治具取料位下方1:
// if (Ops.IsStop($"NozzleZ{curTakeNozzle.NozzleIndex}"))
// {
// logInfo = $"{GetClassName()}已运动到治具取料位下方1";
// MessageQueue.Instance.Insert(logInfo);
// flowStep = EGrrFlowStep.到治具取料位下方2;
// }
// break;
//case EGrrFlowStep.到治具取料位下方2:
// targetPosition.NozzleZ = NozzleManager.GetFixtureTakeProductPos(curFixture.Index, curTakeNozzle.NozzleIndex);
// if (NozzleManager.Go(curTakeNozzle, targetPosition.NozzleZ, GlobalVar.WholeSpeed))
// {
// logInfo = $"{GetClassName()}到治具取料位下方1";
// MessageQueue.Instance.Insert(logInfo);
// flowStep = EGrrFlowStep.等待到治具取料位下方2;
// }
// break;
//case EGrrFlowStep.等待到治具取料位下方2:
// if (Ops.IsStop($"NozzleZ{curTakeNozzle.NozzleIndex}"))
// {
// logInfo = $"{GetClassName()}已运动到治具取料位下方2";
// MessageQueue.Instance.Insert(logInfo);
// if (GlobalVar.RunSpace)
// {
// flowStep = EGrrFlowStep.治具取料完成抬起1;
// }
// else
// {
// curTakeNozzle.VacSuction(EIoOperate.Open,GetClassName());
// curFixture.ColletOff(GetClassName());
// flowStep = EGrrFlowStep.治具取料完成抬起1;
// }
// }
// break;
//case EGrrFlowStep.治具取料完成抬起1:
// if(NozzleManager.GotoSafePos(curTakeNozzle.NozzleIndex))
// {
// logInfo = $"{GetClassName()}治具取料完成抬起1";
// MessageQueue.Instance.Insert(logInfo);
// flowStep = EGrrFlowStep.等待治具取料完成抬起1;
// }
// break;
//case EGrrFlowStep.等待治具取料完成抬起1:
// if (Ops.IsStop($"NozzleZ{curTakeNozzle.NozzleIndex}"))
// {
// logInfo = $"{GetClassName()}治具取料完成已抬起1";
// MessageQueue.Instance.Insert(logInfo);
// flowStep = EGrrFlowStep.治具取料完成抬起2;
// }
// break;
//case EGrrFlowStep.治具取料完成抬起2:
// if (NozzleManager.GotoSafePos(curTakeNozzle.NozzleIndex))
// {
// logInfo = $"{GetClassName()}治具取料完成抬起2";
// MessageQueue.Instance.Insert(logInfo);
// flowStep = EGrrFlowStep.等待治具取料完成抬起2;
// }
// break;
//case EGrrFlowStep.等待治具取料完成抬起2:
// if (Ops.IsStop($"NozzleZ{curTakeNozzle.NozzleIndex}"))
// {
// logInfo = $"{GetClassName()}治具取料完成已抬起2";
// MessageQueue.Instance.Insert(logInfo);
// flowStep = EGrrFlowStep.治具取料完成真空检测;
// }
// break;
//case EGrrFlowStep.治具取料完成真空检测:
// if (Ops.IsOn($"吸料真空{curTakeNozzle.NozzleIndex}检测") || GlobalVar.RunSpace)
// {
// curFixture.AddTestRecordToProduct();
// curTakeNozzle.Product = curFixture.Product;
// string testFixtures = string.Join(",", curTakeNozzle.Product.TestedFixtures);
// logInfo = $"{GetClassName()}取料完成真空检测OK吸嘴 {curTakeNozzle.NozzleIndex} 从治具 {curFixture.Index} 把产品SN {curFixture.Product.SN} 取出,测试治具:{testFixtures},测试次数:{curTakeNozzle.Product.TestNum}";
// MessageQueue.Instance.Insert(logInfo);
// curFixture.Clear();
// GlobalTray.NozzleTray.ChangeStatus(curTakeNozzle.NozzleIndex, ESlotStatus.Have);
// if(GlobalVar.TestMode=="GRR")
// {
// if (curTakeNozzle.Product.TestNum >= GlobalVar.GrrTestNum * needGrrFixtureList.Count)
// {
// testFinishedNum++;
// curTakeNozzle.Status = ENozzleStatus.ToUnload;
// }
// else
// {
// curTakeNozzle.Status = ENozzleStatus.ToTest;
// }
// if (NozzleManager.GetNozzlesByStatus(ENozzleStatus.ToUnload).Count == 3 || testFinishedNum == GlobalVar.GrrProductNum)
// {
// flowStep = EGrrFlowStep.判断是否需要放料到料仓;
// }
// else
// {
// if (NozzleManager.GetToTestNozzle(curTakeNozzle.NozzleIndex) != null)
// {
// flowStep = EGrrFlowStep.到治具拍照位;
// }
// else
// {
// GotoNextFixture();
// flowStep = EGrrFlowStep.等待治具测试完成换料;
// }
// }
// }
// else
// {
// curTakeNozzle.Status = ENozzleStatus.ToUnload;
// if (NozzleManager.GetIdleNozzleCount() == 1 || TestFixtureManager.Instance.GetHasProuctFixtureCount()==0)
// {
// flowStep = EGrrFlowStep.判断是否需要放料到料仓;
// }
// else
// {
// flowStep = EGrrFlowStep.等待治具测试完成换料;
// }
// }
// }
// else
// {
// //取料失败报警
// Msgbox.ShowTipDialog(EButtonType.Retry, "治具取料失败报警", "error", true);
// }
// break;
case EGrrFlowStep.:
if(curFixture!=null)
{
if (NozzleManager.GetIdleNozzleCount() == 2)
{
curDumpNozzle = NozzleManager.GetToTestNozzle(curTakeNozzle.NozzleIndex);
}
else
{
curDumpNozzle = NozzleManager.GetToTestNozzle();
}
FixturePlaceFlow.Instance.Place(curFixture.Index, curDumpNozzle.NozzleIndex);
GotoNextFixture();
//lastFixtureIndex = ((lastFixtureIndex + 1) % needGrrFixtureList.Count);
if (takedNum < GlobalVar.GrrProductNum && NozzleManager.GetIdleNozzleCount() == 4)
{
flowStep = EGrrFlowStep.;
}
else
{
flowStep = EGrrFlowStep.;
}
//targetPosition = curFixture.GetGrabPos();
////if(targetPosition.X-GlobalVar.FixtureSafePosX>50)
////{
//// DischargeModuleGoSafePosFlow.Instance.GoSafePostion(ESafePosSide.PlaceToFixture);
////}
//if(GroupAxisMove.XY1Y2MovePos(targetPosition, GlobalVar.WholeSpeed, EGoWhichSide.FixtureSide))
//{
// AxisPosPrint.PrintXY1Y2TargetPos("到治具拍照位,",targetPosition, GetClassName());
// flowStep = EGrrFlowStep.等待到治具拍照位;
//}
}
break;
//case EGrrFlowStep.等待到治具拍照位:
// if (Ops.IsStop("LoadX", "LoadY1", "LoadY2"))
// {
// AxisPosPrint.PrintXY1Y2CurrentPos("轴loadx,loady1,loady2已停止运动,",GetClassName());
// if (AxisArrived.LoadXY1Y2IsArrived(targetPosition.X, targetPosition.Y1, targetPosition.Y2))
// {
// AxisPosPrint.PrintXY1Y2CurrentPos("已运动到治具拍照位,", GetClassName());
// flowStep = EGrrFlowStep.通知相机拍照;
// }
// else
// {
// flowStep = EGrrFlowStep.到治具拍照位;
// }
// }
// break;
//case EGrrFlowStep.通知相机拍照:
// UpCameraHelper.Grab();
// vResult = VisionHelper.Grab(EVisionScene.FixtureDumpProduct,$"M{curFixture.Index};");
// if((vResult!=null && vResult.Result)||(GlobalVar.RunSpace))
// {
// if(GlobalVar.RunSpace)
// {
// vResult = new VisionResult() { Result = true };
// }
// curFixture.PlaceProductOffsetX = vResult.OffsetX;
// curFixture.PlaceProductOffsetY = vResult.OffsetY;
// flowStep = EGrrFlowStep.到治具放料位上方;
// }
// else
// {
// alarmEntity = AlarmCollection.Get(AlarmConstID.治具放料拍照失败).Transform(curFixture.Index);
// Msgbox.ShowDialog(alarmEntity,EButtonType.Retry);
// }
// break;
//case EGrrFlowStep.到治具放料位上方:
// if(NozzleManager.GetIdleNozzleCount()==2)
// {
// curDumpNozzle = NozzleManager.GetToTestNozzle(curTakeNozzle.NozzleIndex);
// }
// else
// {
// curDumpNozzle = NozzleManager.GetToTestNozzle();
// }
// if (curDumpNozzle != null)
// {
// targetPosition = NozzleManager.GetNozzleToFixturePos(curFixture.Index, curDumpNozzle.NozzleIndex);
// targetPosition.X += vResult.OffsetX;
// targetPosition.Y2 += vResult.OffsetY;
// MessageQueue.Instance.Insert($"相机偏移X:{vResult.OffsetX},相机偏移y:{vResult.OffsetY}");
// if(GroupAxisMove.XY1Y2MovePos(targetPosition, GlobalVar.WholeSpeed, EGoWhichSide.FixtureSide))
// {
// AxisPosPrint.PrintXY1Y2TargetPos("到治具放料位上方,", targetPosition, GetClassName());
// flowStep = EGrrFlowStep.等待到治具放料位上方;
// }
// }
// break;
//case EGrrFlowStep.等待到治具放料位上方:
// if (Ops.IsStop("LoadX", "LoadY1", "LoadY2"))
// {
// AxisPosPrint.PrintXY1Y2CurrentPos("轴loadx,loady1,loady2已停止运动,",GetClassName());
// if (AxisArrived.LoadXY1Y2IsArrived(targetPosition.X, targetPosition.Y1, targetPosition.Y2))
// {
// AxisPosPrint.PrintXY1Y2CurrentPos("已运动到治具放料位上方,", GetClassName());
// flowStep = EGrrFlowStep.到治具放料位下方1;
// }
// else
// {
// flowStep = EGrrFlowStep.到治具放料位上方;
// }
// }
// break;
//case EGrrFlowStep.到治具放料位下方1:
// targetPosition.NozzleZ = NozzleManager.GetFixtureTakeProductPos(curFixture.Index,curDumpNozzle.NozzleIndex);
// if(NozzleManager.Go(curDumpNozzle,targetPosition.NozzleZ,GlobalVar.WholeSpeed))
// {
// logInfo = $"{GetClassName()}到治具放料位下方1";
// MessageQueue.Instance.Insert(logInfo);
// flowStep = EGrrFlowStep.等待到治具放料位下方1;
// }
// break;
//case EGrrFlowStep.等待到治具放料位下方1:
// if (Ops.IsStop($"NozzleZ{curDumpNozzle.NozzleIndex}"))
// {
// logInfo = $"{GetClassName()}已运动到治具放料位下方1";
// MessageQueue.Instance.Insert(logInfo);
// flowStep = EGrrFlowStep.到治具放料位下方2;
// }
// break;
//case EGrrFlowStep.到治具放料位下方2:
// targetPosition.NozzleZ = NozzleManager.GetFixtureTakeProductPos(curFixture.Index, curDumpNozzle.NozzleIndex);
// if (NozzleManager.Go(curDumpNozzle, targetPosition.NozzleZ, GlobalVar.WholeSpeed))
// {
// logInfo = $"{GetClassName()}到治具放料位下方2";
// MessageQueue.Instance.Insert(logInfo);
// flowStep = EGrrFlowStep.等待到治具放料位下方2;
// }
// break;
//case EGrrFlowStep.等待到治具放料位下方2:
// if (Ops.IsStop($"NozzleZ{curDumpNozzle.NozzleIndex}"))
// {
// logInfo = $"{GetClassName()}已运动到治具放料位下方2";
// MessageQueue.Instance.Insert(logInfo);
// if (GlobalVar.RunSpace)
// {
// flowStep = EGrrFlowStep.治具放料完成后抬起;
// }
// else
// {
// curFixture.ColletOn(GetClassName());
// curDumpNozzle.VacSuction(EIoOperate.Close, GetClassName());
// curDumpNozzle.VacBreak(EIoOperate.Open, GetClassName());
// curDumpNozzle.VacBreak(EIoOperate.Close, GetClassName());
// flowStep = EGrrFlowStep.治具放料完成后抬起;
// }
// }
// break;
//case EGrrFlowStep.治具放料完成后抬起:
// if(NozzleManager.GotoSafePos(curDumpNozzle.NozzleIndex))
// {
// logInfo = $"{GetClassName()}治具放料完成后抬起";
// MessageQueue.Instance.Insert(logInfo);
// flowStep = EGrrFlowStep.等待治具放料完成后抬起;
// }
// break;
//case EGrrFlowStep.等待治具放料完成后抬起:
// if (Ops.IsStop($"NozzleZ{curDumpNozzle.NozzleIndex}"))
// {
// logInfo = $"{GetClassName()}放料完成已抬起,吸嘴:{curDumpNozzle.NozzleIndex}把产品SN: {curDumpNozzle.Product.SN} 放入治具:{curFixture.Index}";
// MessageQueue.Instance.Insert(logInfo);
// curFixture.Product = curDumpNozzle.Product;
// curFixture.StartTest();
// curDumpNozzle.Clear();
// GotoNextFixture();
// //lastFixtureIndex = ((lastFixtureIndex + 1) % needGrrFixtureList.Count);
// if(takedNum<GlobalVar.GrrProductNum && NozzleManager.GetIdleNozzleCount()==4)
// {
// flowStep = EGrrFlowStep.判断是否需要从料仓取料;
// }
// else
// {
// flowStep = EGrrFlowStep.等待治具测试完成换料;
// }
// }
// break;
//料仓放料
case EGrrFlowStep.:
//检测有没有需要放料到料仓的吸嘴
if (NozzleManager.GetToUnloadNozzle() != null)
{
flowStep = EGrrFlowStep.;
}
else
{
List<TestFixture> hasProductFixtures = TestFixtureManager.Instance.GetHaveProductFixtureList();
if(hasProductFixtures!=null&&hasProductFixtures.Count>0)
{
flowStep = EGrrFlowStep.;
}
else
{
DischargeModuleGoSafePosFlow.Instance.GoSafePostion();
Msgbox.ShowTipDialog(EButtonType.Ok, "Grr test finished!", "tip", true);
flowStep = EGrrFlowStep.;
Reset();
Ops.Stop();
}
}
break;
case EGrrFlowStep.:
curDumpNozzle = NozzleManager.GetToUnloadNozzle();
if (curDumpNozzle != null)
{
//吸嘴放料,加测吸嘴上的产品的测试结果,决定把料放到哪个料仓
//目前先都方到OK料仓
//curDumpSlot = GlobalTray.GrrTray.GetSlot(ESlotStatus.NotHave);
curDumpSlot = GlobalTray.GrrTray.GetSlot(curDumpNozzle.Product.FromSlotIndex);
if (curDumpSlot != null)
{
StockPlaceFlow.Instance.Place(ETrayType.Grr, curDumpSlot.Index, curDumpNozzle.NozzleIndex);
flowStep = EGrrFlowStep.;
//double curLoadX = Ops.GetCurPosition(AxisControl.LoadX);
//if(curLoadX-GlobalVar.FixtureSafePosX>50)
//{
// DischargeModuleGoSafePosFlow.Instance.GoSafePostion(ESafePosSide.PlaceToStock);
//}
//targetPosition = NozzleManager.GetToTraySlot(ETrayType.Grr, curDumpSlot.Index, curDumpNozzle.NozzleIndex);
//if(GroupAxisMove.XY1Y2MovePos(targetPosition, GlobalVar.WholeSpeed, EGoWhichSide.StockSide))
//{
// AxisPosPrint.PrintXY1Y2TargetPos("到料仓放料位上方,", targetPosition, GetClassName());
// flowStep = EGrrFlowStep.等待到料仓放料位上方;
//}
}
else
{
GlobalTray.GrrTray.ChangeStatus(ESlotStatus.NotHave);
}
}
break;
//case EGrrFlowStep.等待到料仓放料位上方:
// if (Ops.IsStop("LoadX", "LoadY1", "LoadY2"))
// {
// AxisPosPrint.PrintXY1Y2CurrentPos("轴loadx,loady1,loady2已停止运动,",GetClassName());
// if (AxisArrived.LoadXY1Y2IsArrived(targetPosition.X, targetPosition.Y1, targetPosition.Y2))
// {
// AxisPosPrint.PrintXY1Y2CurrentPos("已运动到料仓放料位上方,", GetClassName());
// flowStep = EGrrFlowStep.到料仓放料位下方;
// }
// else
// {
// flowStep = EGrrFlowStep.到料仓放料位上方;
// }
// }
// break;
//case EGrrFlowStep.到料仓放料位下方:
// targetPosition.NozzleZ = NozzleManager.GetNozzleToTrayTakeProductPos(ETrayType.Grr, curDumpNozzle.NozzleIndex);
// if(NozzleManager.Go(curDumpNozzle,targetPosition.NozzleZ,GlobalVar.WholeSpeed))
// {
// logInfo = $"{GetClassName()}到料仓放料位下方";
// MessageQueue.Instance.Insert(logInfo);
// flowStep = EGrrFlowStep.等待到料仓放料位下方;
// }
// break;
//case EGrrFlowStep.等待到料仓放料位下方:
// if (Ops.IsStop($"NozzleZ{curDumpNozzle.NozzleIndex}"))
// {
// logInfo = $"{GetClassName()}已运动到料仓放料位下方";
// MessageQueue.Instance.Insert(logInfo);
// if (GlobalVar.RunSpace)
// {
// flowStep = EGrrFlowStep.料仓放料完成抬起;
// }
// else
// {
// curDumpNozzle.VacSuction(EIoOperate.Close, GetClassName());
// curDumpNozzle.VacBreak(EIoOperate.Open, GetClassName());
// curDumpNozzle.VacBreak(EIoOperate.Close, GetClassName());
// flowStep = EGrrFlowStep.料仓放料完成抬起;
// }
// }
// break;
//case EGrrFlowStep.料仓放料完成抬起:
// if(NozzleManager.GotoSafePos(curDumpNozzle.NozzleIndex))
// {
// logInfo = $"{GetClassName()}料仓放料完成抬起";
// MessageQueue.Instance.Insert(logInfo);
// flowStep = EGrrFlowStep.等待料仓放料完成抬起;
// }
// break;
//case EGrrFlowStep.等待料仓放料完成抬起:
// if (Ops.IsStop($"NozzleZ{curDumpNozzle.NozzleIndex}"))
// {
// logInfo = $"{GetClassName()}料仓放料完成已抬起";
// MessageQueue.Instance.Insert(logInfo);
// flowStep = EGrrFlowStep.料仓放料完成粘料检测;
// }
// break;
//case EGrrFlowStep.料仓放料完成粘料检测:
// if (!curDumpNozzle.HasProduct() || GlobalVar.RunSpace)
// {
// logInfo = $"{GetClassName()}料仓放料完成,吸嘴 {curDumpNozzle.NozzleIndex} 把产品SN {curDumpNozzle.Product.SN} 放入料仓穴位 {curDumpSlot.Index}";
// MessageQueue.Instance.Insert(logInfo);
// GlobalTray.GrrTray.ChangeStatus(curDumpSlot.Index, ESlotStatus.Have);
// curDumpNozzle.Clear();
// flowStep = EGrrFlowStep.判断是否需要放料到料仓;
// }
// break;
}
Thread.Sleep(5);
}
}
public void Start()
{
stop = false;
}
public void Stop()
{
stop = true;
}
private string GetClassName()
{
return "GrrFlow-";
}
/// <summary>
/// 获取吸嘴取料取不起来时,吸嘴在原取料位的偏移
/// 奇数向下偏移
/// 偶数向上偏移
/// </summary>
/// <param name="fetchNum"></param>
/// <returns></returns>
private double GetVacOffsetHeight(int fetchNum)
{
if (fetchNum == 0) return 0;
//先判断是奇数还是偶数
int count = 0;
int oddOrEven = fetchNum & 0x01;
double offsetDisct = 0.0;
if (oddOrEven == 1)
{
count = (fetchNum / 2) + 1;
offsetDisct = -0.1 * count;
}
else if (oddOrEven == 0)
{
count = (fetchNum / 2);
offsetDisct = 0.1 * count;
}
return offsetDisct;
}
public string GetCurStep()
{
return flowStep.ToString();
}
public void VirtualAxisSleep()
{
if (GlobalVar.VirtualAxis)
{
Thread.Sleep(GlobalVar.VirtualAxisMoveTime);
}
}
private void GotoNextFixture()
{
lastFixtureIndex = ((lastFixtureIndex + 1) % needGrrFixtureList.Count);
}
}
}