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.

238 lines
12 KiB
C#

using Rs.Controls;
using Rs.Framework;
using Rs.MotionPlat.Commom;
using Rs.MotionPlat.Entitys;
using Rs.MotionPlat.Flow.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Rs.MotionPlat.Flow.SubFlow
{
enum EStockTakeFlowStep
{
,
,
,
,
,
,
,
,
}
/// <summary>
/// 料仓取料流程
/// </summary>
public class StockTakeFlow
{
bool finished = true;
EStockTakeFlowStep flowStep = EStockTakeFlowStep.;
private StockTakeFlow()
{
}
private static StockTakeFlow instance;
public static StockTakeFlow Instance
{
get
{
if (instance == null)
instance = new StockTakeFlow();
return instance;
}
}
public string GetCurStep()
{
return flowStep.ToString();
}
/// <summary>
/// 料仓取料
/// </summary>
/// <param name="className"></param>
public void Take(ETrayType trayType, int slotIndex,int nozzleIndex)
{
if (finished)
finished = false;
else
return;
flowStep = EStockTakeFlowStep.;
string logInfo = string.Empty;
TargetPosition targetPosition = new TargetPosition();
Nozzle curNozzle = null;
TraySlot waitTakeProductSlot = null;
while (!finished)
{
if (MachineManage.Instance.MachineStatus== EMachineStatus.Stop)
{
Thread.Sleep(10);
continue;
}
switch (flowStep)
{
case EStockTakeFlowStep.:
flowStep = EStockTakeFlowStep.;
break;
case EStockTakeFlowStep.:
//获取空闲吸嘴
curNozzle = NozzleManager.GetNozzle(nozzleIndex);
if (curNozzle != null)
{
if(trayType== ETrayType.Input)
{
waitTakeProductSlot = GlobalTray.InputTray.GetSlot(slotIndex);
}
else if(trayType== ETrayType.Grr)
{
waitTakeProductSlot = GlobalTray.GrrTray.GetSlot(slotIndex);
}
targetPosition = NozzleManager.GetToTraySlot(trayType, waitTakeProductSlot.Index, curNozzle.NozzleIndex);
ProductLocationResult result = OneGrabSixteenManager.Instance.GetResultBySlotIndex(waitTakeProductSlot.Index);
if (result!=null || GlobalVar.RunSpace)
{
if(!GlobalVar.RunSpace)
{
MessageQueue.Instance.Insert($"拍照偏移量 x:{result.OffsetX},y:{result.OffsetY}");
targetPosition.X += result.OffsetX;
targetPosition.Y2 += result.OffsetY;
}
}
if (GroupAxisMove.XY1Y2MovePos(targetPosition, GlobalVar.WholeSpeed))
{
AxisPosPrint.PrintXY1Y2TargetPos($"到料仓{waitTakeProductSlot.Index}号穴位取料位上方,", targetPosition, GetClassName());
flowStep = EStockTakeFlowStep.;
}
}
break;
case EStockTakeFlowStep.:
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 = EStockTakeFlowStep.;
}
else
{
flowStep = EStockTakeFlowStep.;
}
}
break;
case EStockTakeFlowStep.:
targetPosition.StockZ = NozzleManager.GetNozzleToTrayTakeProductPos(ETrayType.Input, curNozzle.NozzleIndex);
if (NozzleManager.Go(curNozzle, targetPosition.StockZ, GlobalVar.WholeSpeed))
{
logInfo = $"{GetClassName()}到料仓取料位下方,tz:{targetPosition.StockZ}";
MessageQueue.Instance.Insert(logInfo);
flowStep = EStockTakeFlowStep.;
}
break;
case EStockTakeFlowStep.:
if (Ops.IsStop($"NozzleZ{curNozzle.NozzleIndex}"))
{
Thread.Sleep(200);
logInfo = $"{GetClassName()} 已运动到料仓取料位下方";
MessageQueue.Instance.Insert(logInfo);
if (!GlobalVar.RunSpace)
{
//打开真空吸
curNozzle.VacSuction(EIoOperate.Open, GetClassName());
}
flowStep = EStockTakeFlowStep.;
}
break;
case EStockTakeFlowStep.:
if (NozzleManager.GotoSafePos(curNozzle.NozzleIndex))
{
logInfo =$"{GetClassName()} 料仓取料完成抬起";
MessageQueue.Instance.Insert(logInfo);
flowStep = EStockTakeFlowStep.;
}
break;
case EStockTakeFlowStep.:
if (Ops.IsStop($"NozzleZ{curNozzle.NozzleIndex}"))
{
logInfo =$"{GetClassName()} 料仓取料完成已抬起";
MessageQueue.Instance.Insert(logInfo);
flowStep = EStockTakeFlowStep.;
}
break;
case EStockTakeFlowStep.:
if (curNozzle.HasProduct()|| GlobalVar.RunSpace)
{
//curNozzle.Product = new TestProduct() { SN = VirtualBarCode.Code, TestNum = 0 };
if(GlobalVar.RunSpace)
{
curNozzle.Product = new TestProduct() { SN = VirtualBarCode.Code, TestNum = 0, From = $"R{waitTakeProductSlot.Row + 1}C{waitTakeProductSlot.Column + 1}" };
}
else
{
curNozzle.Product = new TestProduct() { SN = OneGrabSixteenManager.Instance.GetResultBySlotIndex(slotIndex).SN, TestNum = 0, From = $"R{waitTakeProductSlot.Row + 1}C{waitTakeProductSlot.Column + 1}" };
}
curNozzle.Status = ENozzleStatus.ToTest;
//curNozzle.Status = ENozzleStatus.ToUnload;
GlobalTray.NozzleTray.ChangeStatus(curNozzle.NozzleIndex, ESlotStatus.Have);
GlobalTray.InputTray.ChangeStatus(waitTakeProductSlot.Index, ESlotStatus.NotHave);
logInfo = $"{GetClassName()} from r{waitTakeProductSlot.Row+1}c{waitTakeProductSlot.Column+1} 穴位索引:{waitTakeProductSlot.Index} 产品:{curNozzle.Product.SN}被吸嘴{curNozzle.NozzleIndex}取料完成,";
MessageQueue.Instance.Insert(logInfo);
//flowStep = EStockTakeFlowStep.判断是否需要从料仓取料;
finished = true;
flowStep = EStockTakeFlowStep.;
}
else
{
AlarmEntity alarmEntity = AlarmCollection.Get(AlarmConstID.).Transform($"{curNozzle.NozzleIndex}",$"{waitTakeProductSlot.Row}",$"{waitTakeProductSlot.Column}",$"{waitTakeProductSlot.Index}");
EButtonType btnSelect = Msgbox.ShowDialog(alarmEntity,EButtonType.EndInput | EButtonType.Retry | EButtonType.Skip | EButtonType.Recheck);
switch (btnSelect)
{
case EButtonType.EndInput:
logInfo = GetClassName() + $"选择了结束上料";
MessageQueue.Instance.Insert(logInfo);
GlobalVar.Clear = true;
finished = true;
flowStep = EStockTakeFlowStep.;
break;
case EButtonType.Retry:
logInfo = GetClassName() + $"选择了重试";
MessageQueue.Instance.Insert(logInfo);
//先把产品放下
//StockPlaceFlow.Instance.Place(ETrayType.Input, waitTakeProductSlot.Index, curNozzle.NozzleIndex);
flowStep = EStockTakeFlowStep.;
break;
case EButtonType.Recheck:
logInfo = GetClassName() + $"选择了重新检查真空";
MessageQueue.Instance.Insert(logInfo);
flowStep = EStockTakeFlowStep.;
break;
case EButtonType.Skip:
logInfo = GetClassName() + $"选择了跳过";
MessageQueue.Instance.Insert(logInfo);
finished = true;
flowStep = EStockTakeFlowStep.;
break;
default:
break;
}
}
break;
}
}
}
string GetClassName()
{
return $"{nameof(StockTakeFlow)}-";
}
}
}