SEMFPMSwapRoutine.cs 11 KB

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