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.

181 lines
9.1 KiB
C#

using Rs.Controls;
using Rs.Framework;
using Rs.MotionPlat.Commom;
using Rs.MotionPlat.Entitys;
using Rs.MotionPlat.Flow.Common;
using Rs.MotionPlat.Vision;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rs.MotionPlat.Flow.SubFlow
{
enum EStockLocationFlowStep
{
,
,
,
,
}
public class StockLocationFlow
{
EStockLocationFlowStep flowStep = EStockLocationFlowStep.;
bool finished = false;
private static StockLocationFlow instance;
public static StockLocationFlow Instance
{
get
{
if(instance == null)
instance = new StockLocationFlow();
return instance;
}
}
public void Grab(ETrayType trayType,int slotIndex)
{
if (finished)
finished = false;
else
return;
flowStep = EStockLocationFlowStep.;
string logInfo = string.Empty;
TargetPosition targetPosition = new TargetPosition();
TraySlot grabEndSlot = null;
TraySlot grabStartSlot = null;
Stopwatch tm = new Stopwatch();
tm.Restart();
while (!finished)
{
switch (flowStep)
{
case EStockLocationFlowStep.:
//grabEndSlot = GlobalTray.InputTray.GetSlot(ESlotStatus.Have);
if (trayType == ETrayType.Grr)
{
grabEndSlot = GlobalTray.InputTray.GetSlot(slotIndex);
grabStartSlot = GlobalTray.InputTray.GetSlot(grabEndSlot.Index + 15);
}
else if (trayType == ETrayType.Input)
{
grabEndSlot = GlobalTray.InputTray.GetSlot(slotIndex);
grabStartSlot = GlobalTray.InputTray.GetSlot(grabEndSlot.Index + 15);
}
//grabEndSlot = GlobalTray.InputTray.GetSlot(slotIndex);
//grabStartSlot = GlobalTray.InputTray.GetSlot(grabEndSlot.Index + 15);
if (grabEndSlot != null && grabStartSlot != null)
{
//SlotPoint sp = TrayPointManager.GetSlotPoint(ETrayType.Input, grabStartSlot.Index);
SlotPoint sp = TrayPointManager.GetSlotPoint(trayType, grabStartSlot.Index);
if (sp != null)
{
targetPosition.X = sp.X;
targetPosition.Y1 = GlobalVar.StockSideY1;
targetPosition.Y2 = sp.Y - 30;
//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("到料仓拍照位上方", targetPosition, GetClassName());
flowStep = EStockLocationFlowStep.;
}
}
}
break;
case EStockLocationFlowStep.:
if (Ops.IsStop("LoadX", "LoadY1", "LoadY2"))
{
AxisPosPrint.PrintXY1Y2CurrentPos("轴loadx,loady1,loady2已停止运动,", GetClassName());
if (AxisArrived.LoadXY1Y2IsArrived(targetPosition.X, targetPosition.Y1, targetPosition.Y2))
{
SlotPoint sp = TrayPointManager.GetSlotPoint(trayType, grabStartSlot.Index);
double[] triggerPos = new double[16];
//启动相机触发
for (int i = 0; i < 16; i++)
{
triggerPos[i] = sp.Y + (i * 5);
}
AxisControl.LoadY2.SetPosCompare((ushort)GlobalVar.HightChannel, triggerPos);
AxisPosPrint.PrintXY1Y2CurrentPos("已运动到料仓拍照位上方", GetClassName());
flowStep = EStockLocationFlowStep.;
}
else
{
logInfo = $"{GetClassName()} 轴不在目标位置,重新运动一次";
MessageQueue.Instance.Warn(logInfo);
flowStep = EStockLocationFlowStep.;
}
}
break;
case EStockLocationFlowStep.:
if (grabEndSlot != null)
{
//SlotPoint sp = TrayPointManager.GetSlotPoint(ETrayType.Input, grabEndSlot.Index);
SlotPoint sp = TrayPointManager.GetSlotPoint(trayType, grabEndSlot.Index);
if (sp != null)
{
VisionHelper.loadTakeProductVision.ClearQueue();
targetPosition.X = sp.X;
targetPosition.Y1 = GlobalVar.StockSideY1;
targetPosition.Y2 = sp.Y + 2;
if (GroupAxisMove.XY1Y2MovePos(targetPosition, GlobalVar.FlyCameraSpeed, EGoWhichSide.StockSide))
{
AxisPosPrint.PrintXY1Y2TargetPos("到料仓拍照结束位,", targetPosition, GetClassName());
flowStep = EStockLocationFlowStep.;
}
}
}
break;
case EStockLocationFlowStep.:
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 = EStockLocationFlowStep.;
}
else
{
logInfo = $"{GetClassName()} 轴不在目标位置,重新运动一次";
MessageQueue.Instance.Warn(logInfo);
flowStep = EStockLocationFlowStep.;
}
}
break;
case EStockLocationFlowStep.:
//VisionResult vr = VisionHelper.Grab(Vision.EVisionScene.TrayLocation);
finished = true;
//if (!string.IsNullOrEmpty(vmsg) && vmsg.TrimEnd(new char[] { '#', ',' }).Split('#').Length == 16)
//{
// OneGrabSixteenManager.Instance.ParseResult(vmsg, slotIndex);
// finished = true;
//}
//else
//{
// //alarmEntity = AlarmCollection.Get(AlarmConstID.一拍十六拍照失败报警);
// //Msgbox.ShowDialog(alarmEntity, EButtonType.Retry, true);
// //Msgbox.ShowTipDialog(EButtonType.Retry, "一拍十六拍照失败,请处理后点击重试","grab fail",true);
// flowStep = EStockLocationFlowStep.到料仓拍照起始位;
//}
break;
}
}
tm.Stop();
long s = tm.ElapsedMilliseconds;
MessageQueue.Instance.Insert($"total time:{s}");
}
private string GetClassName()
{
return "StockLocationFlow-";
}
}
}