MFPMPlaceRoutine.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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. using MECF.Framework.Common.DBCore;
  15. using System;
  16. namespace Venus_RT.Modules.TM
  17. {
  18. class MFPMPlaceRoutine : ModuleRoutineBase, IRoutine
  19. {
  20. private enum PlaceStep
  21. {
  22. WaitPMReady,
  23. PreRotation,
  24. OpenPMSlitDoor,
  25. PMPrepare,
  26. ArmExtend,
  27. QueryAWC,
  28. LiftUpWafer,
  29. PlaceDelay,
  30. ArmRetract,
  31. SavePlaceData,
  32. WaitPLCReady,
  33. ClosePMSlitDoor,
  34. NotifyDone,
  35. }
  36. private enum PlaceWithHeaterStep
  37. {
  38. WaitPMReady,
  39. PreRotation,
  40. PMPrepare,
  41. WaitPressreStable,
  42. OpenPMSlitDoor,
  43. Placing,
  44. QueryAWC,
  45. SavePlaceData,
  46. WaitPLCReady,
  47. ClosePMSlitDoor,
  48. NotifyDone,
  49. }
  50. private readonly JetTM _JetTM;
  51. private readonly ITransferRobot _robot;
  52. private int _placingTimeout = 20 * 1000;
  53. private int _liftPinTimeout = 10 * 1000;
  54. private int _placeDelayTime = 0;
  55. private ModuleName _targetModule;
  56. private PMEntity _pmModule;
  57. private int _targetSlot;
  58. private Hand _hand;
  59. private DateTime _starttime;
  60. private bool _queryAwc;
  61. private int _robotTransferAWCOffset;
  62. double maxPressureDifference;
  63. public MFPMPlaceRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  64. {
  65. _JetTM = tm;
  66. _robot = robot;
  67. Name = "Place to PM";
  68. if (SC.GetValue<int>($"TM.QueryAWCOption") == 2 || SC.GetValue<int>($"TM.QueryAWCOption") == 3)
  69. _queryAwc = true;
  70. else
  71. _queryAwc = false;
  72. }
  73. public RState Start(params object[] objs)
  74. {
  75. _starttime = DateTime.Now;
  76. if (!_robot.IsHomed)
  77. {
  78. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  79. return RState.Failed;
  80. }
  81. var placeItem = (Queue<MoveItem>)objs[0];
  82. if (!WaferManager.Instance.CheckDuplicatedWafersBeforeMove(placeItem))
  83. return RState.Failed;
  84. _targetModule = placeItem.Peek().DestinationModule;
  85. _targetSlot = placeItem.Peek().DestinationSlot;
  86. _hand = placeItem.Peek().RobotHand;
  87. if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  88. {
  89. _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
  90. }
  91. else
  92. {
  93. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for placing action");
  94. return RState.Failed;
  95. }
  96. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_hand))
  97. {
  98. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Place as TM Robot Arm: {_hand} has no wafer");
  99. return RState.Failed;
  100. }
  101. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  102. {
  103. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Place as {_targetModule} Slot {_targetSlot + 1} already has a wafer");
  104. return RState.Failed;
  105. }
  106. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)_hand);
  107. LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"{wafer.WaferOrigin} will be move from TM Robot {_hand} to {_targetModule} {_targetSlot + 1}");
  108. Reset();
  109. _placingTimeout = SC.GetValue<int>("TM.PlaceTimeout") * 1000;
  110. _placeDelayTime = SC.GetValue<int>($"{_targetModule}.PlaceDelayTime");
  111. _robotTransferAWCOffset= SC.GetValue<int>("TM.EnterPMAWCAlarmLimit");
  112. maxPressureDifference = SC.GetValue<double>("System.PMTMMaxPressureDifference");
  113. return Runner.Start(Module, $"Place to {_targetModule}");
  114. }
  115. public RState Monitor()
  116. {
  117. switch (_pmModule.ChamberType)
  118. {
  119. //case JetChamber.Venus:
  120. case JetChamber.Kepler2300:
  121. Runner.Wait(PlaceStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  122. .RunIf(PlaceStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  123. .Run(PlaceStep.OpenPMSlitDoor, OpenPMSlitDoor, OpenPMSlitDoorIsOK)
  124. .Run(PlaceStep.PMPrepare, ModulePrepare, IsModulePrepareReady, _delay_60s)
  125. .Run(PlaceStep.ArmExtend, ArmExtend, WaitRobotExtendDone, _placingTimeout)
  126. .Run(PlaceStep.QueryAWC, QueryAWC, WaitRobotQueryDone, _delay_1s)
  127. .Run(PlaceStep.LiftUpWafer, NotifyPMPlaceWafer, WaitPMWaferLiftUp, _delay_30s)
  128. .Delay(PlaceStep.PlaceDelay, _placeDelayTime)
  129. .Run(PlaceStep.ArmRetract, ArmRetract, WaitRobotRetractDone, _delay_30s)
  130. .Run(PlaceStep.SavePlaceData, RecordAWCData, NullFun)
  131. .Run(PlaceStep.ClosePMSlitDoor, ClosePMSlitDoor, ClosePMSlitDoorIsOK)
  132. .End(PlaceStep.NotifyDone, NotifyPMDone, _delay_50ms);
  133. break;
  134. case JetChamber.Kepler2200A:
  135. case JetChamber.Kepler2200B:
  136. Runner.Wait(PlaceWithHeaterStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  137. .RunIf(PlaceWithHeaterStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  138. .Run(PlaceWithHeaterStep.PMPrepare, ModulePrepare, IsModulePrepareReady, _delay_60s)
  139. .Wait(PlaceWithHeaterStep.WaitPressreStable, TMPMPressureIsOK, _delay_60s)
  140. .Run(PlaceWithHeaterStep.OpenPMSlitDoor, OpenPMSlitDoor, OpenPMSlitDoorIsOK)
  141. .Run(PlaceWithHeaterStep.Placing, Placing, WaitPlaceDone)
  142. .Run(PlaceWithHeaterStep.QueryAWC, QueryAWC, WaitRobotQueryDone, _delay_1s)
  143. .Run(PlaceWithHeaterStep.SavePlaceData, RecordAWCData, NullFun)
  144. .Wait(PlaceWithHeaterStep.WaitPLCReady, PLCIsReadyOK)
  145. .Run(PlaceWithHeaterStep.ClosePMSlitDoor, ClosePMSlitDoor, ClosePMSlitDoorIsOK)
  146. .End(PlaceWithHeaterStep.NotifyDone, NotifyPMDone, _delay_50ms);
  147. break;
  148. }
  149. return Runner.Status;
  150. }
  151. private bool TMPMPressureIsOK()
  152. {
  153. if (RouteManager.IsATMMode)
  154. {
  155. return _JetTM.IsTMATM && _JetTM.IsModuleATM(_targetModule);
  156. }
  157. else
  158. {
  159. if (Math.Abs((_pmModule.ChamberPressure - _JetTM.ChamberPressure)) < (maxPressureDifference - 2))
  160. {
  161. return true;
  162. }
  163. else
  164. {
  165. return false;
  166. }
  167. }
  168. }
  169. private bool OpenPMSlitDoor()
  170. {
  171. _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  172. return true;
  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 ModulePrepare()
  187. {
  188. _pmModule.PostMsg(PMEntity.MSG.PreparePlace);
  189. return true;
  190. }
  191. private bool IsModulePrepareReady()
  192. {
  193. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place;
  194. }
  195. private bool RotateArm()
  196. {
  197. _pmModule.PostMsg(PMEntity.MSG.PreparePlace); // Notify PM to Serv pressure in advance for throughput enhancement
  198. return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _hand);
  199. }
  200. private bool WaitRotateDone()
  201. {
  202. if (_robot.Status == RState.Running)
  203. {
  204. return false;
  205. }
  206. else if (_robot.Status == RState.End)
  207. {
  208. return true;
  209. }
  210. else
  211. {
  212. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  213. return true;
  214. }
  215. }
  216. private bool Placing()
  217. {
  218. return _robot.Place(_targetModule, _targetSlot, _hand);
  219. }
  220. private bool WaitPlaceDone()
  221. {
  222. if (_robot.Status == RState.Running)
  223. {
  224. if (Runner.StepElapsedMS > _placingTimeout)
  225. {
  226. WaferManager.Instance.CreateDuplicatedWafer(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  227. Runner.Stop($"TM Robot place wafer to {_targetModule} timeout, {_placingTimeout}ms");
  228. return true;
  229. }
  230. return false;
  231. }
  232. else if (_robot.Status == RState.End && _JetTM.TMRobotNotExtendModule(_targetModule))
  233. {
  234. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  235. return true;
  236. }
  237. else
  238. {
  239. WaferManager.Instance.CreateDuplicatedWafer(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  240. Runner.Stop($"TM Robot Place failed, {_robot.Status}");
  241. return true;
  242. }
  243. }
  244. private bool ArmExtend()
  245. {
  246. return _robot.PlaceExtend(_targetModule, _targetSlot, _hand);
  247. }
  248. private bool ArmRetract()
  249. {
  250. return _robot.PlaceRetract(_targetModule, _targetSlot, _hand);
  251. }
  252. private bool QueryAWC()
  253. {
  254. if (!_queryAwc)
  255. return true;
  256. else
  257. return _robot.QueryAwc();
  258. }
  259. private bool WaitRobotExtendDone()
  260. {
  261. if (_robot.Status == RState.Running)
  262. {
  263. return false;
  264. }
  265. else if (_robot.Status == RState.End)
  266. {
  267. return true;
  268. }
  269. else
  270. {
  271. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  272. return true;
  273. }
  274. }
  275. private bool RecordAWCData()
  276. {
  277. if(!_queryAwc)
  278. return true;
  279. //已经move后的数据
  280. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  281. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  282. //查询完毕 插入数据
  283. OffsetDataRecorder.RecordOffsetData(
  284. Guid.NewGuid().ToString(),
  285. ModuleName.TMRobot, 0,
  286. _targetModule, _targetSlot,
  287. _origin_module, _origin_slot,
  288. _hand, RobotArmPan.None,
  289. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  290. _starttime, DateTime.Now);
  291. return true;
  292. }
  293. private bool WaitRobotQueryDone()
  294. {
  295. if (!_queryAwc)
  296. return true;
  297. if (_robot.Status == RState.Running)
  298. {
  299. return false;
  300. }
  301. else if (_robot.Status == RState.End)
  302. {
  303. return true;
  304. }
  305. else
  306. {
  307. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  308. return true;
  309. }
  310. }
  311. private bool NotifyPMPlaceWafer()
  312. {
  313. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  314. return true;
  315. }
  316. private bool WaitPMWaferLiftUp()
  317. {
  318. if(_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  319. {
  320. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  321. return true;
  322. }
  323. else if(Runner.StepElapsedMS > _liftPinTimeout)
  324. {
  325. WaferManager.Instance.CreateDuplicatedWafer(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  326. Runner.Stop($"Wait {_targetModule} Lift Pin Up timeout, {Runner.StepElapsedMS}");
  327. }
  328. return false;
  329. }
  330. private bool WaitRobotRetractDone()
  331. {
  332. if (_robot.Status == RState.Running)
  333. {
  334. return false;
  335. }
  336. else if (_robot.Status == RState.End)
  337. {
  338. return true;
  339. }
  340. else
  341. {
  342. Runner.Stop($"TM Robot Place Retract failed, {_robot.Status}");
  343. return true;
  344. }
  345. }
  346. private bool NotifyPMDone()
  347. {
  348. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  349. return true;
  350. }
  351. private bool PLCIsReadyOK()
  352. {
  353. return _JetTM.TMRobotNotExtendModule(_targetModule);
  354. }
  355. public void Abort()
  356. {
  357. //_robot.Halt();
  358. }
  359. }
  360. }