SEMFPMSwapRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.Routine;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.Util;
  8. using Aitex.Sorter.Common;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.Schedulers;
  11. using MECF.Framework.Common.SubstrateTrackings;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Windows.Documents;
  18. using Venus_Core;
  19. using Venus_RT.Devices;
  20. using Venus_RT.Devices.TM;
  21. using Venus_RT.Modules.PMs;
  22. namespace Venus_RT.Modules.TM.VenusEntity
  23. {
  24. public class SEMFPMSwapRoutine : ModuleRoutineBase, IRoutine
  25. {
  26. private enum SwapStep
  27. {
  28. WaitPMReady,
  29. OpenMFSlitDoor,
  30. WaitforControlPressure,
  31. PreRotation,
  32. PickPrepare,
  33. PickExtend,
  34. DropDownWafer,
  35. PickDelay,
  36. PickRetract,
  37. PlacePrepare,
  38. PlaceExtend,
  39. LiftUpWafer,
  40. PlaceDelay,
  41. PlaceRetract,
  42. NotifyDone,
  43. CloseMFSlitDoor,
  44. EndDone,
  45. EndDelay
  46. }
  47. private readonly TMBase _TM;
  48. private readonly ITransferRobot _robot;
  49. private int _swapingTimeout = 120 * 1000;
  50. private int _placeDelayTime = 0;
  51. private int _pickDelayTime = 0;
  52. private ModuleName _targetModule;
  53. private PMEntity _pmModule;
  54. private int _targetSlot;
  55. private Hand _pickHand;
  56. private Hand _placeHand;
  57. private JetPMBase _chamber;
  58. private bool NeedControlPressure;
  59. private int _controlPressureSetPoint = 90;
  60. private int _controlFlowSetPoint = 90;
  61. public SEMFPMSwapRoutine(TMBase tm, ITransferRobot robot, ModuleName module) : base(module)
  62. {
  63. _TM = tm;
  64. _robot = robot;
  65. Name = "swap for pm";
  66. }
  67. public RState Start(params object[] objs)
  68. {
  69. if (!_robot.IsHomed)
  70. {
  71. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  72. return RState.Failed;
  73. }
  74. var swapItem = (Queue<MoveItem>)objs[0];
  75. _targetModule = swapItem.Peek().SourceModule;
  76. _targetSlot = swapItem.Peek().SourceSlot;
  77. _pickHand = swapItem.Peek().RobotHand;
  78. _placeHand = _pickHand == Hand.Blade2 ? Hand.Blade1 : Hand.Blade2;
  79. if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  80. {
  81. _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
  82. }
  83. else
  84. {
  85. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for swap action");
  86. return RState.Failed;
  87. }
  88. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_placeHand))
  89. {
  90. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as TM Robot Arm: {_placeHand} has no wafer");
  91. return RState.Failed;
  92. }
  93. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_pickHand))
  94. {
  95. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as TM Robot Arm: {_pickHand} has a wafer");
  96. return RState.Failed;
  97. }
  98. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  99. {
  100. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as {_targetModule} Slot {_targetSlot + 1} has no wafer");
  101. return RState.Failed;
  102. }
  103. Reset();
  104. _swapingTimeout = SC.GetValue<int>($"{Module}.SwapTimeout") * 1000;
  105. _pickDelayTime = SC.GetValue<int>($"{_targetModule}.PickDelayTime");
  106. _placeDelayTime = SC.GetValue<int>($"{_targetModule}.PlaceDelayTime");
  107. if (Singleton<RouteManager>.Instance.GetPM(_targetModule).IsOnline)
  108. {
  109. NeedControlPressure = true;
  110. }
  111. else
  112. {
  113. NeedControlPressure = false;
  114. }
  115. return Runner.Start(Module, $"Swap with {_targetModule}");
  116. }
  117. public RState Monitor()
  118. {
  119. Runner.Wait(SwapStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  120. .Run(SwapStep.OpenMFSlitDoor, OpenSlitDoor, CheckSlitDoorOpen)
  121. .Run(SwapStep.PickPrepare, PickPrepare, IsModuleReadyForPick)
  122. .Run(SwapStep.PickExtend, PickExtend, WaitRobotExtendDone)
  123. .Run(SwapStep.DropDownWafer, NotifyPMPickWafer, WaitPMWaferDropDown)
  124. .Delay(SwapStep.PickDelay, _pickDelayTime)
  125. .Run(SwapStep.PickRetract, PickRetract, WaitRobotRetractDone)
  126. .Run(SwapStep.PlacePrepare, PlacePrepare, IsModuleReadyForPlace)
  127. .Run(SwapStep.PlaceExtend, PlaceExtend, WaitRobotExtendDone)
  128. .Run(SwapStep.LiftUpWafer, NotifyLiftUpWafer, WaitPMWaferLiftUp)
  129. .Delay(SwapStep.PlaceDelay, _placeDelayTime)
  130. .Run(SwapStep.PlaceRetract, PlaceRetract, WaitRobotRetractDone)
  131. .Run(SwapStep.CloseMFSlitDoor, CheckDoorClose, WaitPMDoorClose, 5000)
  132. .Run(SwapStep.NotifyDone, NotifyPMDone, _delay_50ms)
  133. .Delay(SwapStep.EndDelay, _delay_50ms)
  134. .End(SwapStep.EndDone, NullFun, _delay_50ms);
  135. return Runner.Status;
  136. }
  137. private bool OpenSlitDoor()
  138. {
  139. return _TM.TurnSlitDoor(_targetModule, true);
  140. }
  141. private bool CheckSlitDoorOpen()
  142. {
  143. return _TM.CheckSlitValveOpen(_targetModule);
  144. }
  145. private bool PickPrepare()
  146. {
  147. _pmModule.PostMsg(PMEntity.MSG.PreparePick);
  148. //_TM.TurnSlitDoor(_targetModule, true);
  149. return true;
  150. }
  151. private bool PlacePrepare()
  152. {
  153. _pmModule.PostMsg(PMEntity.MSG.PreparePlace);
  154. //_TM.TurnSlitDoor(_targetModule, true);
  155. return true;
  156. }
  157. private bool IsModuleReadyForPick()
  158. {
  159. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick && _pmModule.IsSlitDoorOpen;
  160. }
  161. private bool PickExtend()
  162. {
  163. return _robot.PickExtend(_targetModule, _targetSlot, _pickHand);
  164. }
  165. private bool PickRetract()
  166. {
  167. return _robot.PickRetract(_targetModule, _targetSlot, _pickHand);
  168. }
  169. private bool IsModuleReadyForPlace()
  170. {
  171. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen;
  172. }
  173. private bool PlaceExtend()
  174. {
  175. return _robot.PlaceExtend(_targetModule, _targetSlot, _placeHand);
  176. }
  177. private bool PlaceRetract()
  178. {
  179. return _robot.PlaceRetract(_targetModule, _targetSlot, _placeHand);
  180. }
  181. private bool WaitRobotExtendDone()
  182. {
  183. if (_robot.Status == RState.Running)
  184. {
  185. return false;
  186. }
  187. else if (_robot.Status == RState.End)
  188. {
  189. return true;
  190. }
  191. else
  192. {
  193. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  194. Singleton<RouteManager>.Instance.GetPM(_targetModule).PostMsg(PMEntity.MSG.Error);
  195. return true;
  196. }
  197. }
  198. //private bool RotateArm()
  199. //{
  200. // _pmModule.PostMsg(PMEntity.MSG.PreparePick); // Notify PM to Serv pressure in advance for throughput enhancement
  201. // return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _placeHand);
  202. //}
  203. //private bool WaitRotateDone()
  204. //{
  205. // if (_robot.Status == RState.Running)
  206. // {
  207. // return false;
  208. // }
  209. // else if (_robot.Status == RState.End)
  210. // {
  211. // return true;
  212. // }
  213. // else
  214. // {
  215. // Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  216. // return true;
  217. // }
  218. //}
  219. private bool NotifyPMPickWafer()
  220. {
  221. _pmModule.PostMsg(PMEntity.MSG.DropDownWafer);
  222. return true;
  223. }
  224. private bool WaitPMWaferDropDown()
  225. {
  226. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  227. {
  228. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  229. return true;
  230. }
  231. return false;
  232. }
  233. private bool WaitRobotRetractDone()
  234. {
  235. if (_robot.Status == RState.Running)
  236. {
  237. return false;
  238. }
  239. else if (_robot.Status == RState.End)
  240. {
  241. return true;
  242. }
  243. else
  244. {
  245. Runner.Stop($"TM Robot Swap Retract failed, {_robot.Status}");
  246. Singleton<RouteManager>.Instance.GetPM(_targetModule).PostMsg(PMEntity.MSG.Error);
  247. return true;
  248. }
  249. }
  250. private bool NotifyLiftUpWafer()
  251. {
  252. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  253. return true;
  254. }
  255. private bool WaitPMWaferLiftUp()
  256. {
  257. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  258. {
  259. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  260. return true;
  261. }
  262. return false;
  263. }
  264. private bool NotifyPMDone()
  265. {
  266. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  267. //_TM.TurnSlitDoor(_targetModule, false);
  268. return true;
  269. }
  270. private bool CheckDoorClose()
  271. {
  272. LOG.Write(eEvent.WARN_TM, Module, $"PMSwap Close Door Again");
  273. return _TM.TurnSlitDoor(_targetModule, false);
  274. }
  275. private bool WaitPMDoorClose()
  276. {
  277. if (_TM.CheckSlitValveClose(_targetModule))
  278. {
  279. LOG.Write(eEvent.WARN_TM, Module, $"PMSwap Check Door Close");
  280. return true;
  281. }
  282. else
  283. {
  284. if (DEVICE.GetDevice<IoCylinder>($"{Module}.{_targetModule}SlitDoor").SetPoint != (int)CylinderState.Close)
  285. {
  286. LOG.Write(eEvent.WARN_TM, Module, $"PMSwap {_targetModule}SlitDoor set close again");
  287. DEVICE.GetDevice<IoCylinder>($"{Module}.{_targetModule}SlitDoor").SetCylinder(false, out string reason);
  288. }
  289. //LOG.Write(eEvent.WARN_TM, Module, $"PMSwap Check not Close Door");
  290. return false;
  291. }
  292. }
  293. public void Abort()
  294. {
  295. _robot.Halt();
  296. }
  297. }
  298. }