MFSwapRoutine.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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 _moveTimeout = 30 * 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. _autoVentOptInWafer = SC.GetValue<int>("TM.LLAutoVentInWaferOpt");
  80. _autoVentOptOutWafer = SC.GetValue<int>("TM.LLAutoVentOutWaferOpt");
  81. _sequencePattern = Singleton<RouteManager>.Instance.LLInOutPath;
  82. _bAutoMode = Singleton<RouteManager>.Instance.IsAutoMode;
  83. return Runner.Start(Module, $"Swap with {_targetModule}");
  84. }
  85. public RState Monitor()
  86. {
  87. Runner.Wait(SwapStep.WaitModuleReady, () => _llModule.IsIdle, _delay_60s)
  88. .RunIf(SwapStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  89. .Run(SwapStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  90. .Run(SwapStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen)
  91. .LoopStart(SwapStep.MoveWafer, loopName(), _actionList.Count, MoveWafer)
  92. .LoopEnd(SwapStep.WaitMaferMoved, NullFun, WaitWaferMoved)
  93. .Run(SwapStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed)
  94. .End(SwapStep.NotifyDone, NotifyLLDone, _delay_50ms);
  95. return Runner.Status;
  96. }
  97. private bool ModulePrepare()
  98. {
  99. _llModule.PostMsg(LLEntity.MSG.Prepare_TM);
  100. return true;
  101. }
  102. private string loopName()
  103. {
  104. return "LoadLock Swap" ;
  105. }
  106. private bool IsModulePrepareReady()
  107. {
  108. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  109. }
  110. private bool OpenSlitDoor()
  111. {
  112. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  113. }
  114. private bool CloseSlitDoor()
  115. {
  116. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  117. }
  118. private bool IsSlitDoorOpen()
  119. {
  120. if (_targetModule == ModuleName.LLA)
  121. return _JetTM.IsLLASlitDoorOpen;
  122. else
  123. return _JetTM.IsLLBSlitDoorOpen;
  124. }
  125. private bool IsSlitDoorClosed()
  126. {
  127. if (_targetModule == ModuleName.LLA)
  128. return _JetTM.IsLLASlitDoorClosed;
  129. else
  130. return _JetTM.IsLLBSlitDoorClosed;
  131. }
  132. private bool VerifyWaferExistence(MoveItem item)
  133. {
  134. if (WaferManager.Instance.CheckHasWafer(item.DestinationModule, item.DestinationSlot))
  135. {
  136. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as desitination {_currentAction.DestinationModule},{_currentAction.DestinationSlot + 1} already a wafer: ");
  137. return false;
  138. }
  139. if (WaferManager.Instance.CheckNoWafer(_currentAction.SourceModule, _currentAction.SourceSlot))
  140. {
  141. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as source {_currentAction.SourceModule}, {_currentAction.SourceSlot + 1} has no wafer");
  142. return false;
  143. }
  144. return true;
  145. }
  146. private bool MoveWafer()
  147. {
  148. _currentAction = _actionList.Dequeue();
  149. if (!VerifyWaferExistence(_currentAction))
  150. return false;
  151. var wafer = WaferManager.Instance.GetWafer(_currentAction.SourceModule, _currentAction.SourceSlot);
  152. 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}");
  153. if (ModuleHelper.IsLoadLock(_currentAction.SourceModule) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))
  154. {
  155. return _robot.Pick(_currentAction.SourceModule, _currentAction.SourceSlot, (Hand)_currentAction.DestinationSlot);
  156. }
  157. else if(ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsLoadLock(_currentAction.DestinationModule))
  158. {
  159. return _robot.Place(_currentAction.DestinationModule, _currentAction.DestinationSlot, (Hand)_currentAction.SourceSlot);
  160. }
  161. else
  162. {
  163. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TMRobot, $"Invalid move parameter, source:{_currentAction.SourceModule},{_currentAction.SourceSlot}, destination: {_currentAction.DestinationModule}, {_currentAction.DestinationSlot}");
  164. return false;
  165. }
  166. }
  167. private bool WaitWaferMoved()
  168. {
  169. if (_robot.Status == RState.Running)
  170. {
  171. if(Runner.StepElapsedMS > _moveTimeout)
  172. {
  173. WaferManager.Instance.CreateDuplicatedWafer(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  174. Runner.Stop($"TM Robot moving wafer from {_currentAction.SourceModule}.{_currentAction.SourceSlot + 1} to {_currentAction.DestinationModule}.{_currentAction.DestinationSlot + 1} timeout, {_moveTimeout}ms");
  175. return true;
  176. }
  177. return false;
  178. }
  179. else if (_robot.Status == RState.End)
  180. {
  181. WaferManager.Instance.WaferMoved(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  182. return true;
  183. }
  184. else
  185. {
  186. WaferManager.Instance.CreateDuplicatedWafer(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  187. Runner.Stop($"TM Robot moving wafer failed, {_robot.Status}");
  188. return true;
  189. }
  190. }
  191. private bool RotateArm()
  192. {
  193. ModuleName preModule = _targetModule;
  194. Hand rotateHand = Hand.Blade1;
  195. if (ModuleHelper.IsLoadLock(_actionList.Peek().DestinationModule) && ModuleHelper.IsTMRobot(_actionList.Peek().SourceModule))
  196. {
  197. rotateHand = (Hand)_actionList.Peek().SourceSlot;
  198. preModule = _JetTM.PreRotateModules[_targetModule];
  199. }
  200. else
  201. {
  202. rotateHand = (Hand)_actionList.Peek().DestinationSlot;
  203. }
  204. _llModule.PostMsg(LLEntity.MSG.Prepare_TM); // Notify Loadlock to Serv pressure in advance for throughput enhancement
  205. return _robot.Goto(preModule, 0, rotateHand);
  206. }
  207. private bool WaitRotateDone()
  208. {
  209. if (_robot.Status == RState.Running)
  210. {
  211. return false;
  212. }
  213. else if (_robot.Status == RState.End)
  214. {
  215. return true;
  216. }
  217. else
  218. {
  219. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  220. return true;
  221. }
  222. }
  223. private bool NotifyLLDone()
  224. {
  225. bool bAutoVent = false;
  226. var waferStatus = _llModule.GetWaferProcessStatus();
  227. if(_bAutoMode)
  228. {
  229. if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLA) ||
  230. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLB)) &&
  231. waferStatus.unprocessed <= _autoVentOptInWafer)
  232. {
  233. bAutoVent = true;
  234. }
  235. else if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLB) ||
  236. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLA)) &&
  237. waferStatus.processed >= _autoVentOptOutWafer)
  238. {
  239. bAutoVent = true;
  240. }
  241. else if(_sequencePattern == SequenceLLInOutPath.DInDOut &&
  242. waferStatus.processed >= _autoVentOptOutWafer &&
  243. waferStatus.unprocessed <= _autoVentOptInWafer)
  244. {
  245. bAutoVent = true;
  246. }
  247. }
  248. 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}");
  249. _llModule.PostMsg(bAutoVent ? LLEntity.MSG.AutoVent : LLEntity.MSG.TM_Exchange_Ready);
  250. return true;
  251. }
  252. public void Abort()
  253. {
  254. _robot.Halt();
  255. }
  256. }
  257. }