MFPlaceRoutine.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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 MECF.Framework.Common.Schedulers;
  13. using System.Collections.Generic;
  14. using System;
  15. using MECF.Framework.Common.DBCore;
  16. using System.Runtime.InteropServices;
  17. namespace Venus_RT.Modules.TM
  18. {
  19. class MFPlaceRoutine : ModuleRoutineBase, IRoutine
  20. {
  21. private enum PlaceStep
  22. {
  23. WaitModuleReady,
  24. PreRotation,
  25. ModulePrepare,
  26. WaitPressreStable,
  27. OpenSlitDoor,
  28. Placing,
  29. QueryAwc,
  30. CloseSlitDoor,
  31. NotifyDone,
  32. }
  33. private readonly JetTM _JetTM;
  34. private readonly ITransferRobot _robot;
  35. private int _placingTimeout = 20 * 1000;
  36. private ModuleName _targetModule;
  37. private LLEntity _llModule;
  38. int _targetSlot;
  39. Hand _hand;
  40. private DateTime _starttime;
  41. private bool _queryAwc;
  42. private int _autoVentOptInWafer = 0;
  43. private int _autoVentOptOutWafer = 4;
  44. private SequenceLLInOutPath _sequencePattern = SequenceLLInOutPath.DInDOut;
  45. private bool _bAutoMode = true;
  46. double maxPressureDifference;
  47. public MFPlaceRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  48. {
  49. _JetTM = tm;
  50. _robot = robot;
  51. Name = "Place";
  52. if (SC.GetValue<int>($"TM.QueryAWCOption") == 2 || SC.GetValue<int>($"TM.QueryAWCOption") == 3)
  53. _queryAwc = true;
  54. else
  55. _queryAwc = false;
  56. }
  57. public RState Start(params object[] objs)
  58. {
  59. _starttime = DateTime.Now;
  60. if (!_robot.IsHomed)
  61. {
  62. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  63. return RState.Failed;
  64. }
  65. var placeItem = (Queue<MoveItem>)objs[0];
  66. if (!WaferManager.Instance.CheckDuplicatedWafersBeforeMove(placeItem))
  67. return RState.Failed;
  68. _targetModule = placeItem.Peek().DestinationModule;
  69. _targetSlot = placeItem.Peek().DestinationSlot;
  70. _hand = placeItem.Peek().RobotHand;
  71. if (ModuleHelper.IsLoadLock(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  72. {
  73. _llModule = Singleton<RouteManager>.Instance.GetLL(_targetModule);
  74. }
  75. else
  76. {
  77. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for place action");
  78. return RState.Failed;
  79. }
  80. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_hand))
  81. {
  82. LOG.Write(eEvent.ERR_TM, Module, $"Cannot place as TM Robot Arm: {_hand} has no wafer");
  83. return RState.Failed;
  84. }
  85. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  86. {
  87. LOG.Write(eEvent.ERR_TM, Module, $"Cannot place as {_targetModule} Slot {_targetSlot + 1} already has a wafer");
  88. return RState.Failed;
  89. }
  90. Reset();
  91. _placingTimeout = SC.GetValue<int>($"TM.PlaceTimeout") * 1000;
  92. _autoVentOptInWafer = SC.GetValue<int>("TM.LLAutoVentInWaferOpt");
  93. _autoVentOptOutWafer = SC.GetValue<int>("TM.LLAutoVentOutWaferOpt");
  94. _sequencePattern = Singleton<RouteManager>.Instance.LLInOutPath;
  95. _bAutoMode = Singleton<RouteManager>.Instance.IsAutoMode;
  96. maxPressureDifference = SC.GetValue<double>("System.TMLLMaxPressureDifference");
  97. return Runner.Start(Module, $"Place to {_targetModule}");
  98. }
  99. public RState Monitor()
  100. {
  101. Runner.Wait(PlaceStep.WaitModuleReady, () => _llModule.IsIdle, _delay_3m)
  102. .RunIf(PlaceStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone, _delay_30s)
  103. .Run(PlaceStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  104. .Wait(PlaceStep.WaitPressreStable, TMLLPressureIsOK, _delay_60s)
  105. .Run(PlaceStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen, _delay_30s)
  106. .Run(PlaceStep.Placing, Placing, WaitPlaceDone, _delay_30s)
  107. .Run(PlaceStep.QueryAwc, QueryAwc, WaitQueryDoneAndRecord, _delay_30s)
  108. .Run(PlaceStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed, _delay_30s)
  109. .End(PlaceStep.NotifyDone, NotifyLLDone, _delay_50ms);
  110. return Runner.Status;
  111. }
  112. private bool ModulePrepare()
  113. {
  114. _llModule.PostMsg(LLEntity.MSG.Prepare_TM);
  115. return true;
  116. }
  117. private bool IsModulePrepareReady()
  118. {
  119. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  120. }
  121. private bool OpenSlitDoor()
  122. {
  123. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  124. }
  125. private bool TMLLPressureIsOK()
  126. {
  127. if (RouteManager.IsATMMode)
  128. {
  129. return _JetTM.IsTMATM && _JetTM.IsModuleATM(_targetModule);
  130. }
  131. else
  132. {
  133. double llPressure = 0;
  134. if (_targetModule == ModuleName.LLA)
  135. {
  136. llPressure = _JetTM.LLAPressure;
  137. }
  138. else if (_targetModule == ModuleName.LLB)
  139. {
  140. llPressure = _JetTM.LLBPressure;
  141. }
  142. if (Math.Abs((llPressure - _JetTM.ChamberPressure)) < maxPressureDifference - 2)
  143. {
  144. return true;
  145. }
  146. else
  147. {
  148. return false;
  149. }
  150. }
  151. }
  152. private bool CloseSlitDoor()
  153. {
  154. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  155. }
  156. private bool IsSlitDoorOpen()
  157. {
  158. if (_targetModule == ModuleName.LLA)
  159. return _JetTM.IsLLASlitDoorOpen;
  160. else
  161. return _JetTM.IsLLBSlitDoorOpen;
  162. }
  163. private bool IsSlitDoorClosed()
  164. {
  165. if (_targetModule == ModuleName.LLA)
  166. return _JetTM.IsLLASlitDoorClosed;
  167. else
  168. return _JetTM.IsLLBSlitDoorClosed;
  169. }
  170. private bool Placing()
  171. {
  172. return _robot.Place(_targetModule, _targetSlot, _hand);
  173. }
  174. private bool WaitPlaceDone()
  175. {
  176. if (_robot.Status == RState.Running)
  177. {
  178. return false;
  179. }
  180. else if (_robot.Status == RState.End)
  181. {
  182. //if (ModuleHelper.IsLoadLock(_targetModule))
  183. //{
  184. // _llModule.PostMsg(LLEntity.MSG.Transfer_TM_SlotInfo, _targetSlot);
  185. //}
  186. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  187. return true;
  188. }
  189. else
  190. {
  191. Runner.Stop($"TM Robot Place failed, {_robot.Status}");
  192. return true;
  193. }
  194. }
  195. private bool RotateArm()
  196. {
  197. _llModule.PostMsg(LLEntity.MSG.Prepare_TM); // Notify Loadlock to Serv pressure in advance for throughput enhancement
  198. return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _hand);
  199. }
  200. private bool WaitRotateDone()
  201. {
  202. if (_robot.Status == RState.Running)
  203. {
  204. if (Runner.StepElapsedMS > _placingTimeout)
  205. {
  206. WaferManager.Instance.CreateDuplicatedWafer(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  207. Runner.Stop($"TM Robot place wafer to {_targetModule}.{_targetSlot + 1} timeout, {_placingTimeout}ms");
  208. return true;
  209. }
  210. return false;
  211. }
  212. else if (_robot.Status == RState.End)
  213. {
  214. return true;
  215. }
  216. else
  217. {
  218. WaferManager.Instance.CreateDuplicatedWafer(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  219. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  220. return true;
  221. }
  222. }
  223. private bool QueryAwc()
  224. {
  225. if (!_queryAwc)
  226. return true;
  227. if (_robot.QueryAwc())
  228. return true;
  229. else
  230. return false;
  231. }
  232. private bool WaitQueryDoneAndRecord()
  233. {
  234. if (!_queryAwc)
  235. return true;
  236. if (_robot.Status == RState.Running)
  237. {
  238. return false;
  239. }
  240. else if (_robot.Status == RState.End)
  241. {
  242. //已经move后的数据
  243. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  244. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  245. //查询完毕 插入数据
  246. OffsetDataRecorder.RecordOffsetData(
  247. Guid.NewGuid().ToString(),
  248. ModuleName.TMRobot, 0,
  249. _targetModule, _targetSlot,
  250. _origin_module, _origin_slot,
  251. _hand, RobotArmPan.None,
  252. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  253. _starttime, DateTime.Now);
  254. return true;
  255. }
  256. else
  257. {
  258. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  259. return true;
  260. }
  261. }
  262. private bool NotifyLLDone()
  263. {
  264. bool bAutoVent = false;
  265. var waferStatus = _llModule.GetWaferProcessStatus();
  266. if (_bAutoMode)
  267. {
  268. if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLA) ||
  269. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLB)) &&
  270. waferStatus.unprocessed <= _autoVentOptInWafer)
  271. {
  272. bAutoVent = true;
  273. }
  274. else if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLB) ||
  275. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLA)) &&
  276. waferStatus.processed >= _autoVentOptOutWafer)
  277. {
  278. bAutoVent = true;
  279. }
  280. else if (_sequencePattern == SequenceLLInOutPath.DInDOut &&
  281. waferStatus.processed >= _autoVentOptOutWafer &&
  282. waferStatus.unprocessed <= _autoVentOptInWafer)
  283. {
  284. bAutoVent = true;
  285. }
  286. }
  287. 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}");
  288. _llModule.PostMsg(LLEntity.MSG.TM_Exchange_Ready, true);
  289. return true;
  290. }
  291. public void Abort()
  292. {
  293. //_robot.Halt();
  294. }
  295. }
  296. }