SEMFPMRetractRoutine.cs 5.8 KB

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