using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using Aitex.Sorter.Common; using Aitex.Core.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; using MECF.Framework.Common.Schedulers; using System.Collections.Generic; using System; using MECF.Framework.Common.DBCore; using Aitex.Core.RT.Device; namespace Venus_RT.Modules.TM { class MFPMPickRoutine : ModuleRoutineBase, IRoutine { private enum PickStep { WaitPMReady, OpenPMSlitDoor, PMPrepare, ArmExtend, QueryAWC, DropDownWafer, PickDelay, ArmRetract, SavePickeData, ClosePMSlitDoor, CheckAWC, NotifyDone, } private enum PickStepWithHeater { WaitPMReady, PMPrepare, WaitPressreStable, OpenPMSlitDoor, Picking, QueryAWC, SavePickeData, ClosePMSlitDoor, WaitPLCReady, CheckAWC, NotifyDone, } private readonly JetTM _JetTM; private JetPMBase _jetPM; private readonly ITransferRobot _robot; private int _pickingTimeout = 20 * 1000; private int _liftPinTimeout = 10 * 1000; private int _pickDelayTime = 0; private ModuleName _targetModule; private PMEntity _pmModule; //private TMEntity _tmModule; private int _targetSlot; private Hand _hand; private DateTime _starttime; private bool _queryAwc; double maxPressureDifference ; private int _robotTransferAWCOffset; private int _robotPickDelayTime = 1; public MFPMPickRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot) { _JetTM = tm; _robot = robot; Name = "Pick from PM"; if (SC.GetValue($"TM.QueryAWCOption") == 1 || SC.GetValue($"TM.QueryAWCOption") == 3) _queryAwc = true; else _queryAwc = false; } public RState Start(params object[] objs) { _starttime = DateTime.Now; if (!_robot.IsHomed) { LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first"); return RState.Failed; } var pickItem = (Queue)objs[0]; if (!WaferManager.Instance.CheckDuplicatedWafersBeforeMove(pickItem)) return RState.Failed; _targetModule = pickItem.Peek().SourceModule; _targetSlot = pickItem.Peek().SourceSlot; _hand = pickItem.Peek().RobotHand; if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule)) { _pmModule = Singleton.Instance.GetPM(_targetModule); _jetPM = DEVICE.GetDevice(_targetModule.ToString()); } else { LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for picking action"); return RState.Failed; } if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_hand)) { LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as TM Robot Arm: {_hand} already has a wafer"); return RState.Failed; } if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot)) { LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as {_targetModule} Slot {_targetSlot + 1} has no wafer"); return RState.Failed; } var wafer = WaferManager.Instance.GetWafer(_targetModule, _targetSlot); if(wafer.ChuckState == EnumWaferChuckStatus.Chucked) { LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick the wafer in {_targetModule }as the wafer is chucked"); return RState.Failed; } LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"{wafer.WaferOrigin} will be move from {_targetModule} {_targetSlot + 1} to TM Robot {_hand}"); Reset(); _pickingTimeout = SC.GetValue("TM.PickTimeout") * 1000; _pickDelayTime = SC.GetValue($"{_targetModule}.PickDelayTime"); _robotTransferAWCOffset= SC.GetValue("TM.EnterPMAWCAlarmLimit"); maxPressureDifference = SC.GetValue("System.PMTMMaxPressureDifference"); if (RtInstance.ConfigType == ConfigType.Kepler2200) { _robotPickDelayTime = SC.GetValue($"TM.RobotPickDelayTime"); } if (SC.GetValue($"TM.QueryAWCOption") == 1 || SC.GetValue($"TM.QueryAWCOption") == 3) _queryAwc = true; else _queryAwc = false; return Runner.Start(Module, $"Pick from {_targetModule}"); } public RState Monitor() { switch (_pmModule.ChamberType) { //case JetChamber.Venus: case JetChamber.Kepler2300: Runner.Wait(PickStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s) .Run(PickStep.OpenPMSlitDoor, OpenPMSlitDoor, OpenPMSlitDoorIsOK) .Run(PickStep.PMPrepare, PMPrepare, IsPMPrepareReady) .Run(PickStep.ArmExtend, ArmExtend, WaitRobotExtendDone) .Run(PickStep.QueryAWC, QueryAWC, WaitRobotQueryDone, _delay_1s) .Run(PickStep.DropDownWafer, NotifyPMPickWafer, WaitPMWaferDropDown) .Delay(PickStep.PickDelay, _pickDelayTime) .Run(PickStep.ArmRetract, ArmRetract, WaitRobotRetractDone) .Run(PickStep.ClosePMSlitDoor, ClosePMSlitDoor, ClosePMSlitDoorIsOK) //.Run(PickStep.CheckAWC, CheckAwc ) .End(PickStep.NotifyDone, NotifyPMDone, _delay_50ms); break; case JetChamber.Kepler2200A: case JetChamber.Kepler2200B: Runner.Wait(PickStepWithHeater.WaitPMReady, () => _pmModule.IsIdle, _delay_60s) .Run(PickStepWithHeater.PMPrepare, PMPrepare, IsPMPrepareReady) .Wait(PickStepWithHeater.WaitPressreStable, TMPMPressureIsOK, _delay_60s) .Run(PickStepWithHeater.OpenPMSlitDoor, OpenPMSlitDoor, OpenPMSlitDoorIsOK) .Run(PickStepWithHeater.Picking, Picking, WaitPickDone) .RunIf(PickStepWithHeater.QueryAWC, _queryAwc, QueryAWC, WaitRobotQueryDone) .RunIf(PickStepWithHeater.SavePickeData, _queryAwc, RecordAWCData, NullFun) .Wait(PickStepWithHeater.WaitPLCReady, PLCIsReadyOK) .Run(PickStepWithHeater.ClosePMSlitDoor, ClosePMSlitDoor, ClosePMSlitDoorIsOK) .RunIf(PickStepWithHeater.CheckAWC, _queryAwc, CheckAwc) .End(PickStepWithHeater.NotifyDone, NotifyPMDone, _robotPickDelayTime * 1000); break; } return Runner.Status; } private bool TMPMPressureIsOK() { if (RouteManager.IsATMMode) { return _JetTM.IsTMATM && _JetTM.IsModuleATM(_targetModule); } else { if (Math.Abs((_pmModule.ChamberPressure - _JetTM.ChamberPressure)) < (maxPressureDifference-2)) { return true; } else { return false; } } } private bool PMPrepare() { _pmModule.PostMsg(PMEntity.MSG.PreparePick); return true; } private bool OpenPMSlitDoor() { return _JetTM.TurnMFSlitDoor(_targetModule, true, out _); } private bool OpenPMSlitDoorIsOK() { return _JetTM.IsPMSlitdoorOpened(_targetModule); } private bool ClosePMSlitDoor() { return _JetTM.TurnMFSlitDoor(_targetModule, false, out _); } private bool ClosePMSlitDoorIsOK() { return _JetTM.IsPMSlitdoorClosed(_targetModule); } private bool IsPMPrepareReady() { return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick; } private bool Picking() { if (!_jetPM.IsAllowRobotTransfer) { Runner.Stop($"不允许Pick,传片位置信号不满足"); return false; } if (!_jetPM.PreparePlaceIsOK()) { Runner.Stop($"不允许Pick,传片位置信号满足,但不在Position1"); return false; } return _robot.Pick(_targetModule, _targetSlot, _hand); } private bool WaitPickDone() { if (_robot.Status == RState.Running) { if(Runner.StepElapsedMS > _pickingTimeout) { WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand); Runner.Stop($"TM Robot Picking {_targetModule} wafer timeout, {_pickingTimeout}"); return true; } return false; } else if (_robot.Status == RState.End) { WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand); return true; } else { WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand); Runner.Stop($"TM Robot Picking failed, {_robot.Status}"); return true; } } private bool ArmExtend() { return _robot.PickExtend(_targetModule, _targetSlot, _hand); } private bool ArmRetract() { return _robot.PickRetract(_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 Pick Extend failed, {_robot.Status}"); return true; } } private bool PLCIsReadyOK() { return _JetTM.TMRobotNotExtendModule(_targetModule); } private bool QueryAWC() { if (!_queryAwc) return true; else return _robot.QueryAwc(); ; } private bool WaitRobotQueryDone() { if (!_queryAwc) return true; if (_robot.Status == RState.Running) { return false; } else if (_robot.Status == RState.End) { return true; } else { Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}"); return true; } } private bool RecordAWCData() { if (!_queryAwc) return true; //已经move后的数据 string _origin_module = $"LP{WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)_hand).OriginStation}"; int _origin_slot = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)_hand).OriginSlot; //查询完毕 插入数据 //OffsetDataRecorder.RecordOffsetData( // Guid.NewGuid().ToString(), // _targetModule, _targetSlot, // ModuleName.TMRobot, 0, // _origin_module, _origin_slot, // _hand, RobotArmPan.None, // _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D, // _starttime, DateTime.Now); OffsetDataRecorder.RecordOffsetData( Guid.NewGuid().ToString(), ModuleName.TMRobot, 0, _targetModule, _targetSlot, _origin_module, _origin_slot, _hand, RobotArmPan.None, _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D, _starttime, DateTime.Now); return true; } private bool CheckAwc() { if (Math.Abs(_robot.Offset_X) > _robotTransferAWCOffset) { Stop($"Check AWC 失败, 当前 X AWC [{_robot.Offset_X}um], 高于Alarm最大值: [{_robotTransferAWCOffset}]um"); return false; } if (Math.Abs(_robot.Offset_Y) > _robotTransferAWCOffset) { Stop($"Check AWC 失败, 当前 Y AWC [{_robot.Offset_Y}um], 高于Alarm最大值: [{_robotTransferAWCOffset}]um"); return false; } return true; } private bool NotifyPMPickWafer() { _pmModule.PostMsg(PMEntity.MSG.DropDownWafer); return true; } private bool WaitPMWaferDropDown() { if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready) { WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand); return true; } else if (Runner.StepElapsedMS > _liftPinTimeout) { WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand); Runner.Stop($"Wait {_targetModule} Lift Pin down timeout, {Runner.StepElapsedMS}"); } return false; } private bool WaitRobotRetractDone() { if (_robot.Status == RState.Running) { return false; } else if (_robot.Status == RState.End) { return true; } else { Runner.Stop($"TM Robot Pick Retract failed, {_robot.Status}"); return true; } } private bool NotifyPMDone() { _pmModule.PostMsg(PMEntity.MSG.PickReady); return true; } public void Abort() { //_robot.Halt(); } } }