using System; using Aitex.Core.RT.Event; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using Aitex.Core.Util; using Aitex.Sorter.Common; using MECF.Framework.Common.Equipment; using MECF.Framework.Common.Schedulers; using MECF.Framework.Common.SubstrateTrackings; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots; using MECF.Framework.RT.EquipmentLibrary.LogicUnits; using MECF.Framework.RT.ModuleLibrary.PMModules; using MECF.Framework.RT.ModuleLibrary.SystemModules; namespace FutureEfemLib.Efems { public class EfemPickAndPlaceRoutine : ModuleRoutine, IRoutine { enum RoutineStep { CheckBeforePick, PickWafer, CheckBeforePlace, PlaceWafer, PostTransfer, PickExtend, PickRetract, PlaceExtend, PlaceRetract, PickLiftUp, PickLiftDown, PlaceLiftUp, PlaceLiftDown, } private EfemModule _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 EfemPickAndPlaceRoutine(EfemModule robotModule) { Module = "EfemRobot"; Name = "Pick"; _robotModule = robotModule; } public Result Start(params object[] objs) { _pickTimeout = SC.GetValue("EFEM.EfemRobot.PickTimeout"); _placeTimeout = SC.GetValue("EFEM.EfemRobot.PlaceTimeout"); if (ModuleHelper.IsPm(_targetModule)) { _postTransferTimeout = SC.GetValue($"PM.PostTransferTimeout"); } Reset(); if (!WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_pickBlade)) { EV.PostWarningLog(Module, $"Can not pick by {_pickBlade}, found wafer on"); return Result.FAIL; } if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (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 = Singleton.Instance.Modules[targetModule] as ITransferTarget; } public void Abort() { if (_target != null) { _target.NoteTransferStop(ModuleName.EfemRobot, Hand.Blade1, 0, EnumTransferType.Pick); } _target = null; Notify("Abort"); } public Result Monitor() { try { CheckBeforePick((int)RoutineStep.CheckBeforePick, _targetModule, _pickSlot, _pickBlade); if (ModuleHelper.IsPm(_targetModule)) { RobotExtend((int)RoutineStep.PickExtend, _targetModule, _pickSlot, _pickBlade, RobotPostionEnum.PickExtendLow, _pickTimeout); MovePinDown((int)RoutineStep.PickLiftDown, _target as PMModuleBase, EnumTransferType.Extend, _pickTimeout); RobotRetract((int)RoutineStep.PickRetract, _targetModule, _pickSlot, _pickBlade, RobotPostionEnum.PickRetracted, _pickTimeout); //MovePinDown((int)RoutineStep.PickLiftDown, _target as PMModuleBase, EnumTransferType.Retract, _pickTimeout); RobotExtend((int)RoutineStep.PlaceExtend, _targetModule, _placeSlot, _placeBlade, RobotPostionEnum.PlaceExtendUp, _pickTimeout); MovePinUp((int)RoutineStep.PlaceLiftUp, _target as PMModuleBase, EnumTransferType.Extend, _pickTimeout); RobotRetract((int)RoutineStep.PlaceRetract, _targetModule, _placeSlot, _placeBlade, RobotPostionEnum.PlaceRetract, _pickTimeout); //LiftPinDown((int)RoutineStep.PlaceLiftDown, _target as PMModuleBase, EnumTransferType.Retract, _pickTimeout); } else { PickWafer((int)RoutineStep.PickWafer, _targetModule, _pickSlot, _pickBlade, _pickTimeout); CheckBeforePlace((int)RoutineStep.CheckBeforePlace, _targetModule, _placeSlot, _placeBlade); PlaceWafer((int)RoutineStep.PlaceWafer, _targetModule, _placeSlot, _placeBlade, _pickTimeout); } 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.EfemRobot, 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 ret = Execute(id, () => { Notify("Check pick is enabled"); string reason = string.Empty; if (!_target.CheckReadyForTransfer(ModuleName.EfemRobot, 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.EfemRobot, 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.EfemRobot, 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.EfemRobot, 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 ret = ExecuteAndWait(id, () => { Notify("robot execute pick command"); _target.NoteTransferStart(ModuleName.EfemRobot, 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 CheckBeforePlace(int id, ModuleName source, int slot, Hand blade) { Tuple ret = Execute(id, () => { Notify("Check place condition"); string reason = string.Empty; if (!_target.CheckReadyForTransfer(ModuleName.EfemRobot, 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.EfemRobot, 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.EfemRobot, 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.EfemRobot, 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 ret = ExecuteAndWait(id, () => { Notify("robot start execute place command"); string reason; _target.NoteTransferStart(ModuleName.EfemRobot, 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 PostTransfer(int id, PMModuleBase pm, EnumTransferType type, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"{pm.Name} post transfer "); if (!pm.PostTransfer(ModuleName.EfemRobot, 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()); } } public void RobotExtend(int id, ModuleName chamber, int slot, Hand hand, RobotPostionEnum robotPostion, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify("robot execute goto command"); //string reason; //if (!_robotModule.RobotDevice.GotoRE(chamber, hand, slot, robotPostion, 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 RobotRetract(int id, ModuleName chamber, int slot, Hand hand, RobotPostionEnum robotPostion, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify("robot execute goto command"); //string reason; //if (!_robotModule.RobotDevice.GotoRE(chamber, hand, slot, robotPostion, 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 MovePinUp(int id, PMModuleBase pm, EnumTransferType type, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"{pm.Name} lift pin up "); //if (!pm.ChamberLiftPin.MoveUp(out string reason)) //{ // Stop(reason); // return false; //} return true; }, () => { //if (pm.ChamberLiftPin.IsUp) // 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($"{pm.Name} move lift pin up timeout, over {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void MovePinDown(int id, PMModuleBase pm, EnumTransferType type, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"{pm.Name} lift pin down"); //if (!pm.ChamberLiftPin.MoveDown(out string reason)) //{ // Stop(reason); // return false; //} return true; }, () => { //if (pm.ChamberLiftPin.IsDown) // 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($"{pm.Name} move down lift pin timeout, over {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } } }