SEMFPlaceRoutine.cs 7.9 KB

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