MFSwapRoutine.cs 11 KB

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