MFPlaceRoutine.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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.Routine;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.SubstrateTrackings;
  8. using Venus_Core;
  9. using Aitex.Core.RT.Log;
  10. using Aitex.Core.Util;
  11. using MECF.Framework.Common.Schedulers;
  12. using System.Collections.Generic;
  13. using System;
  14. using MECF.Framework.Common.DBCore;
  15. namespace Venus_RT.Modules.TM
  16. {
  17. class MFPlaceRoutine : ModuleRoutineBase, IRoutine
  18. {
  19. private enum PlaceStep
  20. {
  21. WaitModuleReady,
  22. PreRotation,
  23. ModulePrepare,
  24. OpenSlitDoor,
  25. Placing,
  26. QueryAwc,
  27. CloseSlitDoor,
  28. NotifyDone,
  29. }
  30. private readonly JetTM _JetTM;
  31. private readonly ITransferRobot _robot;
  32. private int _placingTimeout = 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. public MFPlaceRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  40. {
  41. _JetTM = tm;
  42. _robot = robot;
  43. Name = "Place";
  44. if (SC.GetValue<int>($"TM.QueryAWCOption") == 2 || SC.GetValue<int>($"TM.QueryAWCOption") == 3)
  45. _queryAwc = true;
  46. else
  47. _queryAwc = false;
  48. }
  49. public RState Start(params object[] objs)
  50. {
  51. _starttime = DateTime.Now;
  52. if (!_robot.IsHomed)
  53. {
  54. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  55. return RState.Failed;
  56. }
  57. var placeItem = (Queue<MoveItem>)objs[0];
  58. _targetModule = placeItem.Peek().DestinationModule;
  59. _targetSlot = placeItem.Peek().DestinationSlot;
  60. _hand = placeItem.Peek().RobotHand;
  61. if (ModuleHelper.IsLoadLock(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  62. {
  63. _llModule = Singleton<RouteManager>.Instance.GetLL(_targetModule);
  64. }
  65. else
  66. {
  67. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for place action");
  68. return RState.Failed;
  69. }
  70. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_hand))
  71. {
  72. LOG.Write(eEvent.ERR_TM, Module, $"Cannot place as TM Robot Arm: {_hand} has no wafer");
  73. return RState.Failed;
  74. }
  75. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  76. {
  77. LOG.Write(eEvent.ERR_TM, Module, $"Cannot place as {_targetModule} Slot {_targetSlot + 1} already has a wafer");
  78. return RState.Failed;
  79. }
  80. Reset();
  81. _placingTimeout = SC.GetValue<int>($"TM.PlaceTimeout") * 1000;
  82. return Runner.Start(Module, $"Place to {_targetModule}");
  83. }
  84. public RState Monitor()
  85. {
  86. Runner.Wait(PlaceStep.WaitModuleReady, () => _llModule.IsIdle, _delay_60s)
  87. .RunIf(PlaceStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  88. .Run(PlaceStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  89. .Run(PlaceStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen)
  90. .Run(PlaceStep.Placing, Placing, WaitPlaceDone)
  91. .Run(PlaceStep.QueryAwc, QueryAwc, WaitQueryDoneAndRecord)
  92. .Run(PlaceStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed)
  93. .End(PlaceStep.NotifyDone, NotifyLLDone, _delay_50ms);
  94. return Runner.Status;
  95. }
  96. private bool ModulePrepare()
  97. {
  98. _llModule.PostMsg(LLEntity.MSG.Prepare_TM);
  99. return true;
  100. }
  101. private bool IsModulePrepareReady()
  102. {
  103. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  104. }
  105. private bool OpenSlitDoor()
  106. {
  107. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  108. }
  109. private bool CloseSlitDoor()
  110. {
  111. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  112. }
  113. private bool IsSlitDoorOpen()
  114. {
  115. if (_targetModule == ModuleName.LLA)
  116. return _JetTM.IsLLASlitDoorOpen;
  117. else
  118. return _JetTM.IsLLBSlitDoorOpen;
  119. }
  120. private bool IsSlitDoorClosed()
  121. {
  122. if (_targetModule == ModuleName.LLA)
  123. return _JetTM.IsLLASlitDoorClosed;
  124. else
  125. return _JetTM.IsLLBSlitDoorClosed;
  126. }
  127. private bool Placing()
  128. {
  129. return _robot.Place(_targetModule, _targetSlot, _hand);
  130. }
  131. private bool WaitPlaceDone()
  132. {
  133. if (_robot.Status == RState.Running)
  134. {
  135. return false;
  136. }
  137. else if (_robot.Status == RState.End)
  138. {
  139. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  140. return true;
  141. }
  142. else
  143. {
  144. Runner.Stop($"TM Robot Place failed, {_robot.Status}");
  145. return true;
  146. }
  147. }
  148. private bool RotateArm()
  149. {
  150. _llModule.PostMsg(LLEntity.MSG.Prepare_TM); // Notify Loadlock to Serv pressure in advance for throughput enhancement
  151. return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _hand);
  152. }
  153. private bool WaitRotateDone()
  154. {
  155. if (_robot.Status == RState.Running)
  156. {
  157. return false;
  158. }
  159. else if (_robot.Status == RState.End)
  160. {
  161. return true;
  162. }
  163. else
  164. {
  165. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  166. return true;
  167. }
  168. }
  169. private bool QueryAwc()
  170. {
  171. if (!_queryAwc)
  172. return true;
  173. if (_robot.QueryAwc())
  174. return true;
  175. else
  176. return false;
  177. }
  178. private bool WaitQueryDoneAndRecord()
  179. {
  180. if (!_queryAwc)
  181. return true;
  182. if (_robot.Status == RState.Running)
  183. {
  184. return false;
  185. }
  186. else if (_robot.Status == RState.End)
  187. {
  188. //已经move后的数据
  189. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  190. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  191. //查询完毕 插入数据
  192. OffsetDataRecorder.RecordOffsetData(
  193. Guid.NewGuid().ToString(),
  194. ModuleName.TMRobot, 0,
  195. _targetModule, _targetSlot,
  196. _origin_module, _origin_slot,
  197. _hand, RobotArmPan.None,
  198. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  199. _starttime, DateTime.Now);
  200. return true;
  201. }
  202. else
  203. {
  204. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  205. return true;
  206. }
  207. }
  208. private bool NotifyLLDone()
  209. {
  210. _llModule.PostMsg(LLEntity.MSG.TM_Exchange_Ready);
  211. return true;
  212. }
  213. public void Abort()
  214. {
  215. _robot.Halt();
  216. }
  217. }
  218. }