MFPlaceRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. public MFPlaceRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  50. {
  51. _JetTM = tm;
  52. _robot = robot;
  53. Name = "Place";
  54. if (SC.GetValue<int>($"TM.QueryAWCOption") == 2 || 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 placeItem = (Queue<MoveItem>)objs[0];
  68. if (!WaferManager.Instance.CheckDuplicatedWafersBeforeMove(placeItem))
  69. return RState.Failed;
  70. _targetModule = placeItem.Peek().DestinationModule;
  71. _targetSlot = placeItem.Peek().DestinationSlot;
  72. _hand = placeItem.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 place action");
  80. return RState.Failed;
  81. }
  82. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_hand))
  83. {
  84. LOG.Write(eEvent.ERR_TM, Module, $"Cannot place as TM Robot Arm: {_hand} has no wafer");
  85. return RState.Failed;
  86. }
  87. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  88. {
  89. LOG.Write(eEvent.ERR_TM, Module, $"Cannot place as {_targetModule} Slot {_targetSlot + 1} already has a wafer");
  90. return RState.Failed;
  91. }
  92. Reset();
  93. _placingTimeout = SC.GetValue<int>($"TM.PlaceTimeout") * 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. maxPressureDifference = SC.GetValue<double>("System.TMLLMaxPressureDifference");
  99. awcAlarmRange = SC.GetValue<int>($"TM.EnterLLAWCAlarmLimit");
  100. return Runner.Start(Module, $"Place to {_targetModule}");
  101. }
  102. public RState Monitor()
  103. {
  104. Runner.Wait(PlaceStep.WaitModuleReady, () => _llModule.IsIdle, _delay_3m)
  105. .RunIf(PlaceStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone, _delay_30s)
  106. .Run(PlaceStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  107. .Wait(PlaceStep.WaitPressreStable, TMLLPressureIsOK, _delay_60s)
  108. .Run(PlaceStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen, _delay_30s)
  109. .Run(PlaceStep.Placing, Placing, WaitPlaceDone, _delay_30s)
  110. .RunIf(PlaceStep.QueryAwc, _queryAwc, QueryAwc, WaitQueryDoneAndRecord, _delay_30s)
  111. .Run(PlaceStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed, _delay_30s)
  112. .Run_If(PlaceStep.CheckAwc, _queryAwc, CheckAwc)
  113. .End(PlaceStep.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 IsModulePrepareReady()
  122. {
  123. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  124. }
  125. private bool OpenSlitDoor()
  126. {
  127. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  128. }
  129. private bool TMLLPressureIsOK()
  130. {
  131. if (RouteManager.IsATMMode)
  132. {
  133. return _JetTM.IsTMATM && _JetTM.IsModuleATM(_targetModule);
  134. }
  135. else
  136. {
  137. double llPressure = 0;
  138. if (_targetModule == ModuleName.LLA)
  139. {
  140. llPressure = _JetTM.LLAPressure;
  141. }
  142. else if (_targetModule == ModuleName.LLB)
  143. {
  144. llPressure = _JetTM.LLBPressure;
  145. }
  146. if (Math.Abs((llPressure - _JetTM.ChamberPressure)) < maxPressureDifference - 2)
  147. {
  148. return true;
  149. }
  150. else
  151. {
  152. return false;
  153. }
  154. }
  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 Placing()
  175. {
  176. return _robot.Place(_targetModule, _targetSlot, _hand);
  177. }
  178. private bool WaitPlaceDone()
  179. {
  180. if (_robot.Status == RState.Running)
  181. {
  182. return false;
  183. }
  184. else if (_robot.Status == RState.End)
  185. {
  186. //if (ModuleHelper.IsLoadLock(_targetModule))
  187. //{
  188. // _llModule.PostMsg(LLEntity.MSG.Transfer_TM_SlotInfo, _targetSlot);
  189. //}
  190. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  191. return true;
  192. }
  193. else
  194. {
  195. Runner.Stop($"TM Robot Place failed, {_robot.Status}");
  196. return true;
  197. }
  198. }
  199. private bool RotateArm()
  200. {
  201. _llModule.PostMsg(LLEntity.MSG.Prepare_TM); // Notify Loadlock to Serv pressure in advance for throughput enhancement
  202. return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _hand);
  203. }
  204. private bool WaitRotateDone()
  205. {
  206. if (_robot.Status == RState.Running)
  207. {
  208. if (Runner.StepElapsedMS > _placingTimeout)
  209. {
  210. WaferManager.Instance.CreateDuplicatedWafer(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  211. Runner.Stop($"TM Robot place wafer to {_targetModule}.{_targetSlot + 1} timeout, {_placingTimeout}ms");
  212. return true;
  213. }
  214. return false;
  215. }
  216. else if (_robot.Status == RState.End)
  217. {
  218. return true;
  219. }
  220. else
  221. {
  222. WaferManager.Instance.CreateDuplicatedWafer(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  223. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  224. return true;
  225. }
  226. }
  227. private bool QueryAwc()
  228. {
  229. if (!_queryAwc)
  230. return true;
  231. if (_robot.QueryAwc())
  232. return true;
  233. else
  234. return false;
  235. }
  236. private bool WaitQueryDoneAndRecord()
  237. {
  238. if (!_queryAwc)
  239. return true;
  240. if (_robot.Status == RState.Running)
  241. {
  242. return false;
  243. }
  244. else if (_robot.Status == RState.End)
  245. {
  246. //已经move后的数据
  247. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  248. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  249. //查询完毕 插入数据
  250. OffsetDataRecorder.RecordOffsetData(
  251. Guid.NewGuid().ToString(),
  252. ModuleName.TMRobot, 0,
  253. _targetModule, _targetSlot,
  254. _origin_module, _origin_slot,
  255. _hand, RobotArmPan.None,
  256. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  257. _starttime, DateTime.Now);
  258. return true;
  259. }
  260. else
  261. {
  262. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  263. return true;
  264. }
  265. }
  266. private bool NotifyLLDone()
  267. {
  268. _llModule.PostMsg(LLEntity.MSG.TM_Exchange_Ready, false);
  269. return true;
  270. }
  271. private bool CheckAwc()
  272. {
  273. if (Math.Abs(_robot.Offset_X) > awcAlarmRange)
  274. {
  275. Stop($"Check AWC 失败, 当前 X AWC [{_robot.Offset_X}]um, 高于Alarm最大值: [{awcAlarmRange}]um");
  276. return false;
  277. }
  278. if (Math.Abs(_robot.Offset_Y) > awcAlarmRange)
  279. {
  280. Stop($"Check AWC 失败, 当前 Y AWC [{_robot.Offset_Y}]um, 高于Alarm最大值: [{awcAlarmRange}]um");
  281. return false;
  282. }
  283. return true;
  284. }
  285. public void Abort()
  286. {
  287. //_robot.Halt();
  288. }
  289. }
  290. }