123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780 |
- using System;
- using System.Collections.Generic;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Routine;
- 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;
- using Aitex.Core.RT.SCCore;
- using System.Linq;
- using Aitex.Core.Util;
- namespace EfemDualSchedulerLib
- {
- internal interface IManualTransferRoutine : IRoutine
- {
- }
- public class MoveItemEx : MoveItem
- {
- public int CoolingTime { get; set; }
- public MoveItemEx(ModuleName sourceModule, int sourceSlot, ModuleName destinationModule, int destinationSlot, int coolingTime)
- : base(sourceModule, sourceSlot, destinationModule, destinationSlot, Hand.Blade1)
- {
- CoolingTime = coolingTime;
- }
- }
- public class ManualTransfer : SchedulerModuleFactory, IRoutine
- {
- private ModuleName[] _llBuffers = null;
- private Queue<IRoutine> _moveTaskQueue = new Queue<IRoutine>();
- private IRoutine _activeTask;
- public ManualTransfer(EquipmentManager equipment)
- {
- _llBuffers = new ModuleName[] { ModuleName.LLA, ModuleName.LLB }.Where(p=>ModuleHelper.IsInstalled(p)).ToArray();
- }
- public Result Start(object[] objs)
- {
- _moveTaskQueue.Clear();
- ModuleName source = (ModuleName)objs[0];
- int ss = (int)objs[1];
- ModuleName target = (ModuleName)objs[2];
- int ds = (int)objs[3];
- //bool autoAlign = (bool)objs[4];
- //int alignAngle = (int)objs[5];
- bool autoAlign = false;
- bool autoCooling = (bool)objs[6];
- int coolingTime = (int)objs[7];
- if (!WaferManager.Instance.CheckHasWafer(source, ss))
- {
- EV.PostWarningLog("System", "source no wafer");
- return Result.FAIL;
- }
- if (ModuleHelper.IsTMRobot(target))
- {
- if (!Converter.MapBladeToSlots(Converter.MapSlotToHand(ds)).All(p=> WaferManager.Instance.CheckNoWafer(target,p)))
- {
- EV.PostWarningLog("System", "destination has wafer");
- return Result.FAIL;
- }
- }
- else
- {
- if (!WaferManager.Instance.CheckNoWafer(target, ds))
- {
- EV.PostWarningLog("System", "destination has wafer");
- return Result.FAIL;
- }
- }
-
- if (CheckNeedEfemRobot(source, target) && !_efem.Blade1Enable && !_efem.Blade2Enable)
- {
- EV.PostWarningLog("System", "EFEM robot both disabled");
- return Result.FAIL;
- }
- if (CheckNeedEfemRobot(source, target)
- && (!ModuleHelper.IsEfemRobot(source) && !ModuleHelper.IsEfemRobot(target))
- && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0)
- && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1))
- {
- EV.PostWarningLog("System", "EFEM robot has wafer");
- return Result.FAIL;
- }
- if (CheckNeedTMRobot(source, target) && !_tmRobot.Blade1Enable && !_tmRobot.Blade2Enable)
- {
- EV.PostWarningLog("System", "TM robot both disabled");
- return Result.FAIL;
- }
- if (CheckNeedTMRobot(source, target)
- && (!ModuleHelper.IsTMRobot(source) && !ModuleHelper.IsTMRobot(target))
- && Converter.MapBladeToSlots(Hand.Blade1).Any(p=>WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, p))
- && Converter.MapBladeToSlots(Hand.Blade2).Any(p=>WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, p)))
- {
- EV.PostWarningLog("System", "TM robot has wafer");
- return Result.FAIL;
- }
- if (CheckNeedEfemRobot(source, target) && CheckNeedTMRobot(source, target))
- {
- var emptyLoadLockSlot = GetEmptyLoadLockSlot(source, ss, target, ds);
- if (emptyLoadLockSlot == null)
- {
- EV.PostWarningLog("System", "Can not transfer, LoadLock has full wafer");
- return Result.FAIL;
- }
- if (!GetEmptyCooling())
- {
- EV.PostWarningLog("System", "Can not transfer, Cooling is busy");
- return Result.FAIL;
- }
- if (ModuleHelper.IsPm(source) || ModuleHelper.IsTMRobot(source))
- {
- _moveTaskQueue.Enqueue(new TMRobotMover(new MoveItemEx(source, ss, emptyLoadLockSlot.Item1, emptyLoadLockSlot.Item2, 0)));
- if (autoCooling)
- {
- _moveTaskQueue.Enqueue(new EfemRobotMover(new MoveItemEx(emptyLoadLockSlot.Item1, emptyLoadLockSlot.Item2, ModuleName.Cooling1, 0, 0)));
- _moveTaskQueue.Enqueue(new EfemRobotMover(new MoveItemEx(ModuleName.Cooling1, 0, target, ds, coolingTime)));
- }
- else
- {
- _moveTaskQueue.Enqueue(new EfemRobotMover(new MoveItemEx(emptyLoadLockSlot.Item1, emptyLoadLockSlot.Item2, target, ds, 0)));
- }
- }
- else
- {
- _moveTaskQueue.Enqueue(new EfemRobotMover(new MoveItemEx(source, ss, emptyLoadLockSlot.Item1, emptyLoadLockSlot.Item2, 0)));
- _moveTaskQueue.Enqueue(new TMRobotMover(new MoveItemEx(emptyLoadLockSlot.Item1, emptyLoadLockSlot.Item2, target, ds, 0)));
- }
- }
- else if (CheckNeedEfemRobot(source, target))
- {
- if (autoAlign)
- {
- _moveTaskQueue.Enqueue(new EfemRobotMover(new MoveItemEx(source, ss, ModuleName.Aligner, 0, 0)));
- _moveTaskQueue.Enqueue(new EfemRobotMover(new MoveItemEx(ModuleName.Aligner, 0, target, ds, 0)));
- }
- else
- {
- _moveTaskQueue.Enqueue(new EfemRobotMover(new MoveItemEx(source, ss, target, ds, 0)));
- }
- }
- else if (CheckNeedTMRobot(source, target))
- {
- _moveTaskQueue.Enqueue(new TMRobotMover(new MoveItemEx(source, ss, target, ds, 0)));
- }
- _activeTask = _moveTaskQueue.Dequeue();
- return _activeTask.Start();
- }
- public Result Monitor()
- {
- System.Diagnostics.Debug.Assert(_activeTask != null, "mover should not be null, call start first");
- Result ret = _activeTask.Monitor();
- if (ret == Result.FAIL)
- return ret;
- if (ret == Result.DONE)
- {
- if (_moveTaskQueue.Count > 0)
- {
- _activeTask = _moveTaskQueue.Dequeue();
- return _activeTask.Start();
- }
- return Result.DONE;
- }
- return Result.RUN;
- }
- public void Clear()
- {
- _moveTaskQueue.Clear();
- _activeTask = null;
- }
- public void Abort()
- {
- }
- public bool CheckNeedEfemRobot(ModuleName source, ModuleName target)
- {
- if (ModuleHelper.IsLoadPort(source) || ModuleHelper.IsLoadPort(target))
- {
- return true;
- }
- if (ModuleHelper.IsEfemRobot(source) || ModuleHelper.IsEfemRobot(target))
- {
- return true;
- }
- if (ModuleHelper.IsAligner(source) || ModuleHelper.IsAligner(target))
- {
- return true;
- }
- if (ModuleHelper.IsCooling(source) || ModuleHelper.IsCooling(target))
- {
- return true;
- }
- if (ModuleHelper.IsLoadLock(source) || ModuleHelper.IsLoadLock(target))
- {
- if (!CheckNeedTMRobot(source, target))
- return true;
- }
- return false;
- }
- public bool CheckNeedTMRobot(ModuleName source, ModuleName target)
- {
- if (ModuleHelper.IsPm(source) || ModuleHelper.IsPm(target))
- {
- return true;
- }
- if (ModuleHelper.IsTMRobot(source) || ModuleHelper.IsTMRobot(target))
- {
- return true;
- }
- return false;
- }
- public Tuple<ModuleName, int> GetEmptyLoadLockSlot(ModuleName source, int sourceSlot, ModuleName target, int targetSlot )
- {
- Tuple<ModuleName, int> targetModule = null;
- Array.ForEach(_llBuffers, p =>
- {
- var wafers = WaferManager.Instance.GetWafers(p);
- for (int i = 0; i < wafers.Length; i++)
- {
- if (!wafers[i].IsEmpty) continue;
- if (!SC.IsDoubleFork ||
- (ModuleHelper.IsPm(target) && ((targetSlot % 2 > 0 && i % 2 > 0) || (targetSlot % 2 == 0 && i % 2 == 0))) ||
- (ModuleHelper.IsPm(source) && ((sourceSlot % 2 > 0 && i % 2 > 0) || (sourceSlot % 2 == 0 && i % 2 == 0))) ||
- (ModuleHelper.IsTMRobot(source) && ((sourceSlot > 1 && i % 2 > 0) || (sourceSlot <= 1 && i % 2 == 0))) ||
- (ModuleHelper.IsTMRobot(target) && ((targetSlot > 1 && i % 2 > 0) || (targetSlot <= 1 && i % 2 == 0)))
- )
- {
- targetModule = new Tuple<ModuleName, int>(p, i);
- break;
- }
- }
- if (targetModule != null) return;
- });
- return targetModule;
- }
- public bool GetEmptyCooling()
- {
- var coolingList = new ModuleName[] { ModuleName.Cooling1, ModuleName.Cooling2 }.Where(p => SC.GetValueOrDefault<bool>($"System.SetUp.{p.ToString()}.IsInstalled")).ToArray();
- if (coolingList == null || coolingList.Length == 0 || coolingList.Any(p => WaferManager.Instance.CheckNoWafer(p, 0))) return true;
- return false;
- }
- }
- public class EfemRobotMover : SchedulerModuleFactory, IRoutine
- {
- private MoveItemEx _moveTask;
- private SchedulerModule _source;
- private SchedulerModule _destination;
- public EfemRobotMover(MoveItemEx moveTask)
- {
- _moveTask = moveTask;
- }
- public Result Start()
- {
- _source = GetModule(_moveTask.SourceModule.ToString());
- _destination = GetModule(_moveTask.DestinationModule.ToString());
- System.Diagnostics.Debug.Assert(_source != null, $"{_moveTask.SourceModule} not valid");
- System.Diagnostics.Debug.Assert(_destination != null, $"{_moveTask.DestinationModule} not valid");
- if (!_source.HasWafer(_moveTask.SourceSlot))
- {
- EV.PostWarningLog("System", $"Failed transfer, source {_moveTask.SourceModule} slot {_moveTask.SourceSlot + 1} has not wafer");
- return Result.FAIL;
- }
- if (!_destination.NoWafer(_moveTask.DestinationSlot))
- {
- EV.PostWarningLog("System", $"Failed transfer, destination {_moveTask.DestinationModule} slot {_moveTask.DestinationSlot + 1} has wafer");
- return Result.FAIL;
- }
- if (!_source.IsOnline)
- {
- EV.PostWarningLog("System", $"Failed transfer, source {_moveTask.SourceModule} should be put online");
- return Result.FAIL;
- }
- if (!_source.IsAvailable)
- {
- EV.PostWarningLog("System", $"Failed transfer, source {_moveTask.SourceModule} in busy status");
- return Result.FAIL;
- }
- if (!_destination.IsOnline)
- {
- EV.PostWarningLog("System", $"Failed transfer, Destination {_moveTask.DestinationModule} should be put online");
- return Result.FAIL;
- }
- if (!_destination.IsAvailable)
- {
- EV.PostWarningLog("System", $"Failed transfer, Destination {_moveTask.DestinationModule} in busy status");
- return Result.FAIL;
- }
- if (!_efem.IsAvailable)
- {
- EV.PostWarningLog("System", $"Failed transfer, EFEM Robot is busy");
- return Result.FAIL;
- }
- if (ModuleHelper.IsCooling(_source.Module))
- _source.Cooling(_moveTask.CoolingTime);
- if (ModuleHelper.IsEfem(_source.Module) || ModuleHelper.IsEfemRobot(_source.Module))
- {
- _moveTask.RobotHand = (Hand)_moveTask.SourceSlot;
- }
- else if (ModuleHelper.IsEfem(_destination.Module) || ModuleHelper.IsEfemRobot(_destination.Module))
- {
- _moveTask.RobotHand = (Hand)_moveTask.DestinationSlot;
- }
- else
- {
- _moveTask.RobotHand = GetAvailableHand(ModuleName.EfemRobot);
- }
- return Result.RUN;
- }
- public Result Start(params object[] objs)
- {
- return this.Start();
- }
- public Result Monitor()
- {
- if (_source.NoWafer(_moveTask.SourceSlot) && _destination.HasWafer(_moveTask.DestinationSlot) &&
- _efem.IsAvailable)
- {
- if (_source.IsWaitTransfer(ModuleName.EfemRobot))
- _source.StopWaitTransfer(ModuleName.EfemRobot);
- if (_destination.IsWaitTransfer(ModuleName.EfemRobot))
- _destination.StopWaitTransfer(ModuleName.EfemRobot);
- return Result.DONE;
- }
- if (_source.IsError || _destination.IsError || _efem.IsError)
- return Result.FAIL;
- if (!_efem.IsAvailable)
- return Result.RUN;
- //pick
- if (_moveTask.SourceModule != ModuleName.EfemRobot)
- {
- if (_source.HasWafer(_moveTask.SourceSlot))
- {
- if (!_source.IsAvailable)
- return Result.RUN;
- if (!_source.IsReadyForPick(ModuleName.EfemRobot, GetAvailableHand(ModuleName.EfemRobot), _moveTask.SourceSlot))
- {
- if (!_source.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, new int[] { _moveTask.SourceSlot }))
- return Result.FAIL;
- }
- if (!_source.IsAvailable)
- return Result.RUN;
- if (!_efem.HasWafer((int)_moveTask.RobotHand))
- {
- if (!_efem.Pick(_moveTask.SourceModule, _moveTask.SourceSlot, _moveTask.RobotHand))
- {
- return Result.FAIL;
- }
- _source.WaitTransfer(ModuleName.EfemRobot);
- }
- if (!_efem.IsAvailable)
- return Result.RUN;
- }
- else
- {
- if (!_efem.IsAvailable)
- return Result.RUN;
- if (_source.IsWaitTransfer(ModuleName.EfemRobot))
- _source.StopWaitTransfer(ModuleName.EfemRobot);
- }
- }
- //place
- if (_moveTask.DestinationModule != ModuleName.EfemRobot)
- {
- if (!_destination.IsAvailable)
- return Result.RUN;
- if (_destination.NoWafer(_moveTask.DestinationSlot))
- {
- if (!_destination.IsReadyForPlace(ModuleName.EfemRobot, _moveTask.RobotHand, _moveTask.DestinationSlot))
- {
- if (!_destination.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place,
- new int[] { _moveTask.DestinationSlot }))
- return Result.FAIL;
- }
- if (!_destination.IsAvailable)
- return Result.RUN;
- if (_efem.HasWafer((int)_moveTask.RobotHand))
- {
- if (!_efem.Place(_moveTask.DestinationModule, _moveTask.DestinationSlot, _moveTask.RobotHand))
- return Result.FAIL;
- _destination.WaitTransfer(ModuleName.EfemRobot);
- }
- if (!_efem.IsAvailable)
- return Result.RUN;
- }
- else
- {
- if (!_efem.IsAvailable)
- return Result.RUN;
- if (_destination.IsWaitTransfer(ModuleName.EfemRobot))
- _destination.StopWaitTransfer(ModuleName.EfemRobot);
- }
- }
- return Result.RUN;
- }
- public void Abort()
- {
- Clear();
- }
- public void Clear()
- {
- _efem.ResetTask();
- _source?.ResetTask();
- _destination?.ResetTask();
- }
- public Hand GetAvailableHand(ModuleName module)
- {
- var wafers = WaferManager.Instance.GetWafers(module);
- return _efem.Blade1Enable && wafers[0].IsEmpty ? Hand.Blade1 : Hand.Blade2;
- }
- }
- public class TMRobotMover : SchedulerModuleFactory, IRoutine
- {
- private MoveItem _moveTask;
- private SchedulerModule _source;
- private SchedulerModule _destination;
- private bool _pmaIsInstalled;
- private bool _pmbIsInstalled;
- private Dictionary<int, Hand> _slotMapToHand = new Dictionary<int, Hand>()
- {
- {(int)ArmBlade.ArmAFork0, Hand.Blade1},
- {(int)ArmBlade.ArmBFork1,Hand.Blade2 },
- {(int)ArmBlade.ArmAFork2, Hand.Blade1},
- {(int)ArmBlade.ArmBFork3,Hand.Blade2}
- };
- public TMRobotMover(MoveItem moveTask)
- {
- _moveTask = moveTask;
- _pmaIsInstalled = SC.GetValueOrDefault<bool>($"System.SetUp.{ModuleName.PMA}.IsInstalled");
- _pmbIsInstalled = SC.GetValueOrDefault<bool>($"System.SetUp.{ModuleName.PMB}.IsInstalled");
- }
- public Result Start()
- {
- _source = GetModule(_moveTask.SourceModule.ToString());
- _destination = GetModule(_moveTask.DestinationModule.ToString());
- System.Diagnostics.Debug.Assert(_source != null, $"{_moveTask.SourceModule} not valid");
- System.Diagnostics.Debug.Assert(_destination != null, $"{_moveTask.DestinationModule} not valid");
- if(SC.IsDoubleFork)
- {
- if(ModuleHelper.IsTM(_source.Module) && ModuleHelper.IsTM(_destination.Module))
- {
- EV.PostWarningLog("System", $"Failed transfer, source slot wafer can't move to target slot ");
- return Result.FAIL;
- }
- if(ModuleHelper.IsTM(_source.Module) || ModuleHelper.IsTM(_destination.Module))
- {
- var tmSlot = ModuleHelper.IsTM(_source.Module) ? _moveTask.SourceSlot : _moveTask.DestinationSlot;
- var sourceOrTarget = ModuleHelper.IsTM(_source.Module) ? _moveTask.DestinationSlot : _moveTask.SourceSlot;
- if ((tmSlot < 2 && (sourceOrTarget % 2) > 0) || (tmSlot > 1 && (sourceOrTarget % 2) == 0))
- {
- EV.PostWarningLog("System", $"Failed transfer, source slot wafer can't move to target slot ");
- return Result.FAIL;
- }
- }
- else
- {
- if ((((_moveTask.SourceSlot % 2) == 0 && (_moveTask.DestinationSlot % 2) > 0)
- || ((_moveTask.SourceSlot % 2) > 0 && (_moveTask.DestinationSlot % 2) == 0)))
- {
- EV.PostWarningLog("System", $"Failed transfer, source slot wafer can't move to target slot ");
- return Result.FAIL;
- }
- }
- }
- if (!_source.HasWafer(_moveTask.SourceSlot))
- {
- EV.PostWarningLog("System", $"Failed transfer, source {_moveTask.SourceModule} slot {_moveTask.SourceSlot + 1} has not wafer");
- return Result.FAIL;
- }
- if (!_destination.NoWafer(_moveTask.DestinationSlot))
- {
- EV.PostWarningLog("System", $"Failed transfer, destination {_moveTask.DestinationModule} slot {_moveTask.DestinationSlot + 1} has wafer");
- return Result.FAIL;
- }
- if(SC.IsDoubleFork && _moveTask.DestinationModule != ModuleName.TMRobot )
- {
- var leftOrRightSlot = (_moveTask.DestinationSlot % 2 > 0) ? _moveTask.DestinationSlot-1 : _moveTask.DestinationSlot+1;
- if (!_destination.NoWafer(leftOrRightSlot))
- {
- EV.PostWarningLog("System", $"Failed transfer, destination {_moveTask.DestinationModule} slot {leftOrRightSlot + 1} has wafer");
- return Result.FAIL;
- }
- }
- if (!_source.IsOnline)
- {
- EV.PostWarningLog("System", $"Failed transfer, source {_moveTask.SourceModule} should be put online");
- return Result.FAIL;
- }
- if (!_source.IsAvailable)
- {
- EV.PostWarningLog("System", $"Failed transfer, source {_moveTask.SourceModule} in busy status");
- return Result.FAIL;
- }
- if (!_destination.IsOnline)
- {
- EV.PostWarningLog("System", $"Failed transfer, Destination {_moveTask.DestinationModule} should be put online");
- return Result.FAIL;
- }
- if (!_destination.IsAvailable)
- {
- EV.PostWarningLog("System", $"Failed transfer, Destination {_moveTask.DestinationModule} in busy status");
- return Result.FAIL;
- }
- if (!_tmRobot.IsAvailable)
- {
- EV.PostWarningLog("System", $"Failed transfer, TM Robot is busy");
- return Result.FAIL;
- }
- if (ModuleHelper.IsTM(_source.Module) || ModuleHelper.IsTMRobot(_source.Module))
- {
- _moveTask.RobotHand = _slotMapToHand[_moveTask.SourceSlot];
- }
- else if (ModuleHelper.IsTM(_destination.Module) || ModuleHelper.IsTMRobot(_destination.Module))
- {
- _moveTask.RobotHand = _slotMapToHand[_moveTask.DestinationSlot];
- }
- else
- {
- _moveTask.RobotHand = GetAvailableHand(ModuleName.TMRobot);
- }
- return Result.RUN;
- }
- public Result Start(params object[] objs)
- {
- return this.Start();
- }
- public Result Monitor()
- {
- if (_source.NoWafer(_moveTask.SourceSlot) && _destination.HasWafer(_moveTask.DestinationSlot) &&
- _tmRobot.IsAvailable)
- {
- if (_source.IsWaitTransfer(ModuleName.TMRobot))
- _source.StopWaitTransfer(ModuleName.TMRobot);
- if (_destination.IsWaitTransfer(ModuleName.TMRobot))
- _destination.StopWaitTransfer(ModuleName.TMRobot);
- if (ModuleHelper.IsPm(_moveTask.SourceModule) || ModuleHelper.IsPm(_moveTask.DestinationModule))
- {
- if (_pmaIsInstalled && !_pm1.CheckSlitValveClose())
- _pm1.CloseSlitValve();
- if (_pmbIsInstalled && !_pm2.CheckSlitValveClose())
- _pm2.CloseSlitValve();
- }
- return Result.DONE;
- }
- if (_source.IsError || _destination.IsError || _tmRobot.IsError)
- return Result.FAIL;
- if (!_tmRobot.IsAvailable)
- return Result.RUN;
- //pick
- if (_moveTask.SourceModule != ModuleName.TMRobot)
- {
- if (_source.HasWafer(_moveTask.SourceSlot))
- {
- if (!_source.IsAvailable)
- return Result.RUN;
- List<int> sourceSlots = new List<int>() { _moveTask.SourceSlot };
- if(SC.IsDoubleFork)
- {
- var nextPickSlot = (_moveTask.SourceSlot % 2) > 0 ? _moveTask.SourceSlot - 1 : _moveTask.SourceSlot + 1;
- if (_source.HasWafer(nextPickSlot))
- {
- sourceSlots.Add(nextPickSlot);
- }
- }
- var isReadyForPick = sourceSlots.All(p => _source.IsReadyForPick(ModuleName.TMRobot, _moveTask.RobotHand, p));
- if(!isReadyForPick && !_source.PrepareTransfer(ModuleName.TMRobot, EnumTransferType.Pick, sourceSlots.ToArray()))
- return Result.FAIL;
- if (!_source.IsAvailable)
- return Result.RUN;
- if (!_tmRobot.HasWafer((int)_moveTask.RobotHand))
- {
- if (!_tmRobot.Pick(_moveTask.SourceModule, sourceSlots.ToArray(), _moveTask.RobotHand, Converter.GetPanAndSlotFromPick(_moveTask.RobotHand, sourceSlots.ToArray()).Item1, 0, 0, true))
- {
- return Result.FAIL;
- }
- _source.WaitTransfer(ModuleName.TMRobot);
- }
- if (!_tmRobot.IsAvailable)
- return Result.RUN;
- }
- else
- {
- if (!_tmRobot.IsAvailable)
- return Result.RUN;
- if (_source.IsWaitTransfer(ModuleName.TMRobot))
- _source.StopWaitTransfer(ModuleName.TMRobot);
- }
- }
- //place
- if (_moveTask.DestinationModule != ModuleName.TMRobot)
- {
- if (!_destination.IsAvailable)
- return Result.RUN;
- if (_destination.NoWafer(_moveTask.DestinationSlot))
- {
- var sourceSlots = GetHandSlotsByWafer(_moveTask.RobotHand);
- List<int> targetSlots = new List<int>() { _moveTask.DestinationSlot };
- if (SC.IsDoubleFork)
- {
- var nextPlacekSlot = (_moveTask.DestinationSlot % 2) > 0 ? _moveTask.DestinationSlot - 1 : _moveTask.DestinationSlot + 1;
- if (_destination.HasWafer(nextPlacekSlot))
- {
- return Result.FAIL;
- }
- if (sourceSlots.Length > 1) targetSlots.Add(nextPlacekSlot);
- }
- var isReadyForPlace = targetSlots.All(p => _destination.IsReadyForPlace(ModuleName.TMRobot, _moveTask.RobotHand, p));
- if (!isReadyForPlace && !_destination.PrepareTransfer(ModuleName.TMRobot, EnumTransferType.Place, targetSlots.ToArray()))
- return Result.FAIL;
- if (!_destination.IsAvailable)
- return Result.RUN;
- if (sourceSlots.Length > 0 && targetSlots.Count>0)
- {
- if (!_tmRobot.Place(_moveTask.DestinationModule, targetSlots.ToArray(), _moveTask.RobotHand, Converter.GetPanAndSlotFromPlace(_moveTask.RobotHand).Item1, 0, 0, true))
- return Result.FAIL;
- _destination.WaitTransfer(ModuleName.TMRobot);
- }
- if (!_tmRobot.IsAvailable)
- return Result.RUN;
- }
- else
- {
- if (!_tmRobot.IsAvailable)
- return Result.RUN;
- if (_destination.IsWaitTransfer(ModuleName.TMRobot))
- _destination.StopWaitTransfer(ModuleName.TMRobot);
- }
- }
- return Result.RUN;
- }
- private int[] GetHandSlotsByWafer(Hand hand)
- {
- var forkSlots = new int[] { (int)hand, ((int)hand) + 2 };
- var sourceSlots = new List<int>();
- foreach (var forkSlot in forkSlots)
- {
- var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, forkSlot);
- if (wafer != null && !wafer.IsEmpty) sourceSlots.Add(forkSlot);
- }
- return sourceSlots.ToArray();
- }
- public void Abort()
- {
- Clear();
- }
- public void Clear()
- {
- _tmRobot.ResetTask();
- _source?.ResetTask();
- _destination?.ResetTask();
- }
- public Hand GetAvailableHand(ModuleName module)
- {
- if (_tmRobot.Blade1Enable && Converter.MapBladeToSlots(Hand.Blade1).All(p=> WaferManager.Instance.CheckNoWafer(module, p))) return Hand.Blade1;
- return Hand.Blade2;
- }
- }
- }
|