123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Aitex.Core.Common;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using Aitex.Sorter.Common;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.Schedulers;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.RT.ModuleLibrary.SystemModules;
- using EfemDualSchedulerLib.Schedulers;
- namespace EfemDualSchedulerLib
- {
- public class ReturnAllWafer : SchedulerModuleFactory, IRoutine
- {
- Dictionary<ModuleName, int> _checkPosition = new Dictionary<ModuleName, int>()
- {
- {ModuleName.EfemRobot, 2},
- {ModuleName.Aligner, 1},
- {ModuleName.LLA, 8},
- {ModuleName.LLB, 8},
- {ModuleName.TMRobot, 2},
- {ModuleName.PMA, 2},
- {ModuleName.PMB, 2},
- };
- private List<SchedulerPM> _lstPms = new List<SchedulerPM>();
- private List<SchedulerLoadPort> _lstLps = new List<SchedulerLoadPort>();
- private List<SchedulerLoadLock> _lstLls = new List<SchedulerLoadLock>();
- Queue<Action> tmRobotActions = new Queue<Action>() { };
- public ReturnAllWafer(EquipmentManager equipment) : base()
- {
- if (SC.GetValueOrDefault<bool>("System.SetUp.PMA.IsInstalled"))
- _lstPms.Add(_pm1);
- if (SC.GetValueOrDefault<bool>("System.SetUp.PMB.IsInstalled"))
- _lstPms.Add(_pm2);
- //if (SC.GetValueOrDefault<bool>("System.SetUp.PMC.IsInstalled"))
- // _lstPms.Add(_pm3);
- if (SC.GetValueOrDefault<bool>("System.SetUp.LLA.IsInstalled"))
- _lstLls.Add(_loadlockA);
- if (SC.GetValueOrDefault<bool>("System.SetUp.LLB.IsInstalled"))
- _lstLls.Add(_loadlockB);
- if (SC.GetValueOrDefault<bool>("System.SetUp.LP1.IsInstalled"))
- _lstLps.Add(_lp1);
- if (SC.GetValueOrDefault<bool>("System.SetUp.LP2.IsInstalled"))
- _lstLps.Add(_lp2);
- if (SC.GetValueOrDefault<bool>("System.SetUp.LP3.IsInstalled"))
- _lstLps.Add(_lp3);
- tmRobotActions.Enqueue(MonitorTMRobotPMATask);
- tmRobotActions.Enqueue(MonitorTMRobotPMBTask);
- tmRobotActions.Enqueue(MonitorTMRobotLoadLockTask);
- }
- public Result Start(params object[] objs)
- {
- foreach (var positions in _checkPosition)
- {
- for (int i = 0; i < positions.Value; i++)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(positions.Key, i);
- if (!wafer.IsEmpty)
- {
- ModuleName originLoadPort = (ModuleName)wafer.OriginStation;
- if (!ModuleHelper.IsLoadPort(originLoadPort))
- {
- EV.PostWarningLog("System", $"Wafer {positions.Key}.{i + 1} can not return, origin is not LP");
- return Result.FAIL;
- }
- if (wafer.Status == WaferStatus.Dummy)
- {
- EV.PostWarningLog("System", $"Wafer {positions.Key}.{i + 1} can not return, wafer is dummy");
- return Result.FAIL;
- }
- if (WaferManager.Instance.CheckHasWafer(originLoadPort, wafer.OriginSlot))
- {
- EV.PostWarningLog("System", $"Wafer {positions.Key}.{i + 1} can not return, origin has wafer");
- return Result.FAIL;
- }
- if (!(GetModule(originLoadPort.ToString()) as SchedulerLoadPort).IsReadyForPlace(ModuleName.EfemRobot, Hand.Blade1, wafer.OriginSlot))
- {
- EV.PostWarningLog("System", $"{originLoadPort} not ready to place Wafer");
- return Result.FAIL;
- }
- EV.PostInfoLog("System", $"Wafer return, {positions.Key}.{i + 1}=>{(ModuleName)wafer.OriginStation}.{wafer.OriginSlot + 1}");
- }
- }
- }
- return Result.RUN;
- }
- public Result Monitor()
- {
- MonitorModuleTasks();
- if (MonitorTaskDone())
- {
- return Result.DONE;
- }
- return Result.RUN;
- }
- public void Clear()
- {
- }
- public void Abort()
- {
- }
- public Result MonitorModuleTasks()
- {
- MonitorPMTask();
- MonitorTMRobotTask();
- MonitorEfemRobotTask();
- return Result.RUN;
- }
- private void MonitorTMRobotTask()
- {
- if (!_tmRobot.IsAvailable)
- return;
- //_tmRobot is idle, release all the target
- foreach (var ll in _lstLls)
- {
- if (ll.IsWaitTransfer(ModuleName.TMRobot))
- ll.StopWaitTransfer(ModuleName.TMRobot);
- }
- foreach (var pm in _lstPms)
- {
- if (pm.IsWaitTransfer(ModuleName.TMRobot))
- pm.StopWaitTransfer(ModuleName.TMRobot);
- }
- if (!_tmRobot.IsAvailable)
- return;
- var act = tmRobotActions.Peek();
- act.Invoke();
- if (!_tmRobot.IsAvailable)
- return;
- if (act == MonitorTMRobotLoadLockTask && _lstLls.Any(x => !x.IsAvailable))
- return;
- tmRobotActions.Enqueue(tmRobotActions.Dequeue());
- //MonitorTMRobotPMATask();
- //if (!_tmRobot.IsAvailable)
- // return;
- //MonitorTMRobotPMBTask();
- //if (!_tmRobot.IsAvailable)
- // return;
- //MonitorTMRobotLoadLockTask();
- }
- private void MonitorTMRobotLoadLockTask()
- {
- if (!_tmRobot.IsAvailable)
- return;
- //place to loadlock
- {
- bool blade1HasWafer = _tmRobot.Blade1Enable && WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0);
- bool blade2HasWafer = _tmRobot.Blade2Enable && WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1);
- if (blade1HasWafer || blade2HasWafer)
- {
- Hand placeBlade = blade1HasWafer ? Hand.Blade1 : Hand.Blade2;
- foreach (var ll in _lstLls)
- {
- if (!ll.IsAvailable)
- continue;
- var slot = GetSlotCouldBePlace(ll.Module);
- if (slot != null && ll.IsReadyForPlace(ModuleName.TMRobot, placeBlade, (int)slot))
- {
- if (_tmRobot.Place(ll.Module, (int)slot, placeBlade, 0, 0, false))
- {
- ll.WaitTransfer(ModuleName.TMRobot);
- return;
- }
- }
- }
- }
- }
- }
- private void MonitorTMRobotPMATask()
- {
- if (!_tmRobot.IsAvailable)
- return;
- //pick from pm
- {
- bool blade1Empty = _tmRobot.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0);
- bool blade2Empty = _tmRobot.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1);
- if (blade1Empty || blade2Empty)
- {
- Hand pickBlade = blade1Empty ? Hand.Blade1 : Hand.Blade2;
- //foreach (var pm in _lstPms)
- {
- var pm = _pm1;
- if (!pm.IsAvailable)
- return;
- var slot = GetWaferCouldBeReturn(pm.Module);
- if (slot != null /*&& pm.IsReadyForPick(ModuleName.TMRobot, pickBlade, (int)slot)*/)
- {
- if (_tmRobot.Pick(pm.Module, (int)slot, pickBlade, 0, 0, false))
- {
- pm.WaitTransfer(ModuleName.TMRobot);
- return;
- }
- }
- }
- }
- }
- }
- private void MonitorTMRobotPMBTask()
- {
- if (!_tmRobot.IsAvailable)
- return;
- //pick from pm
- {
- bool blade1Empty = _tmRobot.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0);
- bool blade2Empty = _tmRobot.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1);
- if (blade1Empty || blade2Empty)
- {
- Hand pickBlade = blade1Empty ? Hand.Blade1 : Hand.Blade2;
- //foreach (var pm in _lstPms)
- {
- var pm = _pm2;
- if (!pm.IsAvailable)
- return;
- var slot = GetWaferCouldBeReturn(pm.Module);
- if (slot != null /*&& pm.IsReadyForPick(ModuleName.TMRobot, pickBlade, (int)slot)*/)
- {
- if (_tmRobot.Pick(pm.Module, (int)slot, pickBlade, 0, 0, false))
- {
- pm.WaitTransfer(ModuleName.TMRobot);
- return;
- }
- }
- }
- }
- }
- }
- private bool MonitorTaskDone()
- {
- foreach (var positions in _checkPosition)
- {
- for (int i = 0; i < positions.Value; i++)
- {
- if (CheckWaferCouldBeReturn(positions.Key, i))
- {
- return false;
- }
- }
- }
- foreach (var lp in _lstLps)
- {
- if (!lp.IsAvailable)
- return false;
- }
- if (!_tmRobot.IsAvailable)
- return false;
- if (!_efem.IsAvailable)
- return false;
- return true;
- }
- private void MonitorPMTask()
- {
- foreach (var pm in _lstPms)
- {
- if (!pm.IsAvailable)
- continue;
- var wafers = WaferManager.Instance.GetWafers(pm.Module);
- for (int i = 0; i < wafers.Length; i++)
- {
- if (!pm.IsAvailable)
- break;
- if (CheckWaferCouldBeReturn(pm.Module, i))
- {
- if (!pm.IsReadyForPick(ModuleName.TMRobot, Hand.Blade1, i))
- {
- pm.PrepareTransfer(ModuleName.TMRobot, EnumTransferType.Pick, i);
- }
- }
- }
- }
- }
- private void MonitorEfemRobotTask()
- {
- if (!_efem.IsAvailable)
- return;
- //efem robot is idle, release all the target
- if (_aligner.IsWaitTransfer(ModuleName.EfemRobot))
- _aligner.StopWaitTransfer(ModuleName.EfemRobot);
- foreach (var ll in _lstLls)
- {
- if (ll.IsWaitTransfer(ModuleName.EfemRobot))
- ll.StopWaitTransfer(ModuleName.EfemRobot);
- }
- foreach (var lp in _lstLps)
- {
- if (lp.IsWaitTransfer(ModuleName.EfemRobot))
- lp.StopWaitTransfer(ModuleName.EfemRobot);
- }
- MonitorEfemRobotAlignerTask();
- if (!_efem.IsAvailable)
- return;
- MonitorEfemRobotLoadLockTask();
- MonitorEfemRobotLoadPortTask();
- }
- private void MonitorEfemRobotLoadPortTask()
- {
- if (!_efem.IsAvailable)
- return;
- //place
- bool blade0HasWaferAndProcessed = _efem.Blade1Enable && CheckWaferCouldBeReturn(ModuleName.EfemRobot, 0);
- bool blade1HasWaferAndProcessed = _efem.Blade2Enable && CheckWaferCouldBeReturn(ModuleName.EfemRobot, 1);
- if (blade0HasWaferAndProcessed || blade1HasWaferAndProcessed)
- {
- Hand placeBlade = blade0HasWaferAndProcessed ? Hand.Blade1 : Hand.Blade2;
- if (blade0HasWaferAndProcessed && blade1HasWaferAndProcessed)
- {
- if (WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 1).OriginSlot <
- WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0).OriginSlot)
- {
- placeBlade = Hand.Blade2;
- }
- }
- SlotItem destination = GetWaferReturnLoadPort(ModuleName.EfemRobot, (int)placeBlade);
- if (destination != null)
- {
- SchedulerLoadPort lp = (SchedulerLoadPort)GetModule(destination.Module.ToString());
- if (lp.IsReadyForPlace(ModuleName.EfemRobot, Hand.Blade1, destination.Slot))
- {
- if (_efem.Place(destination.Module, destination.Slot, (Hand)placeBlade))
- {
- lp.WaitTransfer(ModuleName.EfemRobot);
- return;
- }
- }
- }
- }
- }
- private void MonitorEfemRobotLoadLockTask()
- {
- if (!_efem.IsAvailable)
- return;
- foreach (var ll in _lstLls)
- {
- if (!ll.IsAvailable)
- continue;
- {
- bool blade1Empty = _efem.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0);
- bool blade2Empty = _efem.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1);
- if (blade1Empty || blade2Empty)
- {
- Hand pickBlade = blade1Empty ? Hand.Blade1 : Hand.Blade2;
- var slot = GetWaferCouldBeReturn(ll.Module);
- if (slot != null)
- {
- if (ll.IsReadyForPick(ModuleName.EfemRobot, pickBlade, (int)slot))
- {
- if (_efem.Pick(ll.Module, (int)slot, pickBlade))
- {
- ll.WaitTransfer(ModuleName.EfemRobot);
- return;
- }
- }
- }
- }
- }
- }
- }
- private void MonitorEfemRobotAlignerTask()
- {
- if (!_efem.IsAvailable)
- return;
- if (!_aligner.IsAvailable)
- return;
- //pick from aligner
- if (WaferManager.Instance.CheckHasWafer(ModuleName.Aligner, 0))
- {
- bool blade1Empty = _efem.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0);
- bool blade2Empty = _efem.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1);
- if (blade1Empty || blade2Empty)
- {
- Hand pickBlade = blade1Empty ? Hand.Blade1 : Hand.Blade2;
- if (_aligner.IsReadyForPick(ModuleName.EfemRobot, pickBlade, 0))
- {
- if (_efem.Pick(_aligner.Module, 0, pickBlade))
- {
- _aligner.WaitTransfer(ModuleName.EfemRobot);
- return;
- }
- }
- }
- }
- }
- private int? GetWaferCouldBeReturn(ModuleName module)
- {
- var wafers = WaferManager.Instance.GetWafers(module);
- for (int i = 0; i < wafers.Length; i++)
- {
- if (CheckWaferCouldBeReturn(wafers[i]))
- return i;
- }
- return null;
- }
- private int? GetSlotCouldBePlace(ModuleName module)
- {
- var wafers = WaferManager.Instance.GetWafers(module);
- for (int i = 0; i < wafers.Length; i++)
- {
- if (wafers[i].IsEmpty)
- return i;
- }
- return null;
- }
- private bool CheckWaferCouldBeReturn(WaferInfo wafer)
- {
- if (!wafer.IsEmpty)
- {
- return ModuleHelper.IsLoadPort((ModuleName)wafer.OriginStation)
- && wafer.Status != WaferStatus.Dummy
- && WaferManager.Instance.CheckNoWafer((ModuleName)wafer.OriginStation, wafer.OriginSlot);
- }
- return false;
- }
- private bool CheckWaferCouldBeReturn(ModuleName module, int slot)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
- if (!wafer.IsEmpty)
- {
- return ModuleHelper.IsLoadPort((ModuleName)wafer.OriginStation)
- && wafer.Status != WaferStatus.Dummy
- && WaferManager.Instance.CheckNoWafer((ModuleName)wafer.OriginStation, wafer.OriginSlot);
- }
- return false;
- }
- private SlotItem GetWaferReturnLoadPort(ModuleName module, int slot)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
- if (!wafer.IsEmpty)
- {
- return new SlotItem((ModuleName)wafer.OriginStation, wafer.OriginSlot);
- }
- return null;
- }
- }
- }
|