MFSwapRoutine.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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 System;
  13. using System.Text;
  14. using System.Collections.Generic;
  15. using MECF.Framework.Common.Schedulers;
  16. using System.Linq;
  17. using MECF.Framework.Common.DBCore;
  18. namespace Venus_RT.Modules.TM
  19. {
  20. class MFSwapRoutine : ModuleRoutineBase, IRoutine
  21. {
  22. private enum SwapStep
  23. {
  24. WaitModuleReady,
  25. PreRotation,
  26. ModulePrepare,
  27. WaitPressreStable,
  28. OpenSlitDoor,
  29. MoveWafer,
  30. WaitMaferMoved,
  31. QueryAwc,
  32. CheckAwc,
  33. MoveEnd,
  34. CloseSlitDoor,
  35. NotifyDone,
  36. }
  37. private readonly JetTM _JetTM;
  38. private readonly ITransferRobot _robot;
  39. private int _moveTimeout = 30 * 1000;
  40. private ModuleName _targetModule;
  41. private LLEntity _llModule;
  42. //private int _autoVentOptInWafer = 0;
  43. //private int _autoVentOptOutWafer = 4;
  44. private SequenceLLInOutPath _sequencePattern = SequenceLLInOutPath.DInDOut;
  45. //private bool _bAutoMode = true;
  46. private bool _isAWC;
  47. Queue<MoveItem> _actionList = new Queue<MoveItem>();
  48. MoveItem _currentAction;
  49. double maxPressureDifference;
  50. List<MoveItem> _currentactionList=new List<MoveItem>();
  51. private DateTime _starttime;
  52. int awcAlarmRange;
  53. private bool _pickQueryAWC;
  54. private bool _placeQueryAWC;
  55. public MFSwapRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  56. {
  57. _JetTM = tm;
  58. _robot = robot;
  59. Name = "Swap";
  60. }
  61. public RState Start(params object[] objs)
  62. {
  63. if (!_robot.IsHomed)
  64. {
  65. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  66. return RState.Failed;
  67. }
  68. _actionList.Clear();
  69. foreach (var item in (Queue<MoveItem>)objs[0])
  70. {
  71. _actionList.Enqueue(new MoveItem(item.SourceModule, item.SourceSlot, item.DestinationModule, item.DestinationSlot, item.RobotHand));
  72. }
  73. if (!WaferManager.Instance.CheckDuplicatedWafersBeforeMove(_actionList))
  74. return RState.Failed;
  75. var firtItem = _actionList.Peek();
  76. if (ModuleHelper.IsLoadLock(firtItem.SourceModule))
  77. _targetModule = firtItem.SourceModule;
  78. else if (ModuleHelper.IsLoadLock(firtItem.DestinationModule))
  79. _targetModule = firtItem.DestinationModule;
  80. else
  81. {
  82. LOG.Write(eEvent.ERR_TM, Module, $"Invalid move parameter: {firtItem.SourceModule},{firtItem.SourceSlot + 1} => {firtItem.DestinationModule},{firtItem.DestinationSlot + 1} ");
  83. return RState.Failed;
  84. }
  85. _llModule = Singleton<RouteManager>.Instance.GetLL(_targetModule);
  86. if (_llModule == null)
  87. {
  88. LOG.Write(eEvent.ERR_TM, Module, $"Invalid Loadlock: {_targetModule}, maybe not installed");
  89. return RState.Failed;
  90. }
  91. Reset();
  92. //_autoVentOptInWafer = SC.GetValue<int>("TM.LLAutoVentInWaferOpt");
  93. //_autoVentOptOutWafer = SC.GetValue<int>("TM.LLAutoVentOutWaferOpt");
  94. _sequencePattern = Singleton<RouteManager>.Instance.LLInOutPath;
  95. //_bAutoMode = Singleton<RouteManager>.Instance.IsAutoMode;
  96. maxPressureDifference = SC.GetValue<double>("System.TMLLMaxPressureDifference");
  97. _currentactionList = _actionList.ToList();
  98. awcAlarmRange = SC.GetValue<int>($"TM.EnterLLAWCAlarmLimit");
  99. int queryAWCType = SC.GetValue<int>($"TM.QueryAWCOption");
  100. if (queryAWCType == 0)
  101. {
  102. _pickQueryAWC = false;
  103. _placeQueryAWC = false;
  104. }
  105. else if(queryAWCType == 1)
  106. {
  107. _pickQueryAWC = true;
  108. }
  109. else if (queryAWCType == 2)
  110. {
  111. _placeQueryAWC = true;
  112. }
  113. else if (queryAWCType == 3)
  114. {
  115. _pickQueryAWC = true;
  116. _placeQueryAWC = true;
  117. }
  118. return Runner.Start(Module, $"Swap with {_targetModule}");
  119. }
  120. public RState Monitor()
  121. {
  122. Runner.Wait(SwapStep.WaitModuleReady, () => _llModule.IsIdle, _delay_3m)
  123. .RunIf(SwapStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone, _delay_30s)
  124. .Run(SwapStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  125. .Wait(SwapStep.WaitPressreStable, TMLLPressureIsOK, _delay_60s)
  126. .Run(SwapStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen, _delay_30s)
  127. .LoopStart(SwapStep.MoveWafer, loopName(), _actionList.Count, MoveWafer)
  128. .LoopRun(SwapStep.WaitMaferMoved, NullFun, WaitWaferMoved)
  129. .LoopRunIf(SwapStep.QueryAwc, _isAWC, QueryAwc, WaitQueryDoneAndRecord,_delay_30s)
  130. .LoopRunIf(SwapStep.CheckAwc, _isAWC, CheckAwc)
  131. .LoopEnd(SwapStep.MoveEnd, NullFun)
  132. .Run(SwapStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed, _delay_30s)
  133. .End(SwapStep.NotifyDone, NotifyLLDone, _delay_50ms);
  134. return Runner.Status;
  135. }
  136. private bool TMLLPressureIsOK()
  137. {
  138. if (RouteManager.IsATMMode)
  139. {
  140. return _JetTM.IsTMATM && _JetTM.IsModuleATM(_targetModule);
  141. }
  142. else
  143. {
  144. double llPressure = 0;
  145. if (_targetModule == ModuleName.LLA)
  146. {
  147. llPressure = _JetTM.LLAPressure;
  148. }
  149. else if (_targetModule == ModuleName.LLB)
  150. {
  151. llPressure = _JetTM.LLBPressure;
  152. }
  153. if (Math.Abs((llPressure - _JetTM.ChamberPressure)) < maxPressureDifference - 2)
  154. {
  155. return true;
  156. }
  157. else
  158. {
  159. return false;
  160. }
  161. }
  162. }
  163. private bool ModulePrepare()
  164. {
  165. _llModule.PostMsg(LLEntity.MSG.Prepare_TM);
  166. return true;
  167. }
  168. private string loopName()
  169. {
  170. return "LoadLock Swap";
  171. }
  172. private bool IsModulePrepareReady()
  173. {
  174. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  175. }
  176. private bool OpenSlitDoor()
  177. {
  178. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  179. }
  180. private bool CloseSlitDoor()
  181. {
  182. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  183. }
  184. private bool IsSlitDoorOpen()
  185. {
  186. //if (_targetModule == ModuleName.LLA)
  187. // return _JetTM.IsLLASlitDoorOpen;
  188. //else
  189. // return _JetTM.IsLLBSlitDoorOpen;
  190. if (_targetModule == ModuleName.LLA)
  191. {
  192. if (_JetTM.IsLLASlitDoorOpen)
  193. {
  194. //_llModule.IsDoorsAllClosed = false;
  195. return true;
  196. }
  197. return false;
  198. }
  199. else
  200. {
  201. if (_JetTM.IsLLBSlitDoorOpen)
  202. {
  203. //_llModule.IsDoorsAllClosed = false;
  204. return true;
  205. }
  206. return false;
  207. }
  208. }
  209. private bool IsSlitDoorClosed()
  210. {
  211. if (_targetModule == ModuleName.LLA)
  212. {
  213. if (_JetTM.IsLLASlitDoorClosed)
  214. {
  215. //_llModule.IsDoorsAllClosed = true;
  216. return true;
  217. }
  218. return false;
  219. }
  220. else
  221. {
  222. if (_JetTM.IsLLBSlitDoorClosed)
  223. {
  224. //_llModule.IsDoorsAllClosed = true;
  225. return true;
  226. }
  227. return false;
  228. }
  229. //if (_targetModule == ModuleName.LLA)
  230. // return _JetTM.IsLLASlitDoorClosed;
  231. //else
  232. // return _JetTM.IsLLBSlitDoorClosed;
  233. }
  234. private bool VerifyWaferExistence(MoveItem item)
  235. {
  236. if (WaferManager.Instance.CheckHasWafer(item.DestinationModule, item.DestinationSlot))
  237. {
  238. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as desitination {_currentAction.DestinationModule},{_currentAction.DestinationSlot + 1} already a wafer: ");
  239. return false;
  240. }
  241. if (WaferManager.Instance.CheckNoWafer(_currentAction.SourceModule, _currentAction.SourceSlot))
  242. {
  243. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as source {_currentAction.SourceModule}, {_currentAction.SourceSlot + 1} has no wafer");
  244. return false;
  245. }
  246. return true;
  247. }
  248. private bool MoveWafer()
  249. {
  250. _currentAction = _actionList.Dequeue();
  251. _starttime=DateTime.Now;
  252. _isAWC= (_currentAction.TransferType == EnumMoveType.Pick && _pickQueryAWC == true) || (_currentAction.TransferType == EnumMoveType.Place && _placeQueryAWC == true);
  253. if (!VerifyWaferExistence(_currentAction))
  254. return false;
  255. var wafer = WaferManager.Instance.GetWafer(_currentAction.SourceModule, _currentAction.SourceSlot);
  256. LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"{wafer.WaferOrigin} will be move from {_currentAction.SourceModule} {_currentAction.SourceSlot + 1} to {_currentAction.DestinationModule} {_currentAction.DestinationSlot + 1}");
  257. if (ModuleHelper.IsLoadLock(_currentAction.SourceModule) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))
  258. {
  259. return _robot.Pick(_currentAction.SourceModule, _currentAction.SourceSlot, (Hand)_currentAction.DestinationSlot);
  260. }
  261. else if (ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsLoadLock(_currentAction.DestinationModule))
  262. {
  263. //if (ModuleHelper.IsLoadLock(_targetModule))
  264. //{
  265. // _llModule.PostMsg(LLEntity.MSG.Transfer_TM_SlotInfo, _currentAction.DestinationSlot);
  266. //}
  267. return _robot.Place(_currentAction.DestinationModule, _currentAction.DestinationSlot, (Hand)_currentAction.SourceSlot);
  268. }
  269. else
  270. {
  271. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TMRobot, $"Invalid move parameter, source:{_currentAction.SourceModule},{_currentAction.SourceSlot}, destination: {_currentAction.DestinationModule}, {_currentAction.DestinationSlot}");
  272. return false;
  273. }
  274. }
  275. private bool WaitWaferMoved()
  276. {
  277. if (_robot.Status == RState.Running)
  278. {
  279. if (Runner.StepElapsedMS > _moveTimeout)
  280. {
  281. WaferManager.Instance.CreateDuplicatedWafer(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  282. Runner.Stop($"TM Robot moving wafer from {_currentAction.SourceModule}.{_currentAction.SourceSlot + 1} to {_currentAction.DestinationModule}.{_currentAction.DestinationSlot + 1} timeout, {_moveTimeout}ms");
  283. return true;
  284. }
  285. return false;
  286. }
  287. else if (_robot.Status == RState.End)
  288. {
  289. WaferManager.Instance.WaferMoved(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  290. return true;
  291. }
  292. else
  293. {
  294. WaferManager.Instance.CreateDuplicatedWafer(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  295. Runner.Stop($"TM Robot moving wafer failed, {_robot.Status}");
  296. return true;
  297. }
  298. }
  299. private bool RotateArm()
  300. {
  301. ModuleName preModule = _targetModule;
  302. Hand rotateHand = Hand.Blade1;
  303. if (ModuleHelper.IsLoadLock(_actionList.Peek().DestinationModule) && ModuleHelper.IsTMRobot(_actionList.Peek().SourceModule))
  304. {
  305. rotateHand = (Hand)_actionList.Peek().SourceSlot;
  306. preModule = _JetTM.PreRotateModules[_targetModule];
  307. }
  308. else
  309. {
  310. rotateHand = (Hand)_actionList.Peek().DestinationSlot;
  311. }
  312. _llModule.PostMsg(LLEntity.MSG.Prepare_TM); // Notify Loadlock to Serv pressure in advance for throughput enhancement
  313. return _robot.Goto(preModule, 0, rotateHand);
  314. }
  315. private bool WaitRotateDone()
  316. {
  317. if (_robot.Status == RState.Running)
  318. {
  319. return false;
  320. }
  321. else if (_robot.Status == RState.End)
  322. {
  323. return true;
  324. }
  325. else
  326. {
  327. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  328. return true;
  329. }
  330. }
  331. private bool NotifyLLDone()
  332. {
  333. _llModule.PostMsg(LLEntity.MSG.TM_Exchange_Ready, _currentactionList.Exists(ac => ModuleHelper.IsLoadLock(ac.DestinationModule)));
  334. return true;
  335. }
  336. private bool QueryAwc()
  337. {
  338. if (_robot.QueryAwc())
  339. return true;
  340. else
  341. return false;
  342. }
  343. private bool WaitQueryDoneAndRecord()
  344. {
  345. if (_robot.Status == RState.Running)
  346. {
  347. return false;
  348. }
  349. else if (_robot.Status == RState.End)
  350. {
  351. var wafer = WaferManager.Instance.GetWafer(_currentAction.DestinationModule, _currentAction.DestinationSlot);
  352. string _origin_module = $"LP{wafer.OriginStation}";
  353. int _origin_slot = wafer.OriginSlot;
  354. //查询完毕 插入数据
  355. OffsetDataRecorder.RecordOffsetData(
  356. Guid.NewGuid().ToString(),
  357. _currentAction.SourceModule, _currentAction.SourceSlot,
  358. _currentAction.DestinationModule, _currentAction.DestinationSlot,
  359. _origin_module, _origin_slot,
  360. _currentAction.RobotHand, RobotArmPan.None,
  361. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  362. _starttime, DateTime.Now);
  363. return true;
  364. }
  365. else
  366. {
  367. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  368. return true;
  369. }
  370. }
  371. private bool CheckAwc()
  372. {
  373. if (Math.Abs(_robot.Offset_X) > awcAlarmRange)
  374. {
  375. Stop($"Wafer from {_currentAction.SourceModule} {_currentAction.SourceSlot} to {_currentAction.DestinationModule} {_currentAction.DestinationSlot} {_currentAction.TransferType},Check AWC 失败, 当前 X AWC [{_robot.Offset_X}]um, 高于Alarm最大值: [{awcAlarmRange}]um");
  376. return false;
  377. }
  378. if (Math.Abs(_robot.Offset_Y) > awcAlarmRange)
  379. {
  380. Stop($"Wafer from {_currentAction.SourceModule} {_currentAction.SourceSlot} to {_currentAction.DestinationModule} {_currentAction.DestinationSlot} {_currentAction.TransferType},Check AWC 失败, 当前 Y AWC [{_robot.Offset_Y}]um, 高于Alarm最大值: [{awcAlarmRange}]um");
  381. return false;
  382. }
  383. return true;
  384. }
  385. public void Abort()
  386. {
  387. //_robot.Halt();
  388. }
  389. }
  390. }