MFPlaceRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. _targetModule = placeItem.Peek().DestinationModule;
  67. _targetSlot = placeItem.Peek().DestinationSlot;
  68. _hand = placeItem.Peek().RobotHand;
  69. if (ModuleHelper.IsLoadLock(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  70. {
  71. _llModule = Singleton<RouteManager>.Instance.GetLL(_targetModule);
  72. }
  73. else
  74. {
  75. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for place action");
  76. return RState.Failed;
  77. }
  78. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_hand))
  79. {
  80. LOG.Write(eEvent.ERR_TM, Module, $"Cannot place as TM Robot Arm: {_hand} has no wafer");
  81. return RState.Failed;
  82. }
  83. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  84. {
  85. LOG.Write(eEvent.ERR_TM, Module, $"Cannot place as {_targetModule} Slot {_targetSlot + 1} already has a wafer");
  86. return RState.Failed;
  87. }
  88. Reset();
  89. _placingTimeout = SC.GetValue<int>($"TM.PlaceTimeout") * 1000;
  90. _autoVentOptInWafer = SC.GetValue<int>("TM.LLAutoVentInWaferOpt");
  91. _autoVentOptOutWafer = SC.GetValue<int>("TM.LLAutoVentOutWaferOpt");
  92. _sequencePattern = Singleton<RouteManager>.Instance.LLInOutPath;
  93. _bAutoMode = Singleton<RouteManager>.Instance.IsAutoMode;
  94. return Runner.Start(Module, $"Place to {_targetModule}");
  95. }
  96. public RState Monitor()
  97. {
  98. Runner.Wait(PlaceStep.WaitModuleReady, () => _llModule.IsIdle, _delay_60s)
  99. .RunIf(PlaceStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  100. .Run(PlaceStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  101. .Wait(PlaceStep.WaitPressreDifference, TMLLPressureIsOK, _delay_60s)
  102. .Run(PlaceStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen)
  103. .Run(PlaceStep.Placing, Placing, WaitPlaceDone)
  104. .Run(PlaceStep.QueryAwc, QueryAwc, WaitQueryDoneAndRecord)
  105. .Run(PlaceStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed)
  106. .End(PlaceStep.NotifyDone, NotifyLLDone, _delay_50ms);
  107. return Runner.Status;
  108. }
  109. private bool ModulePrepare()
  110. {
  111. _llModule.PostMsg(LLEntity.MSG.Prepare_TM);
  112. return true;
  113. }
  114. private bool IsModulePrepareReady()
  115. {
  116. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  117. }
  118. private bool OpenSlitDoor()
  119. {
  120. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  121. }
  122. private bool TMLLPressureIsOK()
  123. {
  124. double llPressure = 0;
  125. if (_targetModule == ModuleName.LLA)
  126. {
  127. llPressure = _JetTM.LLAPressure;
  128. }
  129. else if (_targetModule == ModuleName.LLB)
  130. {
  131. llPressure = _JetTM.LLBPressure;
  132. }
  133. if (Math.Abs((llPressure - _JetTM.ChamberPressure)) < maxPressureDifference)
  134. {
  135. return true;
  136. }
  137. else
  138. {
  139. return false;
  140. }
  141. }
  142. private bool CloseSlitDoor()
  143. {
  144. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  145. }
  146. private bool IsSlitDoorOpen()
  147. {
  148. if (_targetModule == ModuleName.LLA)
  149. return _JetTM.IsLLASlitDoorOpen;
  150. else
  151. return _JetTM.IsLLBSlitDoorOpen;
  152. }
  153. private bool IsSlitDoorClosed()
  154. {
  155. if (_targetModule == ModuleName.LLA)
  156. return _JetTM.IsLLASlitDoorClosed;
  157. else
  158. return _JetTM.IsLLBSlitDoorClosed;
  159. }
  160. private bool Placing()
  161. {
  162. return _robot.Place(_targetModule, _targetSlot, _hand);
  163. }
  164. private bool WaitPlaceDone()
  165. {
  166. if (_robot.Status == RState.Running)
  167. {
  168. return false;
  169. }
  170. else if (_robot.Status == RState.End)
  171. {
  172. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  173. return true;
  174. }
  175. else
  176. {
  177. Runner.Stop($"TM Robot Place failed, {_robot.Status}");
  178. return true;
  179. }
  180. }
  181. private bool RotateArm()
  182. {
  183. _llModule.PostMsg(LLEntity.MSG.Prepare_TM); // Notify Loadlock to Serv pressure in advance for throughput enhancement
  184. return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _hand);
  185. }
  186. private bool WaitRotateDone()
  187. {
  188. if (_robot.Status == RState.Running)
  189. {
  190. return false;
  191. }
  192. else if (_robot.Status == RState.End)
  193. {
  194. return true;
  195. }
  196. else
  197. {
  198. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  199. return true;
  200. }
  201. }
  202. private bool QueryAwc()
  203. {
  204. if (!_queryAwc)
  205. return true;
  206. if (_robot.QueryAwc())
  207. return true;
  208. else
  209. return false;
  210. }
  211. private bool WaitQueryDoneAndRecord()
  212. {
  213. if (!_queryAwc)
  214. return true;
  215. if (_robot.Status == RState.Running)
  216. {
  217. return false;
  218. }
  219. else if (_robot.Status == RState.End)
  220. {
  221. //已经move后的数据
  222. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  223. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  224. //查询完毕 插入数据
  225. OffsetDataRecorder.RecordOffsetData(
  226. Guid.NewGuid().ToString(),
  227. ModuleName.TMRobot, 0,
  228. _targetModule, _targetSlot,
  229. _origin_module, _origin_slot,
  230. _hand, RobotArmPan.None,
  231. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  232. _starttime, DateTime.Now);
  233. return true;
  234. }
  235. else
  236. {
  237. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  238. return true;
  239. }
  240. }
  241. private bool NotifyLLDone()
  242. {
  243. bool bAutoVent = false;
  244. var waferStatus = _llModule.GetWaferProcessStatus();
  245. if (_bAutoMode)
  246. {
  247. if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLA) ||
  248. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLB)) &&
  249. waferStatus.unprocessed <= _autoVentOptInWafer)
  250. {
  251. bAutoVent = true;
  252. }
  253. else if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLB) ||
  254. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLA)) &&
  255. waferStatus.processed >= _autoVentOptOutWafer)
  256. {
  257. bAutoVent = true;
  258. }
  259. else if (_sequencePattern == SequenceLLInOutPath.DInDOut &&
  260. waferStatus.processed >= _autoVentOptOutWafer &&
  261. waferStatus.unprocessed <= _autoVentOptInWafer)
  262. {
  263. bAutoVent = true;
  264. }
  265. }
  266. 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}");
  267. _llModule.PostMsg(bAutoVent ? LLEntity.MSG.AutoVent : LLEntity.MSG.TM_Exchange_Ready);
  268. return true;
  269. }
  270. public void Abort()
  271. {
  272. _robot.Halt();
  273. }
  274. }
  275. }