SEMFPlaceRoutine.cs 7.7 KB

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