MFPickRoutine.cs 9.9 KB

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