MFPMSwapRoutine.cs 13 KB

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