SEMFPickRoutine.cs 7.5 KB

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