MFPMSwapRoutine.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. Runner.Wait(SwapStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  137. .RunIf(SwapStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  138. .Run(SwapStep.PickPrepare, PickPrepare, IsModuleReadyForPick)
  139. .Run(SwapWithHeaterStep.Picking, Picking, WaitPickDone)
  140. .Run(SwapWithHeaterStep.PlacePrepare, PlacePrepare, IsModuleReadyForPlace)
  141. .Run(SwapWithHeaterStep.Placing, Placing, WaitPlaceDone)
  142. .End(SwapStep.NotifyDone, NotifyPMDone, _delay_50ms);
  143. break;
  144. }
  145. return Runner.Status;
  146. }
  147. private bool PickPrepare()
  148. {
  149. _pmModule.PostMsg(PMEntity.MSG.PreparePick);
  150. return true;
  151. }
  152. private bool IsModuleReadyForPick()
  153. {
  154. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick && _pmModule.IsSlitDoorOpen;
  155. }
  156. private bool PickExtend()
  157. {
  158. return _robot.PickExtend(_targetModule, _targetSlot, _pickHand);
  159. }
  160. private bool PickRetract()
  161. {
  162. return _robot.PickRetract(_targetModule, _targetSlot, _pickHand);
  163. }
  164. private bool PlacePrepare()
  165. {
  166. _pmModule.PostMsg(PMEntity.MSG.PreparePlace);
  167. return true;
  168. }
  169. private bool IsModuleReadyForPlace()
  170. {
  171. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen;
  172. }
  173. private bool PlaceExtend()
  174. {
  175. return _robot.PlaceExtend(_targetModule, _targetSlot, _placeHand);
  176. }
  177. private bool PlaceRetract()
  178. {
  179. return _robot.PlaceRetract(_targetModule, _targetSlot, _placeHand);
  180. }
  181. private bool WaitRobotExtendDone()
  182. {
  183. if (_robot.Status == RState.Running)
  184. {
  185. return false;
  186. }
  187. else if (_robot.Status == RState.End)
  188. {
  189. return true;
  190. }
  191. else
  192. {
  193. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  194. return true;
  195. }
  196. }
  197. private bool Picking()
  198. {
  199. return _robot.Pick(_targetModule, _targetSlot, _pickHand);
  200. }
  201. private bool WaitPickDone()
  202. {
  203. if (_robot.Status == RState.Running)
  204. {
  205. return false;
  206. }
  207. else if (_robot.Status == RState.End)
  208. {
  209. //WaferManager.Instance.WaferMoved(ModuleName.TM, (int)_hand, _targetModule, _targetSlot);
  210. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  211. return true;
  212. }
  213. else
  214. {
  215. Runner.Stop($"TM Robot Picking failed, {_robot.Status}");
  216. return true;
  217. }
  218. }
  219. private bool Placing()
  220. {
  221. return _robot.Place(_targetModule, _targetSlot, _placeHand);
  222. }
  223. private bool WaitPlaceDone()
  224. {
  225. if (_robot.Status == RState.Running)
  226. {
  227. return false;
  228. }
  229. else if (_robot.Status == RState.End)
  230. {
  231. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  232. return true;
  233. }
  234. else
  235. {
  236. Runner.Stop($"TM Robot Place failed, {_robot.Status}");
  237. return true;
  238. }
  239. }
  240. private bool RotateArm()
  241. {
  242. _pmModule.PostMsg(PMEntity.MSG.PreparePick); // Notify PM to Serv pressure in advance for throughput enhancement
  243. return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _placeHand);
  244. }
  245. private bool WaitRotateDone()
  246. {
  247. if (_robot.Status == RState.Running)
  248. {
  249. return false;
  250. }
  251. else if (_robot.Status == RState.End)
  252. {
  253. return true;
  254. }
  255. else
  256. {
  257. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  258. return true;
  259. }
  260. }
  261. private bool NotifyPMPickWafer()
  262. {
  263. _pmModule.PostMsg(PMEntity.MSG.DropDownWafer);
  264. return true;
  265. }
  266. private bool WaitPMWaferDropDown()
  267. {
  268. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  269. {
  270. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  271. return true;
  272. }
  273. return false;
  274. }
  275. private bool WaitRobotRetractDone()
  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 Swap Retract failed, {_robot.Status}");
  288. return true;
  289. }
  290. }
  291. private bool NotifyLiftUpWafer()
  292. {
  293. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  294. return true;
  295. }
  296. private bool WaitPMWaferLiftUp()
  297. {
  298. if(_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  299. {
  300. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  301. return true;
  302. }
  303. return false;
  304. }
  305. private bool NotifyPMDone()
  306. {
  307. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  308. return true;
  309. }
  310. public void Abort()
  311. {
  312. _robot.Halt();
  313. }
  314. }
  315. }