SEMFSwapRoutine.cs 8.8 KB

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