MFPlaceRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. namespace Venus_RT.Modules.TM
  17. {
  18. class MFPlaceRoutine : ModuleRoutineBase, IRoutine
  19. {
  20. private enum PlaceStep
  21. {
  22. WaitModuleReady,
  23. PreRotation,
  24. ModulePrepare,
  25. WaitPressreDifference,
  26. OpenSlitDoor,
  27. Placing,
  28. QueryAwc,
  29. CloseSlitDoor,
  30. NotifyDone,
  31. }
  32. private readonly JetTM _JetTM;
  33. private readonly ITransferRobot _robot;
  34. private int _placingTimeout = 120 * 1000;
  35. private ModuleName _targetModule;
  36. private LLEntity _llModule;
  37. int _targetSlot;
  38. Hand _hand;
  39. private DateTime _starttime;
  40. private bool _queryAwc;
  41. private int _autoVentOptInWafer = 0;
  42. private int _autoVentOptOutWafer = 4;
  43. private SequenceLLInOutPath _sequencePattern = SequenceLLInOutPath.DInDOut;
  44. private bool _bAutoMode = true;
  45. double maxPressureDifference;
  46. public MFPlaceRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  47. {
  48. _JetTM = tm;
  49. _robot = robot;
  50. Name = "Place";
  51. if (SC.GetValue<int>($"TM.QueryAWCOption") == 2 || SC.GetValue<int>($"TM.QueryAWCOption") == 3)
  52. _queryAwc = true;
  53. else
  54. _queryAwc = false;
  55. maxPressureDifference = SC.GetValue<double>("System.TMLLMaxPressureDifference");
  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. return Runner.Start(Module, $"Place to {_targetModule}");
  97. }
  98. public RState Monitor()
  99. {
  100. Runner.Wait(PlaceStep.WaitModuleReady, () => _llModule.IsIdle, _delay_60s)
  101. .RunIf(PlaceStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  102. .Run(PlaceStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  103. .Wait(PlaceStep.WaitPressreDifference, TMLLPressureIsOK, _delay_60s)
  104. .Run(PlaceStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen)
  105. .Run(PlaceStep.Placing, Placing, WaitPlaceDone)
  106. .Run(PlaceStep.QueryAwc, QueryAwc, WaitQueryDoneAndRecord)
  107. .Run(PlaceStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed)
  108. .End(PlaceStep.NotifyDone, NotifyLLDone, _delay_50ms);
  109. return Runner.Status;
  110. }
  111. private bool ModulePrepare()
  112. {
  113. _llModule.PostMsg(LLEntity.MSG.Prepare_TM);
  114. return true;
  115. }
  116. private bool IsModulePrepareReady()
  117. {
  118. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  119. }
  120. private bool OpenSlitDoor()
  121. {
  122. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  123. }
  124. private bool TMLLPressureIsOK()
  125. {
  126. double llPressure = 0;
  127. if (_targetModule == ModuleName.LLA)
  128. {
  129. llPressure = _JetTM.LLAPressure;
  130. }
  131. else if (_targetModule == ModuleName.LLB)
  132. {
  133. llPressure = _JetTM.LLBPressure;
  134. }
  135. if (Math.Abs((llPressure - _JetTM.ChamberPressure)) < maxPressureDifference)
  136. {
  137. return true;
  138. }
  139. else
  140. {
  141. return false;
  142. }
  143. }
  144. private bool CloseSlitDoor()
  145. {
  146. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  147. }
  148. private bool IsSlitDoorOpen()
  149. {
  150. if (_targetModule == ModuleName.LLA)
  151. return _JetTM.IsLLASlitDoorOpen;
  152. else
  153. return _JetTM.IsLLBSlitDoorOpen;
  154. }
  155. private bool IsSlitDoorClosed()
  156. {
  157. if (_targetModule == ModuleName.LLA)
  158. return _JetTM.IsLLASlitDoorClosed;
  159. else
  160. return _JetTM.IsLLBSlitDoorClosed;
  161. }
  162. private bool Placing()
  163. {
  164. return _robot.Place(_targetModule, _targetSlot, _hand);
  165. }
  166. private bool WaitPlaceDone()
  167. {
  168. if (_robot.Status == RState.Running)
  169. {
  170. return false;
  171. }
  172. else if (_robot.Status == RState.End)
  173. {
  174. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  175. return true;
  176. }
  177. else
  178. {
  179. Runner.Stop($"TM Robot Place failed, {_robot.Status}");
  180. return true;
  181. }
  182. }
  183. private bool RotateArm()
  184. {
  185. _llModule.PostMsg(LLEntity.MSG.Prepare_TM); // Notify Loadlock to Serv pressure in advance for throughput enhancement
  186. return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _hand);
  187. }
  188. private bool WaitRotateDone()
  189. {
  190. if (_robot.Status == RState.Running)
  191. {
  192. return false;
  193. }
  194. else if (_robot.Status == RState.End)
  195. {
  196. return true;
  197. }
  198. else
  199. {
  200. WaferManager.Instance.CreateDuplicatedWafer(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  201. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  202. return true;
  203. }
  204. }
  205. private bool QueryAwc()
  206. {
  207. if (!_queryAwc)
  208. return true;
  209. if (_robot.QueryAwc())
  210. return true;
  211. else
  212. return false;
  213. }
  214. private bool WaitQueryDoneAndRecord()
  215. {
  216. if (!_queryAwc)
  217. return true;
  218. if (_robot.Status == RState.Running)
  219. {
  220. return false;
  221. }
  222. else if (_robot.Status == RState.End)
  223. {
  224. //已经move后的数据
  225. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  226. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  227. //查询完毕 插入数据
  228. OffsetDataRecorder.RecordOffsetData(
  229. Guid.NewGuid().ToString(),
  230. ModuleName.TMRobot, 0,
  231. _targetModule, _targetSlot,
  232. _origin_module, _origin_slot,
  233. _hand, RobotArmPan.None,
  234. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  235. _starttime, DateTime.Now);
  236. return true;
  237. }
  238. else
  239. {
  240. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  241. return true;
  242. }
  243. }
  244. private bool NotifyLLDone()
  245. {
  246. bool bAutoVent = false;
  247. var waferStatus = _llModule.GetWaferProcessStatus();
  248. if (_bAutoMode)
  249. {
  250. if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLA) ||
  251. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLB)) &&
  252. waferStatus.unprocessed <= _autoVentOptInWafer)
  253. {
  254. bAutoVent = true;
  255. }
  256. else if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLB) ||
  257. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLA)) &&
  258. waferStatus.processed >= _autoVentOptOutWafer)
  259. {
  260. bAutoVent = true;
  261. }
  262. else if (_sequencePattern == SequenceLLInOutPath.DInDOut &&
  263. waferStatus.processed >= _autoVentOptOutWafer &&
  264. waferStatus.unprocessed <= _autoVentOptInWafer)
  265. {
  266. bAutoVent = true;
  267. }
  268. }
  269. 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}");
  270. _llModule.PostMsg(bAutoVent ? LLEntity.MSG.AutoVent : LLEntity.MSG.TM_Exchange_Ready);
  271. return true;
  272. }
  273. public void Abort()
  274. {
  275. _robot.Halt();
  276. }
  277. }
  278. }