using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using Aitex.Sorter.Common; using Venus_RT.Devices; using MECF.Framework.Common.Routine; using MECF.Framework.Common.Equipment; using MECF.Framework.Common.SubstrateTrackings; using Venus_Core; using Aitex.Core.RT.Log; using Aitex.Core.Util; using Venus_RT.Modules.PMs; namespace Venus_RT.Modules.TM { class MFPMPlaceRoutine : ModuleRoutineBase, IRoutine { private enum PlaceStep { WaitPMReady, PMPrepare, ArmExtend, LiftUpWafer, ArmRetract, NotifyDone, } private readonly JetTM _JetTM; private readonly ITransferRobot _robot; private int _placingTimeout = 120 * 1000; private ModuleName _targetModule; private PMEntity _pmModule; int _targetSlot; Hand _hand; public MFPMPlaceRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TM) { _JetTM = tm; _robot = robot; Name = "Place to PM"; } public RState Start(params object[] objs) { if (!_robot.IsHomed) { LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first"); return RState.Failed; } _targetModule = (ModuleName)objs[0]; _targetSlot = (int)objs[1]; _hand = (Hand)objs[2]; if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule)) { _pmModule = Singleton.Instance.GetPM(_targetModule); } else { LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for picking action"); return RState.Failed; } if (WaferManager.Instance.CheckNoWafer(ModuleName.TM, (int)_hand)) { LOG.Write(eEvent.ERR_TM, Module, $"Cannot Place as TM Robot Arm: {_hand} has no wafer"); return RState.Failed; } if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot)) { LOG.Write(eEvent.ERR_TM, Module, $"Cannot Place as {_targetModule} Slot {_targetSlot} already has a wafer"); return RState.Failed; } Reset(); _placingTimeout = SC.GetValue($"{Module}.PlaceTimeout") * 1000; return Runner.Start(Module, Name); } public RState Monitor() { Runner.Wait((int)PlaceStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s) .Run((int)PlaceStep.PMPrepare, ModulePrepare, IsModulePrepareReady) .Run((int)PlaceStep.ArmExtend, ArmExtend, WaitRobotExtendDone) .Run((int)PlaceStep.LiftUpWafer, NotifyPMPlaceWafer, WaitPMWaferLiftUp) .Run((int)PlaceStep.ArmRetract, ArmRetract, WaitRobotRetractDone) .End((int)PlaceStep.NotifyDone, NotifyPMDone, _delay_50ms); return Runner.Status; } private bool ModulePrepare() { _pmModule.PostMsg(PMEntity.MSG.PreparePlace); return true; } private bool IsModulePrepareReady() { return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen; } private bool ArmExtend() { return _robot.PlaceExtend(_targetModule, _targetSlot, _hand); } private bool ArmRetract() { return _robot.PlaceRetract(_targetModule, _targetSlot, _hand); } private bool WaitRobotExtendDone() { if (_robot.Status == RState.Running) { return false; } else if (_robot.Status == RState.End) { return true; } else { Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}"); return true; } } private bool NotifyPMPlaceWafer() { _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer); return true; } private bool WaitPMWaferLiftUp() { return _pmModule.Status == PMEntity.PMStatus.Exchange_Ready; } private bool WaitRobotRetractDone() { if (_robot.Status == RState.Running) { return false; } else if (_robot.Status == RState.End) { return true; } else { Runner.Stop($"TM Robot Place Retract failed, {_robot.Status}"); return true; } } private bool NotifyPMDone() { _pmModule.PostMsg(PMEntity.MSG.PlaceReady); return true; } public void Abort() { _robot.Halt(); } } }