MFPlaceRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  201. return true;
  202. }
  203. }
  204. private bool QueryAwc()
  205. {
  206. if (!_queryAwc)
  207. return true;
  208. if (_robot.QueryAwc())
  209. return true;
  210. else
  211. return false;
  212. }
  213. private bool WaitQueryDoneAndRecord()
  214. {
  215. if (!_queryAwc)
  216. return true;
  217. if (_robot.Status == RState.Running)
  218. {
  219. return false;
  220. }
  221. else if (_robot.Status == RState.End)
  222. {
  223. //已经move后的数据
  224. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  225. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  226. //查询完毕 插入数据
  227. OffsetDataRecorder.RecordOffsetData(
  228. Guid.NewGuid().ToString(),
  229. ModuleName.TMRobot, 0,
  230. _targetModule, _targetSlot,
  231. _origin_module, _origin_slot,
  232. _hand, RobotArmPan.None,
  233. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  234. _starttime, DateTime.Now);
  235. return true;
  236. }
  237. else
  238. {
  239. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  240. return true;
  241. }
  242. }
  243. private bool NotifyLLDone()
  244. {
  245. bool bAutoVent = false;
  246. var waferStatus = _llModule.GetWaferProcessStatus();
  247. if (_bAutoMode)
  248. {
  249. if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLA) ||
  250. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLB)) &&
  251. waferStatus.unprocessed <= _autoVentOptInWafer)
  252. {
  253. bAutoVent = true;
  254. }
  255. else if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLB) ||
  256. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLA)) &&
  257. waferStatus.processed >= _autoVentOptOutWafer)
  258. {
  259. bAutoVent = true;
  260. }
  261. else if (_sequencePattern == SequenceLLInOutPath.DInDOut &&
  262. waferStatus.processed >= _autoVentOptOutWafer &&
  263. waferStatus.unprocessed <= _autoVentOptInWafer)
  264. {
  265. bAutoVent = true;
  266. }
  267. }
  268. 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}");
  269. _llModule.PostMsg(bAutoVent ? LLEntity.MSG.AutoVent : LLEntity.MSG.TM_Exchange_Ready);
  270. return true;
  271. }
  272. public void Abort()
  273. {
  274. _robot.Halt();
  275. }
  276. }
  277. }