SEMFPlaceRoutine.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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.PreAligner;
  17. using Venus_RT.Devices.VCE;
  18. using Venus_RT.Modules.VCE;
  19. namespace Venus_RT.Modules.TM.VenusEntity
  20. {
  21. public class SEMFPlaceRoutine : ModuleRoutineBase, IRoutine
  22. {
  23. private enum PlaceStep
  24. {
  25. seWaitModuleReady,
  26. sePrepareModule,
  27. sePlacing,
  28. seNotifyDone
  29. }
  30. private HongHuTM _tm;
  31. private ITransferRobot _robot;
  32. private IPreAlign _vpa;
  33. private VceEntity _vceModule;
  34. private ModuleName _targetModule;
  35. private int _targetSlot;
  36. private int _placingTimeout;
  37. public int currentStepNo;
  38. Hand _hand;
  39. public SEMFPlaceRoutine(HongHuTM tm, ITransferRobot robot, IPreAlign vpa) : base(ModuleName.TM)
  40. {
  41. _tm = tm;
  42. _robot = robot;
  43. _vpa = vpa;
  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. //MoveItem placeItem = (MoveItem)objs[0];
  53. var placeItem = (Queue<MoveItem>)objs[0];
  54. _targetModule = placeItem.Peek().DestinationModule;
  55. _targetSlot = placeItem.Peek().DestinationSlot;
  56. _hand = placeItem.Peek().RobotHand;
  57. //如果目标是Vce 获取vce
  58. if (ModuleHelper.IsVCE(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  59. {
  60. _vceModule = Singleton<RouteManager>.Instance.GetVCE(_targetModule);
  61. //如果vce有错误 报错
  62. if (_vceModule.IsError)
  63. {
  64. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} is Error! Please solve Error first!");
  65. return RState.Failed;
  66. }
  67. //如果VCE门是关闭的 说明还未进行pump 无法取片等
  68. //if (_tm.VCESlitDoorClosed)
  69. //{
  70. // LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} slitdoor not open! Please pump down vce and open it first!");
  71. // return RState.Failed;
  72. //}
  73. }
  74. //如果目标又不是VPA 报错
  75. else if (!ModuleHelper.IsVPA(_targetModule))
  76. {
  77. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for placing action");
  78. return RState.Failed;
  79. }
  80. //检查目标手臂上有wafer
  81. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_hand))
  82. {
  83. LOG.Write(eEvent.ERR_TM, Module, $"Cannot place as TM Robot Arm: {_hand} has no wafer");
  84. return RState.Failed;
  85. }
  86. //检查目标槽位上没有wafer
  87. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  88. {
  89. LOG.Write(eEvent.ERR_TM, Module, $"Cannot place as {_targetModule} Slot {_targetSlot + 1} has a wafer");
  90. return RState.Failed;
  91. }
  92. //2023/10/13 朱永吉 atm mode的判断不允许自动pump vent 信号不满足手动pump vent
  93. //if (RouteManager.IsATMMode && _targetModule == ModuleName.VCE1)
  94. //{
  95. // if (!_tm.IsVCEATM)
  96. // {
  97. // LOG.Write(eEvent.ERR_TM, Module, $"System in ATM Mode but VCE is not ATM!");
  98. // return RState.Failed;
  99. // }
  100. //
  101. // if (!_tm.IsTMATM)
  102. // {
  103. // LOG.Write(eEvent.ERR_TM, Module, $"System in ATM Mode but TM is not ATM!");
  104. // return RState.Failed;
  105. // }
  106. //}
  107. //else
  108. //{
  109. // if (_tm.IsVCEATM)
  110. // {
  111. // LOG.Write(eEvent.ERR_TM, Module, $"System not in ATM Mode but VCE is ATM!");
  112. // return RState.Failed;
  113. // }
  114. //
  115. // if (_tm.IsTMATM)
  116. // {
  117. // LOG.Write(eEvent.ERR_TM, Module, $"System not in ATM Mode but TM is ATM!");
  118. // return RState.Failed;
  119. // }
  120. //}
  121. Reset();
  122. _placingTimeout = SC.GetValue<int>($"TM.PlaceTimeout") * 1000;
  123. return Runner.Start(Module, $"Place to {_targetModule}");
  124. }
  125. public RState Monitor()
  126. {
  127. Runner.Wait(PlaceStep.seWaitModuleReady, CheckModuleReady, _delay_60s)
  128. .Run(PlaceStep.sePrepareModule, PrepareModule, CheckModuleReady)
  129. .Run(PlaceStep.sePlacing, Placing, WaitPlaceDone, _placingTimeout)
  130. .End(PlaceStep.seNotifyDone, NullFun, 500);
  131. return Runner.Status;
  132. }
  133. private bool PrepareModule()
  134. {
  135. switch (_targetModule)
  136. {
  137. case ModuleName.VCE1:
  138. _vceModule.PostMsg(VceMSG.Goto, _targetSlot);
  139. return true;//移动到目标槽位
  140. case ModuleName.VPA:
  141. return true;//10/17暂时为true 后可能要求旋转
  142. default:
  143. return false;
  144. }
  145. }
  146. private bool WaitPlaceDone()
  147. {
  148. if (_robot.Status == RState.Running)
  149. {
  150. return false;
  151. }
  152. else if (_robot.Status == RState.End)
  153. {
  154. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  155. return true;
  156. }
  157. // timeout failed
  158. else
  159. {
  160. Runner.Stop($"TM Robot Placing failed, {_robot.Status}");
  161. return true;
  162. }
  163. }
  164. private bool Placing()
  165. {
  166. return _robot.Place(_targetModule, 0, _hand);
  167. }
  168. private bool CheckModuleReady()
  169. {
  170. switch (_targetModule)
  171. {
  172. case ModuleName.VCE1:
  173. return _vceModule.IsIdle;
  174. case ModuleName.VPA:
  175. return _vpa.Status == RState.End;
  176. default:
  177. return false;
  178. }
  179. }
  180. public void Abort()
  181. {
  182. }
  183. }
  184. }