MFPickRoutine.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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 MFPickRoutine : ModuleRoutineBase, IRoutine
  19. {
  20. private enum PickStep
  21. {
  22. WaitModuleReady,
  23. ModulePrepare,
  24. WaitPressreDifference,
  25. OpenSlitDoor,
  26. Picking,
  27. QueryAwc,
  28. CloseSlitDoor,
  29. NotifyDone,
  30. }
  31. private readonly JetTM _JetTM;
  32. private readonly ITransferRobot _robot;
  33. private int _pickingTimeout = 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. double maxPressureDifference;
  45. public MFPickRoutine(JetTM tm, ITransferRobot robot) :base(ModuleName.TMRobot)
  46. {
  47. _JetTM = tm;
  48. _robot = robot;
  49. Name = "Pick";
  50. if (SC.GetValue<int>($"TM.QueryAWCOption") == 1 || SC.GetValue<int>($"TM.QueryAWCOption") == 3)
  51. _queryAwc = true;
  52. else
  53. _queryAwc = false;
  54. maxPressureDifference = SC.GetValue<double>("System.TMLLMaxPressureDifference");
  55. }
  56. public RState Start(params object[] objs)
  57. {
  58. _starttime = DateTime.Now;
  59. if (!_robot.IsHomed)
  60. {
  61. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  62. return RState.Failed;
  63. }
  64. var pickItem = (Queue<MoveItem>)objs[0];
  65. if (!WaferManager.Instance.CheckDuplicatedWafersBeforeMove(pickItem))
  66. return RState.Failed;
  67. _targetModule = pickItem.Peek().SourceModule;
  68. _targetSlot = pickItem.Peek().SourceSlot;
  69. _hand = pickItem.Peek().RobotHand;
  70. if (ModuleHelper.IsLoadLock(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  71. {
  72. _llModule = Singleton<RouteManager>.Instance.GetLL(_targetModule);
  73. }
  74. else
  75. {
  76. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for picking action");
  77. return RState.Failed;
  78. }
  79. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_hand))
  80. {
  81. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as TM Robot Arm: {_hand} already has a wafer");
  82. return RState.Failed;
  83. }
  84. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  85. {
  86. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as {_targetModule} Slot {_targetSlot + 1} has no wafer");
  87. return RState.Failed;
  88. }
  89. Reset();
  90. _pickingTimeout = SC.GetValue<int>("TM.PickTimeout") * 1000;
  91. _autoVentOptInWafer = SC.GetValue<int>("TM.LLAutoVentInWaferOpt");
  92. _autoVentOptOutWafer = SC.GetValue<int>("TM.LLAutoVentOutWaferOpt");
  93. _sequencePattern = Singleton<RouteManager>.Instance.LLInOutPath;
  94. _bAutoMode = Singleton<RouteManager>.Instance.IsAutoMode;
  95. return Runner.Start(Module, $"Pick from {_targetModule}");
  96. }
  97. public RState Monitor()
  98. {
  99. Runner.Wait(PickStep.WaitModuleReady, () => _llModule.IsIdle, _delay_60s)
  100. .Run(PickStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  101. .Wait(PickStep.WaitPressreDifference, TMLLPressureIsOK, _delay_60s)
  102. .Run(PickStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen)
  103. .Run(PickStep.Picking, Picking, WaitPickDone)
  104. .Run(PickStep.QueryAwc, QueryAwc, WaitQueryDoneAndRecord)
  105. .Run(PickStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed)
  106. .End(PickStep.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 TMLLPressureIsOK()
  115. {
  116. double llPressure=0;
  117. if (_targetModule == ModuleName.LLA)
  118. {
  119. llPressure = _JetTM.LLAPressure;
  120. }
  121. else if(_targetModule == ModuleName.LLB)
  122. {
  123. llPressure = _JetTM.LLBPressure;
  124. }
  125. if (Math.Abs((llPressure - _JetTM.ChamberPressure)) < maxPressureDifference)
  126. {
  127. return true;
  128. }
  129. else
  130. {
  131. return false;
  132. }
  133. }
  134. private bool IsModulePrepareReady()
  135. {
  136. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  137. }
  138. private bool OpenSlitDoor()
  139. {
  140. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  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 Picking()
  161. {
  162. return _robot.Pick(_targetModule, _targetSlot, _hand);
  163. }
  164. private bool WaitPickDone()
  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.TM, (int)_hand, _targetModule, _targetSlot);
  173. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  174. return true;
  175. }
  176. else
  177. {
  178. Runner.Stop($"TM Robot Picking failed, {_robot.Status}");
  179. return true;
  180. }
  181. }
  182. private bool QueryAwc()
  183. {
  184. if (!_queryAwc)
  185. return true;
  186. if (_robot.QueryAwc())
  187. return true;
  188. else
  189. return false;
  190. }
  191. private bool WaitQueryDoneAndRecord()
  192. {
  193. if (!_queryAwc)
  194. return true;
  195. if (_robot.Status == RState.Running)
  196. {
  197. return false;
  198. }
  199. else if (_robot.Status == RState.End)
  200. {
  201. //已经move后的数据
  202. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  203. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  204. //查询完毕 插入数据
  205. OffsetDataRecorder.RecordOffsetData(
  206. Guid.NewGuid().ToString(),
  207. _targetModule, _targetSlot,
  208. ModuleName.TMRobot, 0,
  209. _origin_module, _origin_slot,
  210. _hand, RobotArmPan.None,
  211. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  212. _starttime, DateTime.Now);
  213. return true;
  214. }
  215. else
  216. {
  217. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  218. return true;
  219. }
  220. }
  221. private bool NotifyLLDone()
  222. {
  223. bool bAutoVent = false;
  224. var waferStatus = _llModule.GetWaferProcessStatus();
  225. if (_bAutoMode)
  226. {
  227. if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLA) ||
  228. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLB)) &&
  229. waferStatus.unprocessed <= _autoVentOptInWafer)
  230. {
  231. bAutoVent = true;
  232. }
  233. else if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLB) ||
  234. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLA)) &&
  235. waferStatus.processed >= _autoVentOptOutWafer)
  236. {
  237. bAutoVent = true;
  238. }
  239. else if (_sequencePattern == SequenceLLInOutPath.DInDOut &&
  240. waferStatus.processed >= _autoVentOptOutWafer &&
  241. waferStatus.unprocessed <= _autoVentOptInWafer)
  242. {
  243. bAutoVent = true;
  244. }
  245. }
  246. 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}");
  247. _llModule.PostMsg(bAutoVent ? LLEntity.MSG.AutoVent : LLEntity.MSG.TM_Exchange_Ready);
  248. return true;
  249. }
  250. public void Abort()
  251. {
  252. _robot.Halt();
  253. }
  254. }
  255. }