123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472 |
- using System;
- 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.EquipmentLibrary.LogicUnits;
- using MECF.Framework.RT.ModuleLibrary.PMModules;
- using MECF.Framework.RT.ModuleLibrary.SystemModules;
- namespace JetMainframe.TMs
- {
- public class TMPickAndPlaceRoutine : ModuleRoutine, IRoutine
- {
- enum RoutineStep
- {
- CheckBeforePick,
- PickWafer,
- UpdateWaferInfoToHand,
- CheckBeforePlace,
- PlaceWafer,
- UpdateWaferInfoToTarget,
- PostTransfer,
- }
- private TMModule _robotModule;
- private ITransferTarget _target;
- private Hand _pickBlade;
- private Hand _placeBlade;
- private ModuleName _targetModule;
- private int _pickSlot;
- private int _placeSlot;
- private int _pickTimeout;
- private int _placeTimeout;
- private int _postTransferTimeout;
- public TMPickAndPlaceRoutine(TMModule robotModule)
- {
- Module = "TM";
- Name = "PickAndPlace";
- _robotModule = robotModule;
- }
- public Result Start(params object[] objs)
- {
- _pickTimeout = SC.GetValue<int>("TM.TMRobot.PickTimeout");
- _placeTimeout = SC.GetValue<int>("TM.TMRobot.PlaceTimeout");
- if (ModuleHelper.IsPm(_targetModule))
- {
- _postTransferTimeout = SC.GetValue<int>($"PM.PostTransferTimeout");
- }
- Reset();
- if (!WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_pickBlade))
- {
- EV.PostWarningLog(Module, $"Can not pick by {_pickBlade}, found wafer on");
- return Result.FAIL;
- }
- if (!WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_placeBlade))
- {
- EV.PostWarningLog(Module, $"Can not place by {_placeBlade}, no wafer on");
- return Result.FAIL;
- }
- if (_pickSlot != _placeSlot)
- {
- if (!WaferManager.Instance.CheckHasWafer(_targetModule, _pickSlot))
- {
- EV.PostWarningLog(Module, $"Can not pick from {_targetModule} slot {_pickSlot + 1}, no wafer on");
- return Result.FAIL;
- }
- if (!WaferManager.Instance.CheckNoWafer(_targetModule, _placeSlot))
- {
- EV.PostWarningLog(Module, $"Can not place to {_targetModule} slot {_placeSlot + 1}, found wafer on");
- return Result.FAIL;
- }
- }
- else
- {
- if (!WaferManager.Instance.CheckHasWafer(_targetModule, _placeSlot))
- {
- {
- EV.PostWarningLog(Module, $"Can not pick&place from {_targetModule} slot {_placeSlot + 1}, no wafer on");
- return Result.FAIL;
- }
- }
- }
- Notify($"Start, swap wafer,pick: {_pickBlade} slot {_pickSlot + 1}, place: {_placeBlade} slot {_placeSlot + 1}");
- return Result.RUN;
- }
- public void Init(ModuleName targetModule, Hand pickBlade, int pickSlot, Hand placeBlade, int placeSlot)
- {
- _pickBlade = pickBlade;
- _placeBlade = placeBlade;
- _targetModule = targetModule;
- _pickSlot = pickSlot;
- _placeSlot = placeSlot;
- _target = EquipmentManager.Modules[targetModule] as ITransferTarget;
- }
- public void Abort()
- {
- if (_target != null)
- {
- _target.NoteTransferStop(ModuleName.TMRobot, Hand.Blade1, 0, EnumTransferType.Pick);
- }
- _target = null;
- Notify("Abort");
- }
- public Result Monitor()
- {
- try
- {
- CheckBeforePick((int)RoutineStep.CheckBeforePick, _targetModule, _pickSlot, _pickBlade);
- PickWafer((int)RoutineStep.PickWafer, _targetModule, _pickSlot, _pickBlade, _pickTimeout);
- UpdateWaferInfoToHand((int)RoutineStep.UpdateWaferInfoToHand, _targetModule, _pickSlot, _pickBlade);
- CheckBeforePlace((int)RoutineStep.CheckBeforePlace, _targetModule, _placeSlot, _placeBlade);
- PlaceWafer((int)RoutineStep.PlaceWafer, _targetModule, _placeSlot, _placeBlade, _pickTimeout);
- UpdateWaferInfoToTarget((int)RoutineStep.UpdateWaferInfoToTarget, _targetModule, _placeSlot, _placeBlade);
-
- if (ModuleHelper.IsPm(_targetModule))
- {
- PostTransfer((int)RoutineStep.PostTransfer, _target as PMModuleBase, EnumTransferType.Place, _postTransferTimeout);
- }
- }
- catch (RoutineBreakException)
- {
- return Result.RUN;
- }
- catch (RoutineFaildException)
- {
- return Result.FAIL;
- }
- _target.NoteTransferStop(ModuleName.TMRobot, Hand.Blade1, 0, EnumTransferType.Pick);
- Notify($"complete, swap wafer,pick: {_pickBlade} slot {_pickSlot + 1}, place: {_placeBlade} slot {_placeSlot + 1}");
- return Result.DONE;
- }
- public void CheckBeforePick(int id, ModuleName source, int slot, Hand blade)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- Notify("Check pick is enabled");
- string reason = string.Empty;
- if (!_target.CheckReadyForTransfer(ModuleName.TMRobot, blade, slot, EnumTransferType.Pick, out reason))
- {
- Stop(reason);
- return false;
- }
- if (blade == Hand.Blade1)
- {
- if (!WaferManager.Instance.CheckHasWafer(source, slot))
- {
- Stop("Source no wafer");
- return false;
- }
- if (!WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0))
- {
- Stop("Blade has wafer");
- return false;
- }
- }
- else if (blade == Hand.Blade2)
- {
- if (!WaferManager.Instance.CheckHasWafer(source, slot))
- {
- Stop("Source no wafer");
- return false;
- }
- if (!WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
- {
- Stop("Blade has wafer");
- return false;
- }
- }
- else
- {
- for (int i = 0; i < 2; i++)
- {
- if (!WaferManager.Instance.CheckHasWafer(source, slot + i))
- {
- Stop("Source no wafer");
- return false;
- }
- if (!WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, i))
- {
- Stop("Blade has wafer");
- return false;
- }
- }
- }
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw new RoutineFaildException();
- }
- }
- }
- public void PickWafer(int id, ModuleName chamber, int slot, Hand hand, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify("robot execute pick command");
- _target.NoteTransferStart(ModuleName.TMRobot, hand, slot, EnumTransferType.Pick);
- //string reason;
- //if (!_robotModule.RobotDevice.Pick(chamber, hand, slot, out reason))
- //{
- // Stop(reason);
- // return false;
- //}
- return true;
- }, () =>
- {
- if (_robotModule.RobotDevice.IsError)
- return null;
- if (_robotModule.RobotDevice.IsIdle)
- return true;
- return false;
- }, timeout * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- Stop(string.Format("failed."));
- throw new RoutineFaildException();
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
- throw new RoutineFaildException();
- }
- else
- throw new RoutineBreakException();
- }
- }
- public void UpdateWaferInfoToHand(int id, ModuleName chamber, int slot, Hand hand)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- WaferManager.Instance.WaferMoved(chamber,slot, ModuleName.TMRobot, (int)hand);
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- Stop(string.Format("failed."));
- throw new RoutineFaildException();
- }
- else
- throw new RoutineBreakException();
- }
- }
- public void CheckBeforePlace(int id, ModuleName source, int slot, Hand blade)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- Notify("Check place condition");
- string reason = string.Empty;
- if (!_target.CheckReadyForTransfer(ModuleName.TMRobot, blade, slot, EnumTransferType.Place, out reason))
- {
- Stop(reason);
- return false;
- }
- if (blade == Hand.Blade1)
- {
- if (!WaferManager.Instance.CheckNoWafer(source, slot))
- {
- Stop("Source has wafer");
- return false;
- }
- if (!WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0))
- {
- Stop("Blade 1 no wafer");
- return false;
- }
- }
- else if (blade == Hand.Blade2)
- {
- if (!WaferManager.Instance.CheckNoWafer(source, slot))
- {
- Stop("Source has wafer");
- return false;
- }
- if (!WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1))
- {
- Stop("Blade no wafer");
- return false;
- }
- }
- else
- {
- for (int i = 0; i < 2; i++)
- {
- if (!WaferManager.Instance.CheckNoWafer(source, slot + i))
- {
- Stop("Source has wafer");
- return false;
- }
- if (!WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, i))
- {
- Stop("Blade no wafer");
- return false;
- }
- }
- }
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw new RoutineFaildException();
- }
- }
- }
- public void PlaceWafer(int id, ModuleName chamber, int slot, Hand hand, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify("robot start execute place command");
- //string reason;
- _target.NoteTransferStart(ModuleName.TMRobot, hand, slot, EnumTransferType.Place);
- //if (!_robotModule.RobotDevice.Place(chamber, hand, slot, out reason))
- //{
- // Stop(reason);
- // return false;
- //}
- return true;
- }, () =>
- {
- if (_robotModule.RobotDevice.IsError)
- return null;
- if (_robotModule.RobotDevice.IsIdle)
- return true;
- return false;
- }, timeout * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw new RoutineFaildException();
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
- throw new RoutineFaildException();
- }
- else
- throw new RoutineBreakException();
- }
- }
- public void UpdateWaferInfoToTarget(int id, ModuleName chamber, int slot, Hand hand)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)hand,chamber, slot);
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- Stop(string.Format("failed."));
- throw new RoutineFaildException();
- }
- else
- throw new RoutineBreakException();
- }
- }
- public void PostTransfer(int id, PMModuleBase pm, EnumTransferType type, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"{pm.Name} post transfer ");
- if (!pm.PostTransfer(ModuleName.TMRobot, Hand.Blade1, 0, type, out string reason))
- {
- Stop(reason);
- return false;
- }
- return true;
- }, () =>
- {
- if (pm.IsError)
- {
- return null;
- }
- return pm.IsReady;
- }, timeout * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- Stop($"{pm.Name} error");
- throw new RoutineFaildException();
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop($"{pm.Name} post transfer timeout, over {timeout} seconds");
- throw new RoutineFaildException();
- }
- else
- throw new RoutineBreakException();
- }
- }
- }
- }
|