SEMFSwapRoutine.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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.IsLoadPort(_targetModule))
  106. return _vceModule.CurrentSlot == (_currentAction.SourceSlot + 1);
  107. else
  108. return true;
  109. }
  110. private bool CheckStatus()
  111. {
  112. if (ModuleHelper.IsLoadPort(_targetModule))
  113. return _vceModule.CheckToPostMessage((int)VceMSG.CheckStatus);
  114. else
  115. return true;
  116. }
  117. private bool VCEDoorOpen()
  118. {
  119. return _TM.TurnSlitDoor(VCE2LP.QueryLP2VCE(_targetModule), true);
  120. }
  121. private bool CheckVCEDoorOpen()
  122. {
  123. return _TM.CheckSlitValveOpen(VCE2LP.QueryLP2VCE(_targetModule));
  124. }
  125. private string loopName()
  126. {
  127. return "VCE Swap";
  128. }
  129. private bool VCEGoto()
  130. {
  131. _currentAction = _actionList.Peek();
  132. if (ModuleHelper.IsVCE(VCE2LP.QueryLP2VCE(_currentAction.SourceModule)) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))
  133. {
  134. return _vceModule.CheckToPostMessage((int)VceMSG.Goto, _currentAction.SourceSlot);
  135. }
  136. else if (ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsVCE(VCE2LP.QueryLP2VCE(_currentAction.DestinationModule)))
  137. {
  138. return _vceModule.CheckToPostMessage((int)VceMSG.Goto, _currentAction.DestinationSlot);
  139. }
  140. else
  141. {
  142. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.VCE1, $"Invalid move parameter, source:{_currentAction.SourceModule},{_currentAction.SourceSlot}, destination: {_currentAction.DestinationModule}, {_currentAction.DestinationSlot}");
  143. return false;
  144. }
  145. }
  146. private bool VCEGoReady()
  147. {
  148. _currentAction = _actionList.Peek();
  149. if (ModuleHelper.IsVCE(VCE2LP.QueryLP2VCE(_currentAction.SourceModule)) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))
  150. {
  151. return _vceModule.IsIdle && _vceModule.MoveSlot == (_currentAction.SourceSlot);
  152. }
  153. if (ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsVCE(VCE2LP.QueryLP2VCE(_currentAction.DestinationModule)))
  154. {
  155. return _vceModule.IsIdle && _vceModule.MoveSlot == (_currentAction.DestinationSlot);
  156. }
  157. return false;
  158. }
  159. private bool VerifyWaferExistence(MoveItem item)
  160. {
  161. if (WaferManager.Instance.CheckHasWafer(item.DestinationModule, item.DestinationSlot))
  162. {
  163. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as desitination {_currentAction.DestinationModule},{_currentAction.DestinationSlot + 1} already has a wafer: ");
  164. return false;
  165. }
  166. if (WaferManager.Instance.CheckNoWafer(_currentAction.SourceModule, _currentAction.SourceSlot))
  167. {
  168. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as source {_currentAction.SourceModule}, {_currentAction.SourceSlot + 1} has no wafer");
  169. return false;
  170. }
  171. return true;
  172. }
  173. private bool MoveWafer()
  174. {
  175. _currentAction = _actionList.Dequeue();
  176. if (!VerifyWaferExistence(_currentAction))
  177. return false;
  178. var wafer = WaferManager.Instance.GetWafer(_currentAction.SourceModule, _currentAction.SourceSlot);
  179. 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}");
  180. if (ModuleHelper.IsVCE(VCE2LP.QueryLP2VCE(_currentAction.SourceModule)) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))
  181. {
  182. return _robot.Pick(VCE2LP.QueryLP2VCE(_currentAction.SourceModule), _currentAction.SourceSlot, (Hand)_currentAction.DestinationSlot);
  183. }
  184. else if (ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsVCE(VCE2LP.QueryLP2VCE(_currentAction.DestinationModule)))
  185. {
  186. return _robot.Place(VCE2LP.QueryLP2VCE(_currentAction.DestinationModule), _currentAction.DestinationSlot, (Hand)_currentAction.SourceSlot);
  187. }
  188. else
  189. {
  190. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TMRobot, $"Invalid move parameter, source:{_currentAction.SourceModule},{_currentAction.SourceSlot}, destination: {_currentAction.DestinationModule}, {_currentAction.DestinationSlot}");
  191. return false;
  192. }
  193. }
  194. private bool WaitWaferMoved()
  195. {
  196. if (_robot.Status == RState.Running)
  197. {
  198. return false;
  199. }
  200. else if (_robot.Status == RState.End)
  201. {
  202. WaferManager.Instance.WaferMoved(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  203. return true;
  204. }
  205. else
  206. {
  207. Runner.Stop($"TM Robot moving wafer failed, {_robot.Status}");
  208. return true;
  209. }
  210. }
  211. public void Abort()
  212. {
  213. //_robot.Halt();
  214. }
  215. }
  216. }