MFPlaceRoutine.cs 9.9 KB

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