MFPlaceRoutine.cs 11 KB

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