MFPMSwapRoutine.cs 16 KB

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