SEMFPMRetractRoutine.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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.Devices.TM;
  17. using Venus_RT.Modules.PMs;
  18. using Venus_RT.Modules.VCE;
  19. namespace Venus_RT.Modules.TM.VenusEntity
  20. {
  21. public class SEMFPMRetractRoutine : ModuleRoutineBase, IRoutine
  22. {
  23. //进入Retract的步骤
  24. private enum RetractStep
  25. {
  26. ArmRetract,
  27. End,
  28. }
  29. private readonly TMBase _TM;
  30. private readonly ITransferRobot _robot;
  31. //private bool _queryAwc;
  32. private IPreAlign _vpa;
  33. private ModuleName _targetModule;
  34. private PMEntity _pmModule;
  35. private VceEntity _vceModule;
  36. private int _targetSlot;
  37. private Hand _hand;
  38. private int _retractingTimeout = 120 * 1000;
  39. public SEMFPMRetractRoutine(TMBase honghutm, ITransferRobot robot, IPreAlign vpa, ModuleName module) : base(module)
  40. {
  41. _TM = honghutm;
  42. _robot = robot;
  43. Name = "Retract 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 retract robot arm");
  67. return RState.Failed;
  68. }
  69. }
  70. else if (ModuleHelper.IsVCE(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  71. {
  72. _vceModule = Singleton<RouteManager>.Instance.GetVCE(_targetModule);
  73. if (_vceModule.IsError)
  74. {
  75. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} is Error! Please solve Error first!");
  76. return RState.Failed;
  77. }
  78. if (_targetSlot < 0)
  79. {
  80. LOG.Write(eEvent.ERR_TM, Module, $"VCE target slot cannot be {_targetSlot}. Please check it first.");
  81. return RState.Failed;
  82. }
  83. //检查槽位置
  84. if (_targetSlot != _vceModule.CurrentSlot)
  85. {
  86. LOG.Write(eEvent.ERR_TM, Module, $"VCE current slot is {_vceModule.CurrentSlot} ,cannot be {_targetSlot}. Please check it first.");
  87. return RState.Failed;
  88. }
  89. //检查开关门状态
  90. if (_TM.VCESlitDoorClosed(_targetModule))
  91. {
  92. LOG.Write(eEvent.ERR_TM, Module, $"{_targetModule} slit door closed, can not retract robot arm");
  93. return RState.Failed;
  94. }
  95. }
  96. else if (ModuleHelper.IsVPA(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  97. {
  98. //LOG.Write(eEvent.ERR_TM, Module, $"{_targetModule}");
  99. }
  100. else
  101. {
  102. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for retracting action");
  103. return RState.Failed;
  104. }
  105. //检查Robot和targetModule的wafer状态
  106. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  107. {
  108. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_hand))
  109. {
  110. LOG.Write(eEvent.ERR_TM, Module, $"Both {_targetModule} and robot arm {_hand} have wafers");
  111. return RState.Failed;
  112. }
  113. if (_pmModule.LiftPinIsDown && ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  114. {
  115. LOG.Write(eEvent.ERR_TM, Module, $"{_targetModule} has a wafer and Lift Pin is down, can not retract robot arm");
  116. return RState.Failed;
  117. }
  118. }
  119. Reset();
  120. _retractingTimeout = SC.GetValue<int>("TM.RetractTimeout") * 1000;
  121. return Runner.Start(Module, $"Retract to {_targetModule}");
  122. }
  123. //状态监控
  124. public RState Monitor()
  125. {
  126. Runner.Run(RetractStep.ArmRetract, ArmRetract, WaitRobotRetractDone)
  127. .End(RetractStep.End, NullFun, _delay_50ms);
  128. return Runner.Status;
  129. }
  130. private bool ArmRetract()
  131. {
  132. return _robot.PickRetract(_targetModule, _targetSlot, _hand);
  133. }
  134. private bool WaitRobotRetractDone()
  135. {
  136. if (_robot.Status == RState.Running)
  137. {
  138. return false;
  139. }
  140. else if (_robot.Status == RState.End)
  141. {
  142. return true;
  143. }
  144. else
  145. {
  146. Runner.Stop($"TM Robot Arm Retract failed, {_robot.Status}");
  147. return true;
  148. }
  149. }
  150. public void Abort()
  151. {
  152. _robot.Halt();
  153. }
  154. }
  155. }