SEMFSwapRoutine.cs 8.7 KB

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