| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 | 
							- using Aitex.Core.Common.DeviceData;
 
- using Aitex.Core.RT.DataCenter;
 
- using Aitex.Core.RT.Device;
 
- using Aitex.Core.RT.Log;
 
- 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 System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Text;
 
- using System.Threading.Tasks;
 
- using System.Windows.Documents;
 
- using Venus_Core;
 
- using Venus_RT.Devices;
 
- using Venus_RT.Modules.PMs;
 
- namespace Venus_RT.Modules.TM.VenusEntity
 
- {
 
-     public class SEMFPMSwapRoutine : ModuleRoutineBase, IRoutine
 
-     {
 
-         private enum SwapStep
 
-         {
 
-             WaitPMReady,
 
-             WaitforControlPressure,
 
-             PreRotation,
 
-             PickPrepare,
 
-             PickExtend,
 
-             DropDownWafer,
 
-             PickDelay,
 
-             PickRetract,
 
-             PlacePrepare,
 
-             PlaceExtend,
 
-             LiftUpWafer,
 
-             PlaceDelay,
 
-             PlaceRetract,
 
-             NotifyDone,
 
-             EndDone,
 
-             EndDelay
 
-         }
 
-         private readonly HongHuTM _TM;
 
-         private readonly ITransferRobot _robot;
 
-         private int _swapingTimeout = 120 * 1000;
 
-         private int _placeDelayTime = 0;
 
-         private int _pickDelayTime = 0;
 
-         private ModuleName _targetModule;
 
-         private PMEntity _pmModule;
 
-         private int _targetSlot;
 
-         private Hand _pickHand;
 
-         private Hand _placeHand;
 
-         private JetPMBase _chamber;
 
-         private bool NeedControlPressure;
 
-         private int _controlPressureSetPoint = 90;
 
-         private int _controlFlowSetPoint = 90;
 
-         public SEMFPMSwapRoutine(HongHuTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
 
-         {
 
-             _TM = tm;
 
-             _robot = robot;
 
-             Name = "swap for 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;
 
-             }
 
-             var swapItem = (Queue<MoveItem>)objs[0];
 
-             _targetModule = swapItem.Peek().SourceModule;
 
-             _targetSlot = swapItem.Peek().SourceSlot;
 
-             _pickHand = swapItem.Peek().RobotHand;
 
-             _placeHand = _pickHand == Hand.Blade2 ? Hand.Blade1 : Hand.Blade2;
 
-             if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
 
-             {
 
-                 _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
 
-             }
 
-             else
 
-             {
 
-                 LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for swap action");
 
-                 return RState.Failed;
 
-             }
 
-             if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_placeHand))
 
-             {
 
-                 LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as TM Robot Arm: {_placeHand} has no wafer");
 
-                 return RState.Failed;
 
-             }
 
-             if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_pickHand))
 
-             {
 
-                 LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as TM Robot Arm: {_pickHand} has a wafer");
 
-                 return RState.Failed;
 
-             }
 
-             if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
 
-             {
 
-                 LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as {_targetModule} Slot {_targetSlot + 1} has no wafer");
 
-                 return RState.Failed;
 
-             }
 
-             Reset();
 
-             _swapingTimeout = SC.GetValue<int>($"SETM.SwapTimeout") * 1000;
 
-             _pickDelayTime = SC.GetValue<int>($"{_targetModule}.PickDelayTime");
 
-             _placeDelayTime = SC.GetValue<int>($"{_targetModule}.PlaceDelayTime");
 
-             if (Singleton<RouteManager>.Instance.GetPM(_targetModule).IsOnline)
 
-             {
 
-                 NeedControlPressure = true;
 
-             }
 
-             else
 
-             {
 
-                 NeedControlPressure = false;
 
-             }
 
-             return Runner.Start(Module, $"Swap with {_targetModule}");
 
-         }
 
-         public RState Monitor()
 
