SEMFSwapRoutine.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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.IsVCE(firtItem.SourceModule))
  61. {
  62. //if (_TM.VCESlitDoorClosed)
  63. //{
  64. // LOG.Write(eEvent.ERR_TM, Module, $"VCE is not open, cannot do it.");
  65. // return RState.Failed;
  66. //}
  67. _targetModule = firtItem.SourceModule;
  68. }
  69. else if (ModuleHelper.IsVCE(firtItem.DestinationModule))
  70. {
  71. //if (_TM.VCESlitDoorClosed)
  72. //{
  73. // LOG.Write(eEvent.ERR_TM, Module, $"VCE is not open, cannot do it.");
  74. // return RState.Failed;
  75. //}
  76. _targetModule = firtItem.DestinationModule;
  77. }
  78. else
  79. {
  80. LOG.Write(eEvent.ERR_TM, Module, $"Invalid move parameter: {firtItem.SourceModule},{firtItem.SourceSlot + 1} => {firtItem.DestinationModule},{firtItem.DestinationSlot + 1} ");
  81. return RState.Failed;
  82. }
  83. _vceModule = Singleton<RouteManager>.Instance.GetVCE(_targetModule);
  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, _delay_60s)
  96. .RunIf(SwapStep.SEDoorOpen, ModuleHelper.IsVCE(_targetModule), VCEDoorOpen, CheckVCEDoorOpen)
  97. .LoopStart(SwapStep.VCEGoto, loopName(), _actionList.Count, VCEGoto, VCEGoReady)
  98. .LoopEnd(SwapStep.MoveWafer, MoveWafer, WaitWaferMoved)
  99. .End(SwapStep.NotifyDone, NullFun, _delay_50ms);
  100. return Runner.Status;
  101. }
  102. private bool VCEDoorOpen()
  103. {
  104. return _TM.TurnSlitDoor(_targetModule, true);
  105. }
  106. private bool CheckVCEDoorOpen()
  107. {
  108. return _TM.CheckSlitValveOpen(_targetModule);
  109. }
  110. private string loopName()
  111. {
  112. return "VCE Swap";
  113. }
  114. private bool VCEGoto()
  115. {
  116. _currentAction = _actionList.Peek();
  117. if (ModuleHelper.IsVCE(_currentAction.SourceModule) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))
  118. {
  119. return _vceModule.CheckToPostMessage((int)VceMSG.Goto, _currentAction.SourceSlot);
  120. }
  121. else if (ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsVCE(_currentAction.DestinationModule))
  122. {
  123. return _vceModule.CheckToPostMessage((int)VceMSG.Goto, _currentAction.DestinationSlot);
  124. }
  125. else
  126. {
  127. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.VCE1, $"Invalid move parameter, source:{_currentAction.SourceModule},{_currentAction.SourceSlot}, destination: {_currentAction.DestinationModule}, {_currentAction.DestinationSlot}");
  128. return false;
  129. }
  130. }
  131. private bool VCEGoReady()
  132. {
  133. _currentAction = _actionList.Peek();
  134. if (ModuleHelper.IsVCE(_currentAction.SourceModule) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))
  135. {
  136. return _vceModule.IsIdle && _vceModule.CurrentSlot == _currentAction.SourceSlot;
  137. }
  138. if (ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsVCE(_currentAction.DestinationModule))
  139. {
  140. return _vceModule.IsIdle && _vceModule.CurrentSlot == _currentAction.DestinationSlot;
  141. }
  142. return false;
  143. }
  144. private bool VerifyWaferExistence(MoveItem item)
  145. {
  146. if (WaferManager.Instance.CheckHasWafer(item.DestinationModule, item.DestinationSlot))
  147. {
  148. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as desitination {_currentAction.DestinationModule},{_currentAction.DestinationSlot + 1} already has a wafer: ");
  149. return false;
  150. }
  151. if (WaferManager.Instance.CheckNoWafer(_currentAction.SourceModule, _currentAction.SourceSlot))
  152. {
  153. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as source {_currentAction.SourceModule}, {_currentAction.SourceSlot + 1} has no wafer");
  154. return false;
  155. }
  156. return true;
  157. }
  158. private bool MoveWafer()
  159. {
  160. _currentAction = _actionList.Dequeue();
  161. if (!VerifyWaferExistence(_currentAction))
  162. return false;
  163. var wafer = WaferManager.Instance.GetWafer(_currentAction.SourceModule, _currentAction.SourceSlot);
  164. 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}");
  165. if (ModuleHelper.IsVCE(_currentAction.SourceModule) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))
  166. {
  167. return _robot.Pick(_currentAction.SourceModule, _currentAction.SourceSlot, (Hand)_currentAction.DestinationSlot);
  168. }
  169. else if (ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsVCE(_currentAction.DestinationModule))
  170. {
  171. return _robot.Place(_currentAction.DestinationModule, _currentAction.DestinationSlot, (Hand)_currentAction.SourceSlot);
  172. }
  173. else
  174. {
  175. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TMRobot, $"Invalid move parameter, source:{_currentAction.SourceModule},{_currentAction.SourceSlot}, destination: {_currentAction.DestinationModule}, {_currentAction.DestinationSlot}");
  176. return false;
  177. }
  178. }
  179. private bool WaitWaferMoved()
  180. {
  181. if (_robot.Status == RState.Running)
  182. {
  183. return false;
  184. }
  185. else if (_robot.Status == RState.End)
  186. {
  187. WaferManager.Instance.WaferMoved(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  188. return true;
  189. }
  190. else
  191. {
  192. Runner.Stop($"TM Robot moving wafer failed, {_robot.Status}");
  193. return true;
  194. }
  195. }
  196. public void Abort()
  197. {
  198. _robot.Halt();
  199. }
  200. }
  201. }