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. if (!WaferManager.Instance.CheckDuplicatedWafersBeforeMove(swapItem))
  74. return RState.Failed;
  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. var wafer = WaferManager.Instance.GetWafer(_targetModule, _targetSlot);
  104. if (wafer.ChuckState == EnumWaferChuckStatus.Chucked)
  105. {
  106. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick the wafer in {_targetModule} as the wafer is chucked");
  107. return RState.Failed;
  108. }
  109. Reset();
  110. _swapingTimeout = SC.GetValue<int>($"TM.SwapTimeout") * 1000;
  111. _pickDelayTime = SC.GetValue<int>($"{_targetModule}.PickDelayTime");
  112. _placeDelayTime = SC.GetValue<int>($"{_targetModule}.PlaceDelayTime");
  113. return Runner.Start(Module, $"Swap with {_targetModule}");
  114. }
  115. public RState Monitor()
  116. {
  117. //Runner.Wait(SwapStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  118. // .RunIf(SwapStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  119. // .Run(SwapStep.PickPrepare, PickPrepare, IsModuleReadyForPick)
  120. // .Run(SwapStep.PickExtend, PickExtend, WaitRobotExtendDone)
  121. // .Run(SwapStep.DropDownWafer, NotifyPMPickWafer, WaitPMWaferDropDown)
  122. // .Delay(SwapStep.PickDelay, _pickDelayTime)
  123. // .Run(SwapStep.PickRetract, PickRetract, WaitRobotRetractDone)
  124. // .Run(SwapStep.PlacePrepare, PlacePrepare, IsModuleReadyForPlace)
  125. // .Run(SwapStep.PlaceExtend, PlaceExtend, WaitRobotExtendDone)
  126. // .Run(SwapStep.LiftUpWafer, NotifyLiftUpWafer, WaitPMWaferLiftUp)
  127. // .Delay(SwapStep.PlaceDelay, _placeDelayTime)
  128. // .Run(SwapStep.PlaceRetract, PlaceRetract, WaitRobotRetractDone)
  129. // .End(SwapStep.NotifyDone, NotifyPMDone, _delay_50ms);
  130. switch (_pmModule.ChamberType)
  131. {
  132. //case JetChamber.Venus:
  133. case JetChamber.Kepler2300:
  134. Runner.Wait(SwapStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  135. .RunIf(SwapStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  136. .Run(SwapStep.OpenSlitDoor, OpenPMSlitDoor, OpenPMSlitDoorIsOK)
  137. .Run(SwapStep.PickPrepare, PickPrepare, IsModuleReadyForPick)
  138. .Run(SwapStep.PickExtend, PickExtend, WaitRobotExtendDone)
  139. .Run(SwapStep.DropDownWafer, NotifyPMPickWafer, WaitPMWaferDropDown)
  140. .Delay(SwapStep.PickDelay, _pickDelayTime)
  141. .Run(SwapStep.PickRetract, PickRetract, WaitRobotRetractDone)
  142. .Run(SwapStep.PlacePrepare, PlacePrepare, IsModuleReadyForPlace)
  143. .Run(SwapStep.PlaceExtend, PlaceExtend, WaitRobotExtendDone)
  144. .Run(SwapStep.LiftUpWafer, NotifyLiftUpWafer, WaitPMWaferLiftUp)
  145. .Delay(SwapStep.PlaceDelay, _placeDelayTime)
  146. .Run(SwapStep.PlaceRetract, PlaceRetract, WaitRobotRetractDone)
  147. .Run(SwapStep.CloseSlitDoor, ClosePMSlitDoor, ClosePMSlitDoorIsOK)
  148. .End(SwapStep.NotifyDone, NotifyPMDone, _delay_50ms);
  149. break;
  150. case JetChamber.Kepler2200A:
  151. case JetChamber.Kepler2200B:
  152. Runner.Wait(SwapWithHeaterStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  153. .RunIf(SwapWithHeaterStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  154. .Run(SwapWithHeaterStep.OpenSlitDoor, OpenPMSlitDoor, OpenPMSlitDoorIsOK)
  155. .Run(SwapWithHeaterStep.PickPrepare, PickPrepare, IsModuleReadyForPick)
  156. .Run(SwapWithHeaterStep.Picking, Picking, WaitPickDone)
  157. .Run(SwapWithHeaterStep.PlacePrepare, PlacePrepare, IsModuleReadyForPlace)
  158. .Run(SwapWithHeaterStep.Placing, Placing, WaitPlaceDone)
  159. .Run(SwapWithHeaterStep.CloseSlitDoor, ClosePMSlitDoor, ClosePMSlitDoorIsOK)
  160. .End(SwapStep.NotifyDone, NotifyPMDone, _delay_50ms);
  161. break;
  162. }
  163. return Runner.Status;
  164. }
  165. private bool PickPrepare()
  166. {
  167. _pmModule.PostMsg(PMEntity.MSG.PreparePick);
  168. return true;
  169. }
  170. private bool OpenPMSlitDoor()
  171. {
  172. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  173. }
  174. private bool OpenPMSlitDoorIsOK()
  175. {
  176. return _JetTM.IsPMSlitdoorOpened(_targetModule);
  177. }
  178. private bool ClosePMSlitDoor()
  179. {
  180. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  181. }
  182. private bool ClosePMSlitDoorIsOK()
  183. {
  184. return _JetTM.IsPMSlitdoorClosed(_targetModule);
  185. }
  186. private bool IsModuleReadyForPick()
  187. {
  188. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick && _pmModule.IsSlitDoorOpen;
  189. //return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick;
  190. }
  191. private bool PickExtend()
  192. {
  193. return _robot.PickExtend(_targetModule, _targetSlot, _pickHand);
  194. }
  195. private bool PickRetract()
  196. {
  197. return _robot.PickRetract(_targetModule, _targetSlot, _pickHand);
  198. }
  199. private bool PlacePrepare()
  200. {
  201. _pmModule.PostMsg(PMEntity.MSG.PreparePlace);
  202. return true;
  203. }
  204. private bool IsModuleReadyForPlace()
  205. {
  206. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen;
  207. //return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place;
  208. }
  209. private bool PlaceExtend()
  210. {
  211. return _robot.PlaceExtend(_targetModule, _targetSlot, _placeHand);
  212. }
  213. private bool PlaceRetract()
  214. {
  215. return _robot.PlaceRetract(_targetModule, _targetSlot, _placeHand);
  216. }
  217. private bool WaitRobotExtendDone()
  218. {
  219. if (_robot.Status == RState.Running)
  220. {
  221. return false;
  222. }
  223. else if (_robot.Status == RState.End)
  224. {
  225. return true;
  226. }
  227. else
  228. {
  229. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  230. return true;
  231. }
  232. }
  233. private bool Picking()
  234. {
  235. return _robot.Pick(_targetModule, _targetSlot, _pickHand);
  236. }
  237. private bool WaitPickDone()
  238. {
  239. if (_robot.Status == RState.Running)
  240. {
  241. return false;
  242. }
  243. else if (_robot.Status == RState.End)
  244. {
  245. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  246. return true;
  247. }
  248. else
  249. {
  250. WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  251. Runner.Stop($"TM Robot Picking failed, {_robot.Status}");
  252. return true;
  253. }
  254. }
  255. private bool Placing()
  256. {
  257. return _robot.Place(_targetModule, _targetSlot, _placeHand);
  258. }
  259. private bool WaitPlaceDone()
  260. {
  261. if (_robot.Status == RState.Running)
  262. {
  263. return false;
  264. }
  265. else if (_robot.Status == RState.End)
  266. {
  267. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  268. return true;
  269. }
  270. else
  271. {
  272. WaferManager.Instance.CreateDuplicatedWafer(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  273. Runner.Stop($"TM Robot Place failed, {_robot.Status}");
  274. return true;
  275. }
  276. }
  277. private bool RotateArm()
  278. {
  279. _pmModule.PostMsg(PMEntity.MSG.PreparePick); // Notify PM to Serv pressure in advance for throughput enhancement
  280. return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _placeHand);
  281. }
  282. private bool WaitRotateDone()
  283. {
  284. if (_robot.Status == RState.Running)
  285. {
  286. return false;
  287. }
  288. else if (_robot.Status == RState.End)
  289. {
  290. return true;
  291. }
  292. else
  293. {
  294. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  295. return true;
  296. }
  297. }
  298. private bool NotifyPMPickWafer()
  299. {
  300. _pmModule.PostMsg(PMEntity.MSG.DropDownWafer);
  301. return true;
  302. }
  303. private bool WaitPMWaferDropDown()
  304. {
  305. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  306. {
  307. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  308. return true;
  309. }
  310. return false;
  311. }
  312. private bool WaitRobotRetractDone()
  313. {
  314. if (_robot.Status == RState.Running)
  315. {
  316. return false;
  317. }
  318. else if (_robot.Status == RState.End)
  319. {
  320. return true;
  321. }
  322. else
  323. {
  324. Runner.Stop($"TM Robot Swap Retract failed, {_robot.Status}");
  325. return true;
  326. }
  327. }
  328. private bool NotifyLiftUpWafer()
  329. {
  330. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  331. return true;
  332. }
  333. private bool WaitPMWaferLiftUp()
  334. {
  335. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  336. {
  337. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  338. return true;
  339. }
  340. return false;
  341. }
  342. private bool NotifyPMDone()
  343. {
  344. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  345. return true;
  346. }
  347. public void Abort()
  348. {
  349. _robot.Halt();
  350. }
  351. }
  352. }