123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554 |
- using System;
- using System.Collections.Generic;
- using System.Security.AccessControl;
- using Aitex.Core.Common;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using Aitex.Sorter.Common;
- using Aitex.Sorter.RT.Module;
- using Aitex.Sorter.RT.SorterCommonFrame.Routines;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
- namespace Aitex.Sorter.RT.SorterCommonFrame.Modules
- {
- public class SingleMoveManager : IMoveManager
- {
- public event Action<MoveErrorArgument> OnMoveError;
- public Hand Blade { get; set; }
- public int TaskCount { get { return tasks.Count; } }
- public bool IsPaused { get { return !_pause; } }
- public int WaferCompleted
- {
- get
- {
- int count = tasks.Count;
- int completed = lastTaskCount - count;
- lastTaskCount = count;
- return completed;
- }
- }
- private PickRoutine pickRoutine = null;
- private PlaceRoutine placeRoutine = null;
- private AlignRoutine alignRoutine = null;
-
- private List<MoveTask> tasks = new List<MoveTask>();
- private IRoutine _robotRoutine = null;
- private AlignRoutine _alignerRoutine = null;
- private MoveTask task1 = null;
- private int lastTaskCount = 0;
- private bool _verifyFail = false;
- private bool _pause = true;
- public SingleMoveManager()
- {
- pickRoutine = new PickRoutine("System", "PickRoutine");
- pickRoutine.Initalize();
- placeRoutine = new PlaceRoutine("System", "PlaceRoutine");
- placeRoutine.Initalize();
- alignRoutine = new AlignRoutine("System", "AlignRoutine");
- alignRoutine.Initalize();
- }
- public bool Initialize()
- {
-
- return true;
- }
- public bool Pause()
- {
- _pause = true;
- return true;
- }
- public bool Resume()
- {
- _pause = false;
- return true;
- }
- public bool Stop()
- {
- tasks.Clear();
- if (task1 != null)
- tasks.Add(task1);
- _pause = false;
- return true;
- }
- public bool Start(List<MoveTask> tasks)
- {
- _robotRoutine = null;
- _alignerRoutine = null;
- this.tasks = tasks;
- _pause = false;
- bool bCheck = true;
- foreach (MoveTask task in tasks)
- {
- if (IsSwap(task))
- {
- string reason = string.Format("single arm can't support swap operation. {0}:{1} ---> {2}:{3}.",
- ((ModuleName)task.SourceStaion).ToString(),
- task.SourceSlot,
- ((ModuleName)task.DestStaion).ToString(),
- task.DestSlot);
- EV.PostMessage(ModuleName.System.ToString(),EventEnum.DefaultWarning, reason);
- bCheck = false;
- }
- }
- if (!bCheck)
- return false;
- foreach (MoveTask task in tasks)
- {
- WaferManager.Instance.UpdateWaferProcessStatus(task.WaferID, ProcessStatus.Wait);
- task.WaferID = WaferManager.Instance.GetWaferID(task.SourceStaion, task.SourceSlot);
- }
-
- newTask();
- if (task1 == null)
- {
- return true;
- }
- _robotRoutine = null;
- _alignerRoutine = null;
- lastTaskCount = tasks.Count;
- return true;
- }
- private void newTask()
- {
- if (tasks.Count > 0)
- task1 = tasks[0];
- if (task1 != null)
- {
- WaferManager.Instance.UpdateWaferProcessStatus(task1.WaferID, ProcessStatus.Busy);
- }
- }
- private bool IsSwap(MoveTask task)
- {
- if ((task.DestStaion == task.SourceStaion) && (task.DestSlot == task.SourceSlot))
- return false;
- return WaferManager.Instance.CheckHasWafer(task.DestStaion, task.DestSlot);
- }
- public bool Monitor(object[] objs)
- {
- Result ret = Result.RUN;
- if (tasks.Count == 0 && task1 == null)
- {
- return true; //completed
- }
- if (task1 == null)
- {
- if (!_pause)
- newTask();
- }
- if (_alignerRoutine != null)
- {
- ret = _alignerRoutine.Monitor();
- if (ret == Result.DONE)
- {
- _alignerRoutine = null;
- AlignCompleted();
- return false;
- }
- else if (ret == Result.FAIL)
- {
- WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 0, ProcessStatus.Failed);
- WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 1, ProcessStatus.Failed);
- WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Aligner, 0, ProcessStatus.Failed);
- NotifyError("Aligner", "Aligner Error");
- return true; //failed
- }
- }
- if (_robotRoutine != null)
- {
- ret = _robotRoutine.Monitor();
- if (ret == Result.DONE)
- {
- _robotRoutine = null;
- return false;
- }
- else if (ret == Result.FAIL)
- {
- WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 0, ProcessStatus.Failed);
- WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 1, ProcessStatus.Failed);
- WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Aligner, 0, ProcessStatus.Failed);
- NotifyError("Robot", "Robot Error");
- return true; //failed
- }
- }
- else
- {
- if (!_pause)
- {
- IRoutine rountine = NextRoutine();
- if (rountine != null)
- {
- rountine.Start();
- _robotRoutine = rountine;
- }
- }
- }
- return false;
- }
- public Result Monitor()
- {
- Result ret = Result.RUN;
- if (tasks.Count == 0 && task1 == null)
- {
- return Result.DONE; //completed
- }
- if (task1 == null)
- {
- if (!_pause)
- newTask();
- }
- if (_alignerRoutine != null)
- {
- ret = _alignerRoutine.Monitor();
- if (ret == Result.DONE)
- {
- _alignerRoutine = null;
- AlignCompleted();
- return Result.RUN;
- }
- else if (ret == Result.FAIL)
- {
- WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 0, ProcessStatus.Failed);
- WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 1, ProcessStatus.Failed);
- WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Aligner, 0, ProcessStatus.Failed);
- NotifyError("Aligner", "Aligner Error");
- return Result.FAIL; //failed
- }
- else if (ret == Result.VERIFYFAIL)
- {
-
- // _alignerRoutine = null;
- if (SC.ContainsItem(SorterCommon.ScPathName.Process_LMMismatchHandle))
- switch (SC.GetValue<int>(SorterCommon.ScPathName.Process_LMMismatchHandle))
- {
- case 2:
-
- task1.DestStaion = task1.SourceStaion;
- task1.DestSlot = task1.SourceSlot;
- WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Aligner, 0, ProcessStatus.Failed);
- _verifyFail = true;
- break;
- case 3:
- ModuleName handleLp;
- if (SC.ContainsItem(SorterCommon.ScPathName.Process_MismatchCollectPort))
- {
- handleLp = ModuleHelper.Converter(SC.GetStringValue(SorterCommon.ScPathName.Process_MismatchCollectPort));
- if (!ModuleHelper.IsLoadPort(handleLp)) break;
- //handleLp = ModuleName.LP1;
- }
- else break;
- task1.DestStaion = handleLp;
- int startSlot = SC.ContainsItem("LoadPort." + handleLp.ToString() + "StartSlot")
- ? SC.GetValue<int>("LoadPort." + handleLp.ToString() + "StartSlot") : 1;
- if (startSlot > 25 || startSlot < 1) startSlot = 1;
- int endSlot = SC.ContainsItem("LoadPort." + handleLp.ToString() + "EndSlot")
- ? SC.GetValue<int>("LoadPort." + handleLp.ToString() + "EndSlot") : 25;
- if (endSlot > 25 || endSlot < 1) endSlot = 25;
- WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Aligner, 0, ProcessStatus.Failed);
- _verifyFail = true;
- var emptySlot = DEVICE.GetDevice<LoadPort>(handleLp.ToString()).GetEmptySlot();
- foreach(int slot in emptySlot)
- {
- if (slot < startSlot || slot > endSlot) emptySlot.Remove(slot);
- }
- if (emptySlot.Count != 0)
- {
- if (SC.ContainsItem("Process.PlaceFromTopOnHostLPMode") && SC.GetValue<bool>("Process.PlaceFromTopOnHostLPMode"))
- {
- task1.DestSlot = emptySlot[emptySlot.Count - 1];
- }
- else
- {
- task1.DestSlot = emptySlot[0];
- }
- break;
- }
- else
- {
- Singleton<RouteManagerSorter>.Instance.PostMsg(RouteManagerSorter.MSG.PauseRecipe);
- EV.PostWarningLog(handleLp.ToString(), $"{handleLp} is full.");
- break;
- }
-
- }
- //AlignCompleted();
- _alignerRoutine.PostAlignValue = SC.ContainsItem("Aligner." + task1.DestStaion + "PostAlignAngle") ?
- SC.GetValue<double>("Aligner." + task1.DestStaion + "PostAlignAngle") : 0;
- return Result.RUN;
- }
- }
- if (_robotRoutine != null)
- {
- ret = _robotRoutine.Monitor();
- if (ret == Result.DONE)
- {
- _robotRoutine = null;
- return Result.RUN;
- }
- else if (ret == Result.FAIL)
- {
- WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 0, ProcessStatus.Failed);
- WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 1, ProcessStatus.Failed);
- WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Aligner, 0, ProcessStatus.Failed);
- NotifyError("Robot", "Robot Error");
- return Result.FAIL; //failed
- }
- }
- else
- {
- if (!_pause)
- {
- IRoutine rountine = NextRoutine();
- if (rountine != null)
- {
- rountine.Start();
- _robotRoutine = rountine;
- }
- }
- }
- return Result.RUN;
- }
- private void AlignCompleted()
- {
- if (task1 != null)
- {
- if (task1.Step == MoveStep.WaitAligner)
- {
- task1.Step = MoveStep.PickFromAligner;
- }
- }
- }
- private IRoutine NextRoutine()
- {
- IRoutine routine = null;
- if (task1.Step == MoveStep.PickFromSource)
- {
- pickRoutine.Source = task1.SourceStaion;
- pickRoutine.Slot = task1.SourceSlot;
- pickRoutine.Blade = GetEmptyHand();
- task1.Blade = pickRoutine.Blade;
- routine = pickRoutine;
-
- if (PassTurnOver(task1.option) && PassAligner(task1.option))
- {
- task1.Step = MoveStep.PlaceToAligner;
- }
- else if(PassTurnOver(task1.option))
- {
- task1.Step = MoveStep.PlaceToTurnOver;
- }
- else if (PassAligner(task1.option))
- {
- task1.Step = MoveStep.PlaceToAligner;
- }
- else
- {
- task1.Step = MoveStep.PlaceToDest;
- }
- }
- else if (task1.Step == MoveStep.PlaceToTurnOver)
- {
- placeRoutine.Station = ModuleName.TurnOverStation;
- placeRoutine.Slot = 0;
- placeRoutine.Blade = task1.Blade;
- task1.Step = MoveStep.PickFromTurnOver;
- routine = placeRoutine;
- }
- else if (task1.Step == MoveStep.PlaceToAligner)
- {
- placeRoutine.Station = ModuleName.Aligner;
- placeRoutine.Slot = 0;
- placeRoutine.Blade = task1.Blade;
- task1.Step = MoveStep.Aligning;
- routine = placeRoutine;
- }
- else if (task1.Step == MoveStep.Aligning)
- {
- alignRoutine.Option = task1.option;
- alignRoutine.Notch = task1.Notch;
- alignRoutine.IsVerifyAny = task1.VerifyAny;
- alignRoutine.IsVerifyLM1 = task1.VerifyLaserMaker;
- alignRoutine.StrLaserMark1 = task1.LaserMaker;
- alignRoutine.IsVerifyLM2 = task1.VerifyT7Code;
- alignRoutine.StrLaserMark2 = task1.T7Code;
- alignRoutine.PostAlignValue = SC.ContainsItem("Aligner." + task1.DestStaion + "PostAlignAngle") ?
- SC.GetValue<double>("Aligner." + task1.DestStaion + "PostAlignAngle") : 0;
- _alignerRoutine = alignRoutine;
- _alignerRoutine.Start();
- task1.Step = MoveStep.WaitAligner;
- }
- else if (task1.Step == MoveStep.PickFromTurnOver)
- {
- pickRoutine.Source = ModuleName.TurnOverStation;
- pickRoutine.Slot = 0;
- pickRoutine.Blade = task1.Blade;
- task1.Step = MoveStep.PlaceToDest;
- routine = pickRoutine;
- }
- else if (task1.Step == MoveStep.PickFromAligner)
- {
- if (_alignerRoutine == null) //aligning completed
- {
- if (PassTurnOver(task1.option))
- {
- pickRoutine.Source = ModuleName.Aligner;
- pickRoutine.Slot = 0;
- pickRoutine.Blade = task1.Blade;
- task1.Step = MoveStep.PlaceToTurnOver;
- routine = pickRoutine;
- }
- else
- {
- pickRoutine.Source = ModuleName.Aligner;
- pickRoutine.Slot = 0;
- pickRoutine.Blade = task1.Blade;
- task1.Step = MoveStep.PlaceToDest;
- routine = pickRoutine;
- }
- }
- }
- else if (task1.Step == MoveStep.PlaceToDest)
- {
- placeRoutine.Station = task1.DestStaion;
- placeRoutine.Slot = task1.DestSlot;
- placeRoutine.Blade = task1.Blade;
- task1.Step = MoveStep.Completed;
- routine = placeRoutine;
- }
- else if (task1.Step == MoveStep.Completed)
- {
- if (_verifyFail)
- {
- WaferManager.Instance.UpdateWaferProcessStatus(task1.DestStaion, task1.DestSlot, ProcessStatus.Failed);
- _verifyFail = false;
- }
- else
- WaferManager.Instance.UpdateWaferProcessStatus(task1.DestStaion, task1.DestSlot, ProcessStatus.Completed);
- tasks.Remove(task1);
- task1 = GetNextTask();
- }
- return routine;
- }
- private bool PassAligner(MoveOption option)
- {
- return (((option & MoveOption.Align) == MoveOption.Align) || ((option & MoveOption.ReadID) == MoveOption.ReadID)
- || ((option & MoveOption.ReadID2) == MoveOption.ReadID2));
- }
-
- private bool PassTurnOver(MoveOption option)
- {
- return (option & MoveOption.Turnover) == MoveOption.Turnover;
- }
- private Hand GetEmptyHand()
- {
- return this.Blade;
- /*
- if (!WaferManager.Instance.CheckWafer(UnitName.Robot, 0, WaferStatus.Normal))
- {
- return Hand.Blade1;
- }
- if (!WaferManager.Instance.CheckWafer(UnitName.Robot, 1, WaferStatus.Normal))
- {
- return Hand.Blade2;
- }
- */
- //return Hand.Blade1;
- }
- private MoveTask GetNextTask()
- {
- MoveTask newTask = null;
- if (tasks.Count > 0)
- newTask = tasks[0];
- if (newTask != null)
- {
- WaferManager.Instance.UpdateWaferProcessStatus(newTask.WaferID, ProcessStatus.Busy);
- }
- return newTask;
- }
- //private void PostMsg(RouteManager.MSG msg, params object[] objs)
- //{
- // Singleton<RouteManager>.Instance.PostMsg(msg, objs);
- //}
- private void NotifyError(string module, string message)
- {
- if (OnMoveError != null)
- {
- OnMoveError(new MoveErrorArgument(module, message));
- }
- }
- }
- }
|