SEMFSwapRoutine.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.RT.Routine;
  3. using Aitex.Core.RT.SCCore;
  4. using Aitex.Core.Util;
  5. using Aitex.Sorter.Common;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.Schedulers;
  8. using MECF.Framework.Common.SubstrateTrackings;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using Venus_Core;
  15. using Venus_RT.Devices;
  16. using Venus_RT.Devices.TM;
  17. using Venus_RT.Modules.VCE;
  18. namespace Venus_RT.Modules.TM.VenusEntity
  19. {
  20. public class SEMFSwapRoutine : ModuleRoutineBase, IRoutine
  21. {
  22. private enum SwapStep
  23. {
  24. WaitModuleReady,
  25. //PreRotation,
  26. SEDoorOpen,
  27. ModulePrepare,
  28. OpenSlitDoor,
  29. MoveWafer,
  30. VCEGoto,
  31. CheckStatus,
  32. CloseSlitDoor,
  33. NotifyDone,
  34. }
  35. private readonly TMBase _TM;
  36. private readonly ITransferRobot _robot;
  37. private int _swapTimeout = 120 * 1000;
  38. private ModuleName _targetModule;
  39. private VceEntity _vceModule;
  40. Queue<MoveItem> _actionList = new Queue<MoveItem>();
  41. MoveItem _currentAction;
  42. public SEMFSwapRoutine(TMBase tm, ITransferRobot robot,ModuleName module) : base(module)
  43. {
  44. _TM = tm;
  45. _robot = robot;
  46. Name = "Swap";
  47. }
  48. public RState Start(params object[] objs)
  49. {
  50. if (!_robot.IsHomed)
  51. {
  52. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  53. return RState.Failed;
  54. }
  55. _actionList.Clear();
  56. foreach (var item in (Queue<MoveItem>)objs[0])
  57. {
  58. _actionList.Enqueue(new MoveItem(item.SourceModule, item.SourceSlot, item.DestinationModule, item.DestinationSlot, item.RobotHand));
  59. }
  60. var firtItem = _actionList.Peek();
  61. if (ModuleHelper.IsLoadPort(firtItem.SourceModule))
  62. {
  63. _targetModule = firtItem.SourceModule;
  64. }
  65. else if (ModuleHelper.IsLoadPort(firtItem.DestinationModule))
  66. {
  67. _targetModule = firtItem.DestinationModule;
  68. }
  69. else
  70. {
  71. LOG.Write(eEvent.ERR_TM, Module, $"Invalid move parameter: {firtItem.SourceModule},{firtItem.SourceSlot + 1} => {firtItem.DestinationModule},{firtItem.DestinationSlot + 1} ");
  72. return RState.Failed;
  73. }
  74. if (ModuleHelper.IsVCE(VCE2LP.QueryLP2VCE(_targetModule)))
  75. {
  76. _vceModule = Singleton<RouteManager>.Instance.GetVCE(VCE2LP.QueryLP2VCE(_targetModule));
  77. }
  78. else
  79. {
  80. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} ,which cannot find VCE2LP");
  81. return RState.Failed;
  82. }
  83. if (_vceModule == null)
  84. {
  85. LOG.Write(eEvent.ERR_TM, Module, $"Invalid vce: {_targetModule}, maybe not installed");
  86. return RState.Failed;
  87. }
  88. Reset();
  89. _swapTimeout = SC.GetValue<int>($"{Module}.SwapTimeout") * 1000;
  90. return Runner.Start(Module, $"Swap with {_targetModule}");
  91. }
  92. public RState Monitor()
  93. {
  94. Runner.Wait(SwapStep.WaitModuleReady, () => _vceModule.IsIdle, _delay_60s)
  95. .RunIf(SwapStep.SEDoorOpen, ModuleHelper.IsLoadPort(_targetModule), VCEDoorOpen, CheckVCEDoorOpen)
  96. .LoopStart(SwapStep.VCEGoto, loopName(), _actionList.Count, VCEGoto, VCEGoReady)
  97. .LoopRun(SwapStep.CheckStatus, CheckStatus, CheckSlotOk, _delay_10s)
  98. .LoopEnd(SwapStep.MoveWafer, MoveWafer, WaitWaferMoved)
  99. .End(SwapStep.NotifyDone, NullFun, _delay_50ms);
  100. return Runner.Status;
  101. }
  102. private bool CheckSlotOk()
  103. {
  104. _currentAction = _actionList.Peek();
  105. if (ModuleHelper.IsVCE(VCE2LP.QueryLP2VCE(_currentAction.SourceModule)))
  106. {
  107. return _vceModule.CurrentSlot == (_currentAction.SourceSlot + 1);
  108. }
  109. if (ModuleHelper.IsVCE(VCE2LP.QueryLP2VCE(_currentAction.DestinationModule)))
  110. {
  111. return _vceModule.CurrentSlot == (_currentAction.DestinationSlot + 1);
  112. }
  113. return true;
  114. }
  115. private bool CheckStatus()
  116. {
  117. if (ModuleHelper.IsLoadPort(_targetModule))
  118. return _vceModule.CheckToPostMessage((int)VceMSG.CheckStatus);
  119. else
  120. return true;
  121. }
  122. private bool VCEDoorOpen()
  123. {
  124. return _TM.TurnSlitDoor(VCE2LP.QueryLP2VCE(_targetModule), true);
  125. }
  126. private bool CheckVCEDoorOpen()
  127. {
  128. return _TM.CheckSlitValveOpen(VCE2LP.QueryLP2VCE(_targetModule));
  129. }
  130. private string loopName()
  131. {
  132. return "VCE Swap";
  133. }
  134. private bool VCEGoto()
  135. {
  136. _currentAction = _actionList.Peek();
  137. if (ModuleHelper.IsVCE(VCE2LP.QueryLP2VCE(_currentAction.SourceModule)) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))
  138. {
  139. return _vceModule.CheckToPostMessage((int)VceMSG.Goto, _currentAction.SourceSlot);
  140. }
  141. else if (ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsVCE(VCE2LP.QueryLP2VCE(_currentAction.DestinationModule)))
  142. {
  143. return _vceModule.CheckToPostMessage((int)VceMSG.Goto, _currentAction.DestinationSlot);
  144. }
  145. else
  146. {
  147. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.VCE1, $"Invalid move parameter, source:{_currentAction.SourceModule},{_currentAction.SourceSlot}, destination: {_currentAction.DestinationModule}, {_currentAction.DestinationSlot}");
  148. return false;
  149. }
  150. }
  151. private bool VCEGoReady()
  152. {
  153. _currentAction = _actionList.Peek();
  154. if (ModuleHelper.IsVCE(VCE2LP.QueryLP2VCE(_currentAction.SourceModule)) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))
  155. {
  156. return _vceModule.IsIdle && _vceModule.MoveSlot == _currentAction.SourceSlot;
  157. }
  158. if (ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsVCE(VCE2LP.QueryLP2VCE(_currentAction.DestinationModule)))
  159. {
  160. return _vceModule.IsIdle && _vceModule.MoveSlot == _currentAction.DestinationSlot;
  161. }
  162. return false;
  163. }
  164. private bool VerifyWaferExistence(MoveItem item)
  165. {
  166. if (WaferManager.Instance.CheckHasWafer(item.DestinationModule, item.DestinationSlot))
  167. {
  168. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as desitination {_currentAction.DestinationModule},{_currentAction.DestinationSlot + 1} already has a wafer: ");
  169. return false;
  170. }
  171. if (WaferManager.Instance.CheckNoWafer(_currentAction.SourceModule, _currentAction.SourceSlot))
  172. {
  173. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as source {_currentAction.SourceModule}, {_currentAction.SourceSlot + 1} has no wafer");
  174. return false;
  175. }
  176. return true;
  177. }
  178. private bool MoveWafer()
  179. {
  180. _currentAction = _actionList.Dequeue();
  181. if (!VerifyWaferExistence(_currentAction))
  182. return false;
  183. var wafer = WaferManager.Instance.GetWafer(_currentAction.SourceModule, _currentAction.SourceSlot);
  184. LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"{wafer.WaferOrigin} will be move from {_currentAction.SourceModule} {_currentAction.SourceSlot + 1} to {_currentAction.DestinationModule} {_currentAction.DestinationSlot + 1}");
  185. if (ModuleHelper.IsVCE(VCE2LP.QueryLP2VCE(_currentAction.SourceModule)) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))
  186. {
  187. return _robot.Pick(VCE2LP.QueryLP2VCE(_currentAction.SourceModule), _currentAction.SourceSlot, (Hand)_currentAction.DestinationSlot);
  188. }
  189. else if (ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsVCE(VCE2LP.QueryLP2VCE(_currentAction.DestinationModule)))
  190. {
  191. return _robot.Place(VCE2LP.QueryLP2VCE(_currentAction.DestinationModule), _currentAction.DestinationSlot, (Hand)_currentAction.SourceSlot);
  192. }
  193. else
  194. {
  195. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TMRobot, $"Invalid move parameter, source:{_currentAction.SourceModule},{_currentAction.SourceSlot}, destination: {_currentAction.DestinationModule}, {_currentAction.DestinationSlot}");
  196. return false;
  197. }
  198. }
  199. private bool WaitWaferMoved()
  200. {
  201. if (_robot.Status == RState.Running)
  202. {
  203. return false;
  204. }
  205. else if (_robot.Status == RState.End)
  206. {
  207. WaferManager.Instance.WaferMoved(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  208. return true;
  209. }
  210. else
  211. {
  212. Runner.Stop($"TM Robot moving wafer failed, {_robot.Status}");
  213. return true;
  214. }
  215. }
  216. public void Abort()
  217. {
  218. //_robot.Halt();
  219. }
  220. }
  221. }