-         {
 
-             Runner.Wait(SwapStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
 
-                  .RunIf(SwapStep.WaitforControlPressure, NeedControlPressure, StartControlPressure, IsPressureReady, _delay_60s)
 
-                 //.RunIf(SwapStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
 
-                 .Run(SwapStep.PickPrepare, PickPrepare, IsModuleReadyForPick)
 
-                 .Run(SwapStep.PickExtend, PickExtend, WaitRobotExtendDone)
 
-                 .Run(SwapStep.DropDownWafer, NotifyPMPickWafer, WaitPMWaferDropDown)
 
-                 .Delay(SwapStep.PickDelay, _pickDelayTime)
 
-                 .Run(SwapStep.PickRetract, PickRetract, WaitRobotRetractDone)
 
-                 .Run(SwapStep.PlacePrepare, PlacePrepare, IsModuleReadyForPlace)
 
-                 .Run(SwapStep.PlaceExtend, PlaceExtend, WaitRobotExtendDone)
 
-                 .Run(SwapStep.LiftUpWafer, NotifyLiftUpWafer, WaitPMWaferLiftUp)
 
-                 .Delay(SwapStep.PlaceDelay, _placeDelayTime)
 
-                 .Run(SwapStep.PlaceRetract, PlaceRetract, WaitRobotRetractDone)
 
-                 .Run(SwapStep.NotifyDone, NotifyPMDone, _delay_50ms)
 
-                 .Delay(SwapStep.PlaceDelay, _delay_50ms)
 
-                 .Run(SwapStep.EndDone, CheckDoorClose, WaitPMDoorClose, 5000)
 
-                 .End(SwapStep.EndDelay, NullFun, _delay_50ms);
 
-             return Runner.Status;
 
-         }
 
-         private bool StartControlPressure()
 
-         {
 
-             _chamber = DEVICE.GetDevice<JetPMBase>(_targetModule.ToString());
 
-             _controlPressureSetPoint = SC.GetValue<int>($"{_targetModule}.ControlPressureSetPoint");
 
-             _controlFlowSetPoint = SC.GetValue<int>($"{_targetModule}.ControlPressureN2FlowSetPoint");
 
-             _chamber.StartControlPressure(_controlPressureSetPoint, _controlFlowSetPoint);
 
-             return true;
 
-         }
 
-         private bool IsPressureReady()
 
-         {
 
-             double ControlPressure = SC.GetValue<int>($"{_targetModule}.ControlPressureSetPoint");
 
-             //double PMPressure = Singleton<RouteManager>.Instance.GetPM(_targetModule).ChamberPressure;
 
-             double PMPressure = (double)DATA.Poll($"{_targetModule}.ChamberPressure");
 
-             double range = SC.GetValue<int>($"{_targetModule}.ControlPressureOffset");
 
-             if ((PMPressure >= (ControlPressure - range)) && (PMPressure <= (ControlPressure + range)))
 
-             {
 
-                 //LOG.Write(eEvent.WARN_DEFAULT_WARN, _targetModule, "current pmpressure" + PMPressure);
 
-                 //LOG.Write(eEvent.WARN_DEFAULT_WARN, _targetModule, "DATA current pmpressure" + DATA.Poll($"{_targetModule}.ChamberPressure"));
 
-                 //string reason = $"{Module} and TM pressure difference exceeds the max limit {maxPressureDifference}, TMPressure:{TMPressure}, {Module}Pressure:{PMPressure}";
 
-                 //LOG.Write(eEvent.ERR_DEVICE_INFO, Module, reason);
 
-                 return true;
 
-             }
 
-             else return false;
 
-         }
 
-         private bool PickPrepare()
 
-         {
 
-             _pmModule.PostMsg(PMEntity.MSG.PreparePick);
 
-             //_TM.TurnSlitDoor(_targetModule, true);
 
-             return true;
 
-         }
 
-         private bool PlacePrepare()
 
-         {
 
-             _pmModule.PostMsg(PMEntity.MSG.PreparePlace);
 
-             //_TM.TurnSlitDoor(_targetModule, true);
 
-             return true;
 
-         }
 
-         private bool IsModuleReadyForPick()
 
-         {
 
-             return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick && _pmModule.IsSlitDoorOpen;
 
-         }
 
-         private bool PickExtend()
 
-         {
 
-             return _robot.PickExtend(_targetModule, _targetSlot, _pickHand);
 
-         }
 
-         private bool PickRetract()
 
-         {
 
-             return _robot.PickRetract(_targetModule, _targetSlot, _pickHand);
 
-         }
 
-         private bool IsModuleReadyForPlace()
 
-         {
 
-             return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen;
 
-         }
 
-         private bool PlaceExtend()
 
-         {
 
-             return _robot.PlaceExtend(_targetModule, _targetSlot, _placeHand);
 
-         }
 
-         private bool PlaceRetract()
 
-         {
 
-             return _robot.PlaceRetract(_targetModule, _targetSlot, _placeHand);
 
-         }
 
-         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}");
 
