From 905c376e37aa0f058580419cd6bce0020bdc4e54 Mon Sep 17 00:00:00 2001 From: lhiven Date: Fri, 2 Aug 2024 16:10:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=99=E7=9B=98=E9=A3=9E?= =?UTF-8?q?=E6=8B=8D=E5=AE=9A=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Flow/SubFlow/StockLocationFlow.cs | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 Rs.DeweyTester/Flow/SubFlow/StockLocationFlow.cs diff --git a/Rs.DeweyTester/Flow/SubFlow/StockLocationFlow.cs b/Rs.DeweyTester/Flow/SubFlow/StockLocationFlow.cs new file mode 100644 index 0000000..427b86b --- /dev/null +++ b/Rs.DeweyTester/Flow/SubFlow/StockLocationFlow.cs @@ -0,0 +1,180 @@ +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(1, 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-"; + } + } +}