SEMFPMSwapRoutine.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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.Modules.PMs;
  17. namespace Venus_RT.Modules.TM.VenusEntity
  18. {
  19. public class SEMFPMSwapRoutine : ModuleRoutineBase, IRoutine
  20. {
  21. private enum SwapStep
  22. {
  23. WaitPMReady,
  24. PreRotation,
  25. PickPrepare,
  26. PickExtend,
  27. DropDownWafer,
  28. PickDelay,
  29. PickRetract,
  30. PlacePrepare,
  31. PlaceExtend,
  32. LiftUpWafer,
  33. PlaceDelay,
  34. PlaceRetract,
  35. NotifyDone,
  36. }
  37. private readonly HongHuTM _TM;
  38. private readonly ITransferRobot _robot;
  39. private int _swapingTimeout = 120 * 1000;
  40. private int _placeDelayTime = 0;
  41. private int _pickDelayTime = 0;
  42. private ModuleName _targetModule;
  43. private PMEntity _pmModule;
  44. private int _targetSlot;
  45. private Hand _pickHand;
  46. private Hand _placeHand;
  47. public SEMFPMSwapRoutine(HongHuTM tm,ITransferRobot robot) : base(ModuleName.TMRobot)
  48. {
  49. _TM = tm;
  50. _robot = robot;
  51. Name = "swap for pm";
  52. }
  53. public RState Start(params object[] objs)
  54. {
  55. if (!_robot.IsHomed)
  56. {
  57. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  58. return RState.Failed;
  59. }
  60. var swapItem = (Queue<MoveItem>)objs[0];
  61. _targetModule = swapItem.Peek().SourceModule;
  62. _targetSlot = swapItem.Peek().SourceSlot;
  63. _pickHand = swapItem.Peek().RobotHand;
  64. _placeHand = _pickHand == Hand.Blade2 ? Hand.Blade1 : Hand.Blade2;
  65. if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  66. {
  67. _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
  68. }
  69. else
  70. {
  71. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for swap action");
  72. return RState.Failed;
  73. }
  74. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_placeHand))
  75. {
  76. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as TM Robot Arm: {_placeHand} has no wafer");
  77. return RState.Failed;
  78. }
  79. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_pickHand))
  80. {
  81. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as TM Robot Arm: {_pickHand} has a wafer");
  82. return RState.Failed;
  83. }
  84. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  85. {
  86. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as {_targetModule} Slot {_targetSlot + 1} has no wafer");
  87. return RState.Failed;
  88. }
  89. Reset();
  90. _swapingTimeout = SC.GetValue<int>($"SETM.SwapTimeout") * 1000;
  91. _pickDelayTime = SC.GetValue<int>($"{_targetModule}.PickDelayTime");
  92. _placeDelayTime = SC.GetValue<int>($"{_targetModule}.PlaceDelayTime");
  93. return Runner.Start(Module, $"Swap with {_targetModule}");
  94. }
  95. public RState Monitor()
  96. {
  97. Runner.Wait(SwapStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  98. //.RunIf(SwapStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  99. .Run(SwapStep.PickPrepare, PickPrepare, IsModuleReadyForPick)
  100. .Run(SwapStep.PickExtend, PickExtend, WaitRobotExtendDone)
  101. .Run(SwapStep.DropDownWafer, NotifyPMPickWafer, WaitPMWaferDropDown)
  102. .Delay(SwapStep.PickDelay, _pickDelayTime)
  103. .Run(SwapStep.PickRetract, PickRetract, WaitRobotRetractDone)
  104. .Run(SwapStep.PlacePrepare, PlacePrepare, IsModuleReadyForPlace)
  105. .Run(SwapStep.PlaceExtend, PlaceExtend, WaitRobotExtendDone)
  106. .Run(SwapStep.LiftUpWafer, NotifyLiftUpWafer, WaitPMWaferLiftUp)
  107. .Delay(SwapStep.PlaceDelay, _placeDelayTime)
  108. .Run(SwapStep.PlaceRetract, PlaceRetract, WaitRobotRetractDone)
  109. .End(SwapStep.NotifyDone, NotifyPMDone, _delay_50ms);
  110. return Runner.Status;
  111. }
  112. private bool PickPrepare()
  113. {
  114. _pmModule.PostMsg(PMEntity.MSG.PreparePick);
  115. _TM.TurnSlitDoor(_targetModule, true);
  116. return true;
  117. }
  118. private bool PlacePrepare()
  119. {
  120. _pmModule.PostMsg(PMEntity.MSG.PreparePlace);
  121. _TM.TurnSlitDoor(_targetModule, true);
  122. return true;
  123. }
  124. private bool IsModuleReadyForPick()
  125. {
  126. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick && _pmModule.IsSlitDoorOpen;
  127. }
  128. private bool PickExtend()
  129. {
  130. return _robot.PickExtend(_targetModule, _targetSlot, _pickHand);
  131. }
  132. private bool PickRetract()
  133. {
  134. return _robot.PickRetract(_targetModule, _targetSlot, _pickHand);
  135. }
  136. private bool IsModuleReadyForPlace()
  137. {
  138. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen;
  139. }
  140. private bool PlaceExtend()
  141. {
  142. return _robot.PlaceExtend(_targetModule, _targetSlot, _placeHand);
  143. }
  144. private bool PlaceRetract()
  145. {
  146. return _robot.PlaceRetract(_targetModule, _targetSlot, _placeHand);
  147. }
  148. private bool WaitRobotExtendDone()
  149. {
  150. if (_robot.Status == RState.Running)
  151. {
  152. return false;
  153. }
  154. else if (_robot.Status == RState.End)
  155. {
  156. return true;
  157. }
  158. else
  159. {
  160. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  161. return true;
  162. }
  163. }
  164. //private bool RotateArm()
  165. //{
  166. // _pmModule.PostMsg(PMEntity.MSG.PreparePick); // Notify PM to Serv pressure in advance for throughput enhancement
  167. // return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _placeHand);
  168. //}
  169. //private bool WaitRotateDone()
  170. //{
  171. // if (_robot.Status == RState.Running)
  172. // {
  173. // return false;
  174. // }
  175. // else if (_robot.Status == RState.End)
  176. // {
  177. // return true;
  178. // }
  179. // else
  180. // {
  181. // Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  182. // return true;
  183. // }
  184. //}
  185. private bool NotifyPMPickWafer()
  186. {
  187. _pmModule.PostMsg(PMEntity.MSG.DropDownWafer);
  188. return true;
  189. }
  190. private bool WaitPMWaferDropDown()
  191. {
  192. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  193. {
  194. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  195. return true;
  196. }
  197. return false;
  198. }
  199. private bool WaitRobotRetractDone()
  200. {
  201. if (_robot.Status == RState.Running)
  202. {
  203. return false;
  204. }
  205. else if (_robot.Status == RState.End)
  206. {
  207. return true;
  208. }
  209. else
  210. {
  211. Runner.Stop($"TM Robot Swap Retract failed, {_robot.Status}");
  212. return true;
  213. }
  214. }
  215. private bool NotifyLiftUpWafer()
  216. {
  217. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  218. return true;
  219. }
  220. private bool WaitPMWaferLiftUp()
  221. {
  222. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  223. {
  224. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  225. return true;
  226. }
  227. return false;
  228. }
  229. private bool NotifyPMDone()
  230. {
  231. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  232. _TM.TurnSlitDoor(_targetModule, false);
  233. return true;
  234. }
  235. public void Abort()
  236. {
  237. _robot.Halt();
  238. }
  239. }
  240. }