MFPMSwapRoutine.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. using Aitex.Core.RT.Routine;
  2. using Aitex.Core.RT.SCCore;
  3. using Aitex.Sorter.Common;
  4. using Venus_RT.Devices;
  5. using Aitex.Core.Common;
  6. using MECF.Framework.Common.Routine;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.SubstrateTrackings;
  9. using Venus_Core;
  10. using Aitex.Core.RT.Log;
  11. using Aitex.Core.Util;
  12. using Venus_RT.Modules.PMs;
  13. using MECF.Framework.Common.Schedulers;
  14. using System.Collections.Generic;
  15. namespace Venus_RT.Modules.TM
  16. {
  17. class MFPMSwapRoutine : ModuleRoutineBase, IRoutine
  18. {
  19. private enum SwapStep
  20. {
  21. WaitPMReady,
  22. PreRotation,
  23. OpenSlitDoor,
  24. PickPrepare,
  25. PickExtend,
  26. DropDownWafer,
  27. PickDelay,
  28. PickRetract,
  29. PlacePrepare,
  30. PlaceExtend,
  31. LiftUpWafer,
  32. PlaceDelay,
  33. PlaceRetract,
  34. CloseSlitDoor,
  35. NotifyDone,
  36. }
  37. private enum SwapWithHeaterStep
  38. {
  39. WaitPMReady,
  40. PreRotation,
  41. OpenSlitDoor,
  42. PickPrepare,
  43. Picking,
  44. PlacePrepare,
  45. Placing,
  46. CloseSlitDoor,
  47. NotifyDone,
  48. }
  49. private readonly JetTM _JetTM;
  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. public MFPMSwapRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  60. {
  61. _JetTM = tm;
  62. _robot = robot;
  63. Name = "Swap with PM";
  64. }
  65. public RState Start(params object[] objs)
  66. {
  67. if (!_robot.IsHomed)
  68. {
  69. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  70. return RState.Failed;
  71. }
  72. var swapItem = (Queue<MoveItem>)objs[0];
  73. _targetModule = swapItem.Peek().SourceModule;
  74. _targetSlot = swapItem.Peek().SourceSlot;
  75. _pickHand = swapItem.Peek().RobotHand;
  76. _placeHand = _pickHand == Hand.Blade2 ? Hand.Blade1 : Hand.Blade2;
  77. if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  78. {
  79. _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
  80. }
  81. else
  82. {
  83. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for swap action");
  84. return RState.Failed;
  85. }
  86. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_placeHand))
  87. {
  88. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as TM Robot Arm: {_placeHand} has no wafer");
  89. return RState.Failed;
  90. }
  91. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_pickHand))
  92. {
  93. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as TM Robot Arm: {_pickHand} has a wafer");
  94. return RState.Failed;
  95. }
  96. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  97. {
  98. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as {_targetModule} Slot {_targetSlot + 1} has no wafer");
  99. return RState.Failed;
  100. }
  101. var wafer = WaferManager.Instance.GetWafer(_targetModule, _targetSlot);
  102. if (wafer.ChuckState == EnumWaferChuckStatus.Chucked)
  103. {
  104. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick the wafer in {_targetModule} as the wafer is chucked");
  105. return RState.Failed;
  106. }
  107. Reset();
  108. _swapingTimeout = SC.GetValue<int>($"TM.SwapTimeout") * 1000;
  109. _pickDelayTime = SC.GetValue<int>($"{_targetModule}.PickDelayTime");
  110. _placeDelayTime = SC.GetValue<int>($"{_targetModule}.PlaceDelayTime");
  111. return Runner.Start(Module, $"Swap with {_targetModule}");
  112. }
  113. public RState Monitor()
  114. {
  115. //Runner.Wait(SwapStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  116. // .RunIf(SwapStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  117. // .Run(SwapStep.PickPrepare, PickPrepare, IsModuleReadyForPick)
  118. // .Run(SwapStep.PickExtend, PickExtend, WaitRobotExtendDone)
  119. // .Run(SwapStep.DropDownWafer, NotifyPMPickWafer, WaitPMWaferDropDown)
  120. // .Delay(SwapStep.PickDelay, _pickDelayTime)
  121. // .Run(SwapStep.PickRetract, PickRetract, WaitRobotRetractDone)
  122. // .Run(SwapStep.PlacePrepare, PlacePrepare, IsModuleReadyForPlace)
  123. // .Run(SwapStep.PlaceExtend, PlaceExtend, WaitRobotExtendDone)
  124. // .Run(SwapStep.LiftUpWafer, NotifyLiftUpWafer, WaitPMWaferLiftUp)
  125. // .Delay(SwapStep.PlaceDelay, _placeDelayTime)
  126. // .Run(SwapStep.PlaceRetract, PlaceRetract, WaitRobotRetractDone)
  127. // .End(SwapStep.NotifyDone, NotifyPMDone, _delay_50ms);
  128. switch (_pmModule.ChamberType)
  129. {
  130. case JetChamber.Venus:
  131. case JetChamber.Kepler2300:
  132. Runner.Wait(SwapStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  133. .RunIf(SwapStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  134. .Run(SwapStep.OpenSlitDoor, OpenPMSlitDoor, OpenPMSlitDoorIsOK)
  135. .Run(SwapStep.PickPrepare, PickPrepare, IsModuleReadyForPick)
  136. .Run(SwapStep.PickExtend, PickExtend, WaitRobotExtendDone)
  137. .Run(SwapStep.DropDownWafer, NotifyPMPickWafer, WaitPMWaferDropDown)
  138. .Delay(SwapStep.PickDelay, _pickDelayTime)
  139. .Run(SwapStep.PickRetract, PickRetract, WaitRobotRetractDone)
  140. .Run(SwapStep.PlacePrepare, PlacePrepare, IsModuleReadyForPlace)
  141. .Run(SwapStep.PlaceExtend, PlaceExtend, WaitRobotExtendDone)
  142. .Run(SwapStep.LiftUpWafer, NotifyLiftUpWafer, WaitPMWaferLiftUp)
  143. .Delay(SwapStep.PlaceDelay, _placeDelayTime)
  144. .Run(SwapStep.PlaceRetract, PlaceRetract, WaitRobotRetractDone)
  145. .Run(SwapStep.CloseSlitDoor, ClosePMSlitDoor, ClosePMSlitDoorIsOK)
  146. .End(SwapStep.NotifyDone, NotifyPMDone, _delay_50ms);
  147. break;
  148. case JetChamber.Kepler2200A:
  149. case JetChamber.Kepler2200B:
  150. Runner.Wait(SwapWithHeaterStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  151. .RunIf(SwapWithHeaterStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  152. .Run(SwapWithHeaterStep.OpenSlitDoor, OpenPMSlitDoor, OpenPMSlitDoorIsOK)
  153. .Run(SwapWithHeaterStep.PickPrepare, PickPrepare, IsModuleReadyForPick)
  154. .Run(SwapWithHeaterStep.Picking, Picking, WaitPickDone)
  155. .Run(SwapWithHeaterStep.PlacePrepare, PlacePrepare, IsModuleReadyForPlace)
  156. .Run(SwapWithHeaterStep.Placing, Placing, WaitPlaceDone)
  157. .Run(SwapWithHeaterStep.CloseSlitDoor, ClosePMSlitDoor, ClosePMSlitDoorIsOK)
  158. .End(SwapStep.NotifyDone, NotifyPMDone, _delay_50ms);
  159. break;
  160. }
  161. return Runner.Status;
  162. }
  163. private bool PickPrepare()
  164. {
  165. _pmModule.PostMsg(PMEntity.MSG.PreparePick);
  166. return true;
  167. }
  168. private bool OpenPMSlitDoor()
  169. {
  170. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  171. }
  172. private bool OpenPMSlitDoorIsOK()
  173. {
  174. return _JetTM.IsPMSlitdoorOpened(_targetModule);
  175. }
  176. private bool ClosePMSlitDoor()
  177. {
  178. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  179. }
  180. private bool ClosePMSlitDoorIsOK()
  181. {
  182. return _JetTM.IsPMSlitdoorClosed(_targetModule);
  183. }
  184. private bool IsModuleReadyForPick()
  185. {
  186. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick && _pmModule.IsSlitDoorOpen;
  187. //return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick;
  188. }
  189. private bool PickExtend()
  190. {
  191. return _robot.PickExtend(_targetModule, _targetSlot, _pickHand);
  192. }
  193. private bool PickRetract()
  194. {
  195. return _robot.PickRetract(_targetModule, _targetSlot, _pickHand);
  196. }
  197. private bool PlacePrepare()
  198. {
  199. _pmModule.PostMsg(PMEntity.MSG.PreparePlace);
  200. return true;
  201. }
  202. private bool IsModuleReadyForPlace()
  203. {
  204. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen;
  205. //return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place;
  206. }
  207. private bool PlaceExtend()
  208. {
  209. return _robot.PlaceExtend(_targetModule, _targetSlot, _placeHand);
  210. }
  211. private bool PlaceRetract()
  212. {
  213. return _robot.PlaceRetract(_targetModule, _targetSlot, _placeHand);
  214. }
  215. private bool WaitRobotExtendDone()
  216. {
  217. if (_robot.Status == RState.Running)
  218. {
  219. return false;
  220. }
  221. else if (_robot.Status == RState.End)
  222. {
  223. return true;
  224. }
  225. else
  226. {
  227. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  228. return true;
  229. }
  230. }
  231. private bool Picking()
  232. {
  233. return _robot.Pick(_targetModule, _targetSlot, _pickHand);
  234. }
  235. private bool WaitPickDone()
  236. {
  237. if (_robot.Status == RState.Running)
  238. {
  239. return false;
  240. }
  241. else if (_robot.Status == RState.End)
  242. {
  243. //WaferManager.Instance.WaferMoved(ModuleName.TM, (int)_hand, _targetModule, _targetSlot);
  244. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  245. return true;
  246. }
  247. else
  248. {
  249. Runner.Stop($"TM Robot Picking failed, {_robot.Status}");
  250. return true;
  251. }
  252. }
  253. private bool Placing()
  254. {
  255. return _robot.Place(_targetModule, _targetSlot, _placeHand);
  256. }
  257. private bool WaitPlaceDone()
  258. {
  259. if (_robot.Status == RState.Running)
  260. {
  261. return false;
  262. }
  263. else if (_robot.Status == RState.End)
  264. {
  265. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  266. return true;
  267. }
  268. else
  269. {
  270. Runner.Stop($"TM Robot Place failed, {_robot.Status}");
  271. return true;
  272. }
  273. }
  274. private bool RotateArm()
  275. {
  276. _pmModule.PostMsg(PMEntity.MSG.PreparePick); // Notify PM to Serv pressure in advance for throughput enhancement
  277. return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _placeHand);
  278. }
  279. private bool WaitRotateDone()
  280. {
  281. if (_robot.Status == RState.Running)
  282. {
  283. return false;
  284. }
  285. else if (_robot.Status == RState.End)
  286. {
  287. return true;
  288. }
  289. else
  290. {
  291. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  292. return true;
  293. }
  294. }
  295. private bool NotifyPMPickWafer()
  296. {
  297. _pmModule.PostMsg(PMEntity.MSG.DropDownWafer);
  298. return true;
  299. }
  300. private bool WaitPMWaferDropDown()
  301. {
  302. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  303. {
  304. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  305. return true;
  306. }
  307. return false;
  308. }
  309. private bool WaitRobotRetractDone()
  310. {
  311. if (_robot.Status == RState.Running)
  312. {
  313. return false;
  314. }
  315. else if (_robot.Status == RState.End)
  316. {
  317. return true;
  318. }
  319. else
  320. {
  321. Runner.Stop($"TM Robot Swap Retract failed, {_robot.Status}");
  322. return true;
  323. }
  324. }
  325. private bool NotifyLiftUpWafer()
  326. {
  327. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  328. return true;
  329. }
  330. private bool WaitPMWaferLiftUp()
  331. {
  332. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  333. {
  334. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  335. return true;
  336. }
  337. return false;
  338. }
  339. private bool NotifyPMDone()
  340. {
  341. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  342. return true;
  343. }
  344. public void Abort()
  345. {
  346. _robot.Halt();
  347. }
  348. }
  349. }