MFPickRoutine.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. OpenSlitDoor,
  25. Picking,
  26. QueryAwc,
  27. CloseSlitDoor,
  28. NotifyDone,
  29. }
  30. private readonly JetTM _JetTM;
  31. private readonly ITransferRobot _robot;
  32. private int _pickingTimeout = 120 * 1000;
  33. private ModuleName _targetModule;
  34. private LLEntity _llModule;
  35. int _targetSlot;
  36. Hand _hand;
  37. private DateTime _starttime;
  38. private bool _queryAwc;
  39. private int _autoVentOptInWafer = 0;
  40. private int _autoVentOptOutWafer = 4;
  41. private SequenceLLInOutPath _sequencePattern = SequenceLLInOutPath.DInDOut;
  42. private bool _bAutoMode = true;
  43. public MFPickRoutine(JetTM tm, ITransferRobot robot) :base(ModuleName.TMRobot)
  44. {
  45. _JetTM = tm;
  46. _robot = robot;
  47. Name = "Pick";
  48. if (SC.GetValue<int>($"TM.QueryAWCOption") == 1 || SC.GetValue<int>($"TM.QueryAWCOption") == 3)
  49. _queryAwc = true;
  50. else
  51. _queryAwc = false;
  52. }
  53. public RState Start(params object[] objs)
  54. {
  55. _starttime = DateTime.Now;
  56. if (!_robot.IsHomed)
  57. {
  58. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  59. return RState.Failed;
  60. }
  61. var pickItem = (Queue<MoveItem>)objs[0];
  62. _targetModule = pickItem.Peek().SourceModule;
  63. _targetSlot = pickItem.Peek().SourceSlot;
  64. _hand = pickItem.Peek().RobotHand;
  65. if (ModuleHelper.IsLoadLock(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  66. {
  67. _llModule = Singleton<RouteManager>.Instance.GetLL(_targetModule);
  68. }
  69. else
  70. {
  71. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for picking action");
  72. return RState.Failed;
  73. }
  74. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_hand))
  75. {
  76. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as TM Robot Arm: {_hand} already has a wafer");
  77. return RState.Failed;
  78. }
  79. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  80. {
  81. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as {_targetModule} Slot {_targetSlot + 1} has no wafer");
  82. return RState.Failed;
  83. }
  84. Reset();
  85. _pickingTimeout = SC.GetValue<int>("TM.PickTimeout") * 1000;
  86. _autoVentOptInWafer = SC.GetValue<int>("TM.LLAutoVentInWaferOpt");
  87. _autoVentOptOutWafer = SC.GetValue<int>("TM.LLAutoVentOutWaferOpt");
  88. _sequencePattern = Singleton<RouteManager>.Instance.LLInOutPath;
  89. _bAutoMode = Singleton<RouteManager>.Instance.IsAutoMode;
  90. return Runner.Start(Module, $"Pick from {_targetModule}");
  91. }
  92. public RState Monitor()
  93. {
  94. Runner.Wait(PickStep.WaitModuleReady, () => _llModule.IsIdle, _delay_60s)
  95. .Run(PickStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  96. .Run(PickStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen)
  97. .Run(PickStep.Picking, Picking, WaitPickDone)
  98. .Run(PickStep.QueryAwc, QueryAwc, WaitQueryDoneAndRecord)
  99. .Run(PickStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed)
  100. .End(PickStep.NotifyDone, NotifyLLDone, _delay_50ms);
  101. return Runner.Status;
  102. }
  103. private bool ModulePrepare()
  104. {
  105. _llModule.PostMsg(LLEntity.MSG.Prepare_TM);
  106. return true;
  107. }
  108. private bool IsModulePrepareReady()
  109. {
  110. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  111. }
  112. private bool OpenSlitDoor()
  113. {
  114. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  115. }
  116. private bool CloseSlitDoor()
  117. {
  118. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  119. }
  120. private bool IsSlitDoorOpen()
  121. {
  122. if (_targetModule == ModuleName.LLA)
  123. return _JetTM.IsLLASlitDoorOpen;
  124. else
  125. return _JetTM.IsLLBSlitDoorOpen;
  126. }
  127. private bool IsSlitDoorClosed()
  128. {
  129. if (_targetModule == ModuleName.LLA)
  130. return _JetTM.IsLLASlitDoorClosed;
  131. else
  132. return _JetTM.IsLLBSlitDoorClosed;
  133. }
  134. private bool Picking()
  135. {
  136. return _robot.Pick(_targetModule, _targetSlot, _hand);
  137. }
  138. private bool WaitPickDone()
  139. {
  140. if (_robot.Status == RState.Running)
  141. {
  142. return false;
  143. }
  144. else if (_robot.Status == RState.End)
  145. {
  146. //WaferManager.Instance.WaferMoved(ModuleName.TM, (int)_hand, _targetModule, _targetSlot);
  147. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  148. return true;
  149. }
  150. else
  151. {
  152. Runner.Stop($"TM Robot Picking failed, {_robot.Status}");
  153. return true;
  154. }
  155. }
  156. private bool QueryAwc()
  157. {
  158. if (!_queryAwc)
  159. return true;
  160. if (_robot.QueryAwc())
  161. return true;
  162. else
  163. return false;
  164. }
  165. private bool WaitQueryDoneAndRecord()
  166. {
  167. if (!_queryAwc)
  168. return true;
  169. if (_robot.Status == RState.Running)
  170. {
  171. return false;
  172. }
  173. else if (_robot.Status == RState.End)
  174. {
  175. //已经move后的数据
  176. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  177. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  178. //查询完毕 插入数据
  179. OffsetDataRecorder.RecordOffsetData(
  180. Guid.NewGuid().ToString(),
  181. _targetModule, _targetSlot,
  182. ModuleName.TMRobot, 0,
  183. _origin_module, _origin_slot,
  184. _hand, RobotArmPan.None,
  185. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  186. _starttime, DateTime.Now);
  187. return true;
  188. }
  189. else
  190. {
  191. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  192. return true;
  193. }
  194. }
  195. private bool NotifyLLDone()
  196. {
  197. bool bAutoVent = false;
  198. var waferStatus = _llModule.GetWaferProcessStatus();
  199. if (_bAutoMode)
  200. {
  201. if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLA) ||
  202. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLB)) &&
  203. waferStatus.unprocessed <= _autoVentOptInWafer)
  204. {
  205. bAutoVent = true;
  206. }
  207. else if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLB) ||
  208. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLA)) &&
  209. waferStatus.processed >= _autoVentOptOutWafer)
  210. {
  211. bAutoVent = true;
  212. }
  213. else if (_sequencePattern == SequenceLLInOutPath.DInDOut &&
  214. waferStatus.processed >= _autoVentOptOutWafer &&
  215. waferStatus.unprocessed <= _autoVentOptInWafer)
  216. {
  217. bAutoVent = true;
  218. }
  219. }
  220. 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}");
  221. _llModule.PostMsg(bAutoVent ? LLEntity.MSG.AutoVent : LLEntity.MSG.TM_Exchange_Ready);
  222. return true;
  223. }
  224. public void Abort()
  225. {
  226. _robot.Halt();
  227. }
  228. }
  229. }