SEMFSwapRoutine.cs 8.3 KB

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