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