SEMFSwapRoutine.cs 9.9 KB

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