MFPickRoutine.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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-2))
  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. {
  164. if (_JetTM.IsLLASlitDoorOpen)
  165. {
  166. //_llModule.IsDoorsAllClosed = false;
  167. return true;
  168. }
  169. return false;
  170. }
  171. else
  172. {
  173. if (_JetTM.IsLLBSlitDoorOpen)
  174. {
  175. //_llModule.IsDoorsAllClosed = false;
  176. return true;
  177. }
  178. return false;
  179. }
  180. }
  181. private bool IsSlitDoorClosed()
  182. {
  183. if (_targetModule == ModuleName.LLA)
  184. return _JetTM.IsLLASlitDoorClosed;
  185. else
  186. return _JetTM.IsLLBSlitDoorClosed;
  187. }
  188. private bool Picking()
  189. {
  190. return _robot.Pick(_targetModule, _targetSlot, _hand);
  191. }
  192. private bool WaitPickDone()
  193. {
  194. if (_robot.Status == RState.Running)
  195. {
  196. if (Runner.StepElapsedMS > _pickingTimeout)
  197. {
  198. WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  199. Runner.Stop($"TM Robot Picking {_targetModule}.{_targetSlot + 1} wafer timeout, {_pickingTimeout}");
  200. return true;
  201. }
  202. return false;
  203. }
  204. else if (_robot.Status == RState.End)
  205. {
  206. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  207. return true;
  208. }
  209. else
  210. {
  211. WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  212. Runner.Stop($"TM Robot Picking failed, {_robot.Status}");
  213. return true;
  214. }
  215. }
  216. private bool QueryAwc()
  217. {
  218. if (!_queryAwc)
  219. return true;
  220. if (_robot.QueryAwc())
  221. return true;
  222. else
  223. return false;
  224. }
  225. //private bool CheckAwc()
  226. //{
  227. // if (Math.Abs(_robot.Offset_D) > awcAlarmRange*1000)
  228. // {
  229. // Stop($"Check AWC 失败, 当前 AWC [{_robot.Offset_D}um], 高于Alarm最大值: [{awcAlarmRange}mm]");
  230. // return false;
  231. // }
  232. // if (Math.Abs(_robot.Offset_D) > awcWarningRange*1000)
  233. // {
  234. // Stop($"Check AWC 报警, 当前 AWC [{_robot.Offset_D}um], 高于Warning最大值: [{awcWarningRange}mm]");
  235. // }
  236. // return true;
  237. //}
  238. private bool WaitQueryDoneAndRecord()
  239. {
  240. if (!_queryAwc)
  241. return true;
  242. if (_robot.Status == RState.Running)
  243. {
  244. return false;
  245. }
  246. else if (_robot.Status == RState.End)
  247. {
  248. //已经move后的数据
  249. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  250. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  251. //查询完毕 插入数据
  252. OffsetDataRecorder.RecordOffsetData(
  253. Guid.NewGuid().ToString(),
  254. _targetModule, _targetSlot,
  255. ModuleName.TMRobot, 0,
  256. _origin_module, _origin_slot,
  257. _hand, RobotArmPan.None,
  258. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  259. _starttime, DateTime.Now);
  260. return true;
  261. }
  262. else
  263. {
  264. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  265. return true;
  266. }
  267. }
  268. private bool NotifyLLDone()
  269. {
  270. bool bAutoVent = false;
  271. var waferStatus = _llModule.GetWaferProcessStatus();
  272. if (_bAutoMode)
  273. {
  274. if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLA) ||
  275. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLB)) &&
  276. waferStatus.unprocessed <= _autoVentOptInWafer)
  277. {
  278. bAutoVent = true;
  279. }
  280. else if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLB) ||
  281. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLA)) &&
  282. waferStatus.processed >= _autoVentOptOutWafer)
  283. {
  284. bAutoVent = true;
  285. }
  286. else if (_sequencePattern == SequenceLLInOutPath.DInDOut &&
  287. waferStatus.processed >= _autoVentOptOutWafer &&
  288. waferStatus.unprocessed <= _autoVentOptInWafer)
  289. {
  290. bAutoVent = true;
  291. }
  292. }
  293. 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}");
  294. _llModule.PostMsg(LLEntity.MSG.TM_Exchange_Ready, false);
  295. return true;
  296. }
  297. public void Abort()
  298. {
  299. //_robot.Halt();
  300. }
  301. }
  302. }