MFPMSwapRoutine.cs 14 KB

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