MFSwapRoutine.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. using System.Linq;
  17. namespace Venus_RT.Modules.TM
  18. {
  19. class MFSwapRoutine : ModuleRoutineBase, IRoutine
  20. {
  21. private enum SwapStep
  22. {
  23. WaitModuleReady,
  24. PreRotation,
  25. ModulePrepare,
  26. WaitPressreStable,
  27. OpenSlitDoor,
  28. MoveWafer,
  29. WaitMaferMoved,
  30. CloseSlitDoor,
  31. NotifyDone,
  32. }
  33. private readonly JetTM _JetTM;
  34. private readonly ITransferRobot _robot;
  35. private int _moveTimeout = 30 * 1000;
  36. private ModuleName _targetModule;
  37. private LLEntity _llModule;
  38. private int _autoVentOptInWafer = 0;
  39. private int _autoVentOptOutWafer = 4;
  40. private SequenceLLInOutPath _sequencePattern = SequenceLLInOutPath.DInDOut;
  41. private bool _bAutoMode = true;
  42. Queue<MoveItem> _actionList = new Queue<MoveItem>();
  43. MoveItem _currentAction;
  44. double maxPressureDifference;
  45. List<MoveItem> _currentactionList=new List<MoveItem>();
  46. public MFSwapRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  47. {
  48. _JetTM = tm;
  49. _robot = robot;
  50. Name = "Swap";
  51. }
  52. public RState Start(params object[] objs)
  53. {
  54. if (!_robot.IsHomed)
  55. {
  56. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  57. return RState.Failed;
  58. }
  59. _actionList.Clear();
  60. foreach (var item in (Queue<MoveItem>)objs[0])
  61. {
  62. _actionList.Enqueue(new MoveItem(item.SourceModule, item.SourceSlot, item.DestinationModule, item.DestinationSlot, item.RobotHand));
  63. }
  64. if (!WaferManager.Instance.CheckDuplicatedWafersBeforeMove(_actionList))
  65. return RState.Failed;
  66. var firtItem = _actionList.Peek();
  67. if (ModuleHelper.IsLoadLock(firtItem.SourceModule))
  68. _targetModule = firtItem.SourceModule;
  69. else if (ModuleHelper.IsLoadLock(firtItem.DestinationModule))
  70. _targetModule = firtItem.DestinationModule;
  71. else
  72. {
  73. LOG.Write(eEvent.ERR_TM, Module, $"Invalid move parameter: {firtItem.SourceModule},{firtItem.SourceSlot + 1} => {firtItem.DestinationModule},{firtItem.DestinationSlot + 1} ");
  74. return RState.Failed;
  75. }
  76. _llModule = Singleton<RouteManager>.Instance.GetLL(_targetModule);
  77. if (_llModule == null)
  78. {
  79. LOG.Write(eEvent.ERR_TM, Module, $"Invalid Loadlock: {_targetModule}, maybe not installed");
  80. return RState.Failed;
  81. }
  82. Reset();
  83. _autoVentOptInWafer = SC.GetValue<int>("TM.LLAutoVentInWaferOpt");
  84. _autoVentOptOutWafer = SC.GetValue<int>("TM.LLAutoVentOutWaferOpt");
  85. _sequencePattern = Singleton<RouteManager>.Instance.LLInOutPath;
  86. _bAutoMode = Singleton<RouteManager>.Instance.IsAutoMode;
  87. maxPressureDifference = SC.GetValue<double>("System.TMLLMaxPressureDifference");
  88. _currentactionList = _actionList.ToList();
  89. return Runner.Start(Module, $"Swap with {_targetModule}");
  90. }
  91. public RState Monitor()
  92. {
  93. Runner.Wait(SwapStep.WaitModuleReady, () => _llModule.IsIdle, _delay_3m)
  94. .RunIf(SwapStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone, _delay_30s)
  95. .Run(SwapStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  96. .Wait(SwapStep.WaitPressreStable, TMLLPressureIsOK, _delay_60s)
  97. .Run(SwapStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen, _delay_30s)
  98. .LoopStart(SwapStep.MoveWafer, loopName(), _actionList.Count, MoveWafer)
  99. .LoopEnd(SwapStep.WaitMaferMoved, NullFun, WaitWaferMoved)
  100. .Run(SwapStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed, _delay_30s)
  101. .End(SwapStep.NotifyDone, NotifyLLDone, _delay_50ms);
  102. return Runner.Status;
  103. }
  104. private bool TMLLPressureIsOK()
  105. {
  106. if (RouteManager.IsATMMode)
  107. {
  108. return _JetTM.IsTMATM && _JetTM.IsModuleATM(_targetModule);
  109. }
  110. else
  111. {
  112. double llPressure = 0;
  113. if (_targetModule == ModuleName.LLA)
  114. {
  115. llPressure = _JetTM.LLAPressure;
  116. }
  117. else if (_targetModule == ModuleName.LLB)
  118. {
  119. llPressure = _JetTM.LLBPressure;
  120. }
  121. if (Math.Abs((llPressure - _JetTM.ChamberPressure)) < maxPressureDifference - 2)
  122. {
  123. return true;
  124. }
  125. else
  126. {
  127. return false;
  128. }
  129. }
  130. }
  131. private bool ModulePrepare()
  132. {
  133. _llModule.PostMsg(LLEntity.MSG.Prepare_TM);
  134. return true;
  135. }
  136. private string loopName()
  137. {
  138. return "LoadLock Swap";
  139. }
  140. private bool IsModulePrepareReady()
  141. {
  142. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  143. }
  144. private bool OpenSlitDoor()
  145. {
  146. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  147. }
  148. private bool CloseSlitDoor()
  149. {
  150. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  151. }
  152. private bool IsSlitDoorOpen()
  153. {
  154. //if (_targetModule == ModuleName.LLA)
  155. // return _JetTM.IsLLASlitDoorOpen;
  156. //else
  157. // return _JetTM.IsLLBSlitDoorOpen;
  158. if (_targetModule == ModuleName.LLA)
  159. {
  160. if (_JetTM.IsLLASlitDoorOpen)
  161. {
  162. //_llModule.IsDoorsAllClosed = false;
  163. return true;
  164. }
  165. return false;
  166. }
  167. else
  168. {
  169. if (_JetTM.IsLLBSlitDoorOpen)
  170. {
  171. //_llModule.IsDoorsAllClosed = false;
  172. return true;
  173. }
  174. return false;
  175. }
  176. }
  177. private bool IsSlitDoorClosed()
  178. {
  179. if (_targetModule == ModuleName.LLA)
  180. {
  181. if (_JetTM.IsLLASlitDoorClosed)
  182. {
  183. //_llModule.IsDoorsAllClosed = true;
  184. return true;
  185. }
  186. return false;
  187. }
  188. else
  189. {
  190. if (_JetTM.IsLLBSlitDoorClosed)
  191. {
  192. //_llModule.IsDoorsAllClosed = true;
  193. return true;
  194. }
  195. return false;
  196. }
  197. //if (_targetModule == ModuleName.LLA)
  198. // return _JetTM.IsLLASlitDoorClosed;
  199. //else
  200. // return _JetTM.IsLLBSlitDoorClosed;
  201. }
  202. private bool VerifyWaferExistence(MoveItem item)
  203. {
  204. if (WaferManager.Instance.CheckHasWafer(item.DestinationModule, item.DestinationSlot))
  205. {
  206. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as desitination {_currentAction.DestinationModule},{_currentAction.DestinationSlot + 1} already a wafer: ");
  207. return false;
  208. }
  209. if (WaferManager.Instance.CheckNoWafer(_currentAction.SourceModule, _currentAction.SourceSlot))
  210. {
  211. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as source {_currentAction.SourceModule}, {_currentAction.SourceSlot + 1} has no wafer");
  212. return false;
  213. }
  214. return true;
  215. }
  216. private bool MoveWafer()
  217. {
  218. _currentAction = _actionList.Dequeue();
  219. if (!VerifyWaferExistence(_currentAction))
  220. return false;
  221. var wafer = WaferManager.Instance.GetWafer(_currentAction.SourceModule, _currentAction.SourceSlot);
  222. 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}");
  223. if (ModuleHelper.IsLoadLock(_currentAction.SourceModule) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))
  224. {
  225. return _robot.Pick(_currentAction.SourceModule, _currentAction.SourceSlot, (Hand)_currentAction.DestinationSlot);
  226. }
  227. else if (ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsLoadLock(_currentAction.DestinationModule))
  228. {
  229. //if (ModuleHelper.IsLoadLock(_targetModule))
  230. //{
  231. // _llModule.PostMsg(LLEntity.MSG.Transfer_TM_SlotInfo, _currentAction.DestinationSlot);
  232. //}
  233. return _robot.Place(_currentAction.DestinationModule, _currentAction.DestinationSlot, (Hand)_currentAction.SourceSlot);
  234. }
  235. else
  236. {
  237. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TMRobot, $"Invalid move parameter, source:{_currentAction.SourceModule},{_currentAction.SourceSlot}, destination: {_currentAction.DestinationModule}, {_currentAction.DestinationSlot}");
  238. return false;
  239. }
  240. }
  241. private bool WaitWaferMoved()
  242. {
  243. if (_robot.Status == RState.Running)
  244. {
  245. if (Runner.StepElapsedMS > _moveTimeout)
  246. {
  247. WaferManager.Instance.CreateDuplicatedWafer(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  248. Runner.Stop($"TM Robot moving wafer from {_currentAction.SourceModule}.{_currentAction.SourceSlot + 1} to {_currentAction.DestinationModule}.{_currentAction.DestinationSlot + 1} timeout, {_moveTimeout}ms");
  249. return true;
  250. }
  251. return false;
  252. }
  253. else if (_robot.Status == RState.End)
  254. {
  255. WaferManager.Instance.WaferMoved(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  256. return true;
  257. }
  258. else
  259. {
  260. WaferManager.Instance.CreateDuplicatedWafer(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  261. Runner.Stop($"TM Robot moving wafer failed, {_robot.Status}");
  262. return true;
  263. }
  264. }
  265. private bool RotateArm()
  266. {
  267. ModuleName preModule = _targetModule;
  268. Hand rotateHand = Hand.Blade1;
  269. if (ModuleHelper.IsLoadLock(_actionList.Peek().DestinationModule) && ModuleHelper.IsTMRobot(_actionList.Peek().SourceModule))
  270. {
  271. rotateHand = (Hand)_actionList.Peek().SourceSlot;
  272. preModule = _JetTM.PreRotateModules[_targetModule];
  273. }
  274. else
  275. {
  276. rotateHand = (Hand)_actionList.Peek().DestinationSlot;
  277. }
  278. _llModule.PostMsg(LLEntity.MSG.Prepare_TM); // Notify Loadlock to Serv pressure in advance for throughput enhancement
  279. return _robot.Goto(preModule, 0, rotateHand);
  280. }
  281. private bool WaitRotateDone()
  282. {
  283. if (_robot.Status == RState.Running)
  284. {
  285. return false;
  286. }
  287. else if (_robot.Status == RState.End)
  288. {
  289. return true;
  290. }
  291. else
  292. {
  293. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  294. return true;
  295. }
  296. }
  297. private bool NotifyLLDone()
  298. {
  299. _llModule.PostMsg(LLEntity.MSG.TM_Exchange_Ready, _currentactionList.Exists(ac => ModuleHelper.IsLoadLock(ac.DestinationModule)));
  300. return true;
  301. }
  302. public void Abort()
  303. {
  304. //_robot.Halt();
  305. }
  306. }
  307. }