MFPMPlaceRoutine.cs 15 KB

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