-                 Singleton<RouteManager>.Instance.GetPM(_targetModule).PostMsg(PMEntity.MSG.Error);
 
-                 return true;
 
-             }
 
-         }
 
-         //private bool RotateArm()
 
-         //{
 
-         //    _pmModule.PostMsg(PMEntity.MSG.PreparePick); // Notify PM to Serv pressure in advance for throughput enhancement
 
-         //    return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _placeHand);
 
-         //}
 
-         //private bool WaitRotateDone()
 
-         //{
 
-         //    if (_robot.Status == RState.Running)
 
-         //    {
 
-         //        return false;
 
-         //    }
 
-         //    else if (_robot.Status == RState.End)
 
-         //    {
 
-         //        return true;
 
-         //    }
 
-         //    else
 
-         //    {
 
-         //        Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
 
-         //        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)_pickHand);
 
-                 return true;
 
-             }
 
-             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 Swap Retract failed, {_robot.Status}");
 
-                 Singleton<RouteManager>.Instance.GetPM(_targetModule).PostMsg(PMEntity.MSG.Error);
 
-                 return true;
 
-             }
 
-         }
 
-         private bool NotifyLiftUpWafer()
 
-         {
 
-             _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
 
-             return true;
 
-         }
 
-         private bool WaitPMWaferLiftUp()
 
-         {
 
-             if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
 
-             {
 
-                 WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
 
-                 return true;
 
-             }
 
-             return false;
 
-         }
 
-         private bool NotifyPMDone()
 
-         {
 
-             _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
 
-             //_TM.TurnSlitDoor(_targetModule, false);
 
-             return true;
 
-         }
 
-         private bool CheckDoorClose()
 
-         {
 
-             LOG.Write(eEvent.WARN_TM, Module, $"PMSwap Close Door Again");
 
-             return _TM.TurnSlitDoor(_targetModule, false);
 
-         }
 
-         private bool WaitPMDoorClose()
 
-         {
 
-             if (_TM.CheckSlitValveClose(_targetModule))
 
-             {
 
-                 LOG.Write(eEvent.WARN_TM, Module, $"PMSwap Check Door Close");
 
-                 return true;
 
-             }
 
-             else
 
-             {
 
-                 if (DEVICE.GetDevice<IoCylinder>($"SETM.{_targetModule}SlitDoor").SetPoint != (int)CylinderState.Close)
 
-                 {
 
-                     LOG.Write(eEvent.WARN_TM, Module, $"PMSwap {_targetModule}SlitDoor set close again");
 
-                     DEVICE.GetDevice<IoCylinder>($"SETM.{_targetModule}SlitDoor").SetCylinder(false, out string reason);
 
-                 }
 
-                 //LOG.Write(eEvent.WARN_TM, Module, $"PMSwap Check not Close Door");
 
-                 return false;
 
-             }
 
-         }
 
-         public void Abort()
 
-         {
 
-             _robot.Halt();
 
-         }
 
-     }
 
- }
 
 
  |