MFPickRoutine.cs 11 KB

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