MFPickRoutine.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. using MECF.Framework.RT.Core.Equipments;
  17. namespace Venus_RT.Modules.TM
  18. {
  19. class MFPickRoutine : ModuleRoutineBase, IRoutine
  20. {
  21. private enum PickStep
  22. {
  23. WaitModuleReady,
  24. ModulePrepare,
  25. WaitPressreStable,
  26. OpenSlitDoor,
  27. Picking,
  28. QueryAwc,
  29. CloseSlitDoor,
  30. CheckAwc,
  31. NotifyDone,
  32. }
  33. private readonly JetTM _JetTM;
  34. private readonly ITransferRobot _robot;
  35. private int _pickingTimeout = 20 * 1000;
  36. private ModuleName _targetModule;
  37. private LLEntity _llModule;
  38. int _targetSlot;
  39. Hand _hand;
  40. private DateTime _starttime;
  41. private bool _queryAwc;
  42. private int _autoVentOptInWafer = 0;
  43. private int _autoVentOptOutWafer = 4;
  44. private SequenceLLInOutPath _sequencePattern = SequenceLLInOutPath.DInDOut;
  45. private bool _bAutoMode = true;
  46. double maxPressureDifference;
  47. int awcAlarmRange;
  48. int awcWarningRange;
  49. public MFPickRoutine(JetTM tm, ITransferRobot robot) :base(ModuleName.TMRobot)
  50. {
  51. _JetTM = tm;
  52. _robot = robot;
  53. Name = "Pick";
  54. if (SC.GetValue<int>($"TM.QueryAWCOption") == 1 || SC.GetValue<int>($"TM.QueryAWCOption") == 3)
  55. _queryAwc = true;
  56. else
  57. _queryAwc = false;
  58. }
  59. public RState Start(params object[] objs)
  60. {
  61. _starttime = DateTime.Now;
  62. if (!_robot.IsHomed)
  63. {
  64. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  65. return RState.Failed;
  66. }
  67. var pickItem = (Queue<MoveItem>)objs[0];
  68. if (!WaferManager.Instance.CheckDuplicatedWafersBeforeMove(pickItem))
  69. return RState.Failed;
  70. _targetModule = pickItem.Peek().SourceModule;
  71. _targetSlot = pickItem.Peek().SourceSlot;
  72. _hand = pickItem.Peek().RobotHand;
  73. if (ModuleHelper.IsLoadLock(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  74. {
  75. _llModule = Singleton<RouteManager>.Instance.GetLL(_targetModule);
  76. }
  77. else
  78. {
  79. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for picking action");
  80. return RState.Failed;
  81. }
  82. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_hand))
  83. {
  84. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as TM Robot Arm: {_hand} already has a wafer");
  85. return RState.Failed;
  86. }
  87. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  88. {
  89. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as {_targetModule} Slot {_targetSlot + 1} has no wafer");
  90. return RState.Failed;
  91. }
  92. Reset();
  93. _pickingTimeout = SC.GetValue<int>("TM.PickTimeout") * 1000;
  94. _autoVentOptInWafer = SC.GetValue<int>("TM.LLAutoVentInWaferOpt");
  95. _autoVentOptOutWafer = SC.GetValue<int>("TM.LLAutoVentOutWaferOpt");
  96. _sequencePattern = Singleton<RouteManager>.Instance.LLInOutPath;
  97. _bAutoMode = Singleton<RouteManager>.Instance.IsAutoMode;
  98. awcAlarmRange = SC.GetValue<int>($"TM.AWCAlarmRange");
  99. awcWarningRange = SC.GetValue<int>($"TM.AWCWarningRange");
  100. maxPressureDifference = SC.GetValue<double>("System.TMLLMaxPressureDifference");
  101. return Runner.Start(Module, $"Pick from {_targetModule}");
  102. }
  103. public RState Monitor()
  104. {
  105. Runner.Wait(PickStep.WaitModuleReady, () => _llModule.IsIdle, _delay_60s)
  106. .Run(PickStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  107. .Wait(PickStep.WaitPressreStable, TMLLPressureIsOK, _delay_60s)
  108. .Run(PickStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen, _delay_30s)
  109. .Run(PickStep.Picking, Picking, WaitPickDone, _delay_30s)
  110. .Run(PickStep.QueryAwc, QueryAwc, WaitQueryDoneAndRecord, _delay_30s)
  111. .Run(PickStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed, _delay_30s)
  112. //.Run(PickStep.CheckAwc, CheckAwc )
  113. .End(PickStep.NotifyDone, NotifyLLDone, _delay_50ms);
  114. return Runner.Status;
  115. }
  116. private bool ModulePrepare()
  117. {
  118. _llModule.PostMsg(LLEntity.MSG.Prepare_TM);
  119. return true;
  120. }
  121. private bool TMLLPressureIsOK()
  122. {
  123. if (RouteManager.IsATMMode)
  124. {
  125. return _JetTM.IsTMATM && _JetTM.IsModuleATM(_targetModule);
  126. }
  127. else
  128. {
  129. double llPressure = 0;
  130. if (_targetModule == ModuleName.LLA)
  131. {
  132. llPressure = _JetTM.LLAPressure;
  133. }
  134. else if (_targetModule == ModuleName.LLB)
  135. {
  136. llPressure = _JetTM.LLBPressure;
  137. }
  138. if (Math.Abs((llPressure - _JetTM.ChamberPressure)) < (maxPressureDifference-5))
  139. {
  140. return true;
  141. }
  142. else
  143. {
  144. return false;
  145. }
  146. }
  147. }
  148. private bool IsModulePrepareReady()
  149. {
  150. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  151. }
  152. private bool OpenSlitDoor()
  153. {
  154. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  155. }
  156. private bool CloseSlitDoor()
  157. {
  158. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  159. }
  160. private bool IsSlitDoorOpen()
  161. {
  162. if (_targetModule == ModuleName.LLA)
  163. return _JetTM.IsLLASlitDoorOpen;
  164. else
  165. return _JetTM.IsLLBSlitDoorOpen;
  166. }
  167. private bool IsSlitDoorClosed()
  168. {
  169. if (_targetModule == ModuleName.LLA)
  170. return _JetTM.IsLLASlitDoorClosed;
  171. else
  172. return _JetTM.IsLLBSlitDoorClosed;
  173. }
  174. private bool Picking()
  175. {
  176. return _robot.Pick(_targetModule, _targetSlot, _hand);
  177. }
  178. private bool WaitPickDone()
  179. {
  180. if (_robot.Status == RState.Running)
  181. {
  182. if (Runner.StepElapsedMS > _pickingTimeout)
  183. {
  184. WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  185. Runner.Stop($"TM Robot Picking {_targetModule}.{_targetSlot + 1} wafer timeout, {_pickingTimeout}");
  186. return true;
  187. }
  188. return false;
  189. }
  190. else if (_robot.Status == RState.End)
  191. {
  192. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  193. return true;
  194. }
  195. else
  196. {
  197. WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  198. Runner.Stop($"TM Robot Picking 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 CheckAwc()
  212. //{
  213. // if (Math.Abs(_robot.Offset_D) > awcAlarmRange*1000)
  214. // {
  215. // Stop($"Check AWC 失败, 当前 AWC [{_robot.Offset_D}um], 高于Alarm最大值: [{awcAlarmRange}mm]");
  216. // return false;
  217. // }
  218. // if (Math.Abs(_robot.Offset_D) > awcWarningRange*1000)
  219. // {
  220. // Stop($"Check AWC 报警, 当前 AWC [{_robot.Offset_D}um], 高于Warning最大值: [{awcWarningRange}mm]");
  221. // }
  222. // return true;
  223. //}
  224. private bool WaitQueryDoneAndRecord()
  225. {
  226. if (!_queryAwc)
  227. return true;
  228. if (_robot.Status == RState.Running)
  229. {
  230. return false;
  231. }
  232. else if (_robot.Status == RState.End)
  233. {
  234. //已经move后的数据
  235. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  236. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  237. //查询完毕 插入数据
  238. OffsetDataRecorder.RecordOffsetData(
  239. Guid.NewGuid().ToString(),
  240. _targetModule, _targetSlot,
  241. ModuleName.TMRobot, 0,
  242. _origin_module, _origin_slot,
  243. _hand, RobotArmPan.None,
  244. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  245. _starttime, DateTime.Now);
  246. return true;
  247. }
  248. else
  249. {
  250. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  251. return true;
  252. }
  253. }
  254. private bool NotifyLLDone()
  255. {
  256. bool bAutoVent = false;
  257. var waferStatus = _llModule.GetWaferProcessStatus();
  258. if (_bAutoMode)
  259. {
  260. if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLA) ||
  261. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLB)) &&
  262. waferStatus.unprocessed <= _autoVentOptInWafer)
  263. {
  264. bAutoVent = true;
  265. }
  266. else if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLB) ||
  267. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLA)) &&
  268. waferStatus.processed >= _autoVentOptOutWafer)
  269. {
  270. bAutoVent = true;
  271. }
  272. else if (_sequencePattern == SequenceLLInOutPath.DInDOut &&
  273. waferStatus.processed >= _autoVentOptOutWafer &&
  274. waferStatus.unprocessed <= _autoVentOptInWafer)
  275. {
  276. bAutoVent = true;
  277. }
  278. }
  279. 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}");
  280. _llModule.PostMsg(bAutoVent ? LLEntity.MSG.AutoVent : LLEntity.MSG.TM_Exchange_Ready);
  281. return true;
  282. }
  283. public void Abort()
  284. {
  285. //_robot.Halt();
  286. }
  287. }
  288. }