MFPMSwapRoutine.cs 13 KB

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