MFPickRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. namespace Venus_RT.Modules.TM
  17. {
  18. class MFPickRoutine : ModuleRoutineBase, IRoutine
  19. {
  20. private enum PickStep
  21. {
  22. WaitModuleReady,
  23. ModulePrepare,
  24. WaitPressreDifference,
  25. OpenSlitDoor,
  26. Picking,
  27. QueryAwc,
  28. CloseSlitDoor,
  29. CheckAwc,
  30. NotifyDone,
  31. }
  32. private readonly JetTM _JetTM;
  33. private readonly ITransferRobot _robot;
  34. private int _pickingTimeout = 20 * 1000;
  35. private ModuleName _targetModule;
  36. private LLEntity _llModule;
  37. int _targetSlot;
  38. Hand _hand;
  39. private DateTime _starttime;
  40. private bool _queryAwc;
  41. private int _autoVentOptInWafer = 0;
  42. private int _autoVentOptOutWafer = 4;
  43. private SequenceLLInOutPath _sequencePattern = SequenceLLInOutPath.DInDOut;
  44. private bool _bAutoMode = true;
  45. double maxPressureDifference;
  46. int awcAlarmRange;
  47. int awcWarningRange;
  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. maxPressureDifference = SC.GetValue<double>("System.TMLLMaxPressureDifference");
  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. return Runner.Start(Module, $"Pick from {_targetModule}");
  101. }
  102. public RState Monitor()
  103. {
  104. Runner.Wait(PickStep.WaitModuleReady, () => _llModule.IsIdle, _delay_60s)
  105. .Run(PickStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  106. .Wait(PickStep.WaitPressreDifference, TMLLPressureIsOK, _delay_60s)
  107. .Run(PickStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen)
  108. .Run(PickStep.Picking, Picking, WaitPickDone)
  109. .Run(PickStep.QueryAwc, QueryAwc, WaitQueryDoneAndRecord)
  110. .Run(PickStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed)
  111. //.Run(PickStep.CheckAwc, CheckAwc )
  112. .End(PickStep.NotifyDone, NotifyLLDone, _delay_50ms);
  113. return Runner.Status;
  114. }
  115. private bool ModulePrepare()
  116. {
  117. _llModule.PostMsg(LLEntity.MSG.Prepare_TM);
  118. return true;
  119. }
  120. private bool TMLLPressureIsOK()
  121. {
  122. double llPressure=0;
  123. if (_targetModule == ModuleName.LLA)
  124. {
  125. llPressure = _JetTM.LLAPressure;
  126. }
  127. else if(_targetModule == ModuleName.LLB)
  128. {
  129. llPressure = _JetTM.LLBPressure;
  130. }
  131. if (Math.Abs((llPressure - _JetTM.ChamberPressure)) < maxPressureDifference)
  132. {
  133. return true;
  134. }
  135. else
  136. {
  137. return false;
  138. }
  139. }
  140. private bool IsModulePrepareReady()
  141. {
  142. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  143. }
  144. private bool OpenSlitDoor()
  145. {
  146. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  147. }
  148. private bool CloseSlitDoor()
  149. {
  150. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  151. }
  152. private bool IsSlitDoorOpen()
  153. {
  154. if (_targetModule == ModuleName.LLA)
  155. return _JetTM.IsLLASlitDoorOpen;
  156. else
  157. return _JetTM.IsLLBSlitDoorOpen;
  158. }
  159. private bool IsSlitDoorClosed()
  160. {
  161. if (_targetModule == ModuleName.LLA)
  162. return _JetTM.IsLLASlitDoorClosed;
  163. else
  164. return _JetTM.IsLLBSlitDoorClosed;
  165. }
  166. private bool Picking()
  167. {
  168. return _robot.Pick(_targetModule, _targetSlot, _hand);
  169. }
  170. private bool WaitPickDone()
  171. {
  172. if (_robot.Status == RState.Running)
  173. {
  174. if (Runner.StepElapsedMS > _pickingTimeout)
  175. {
  176. WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  177. Runner.Stop($"TM Robot Picking {_targetModule}.{_targetSlot + 1} wafer timeout, {_pickingTimeout}");
  178. return true;
  179. }
  180. return false;
  181. }
  182. else if (_robot.Status == RState.End)
  183. {
  184. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  185. return true;
  186. }
  187. else
  188. {
  189. WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  190. Runner.Stop($"TM Robot Picking failed, {_robot.Status}");
  191. return true;
  192. }
  193. }
  194. private bool QueryAwc()
  195. {
  196. if (!_queryAwc)
  197. return true;
  198. if (_robot.QueryAwc())
  199. return true;
  200. else
  201. return false;
  202. }
  203. //private bool CheckAwc()
  204. //{
  205. // if (Math.Abs(_robot.Offset_D) > awcAlarmRange*1000)
  206. // {
  207. // Stop($"Check AWC 失败, 当前 AWC [{_robot.Offset_D}um], 高于Alarm最大值: [{awcAlarmRange}mm]");
  208. // return false;
  209. // }
  210. // if (Math.Abs(_robot.Offset_D) > awcWarningRange*1000)
  211. // {
  212. // Stop($"Check AWC 报警, 当前 AWC [{_robot.Offset_D}um], 高于Warning最大值: [{awcWarningRange}mm]");
  213. // }
  214. // return true;
  215. //}
  216. private bool WaitQueryDoneAndRecord()
  217. {
  218. if (!_queryAwc)
  219. return true;
  220. if (_robot.Status == RState.Running)
  221. {
  222. return false;
  223. }
  224. else if (_robot.Status == RState.End)
  225. {
  226. //已经move后的数据
  227. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  228. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  229. //查询完毕 插入数据
  230. OffsetDataRecorder.RecordOffsetData(
  231. Guid.NewGuid().ToString(),
  232. _targetModule, _targetSlot,
  233. ModuleName.TMRobot, 0,
  234. _origin_module, _origin_slot,
  235. _hand, RobotArmPan.None,
  236. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  237. _starttime, DateTime.Now);
  238. return true;
  239. }
  240. else
  241. {
  242. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  243. return true;
  244. }
  245. }
  246. private bool NotifyLLDone()
  247. {
  248. bool bAutoVent = false;
  249. var waferStatus = _llModule.GetWaferProcessStatus();
  250. if (_bAutoMode)
  251. {
  252. if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLA) ||
  253. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLB)) &&
  254. waferStatus.unprocessed <= _autoVentOptInWafer)
  255. {
  256. bAutoVent = true;
  257. }
  258. else if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLB) ||
  259. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLA)) &&
  260. waferStatus.processed >= _autoVentOptOutWafer)
  261. {
  262. bAutoVent = true;
  263. }
  264. else if (_sequencePattern == SequenceLLInOutPath.DInDOut &&
  265. waferStatus.processed >= _autoVentOptOutWafer &&
  266. waferStatus.unprocessed <= _autoVentOptInWafer)
  267. {
  268. bAutoVent = true;
  269. }
  270. }
  271. 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}");
  272. _llModule.PostMsg(bAutoVent ? LLEntity.MSG.AutoVent : LLEntity.MSG.TM_Exchange_Ready);
  273. return true;
  274. }
  275. public void Abort()
  276. {
  277. _robot.Halt();
  278. }
  279. }
  280. }