SEMFPMExtendRoutine.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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.SubstrateTrackings;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using Venus_Core;
  14. using Venus_RT.Devices;
  15. using Venus_RT.Devices.PreAligner;
  16. using Venus_RT.Modules.PMs;
  17. using Venus_RT.Modules.VCE;
  18. namespace Venus_RT.Modules.TM.VenusEntity
  19. {
  20. public class SEMFPMExtendRoutine : ModuleRoutineBase, IRoutine
  21. {
  22. //Extend的步骤
  23. private enum ExtendStep
  24. {
  25. ArmExtend,
  26. End,
  27. }
  28. private readonly HongHuTM _TM;
  29. private readonly ITransferRobot _robot;
  30. private IPreAlign _vpa;
  31. private bool _queryAwc;
  32. private ModuleName _targetModule;
  33. private PMEntity _pmModule;
  34. private VceEntity _vceModule;
  35. private bool _VCEFlag = false; //是否考虑VCE slot对齐准备
  36. private int _targetSlot;
  37. private Hand _hand;
  38. private int _extendingTimeout = 120 * 1000;
  39. public SEMFPMExtendRoutine(HongHuTM honghutm, ITransferRobot robot, IPreAlign vpa) : base(ModuleName.TM)
  40. {
  41. _TM = honghutm;
  42. _robot = robot;
  43. Name = "Extend to PM VCE VPA";
  44. _vpa = vpa;
  45. _queryAwc = false;
  46. }
  47. //开始执行
  48. public RState Start(params object[] objs)
  49. {
  50. //检查robot home
  51. if (!_robot.IsHomed)
  52. {
  53. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  54. return RState.Failed;
  55. }
  56. _targetModule = (ModuleName)objs[0];
  57. _targetSlot = (int)objs[1];
  58. _hand = (Hand)objs[2];
  59. //检查targetModule是否合法
  60. if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  61. {
  62. _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
  63. //检查开关门状态
  64. if (_pmModule.IsSlitDoorClose)
  65. {
  66. LOG.Write(eEvent.ERR_TM, Module, $"{_targetModule} slit door closed, can not extend robot arm");
  67. return RState.Failed;
  68. }
  69. }
  70. else if (ModuleHelper.IsVCE(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  71. {
  72. _VCEFlag = true;
  73. _vceModule = Singleton<RouteManager>.Instance.GetVCE(_targetModule);
  74. if (_vceModule.IsError)
  75. {
  76. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} is Error! Please solve Error first!");
  77. return RState.Failed;
  78. }
  79. if (_targetSlot < 0)
  80. {
  81. LOG.Write(eEvent.ERR_TM, Module, $"VCE target slot cannot be {_targetSlot}. Please check it first.");
  82. return RState.Failed;
  83. }
  84. //检查槽位置
  85. if (_targetSlot != _vceModule.CurrentSlot)
  86. {
  87. LOG.Write(eEvent.ERR_TM, Module, $"VCE current slot is {_vceModule.CurrentSlot} ,cannot be {_targetSlot}. Please check it first.");
  88. return RState.Failed;
  89. }
  90. //检查开关门状态
  91. if (_TM.VCESlitDoorClosed)
  92. {
  93. LOG.Write(eEvent.ERR_TM, Module, $"{_targetModule} slit door closed, can not extend robot arm");
  94. return RState.Failed;
  95. }
  96. }
  97. else if (ModuleHelper.IsVPA(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  98. {
  99. //LOG.Write(eEvent.ERR_TM, Module, $"{_targetModule}");
  100. }
  101. else
  102. {
  103. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for extending action");
  104. return RState.Failed;
  105. }
  106. //检查Robot和targetModule的wafer状态
  107. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  108. {
  109. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_hand))
  110. {
  111. LOG.Write(eEvent.ERR_TM, Module, $"Both {_targetModule} and robot arm {_hand} have wafers");
  112. return RState.Failed;
  113. }
  114. if (_pmModule.LiftPinIsDown && ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  115. {
  116. LOG.Write(eEvent.ERR_TM, Module, $"{_targetModule} has a wafer and Lift Pin is down, can not extend robot arm");
  117. return RState.Failed;
  118. }
  119. }
  120. Reset();
  121. _extendingTimeout = SC.GetValue<int>("TM.ExtendTimeout") * 1000;
  122. return Runner.Start(Module, $"Extend to {_targetModule}");
  123. }
  124. //状态监控
  125. public RState Monitor()
  126. {
  127. Runner.Run(ExtendStep.ArmExtend, ArmExtend, WaitRobotExtendDone)
  128. .End(ExtendStep.End, NullFun, _delay_50ms);
  129. return Runner.Status;
  130. }
  131. private bool ArmExtend()
  132. {
  133. return _robot.PickExtend(_targetModule, _targetSlot, _hand);
  134. }
  135. private bool WaitRobotExtendDone()
  136. {
  137. if (_robot.Status == RState.Running)
  138. {
  139. return false;
  140. }
  141. else if (_robot.Status == RState.End)
  142. {
  143. return true;
  144. }
  145. else
  146. {
  147. Runner.Stop($"TM Robot Arm Extend failed, {_robot.Status}");
  148. return true;
  149. }
  150. }
  151. public void Abort()
  152. {
  153. _robot.Halt();
  154. }
  155. }
  156. }