MFPMPlaceRoutine.cs 16 KB

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