MFSwapRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. using Aitex.Core.RT.Routine;
  2. using Aitex.Core.RT.SCCore;
  3. using Aitex.Sorter.Common;
  4. using Venus_RT.Devices;
  5. using MECF.Framework.Common.Jobs;
  6. using MECF.Framework.Common.Routine;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.SubstrateTrackings;
  9. using Venus_Core;
  10. using Aitex.Core.RT.Log;
  11. using Aitex.Core.Util;
  12. using System;
  13. using System.Text;
  14. using System.Collections.Generic;
  15. using MECF.Framework.Common.Schedulers;
  16. namespace Venus_RT.Modules.TM
  17. {
  18. class MFSwapRoutine : ModuleRoutineBase, IRoutine
  19. {
  20. private enum SwapStep
  21. {
  22. WaitModuleReady,
  23. PreRotation,
  24. ModulePrepare,
  25. OpenSlitDoor,
  26. MoveWafer,
  27. WaitMaferMoved,
  28. CloseSlitDoor,
  29. NotifyDone,
  30. }
  31. private readonly JetTM _JetTM;
  32. private readonly ITransferRobot _robot;
  33. private int _swapTimeout = 120 * 1000;
  34. private ModuleName _targetModule;
  35. private LLEntity _llModule;
  36. private int _autoVentOptInWafer = 0;
  37. private int _autoVentOptOutWafer = 4;
  38. Queue<MoveItem> _actionList = new Queue<MoveItem>();
  39. MoveItem _currentAction;
  40. public MFSwapRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  41. {
  42. _JetTM = tm;
  43. _robot = robot;
  44. Name = "Swap";
  45. }
  46. public RState Start(params object[] objs)
  47. {
  48. if (!_robot.IsHomed)
  49. {
  50. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  51. return RState.Failed;
  52. }
  53. _actionList.Clear();
  54. foreach(var item in (Queue<MoveItem>)objs[0])
  55. {
  56. _actionList.Enqueue(new MoveItem(item.SourceModule, item.SourceSlot, item.DestinationModule, item.DestinationSlot, item.RobotHand));
  57. }
  58. var firtItem = _actionList.Peek();
  59. if (ModuleHelper.IsLoadLock(firtItem.SourceModule))
  60. _targetModule = firtItem.SourceModule;
  61. else if (ModuleHelper.IsLoadLock(firtItem.DestinationModule))
  62. _targetModule = firtItem.DestinationModule;
  63. else
  64. {
  65. LOG.Write(eEvent.ERR_TM, Module, $"Invalid move parameter: {firtItem.SourceModule},{firtItem.SourceSlot + 1} => {firtItem.DestinationModule},{firtItem.DestinationSlot + 1} ");
  66. return RState.Failed;
  67. }
  68. _llModule = Singleton<RouteManager>.Instance.GetLL(_targetModule);
  69. if(_llModule == null)
  70. {
  71. LOG.Write(eEvent.ERR_TM, Module, $"Invalid Loadlock: {_targetModule}, maybe not installed");
  72. return RState.Failed;
  73. }
  74. Reset();
  75. _swapTimeout = SC.GetValue<int>($"TM.SwapTimeout") * 1000;
  76. _autoVentOptInWafer = SC.GetValue<int>("TM.LLAutoVentInWaferOpt");
  77. _autoVentOptOutWafer = SC.GetValue<int>("TM.LLAutoVentOutWaferOpt");
  78. return Runner.Start(Module, $"Swap with {_targetModule}");
  79. }
  80. public RState Monitor()
  81. {
  82. Runner.Wait(SwapStep.WaitModuleReady, () => _llModule.IsIdle, _delay_60s)
  83. .RunIf(SwapStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  84. .Run(SwapStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  85. .Run(SwapStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen)
  86. .LoopStart(SwapStep.MoveWafer, loopName(), _actionList.Count, MoveWafer)
  87. .LoopEnd(SwapStep.WaitMaferMoved, NullFun, WaitWaferMoved)
  88. .Run(SwapStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed)
  89. .End(SwapStep.NotifyDone, NotifyLLDone, _delay_50ms);
  90. return Runner.Status;
  91. }
  92. private bool ModulePrepare()
  93. {
  94. _llModule.PostMsg(LLEntity.MSG.Prepare_TM);
  95. return true;
  96. }
  97. private string loopName()
  98. {
  99. return "LoadLock Swap" ;
  100. }
  101. private bool IsModulePrepareReady()
  102. {
  103. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  104. }
  105. private bool OpenSlitDoor()
  106. {
  107. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  108. }
  109. private bool CloseSlitDoor()
  110. {
  111. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  112. }
  113. private bool IsSlitDoorOpen()
  114. {
  115. if (_targetModule == ModuleName.LLA)
  116. return _JetTM.IsLLASlitDoorOpen;
  117. else
  118. return _JetTM.IsLLBSlitDoorOpen;
  119. }
  120. private bool IsSlitDoorClosed()
  121. {
  122. if (_targetModule == ModuleName.LLA)
  123. return _JetTM.IsLLASlitDoorClosed;
  124. else
  125. return _JetTM.IsLLBSlitDoorClosed;
  126. }
  127. private bool VerifyWaferExistence(MoveItem item)
  128. {
  129. if (WaferManager.Instance.CheckHasWafer(item.DestinationModule, item.DestinationSlot))
  130. {
  131. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as desitination {_currentAction.DestinationModule},{_currentAction.DestinationSlot + 1} already a wafer: ");
  132. return false;
  133. }
  134. if (WaferManager.Instance.CheckNoWafer(_currentAction.SourceModule, _currentAction.SourceSlot))
  135. {
  136. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as source {_currentAction.SourceModule}, {_currentAction.SourceSlot + 1} has no wafer");
  137. return false;
  138. }
  139. return true;
  140. }
  141. private bool MoveWafer()
  142. {
  143. _currentAction = _actionList.Dequeue();
  144. if (!VerifyWaferExistence(_currentAction))
  145. return false;
  146. var wafer = WaferManager.Instance.GetWafer(_currentAction.SourceModule, _currentAction.SourceSlot);
  147. LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"{wafer.WaferOrigin} will be move from {_currentAction.SourceModule} {_currentAction.SourceSlot + 1} to {_currentAction.DestinationModule} {_currentAction.DestinationSlot + 1}");
  148. if (ModuleHelper.IsLoadLock(_currentAction.SourceModule) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))
  149. {
  150. return _robot.Pick(_currentAction.SourceModule, _currentAction.SourceSlot, (Hand)_currentAction.DestinationSlot);
  151. }
  152. else if(ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsLoadLock(_currentAction.DestinationModule))
  153. {
  154. return _robot.Place(_currentAction.DestinationModule, _currentAction.DestinationSlot, (Hand)_currentAction.SourceSlot);
  155. }
  156. else
  157. {
  158. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TMRobot, $"Invalid move parameter, source:{_currentAction.SourceModule},{_currentAction.SourceSlot}, destination: {_currentAction.DestinationModule}, {_currentAction.DestinationSlot}");
  159. return false;
  160. }
  161. }
  162. private bool WaitWaferMoved()
  163. {
  164. if (_robot.Status == RState.Running)
  165. {
  166. return false;
  167. }
  168. else if (_robot.Status == RState.End)
  169. {
  170. WaferManager.Instance.WaferMoved(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  171. return true;
  172. }
  173. else
  174. {
  175. Runner.Stop($"TM Robot moving wafer failed, {_robot.Status}");
  176. return true;
  177. }
  178. }
  179. private bool RotateArm()
  180. {
  181. ModuleName preModule = _targetModule;
  182. Hand rotateHand = Hand.Blade1;
  183. if (ModuleHelper.IsLoadLock(_actionList.Peek().DestinationModule) && ModuleHelper.IsTMRobot(_actionList.Peek().SourceModule))
  184. {
  185. rotateHand = (Hand)_actionList.Peek().SourceSlot;
  186. preModule = _JetTM.PreRotateModules[_targetModule];
  187. }
  188. else
  189. {
  190. rotateHand = (Hand)_actionList.Peek().DestinationSlot;
  191. }
  192. _llModule.PostMsg(LLEntity.MSG.Prepare_TM); // Notify Loadlock to Serv pressure in advance for throughput enhancement
  193. return _robot.Goto(preModule, 0, rotateHand);
  194. }
  195. private bool WaitRotateDone()
  196. {
  197. if (_robot.Status == RState.Running)
  198. {
  199. return false;
  200. }
  201. else if (_robot.Status == RState.End)
  202. {
  203. return true;
  204. }
  205. else
  206. {
  207. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  208. return true;
  209. }
  210. }
  211. private bool NotifyLLDone()
  212. {
  213. var waferStatus = _llModule.GetWaferProcessStatus();
  214. bool bAutoVent = false;
  215. if(Singleton<RouteManager>.Instance.IsAutoMode)
  216. {
  217. if (((Singleton<RouteManager>.Instance.LLInOutPath == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLA) ||
  218. (Singleton<RouteManager>.Instance.LLInOutPath == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLB)) &&
  219. waferStatus.unprocessed <= _autoVentOptInWafer)
  220. {
  221. bAutoVent = true;
  222. }
  223. else if (((Singleton<RouteManager>.Instance.LLInOutPath == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLB) ||
  224. (Singleton<RouteManager>.Instance.LLInOutPath == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLA)) &&
  225. waferStatus.processed >= _autoVentOptOutWafer)
  226. {
  227. bAutoVent = true;
  228. }
  229. else if(Singleton<RouteManager>.Instance.LLInOutPath == SequenceLLInOutPath.DInDOut &&
  230. waferStatus.processed >= _autoVentOptOutWafer &&
  231. waferStatus.unprocessed <= _autoVentOptInWafer)
  232. {
  233. bAutoVent = true;
  234. }
  235. }
  236. _llModule.PostMsg(bAutoVent ? LLEntity.MSG.AutoVent : LLEntity.MSG.TM_Exchange_Ready);
  237. return true;
  238. }
  239. public void Abort()
  240. {
  241. _robot.Halt();
  242. }
  243. }
  244. }