123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Aitex.Core.Common;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using Aitex.Sorter.Common;
- using Aitex.Core.RT.Log;
- using Aitex.Core.Util;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.RecipeCenter;
- using Aitex.Core.RT.Fsm;
- using MECF.Framework.Common.Jobs;
- using MECF.Framework.Common.Routine;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.Common.Schedulers;
- using MECF.Framework.Common.DBCore;
- using Venus_Core;
- using Venus_RT.Modules.Schedulers;
- using Venus_RT.Scheduler;
- namespace Venus_RT.Modules
- {
- public class ManualTransfer : IRoutine
- {
- SchedulerTMRobot _tmRobot = (SchedulerTMRobot)Singleton<TransferModule>.Instance.GetScheduler(ModuleName.TMRobot);
- SchedulerEfemRobot _efemRobot = (SchedulerEfemRobot)Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot);
- private Queue<MoveItem> _moveTaskQueue = new Queue<MoveItem>();
- private MoveItem _move_item = new MoveItem(ModuleName.System, 0, ModuleName.System, 0, Hand.None);
- private MoveItem _current_item = new MoveItem(ModuleName.System, 0, ModuleName.System, 0, Hand.None);
- private Guid _wafer_id;
- private R_TRIG _wafer_arrive_trig = new R_TRIG();
- private MovingStatus _moving_status = MovingStatus.Idle;
- private int _tmRobotSingleArmOption = 0;
- private int _efemRobotSingleArmOption = 0;
- public ManualTransfer()
- {
- _tmRobotSingleArmOption = SC.GetValue<int>("TM.SingleArmOption");
- _efemRobotSingleArmOption = SC.GetValue<int>("EFEM.SingleArmOption");
- }
- public RState Start(params object[] objs)
- {
- _tmRobotSingleArmOption = SC.GetValue<int>("TM.SingleArmOption");
- _efemRobotSingleArmOption = SC.GetValue<int>("EFEM.SingleArmOption");
- // rounding the single arm option
- if (_tmRobotSingleArmOption > 2)
- _tmRobotSingleArmOption = 0;
- if (_efemRobotSingleArmOption > 2)
- _efemRobotSingleArmOption = 0;
- // RESET
- _moveTaskQueue.Clear();
- _moving_status = MovingStatus.Idle;
- _wafer_arrive_trig.RST = true ;
- _move_item.SourceModule = (ModuleName)objs[0];
- _move_item.SourceSlot = (int)objs[1];
- _move_item.DestinationModule = (ModuleName)objs[2];
- _move_item.DestinationSlot = (int)objs[3];
- _wafer_id = WaferManager.Instance.GetWafer(_move_item.SourceModule, _move_item.SourceSlot).InnerId;
- if (ModuleHelper.IsLoadPort(_move_item.DestinationModule) && !Singleton<TransferModule>.Instance.GetScheduler(_move_item.DestinationModule).IsAvailable)
- {
- LOG.Write(eEvent.ERR_ROUTER, _move_item.DestinationModule, $"The destination Loadport {_move_item.DestinationModule} is not ready for move wafer.");
- return RState.Failed;
- }
- if (!CheckSingleArmOption(_move_item.DestinationModule, _move_item.DestinationSlot))
- return RState.Failed;
- if (!CheckSingleArmOption(_move_item.SourceModule, _move_item.SourceSlot))
- return RState.Failed;
- if (IsCrossTransfer(_move_item))
- {
- var slot = SelectLLFreeSlot();
- if (slot.Module == ModuleName.System)
- return RState.Failed;
- // vac to atm
- if (ModuleHelper.IsPm(_move_item.SourceModule) || ModuleHelper.IsTMRobot(_move_item.SourceModule))
- {
- _moveTaskQueue.Enqueue(new MoveItem(_move_item.SourceModule, _move_item.SourceSlot, slot.Module, slot.Slot, Hand.Blade1));
- if(ModuleHelper.IsEFEMRobot(_move_item.DestinationModule))
- {
- _moveTaskQueue.Enqueue(new MoveItem(slot.Module, slot.Slot, _move_item.DestinationModule, _move_item.DestinationSlot, (Hand)_move_item.DestinationSlot));
- }
- else
- {
- Hand hand = SelectEfemRobotFreeHand();
- if(hand == Hand.None)
- {
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.EfemRobot, "No free efem robot arm for wafer move.");
- return RState.Failed;
- }
- _moveTaskQueue.Enqueue(new MoveItem(slot.Module, slot.Slot, ModuleName.EfemRobot, (int)hand, hand));
- _moveTaskQueue.Enqueue(new MoveItem(ModuleName.EfemRobot, (int)hand, _move_item.DestinationModule, _move_item.DestinationSlot, hand));
- }
- }
- // atm to vac
- else
- {
- if (ModuleHelper.IsEFEMRobot(_move_item.SourceModule))
- {
- _moveTaskQueue.Enqueue(new MoveItem(_move_item.SourceModule, _move_item.SourceSlot, slot.Module, slot.Slot, (Hand)_move_item.SourceSlot));
- }
- else
- {
- Hand hand = SelectEfemRobotFreeHand();
- if (hand == Hand.None)
- {
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.EfemRobot, "No free efem robot arm for wafer move.");
- return RState.Failed;
- }
- _moveTaskQueue.Enqueue(new MoveItem(_move_item.SourceModule, _move_item.SourceSlot, ModuleName.EfemRobot, (int)hand, hand));
- _moveTaskQueue.Enqueue(new MoveItem(ModuleName.EfemRobot, (int)hand, slot.Module, slot.Slot, hand));
- }
- _moveTaskQueue.Enqueue(new MoveItem(slot.Module, slot.Slot, _move_item.DestinationModule, _move_item.DestinationSlot, Hand.Blade1));
- }
- }
- else if(IsVacTransfer(_move_item))
- {
- _moveTaskQueue.Enqueue(_move_item);
- }
- else // atm transfer
- {
- if(ModuleHelper.IsEFEMRobot(_move_item.SourceModule))
- {
- _moveTaskQueue.Enqueue(new MoveItem(_move_item.SourceModule, _move_item.SourceSlot, _move_item.DestinationModule, _move_item.DestinationSlot, (Hand)_move_item.SourceSlot));
- }
- else if (ModuleHelper.IsEFEMRobot(_move_item.DestinationModule))
- {
- _moveTaskQueue.Enqueue(new MoveItem(_move_item.SourceModule, _move_item.SourceSlot, _move_item.DestinationModule, _move_item.DestinationSlot, (Hand)_move_item.DestinationSlot));
- }
- else
- {
- Hand hand = SelectEfemRobotFreeHand();
- if (hand == Hand.None)
- {
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.EfemRobot, "No free efem robot arm for wafer move.");
- return RState.Failed;
- }
- _moveTaskQueue.Enqueue(new MoveItem(_move_item.SourceModule, _move_item.SourceSlot, ModuleName.EfemRobot, (int)hand, hand));
- _moveTaskQueue.Enqueue(new MoveItem(ModuleName.EfemRobot, (int)hand, _move_item.DestinationModule, _move_item.DestinationSlot, hand));
- }
- }
- _current_item = _moveTaskQueue.Dequeue();
- _moving_status = MovingStatus.Waiting;
- return RState.Running;
- }
- public RState Monitor()
- {
- return MoveWaferForward();
- }
- public void Abort()
- {
- }
- public void Clear()
- {
- _moveTaskQueue.Clear();
- Singleton<TransferModule>.Instance.GetScheduler(ModuleName.TMRobot).ResetTask();
- Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot).ResetTask();
- }
- private RState MoveWaferForward()
- {
- switch(_moving_status)
- {
- case MovingStatus.Waiting:
- {
- if(IsCurrentModuleReady())
- {
- // Post current item
- if(IsVacTransfer(_current_item))
- {
- _tmRobot.PostMoveItems(new MoveItem[1] { _current_item });
- }
- else
- {
- _efemRobot.PostMoveItems(new MoveItem[1] { _current_item });
- }
- _moving_status = MovingStatus.Moving;
- }
- }
- break;
- case MovingStatus.Moving:
- {
- _wafer_arrive_trig.CLK = IsArriveCurrentTarget();
- if (_wafer_arrive_trig.Q)
- {
- _moving_status = MovingStatus.Idle;
- }
- }
- break;
- case MovingStatus.Idle:
- {
- if(IsCurrentModuleReady())
- {
- if(_moveTaskQueue.Count > 0)
- {
- _current_item = _moveTaskQueue.Dequeue();
- _moving_status = MovingStatus.Waiting;
- }
- }
- break;
- }
- }
- return TransferStatus();
- }
- private bool IsVacTransfer(MoveItem item)
- {
- return ModuleHelper.IsPm(item.SourceModule) ||
- ModuleHelper.IsTMRobot(item.SourceModule) ||
- ModuleHelper.IsPm(item.DestinationModule) ||
- ModuleHelper.IsTMRobot(item.DestinationModule);
- }
- private bool IsCrossTransfer(MoveItem item)
- {
- if (ModuleHelper.IsLoadLock(item.DestinationModule) || ModuleHelper.IsLoadLock(item.SourceModule))
- return false;
- if (((ModuleHelper.IsPm(item.SourceModule) || ModuleHelper.IsTMRobot(item.SourceModule)) &&
- !ModuleHelper.IsPm(item.DestinationModule) && !ModuleHelper.IsTMRobot(item.DestinationModule)) ||
- ((ModuleHelper.IsPm(item.DestinationModule) || ModuleHelper.IsTMRobot(item.DestinationModule)) &&
- !ModuleHelper.IsPm(item.SourceModule) && !ModuleHelper.IsTMRobot(item.SourceModule)))
- return true;
- return false;
- }
- private bool IsArriveCurrentTarget()
- {
- var wafer = WaferManager.Instance.GetWafer(_current_item.DestinationModule, _current_item.DestinationSlot);
- return !wafer.IsEmpty && wafer.InnerId == _wafer_id;
- }
- private bool IsCurrentModuleReady()
- {
- return (IsVacTransfer(_current_item) ? _tmRobot.IsAvailable : _efemRobot.IsAvailable) &&
- _isModuleReady(_current_item.SourceModule) &&
- _isModuleReady(_current_item.DestinationModule);
- }
- private bool IsTransferError()
- {
- return (IsVacTransfer(_current_item) ? _tmRobot.IsError : _efemRobot.IsError) ||
- _isModuleError(_current_item.SourceModule) ||
- _isModuleError(_current_item.DestinationModule);
- }
- private bool _isModuleReady(ModuleName module)
- {
- return Singleton<TransferModule>.Instance.GetScheduler(module).IsAvailable;
- }
- private bool _isModuleError(ModuleName module)
- {
- return Singleton<TransferModule>.Instance.GetScheduler(module).IsError;
- }
- private Hand SelectEfemRobotFreeHand()
- {
- if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0))
- return Hand.Blade1;
- else if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1))
- return Hand.Blade2;
- else
- return Hand.None;
- }
- private SlotItem SelectLLFreeSlot()
- {
- foreach(var ll in new ModuleName[2] { ModuleName.LLA, ModuleName.LLB})
- {
- if (ModuleHelper.IsInstalled(ll) && _isModuleReady(ll))
- {
- for (int i = 0; i < 4; i++)
- {
- if (WaferManager.Instance.CheckNoWafer(ll, i))
- return new SlotItem(ll, i);
- }
- }
- }
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, "Cannot move wafer as no valid Loadlock slot");
- return new SlotItem(ModuleName.System, -1);
- }
- private RState TransferStatus()
- {
- if (IsTransferError())
- return RState.Failed;
- if (IsCurrentModuleReady() && _moveTaskQueue.Count == 0 && _moving_status == MovingStatus.Idle)
- return RState.End;
- return RState.Running;
- }
- private bool CheckSingleArmOption(ModuleName robot, int slot)
- {
- if(ModuleHelper.IsTMRobot(robot))
- {
- if (_tmRobotSingleArmOption != 0 && _tmRobotSingleArmOption != slot + 1)
- {
- LOG.Write(eEvent.ERR_ROUTER, ModuleName.TMRobot, $"Cannot move the wafer as TM Robot {(Hand)slot} is disabled.");
- return false;
- }
- }
- else if(ModuleHelper.IsEFEMRobot(robot))
- {
- if (_efemRobotSingleArmOption != 0 && _efemRobotSingleArmOption != slot + 1)
- {
- LOG.Write(eEvent.ERR_ROUTER, ModuleName.EfemRobot, $"Cannot move the wafer as EFEM Robot {(Hand)slot} is disabled.");
- return false;
- }
- }
- return true;
- }
- public int GetSingleArmOption(ModuleName robot)
- {
- return ModuleHelper.IsTMRobot(robot) ? _tmRobotSingleArmOption : _efemRobotSingleArmOption;
- }
- }
- public class ReturnAllWafer : IRoutine
- {
- private List<ModuleName> _moduleList = new List<ModuleName> { ModuleName.EfemRobot, ModuleName.Aligner1, ModuleName.Aligner, ModuleName.LLA, ModuleName.LLB, ModuleName.TMRobot, ModuleName.PMA, ModuleName.PMB, ModuleName.PMC, ModuleName.PMD };
- private ManualTransfer _manualTransfer;
- private Queue<MoveItem> _returnTaskQueue = new Queue<MoveItem>();
- private MoveItem _current_item;
- public ReturnAllWafer(ManualTransfer manualTransfer)
- {
- _manualTransfer = manualTransfer;
- }
- public RState Start(params object[] objs)
- {
- Singleton<TransferModule>.Instance.GetScheduler(ModuleName.TMRobot).ResetTask();
- Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot).ResetTask();
- foreach(var mod in _moduleList)
- {
- if (ModuleHelper.IsInstalled(mod) && Singleton<TransferModule>.Instance.GetScheduler(mod).IsAvailable)
- {
- if (ModuleHelper.IsEFEMRobot(mod) || ModuleHelper.IsTMRobot(mod))
- {
- if (_manualTransfer.GetSingleArmOption(mod) != 2)
- PushWaferToReturnQueqe(mod, 0);
- if (_manualTransfer.GetSingleArmOption(mod) != 1)
- PushWaferToReturnQueqe(mod, 1);
- }
- else if (ModuleHelper.IsLoadLock(mod))
- {
- int nSlotNumber = SC.GetValue<int>($"{mod}.SlotNumber");
- for (int i = 0; i < nSlotNumber; i++)
- {
- PushWaferToReturnQueqe(mod, i);
- }
- }
- else
- {
- PushWaferToReturnQueqe(mod, 0);
- }
- }
- }
- if (_returnTaskQueue.Count == 0)
- return RState.Failed;
- _current_item = _returnTaskQueue.Dequeue();
- _manualTransfer.Start(_current_item.SourceModule, _current_item.SourceSlot, _current_item.DestinationModule, _current_item.DestinationSlot);
- return RState.Running;
- }
- public RState Monitor()
- {
- var ret = _manualTransfer.Monitor();
- if (ret == RState.End)
- {
- if (_returnTaskQueue.Count > 0)
- {
- _current_item = _returnTaskQueue.Dequeue();
- _manualTransfer.Start(_current_item.SourceModule, _current_item.SourceSlot, _current_item.DestinationModule, _current_item.DestinationSlot);
- }
- else
- return RState.End;
- }
- else if (ret == RState.Failed || ret == RState.Timeout)
- {
- LOG.Write(eEvent.ERR_ROUTINE_FAILED, ModuleName.System,"Manual Transfer", $"Return Wafer {_current_item.SourceModule}{_current_item.SourceSlot} failed");
- return RState.Failed;
- }
- return RState.Running;
- }
- public void Abort()
- {
- }
- public void Clear()
- {
- _returnTaskQueue.Clear();
- Singleton<TransferModule>.Instance.GetScheduler(ModuleName.TMRobot).ResetTask();
- Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot).ResetTask();
- }
- private void PushWaferToReturnQueqe(ModuleName mod, int nSlot)
- {
- var wafer = WaferManager.Instance.GetWafer(mod, nSlot);
- if (!wafer.IsEmpty)
- {
- _returnTaskQueue.Enqueue(new MoveItem(mod, nSlot, (ModuleName)wafer.OriginStation, wafer.OriginSlot, Hand.Blade1));
- }
- }
- }
- }
|