LLEntity.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. using System;
  2. using Aitex.Core.Util;
  3. using Aitex.Core.RT.Fsm;
  4. using Aitex.Core.RT.Log;
  5. using MECF.Framework.Common.Equipment;
  6. using MECF.Framework.Common.SubstrateTrackings;
  7. using Venus_RT.Modules.TM;
  8. using Venus_RT.Devices;
  9. using Venus_Core;
  10. using Aitex.Core.RT.DataCenter;
  11. using Aitex.Core.RT.OperationCenter;
  12. using Aitex.Core.RT.Device;
  13. using Aitex.Core.RT.SCCore;
  14. using System.Threading.Tasks;
  15. using System.Threading;
  16. namespace Venus_RT.Modules
  17. {
  18. class LLEntity : Entity, IEntity, IModuleEntity
  19. {
  20. public enum LLStatus
  21. {
  22. Not_Ready,
  23. Ready_For_TM,
  24. Ready_For_EFEM,
  25. }
  26. public enum STATE
  27. {
  28. Unknown,
  29. Init,
  30. Initializing,
  31. Idle,
  32. Error,
  33. Pumping,
  34. Venting,
  35. Purging,
  36. LeakCheck,
  37. Prepare_For_TM,
  38. Prepare_For_EFEM,
  39. Ready_For_TM,
  40. Ready_For_EFEM,
  41. }
  42. public enum MSG
  43. {
  44. Home,
  45. Online,
  46. Offline,
  47. Pump,
  48. Vent,
  49. AutoPump,
  50. AutoVent,
  51. Purge,
  52. CyclePurge,
  53. LeakCheck,
  54. Prepare_TM,
  55. Prepare_EFEM,
  56. TM_Exchange_Ready,
  57. EFEM_Exchange_Ready,
  58. Error,
  59. Abort,
  60. }
  61. public ModuleName Module { get; private set; }
  62. public LLStatus Status { get; private set; }
  63. public bool Check(int msg, out string reason, params object[] args)
  64. {
  65. throw new NotImplementedException();
  66. }
  67. public bool IsIdle
  68. {
  69. get { return fsm.State == (int)STATE.Idle; }
  70. }
  71. public bool IsError
  72. {
  73. get { return fsm.State == (int)STATE.Error; }
  74. }
  75. public bool IsInit
  76. {
  77. get { return fsm.State == (int)STATE.Unknown || fsm.State == (int)STATE.Init; }
  78. }
  79. public bool IsBusy
  80. {
  81. get { return !IsInit && !IsError && !IsIdle; }
  82. }
  83. public bool IsOnline { get; internal set; }
  84. public bool IsVac { get { return _JetTM.IsModuleVaccum(Module); } }
  85. public bool IsATM { get { return _JetTM.IsModuleATM(Module); } }
  86. private readonly JetTM _JetTM;
  87. private readonly MFPumpRoutine _pumpingRoutine;
  88. private readonly MFVentRoutine _ventingRoutine;
  89. private readonly MFLeakCheckRoutine _leakCheckRoutine;
  90. private readonly MFPurgeRoutine _purgeRoutine;
  91. private readonly int _slotNumber = 4;
  92. private bool startControlPressureFlag = true;
  93. private int _controlPressureCheckPoint = 100;
  94. private int _controlPressureSetPoint = 90;
  95. private int _controlFlowSetPoint = 90;
  96. public LLEntity(ModuleName module)
  97. {
  98. Module = module;
  99. _JetTM = DEVICE.GetDevice<JetTM>("TM");
  100. _pumpingRoutine = new MFPumpRoutine(_JetTM, Module);
  101. _ventingRoutine = new MFVentRoutine(_JetTM, Module);
  102. _leakCheckRoutine = new MFLeakCheckRoutine(_JetTM, Module);
  103. _purgeRoutine = new MFPurgeRoutine(_JetTM, Module);
  104. _slotNumber = SC.GetValue<int>($"{module.ToString()}.SlotNumber");
  105. WaferManager.Instance.SubscribeLocation(Module, _slotNumber);
  106. InitFsmMap();
  107. }
  108. protected override bool Init()
  109. {
  110. OP.Subscribe($"{Module}.Home", (cmd, args) => CheckToPostMessage((int)MSG.Home));
  111. OP.Subscribe($"{Module}.{RtOperation.Pump}", (cmd, args) => CheckToPostMessage((int)MSG.Pump));
  112. OP.Subscribe($"{Module}.{RtOperation.Vent}", (cmd, args) => CheckToPostMessage((int)MSG.Vent));
  113. OP.Subscribe($"{Module}.{RtOperation.Purge}", (cmd, args) => CheckToPostMessage((int)MSG.Purge));
  114. OP.Subscribe($"{Module}.{RtOperation.Abort}", (cmd, args) => CheckToPostMessage((int)MSG.Abort));
  115. OP.Subscribe($"{Module}.{RtOperation.LeakCheck}", (cmd, args) => CheckToPostMessage((int)MSG.LeakCheck));
  116. OP.Subscribe($"{Module}.{RtOperation.Online}", (cmd, args) => CheckToPostMessage((int)MSG.Online));
  117. OP.Subscribe($"{Module}.{RtOperation.Offline}", (cmd, args) => CheckToPostMessage((int)MSG.Offline));
  118. DATA.Subscribe($"{Module}.FsmState", () => (((STATE)fsm.State).ToString()), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  119. DATA.Subscribe($"{Module}.FsmPrevState", () => (((PMState)fsm.PrevState).ToString()), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  120. DATA.Subscribe($"{Module}.FsmLastMessage", () => (((MSG)fsm.LastMsg).ToString()), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  121. DATA.Subscribe($"{Module}.IsOnline", () => IsOnline, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  122. return true;
  123. }
  124. private void InitFsmMap()
  125. {
  126. fsm = new StateMachine<LLEntity>(Module.ToString(), (int)STATE.Init, 50);
  127. fsm.EnableRepeatedMsg(true);
  128. EnterExitTransition<STATE, FSM_MSG>(STATE.Ready_For_TM, fnEnterTMReady, FSM_MSG.NONE, fnExitTMReady);
  129. EnterExitTransition<STATE, FSM_MSG>(STATE.Ready_For_EFEM, fnEnterEFEMReady, FSM_MSG.NONE, fnExitEFEMReady);
  130. //AnyStateTransition(FSM_MSG.TIMER, fnMonitor, FSM_STATE.SAME);
  131. AnyStateTransition(MSG.Error, fnError, STATE.Error);
  132. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  133. AnyStateTransition(MSG.Offline, fnOffline, FSM_STATE.SAME);
  134. AnyStateTransition(MSG.Home, fnHome, STATE.Initializing);
  135. // Home
  136. Transition(STATE.Initializing, FSM_MSG.TIMER, fnHoming, STATE.Idle);
  137. Transition(STATE.Idle, FSM_MSG.TIMER, fnMonitor, STATE.Idle);
  138. Transition(STATE.Init, FSM_MSG.TIMER, fnMonitor, STATE.Init);
  139. //vent sequence
  140. Transition(STATE.Idle, MSG.Vent, FnStartVent, STATE.Venting);
  141. Transition(STATE.Venting, FSM_MSG.TIMER, FnVentTimeout, STATE.Idle);
  142. Transition(STATE.Venting, MSG.Abort, FnAbortVent, STATE.Idle);
  143. //Pump sequence
  144. Transition(STATE.Idle, MSG.Pump, FnStartPump, STATE.Pumping);
  145. Transition(STATE.Pumping, FSM_MSG.TIMER, FnPumpTimeout, STATE.Idle);
  146. Transition(STATE.Pumping, MSG.Abort, FnAbortPump, STATE.Idle);
  147. // Purge sequence
  148. Transition(STATE.Idle, MSG.Purge, FnStartPurge, STATE.Purging);
  149. Transition(STATE.Purging, FSM_MSG.TIMER, FnPurgeTimeout, STATE.Idle);
  150. Transition(STATE.Purging, MSG.Abort, FnAbortPurge, STATE.Idle);
  151. // Leak check sequence
  152. Transition(STATE.Idle, MSG.LeakCheck, FnStartLeakCheck, STATE.LeakCheck);
  153. Transition(STATE.LeakCheck, FSM_MSG.TIMER, FnLeakCheckTimeout, STATE.Idle);
  154. Transition(STATE.LeakCheck, MSG.Abort, FnAbortLeakCheck, STATE.Idle);
  155. // Prepare TM Transfer
  156. Transition(STATE.Idle, MSG.Prepare_TM, FnStartPrepareTM, STATE.Prepare_For_TM);
  157. Transition(STATE.Prepare_For_TM, FSM_MSG.TIMER, FnPreparaTMTimeout, STATE.Ready_For_TM);
  158. Transition(STATE.Prepare_For_TM, MSG.Prepare_TM, null, STATE.Prepare_For_TM);
  159. Transition(STATE.Prepare_For_TM, MSG.Abort, FnAbortPreparaTM, STATE.Idle);
  160. Transition(STATE.Ready_For_TM, MSG.TM_Exchange_Ready, null, STATE.Idle);
  161. Transition(STATE.Ready_For_TM, MSG.Prepare_TM, null, STATE.Ready_For_TM);
  162. Transition(STATE.Ready_For_TM, MSG.Abort, null, STATE.Idle);
  163. Transition(STATE.Ready_For_TM, MSG.AutoVent, FnTryAutoVent, STATE.Venting);
  164. // Prepare EFEM Transfer
  165. Transition(STATE.Idle, MSG.Prepare_EFEM, FnStartPrepareEFEM, STATE.Prepare_For_EFEM);
  166. Transition(STATE.Prepare_For_EFEM, FSM_MSG.TIMER, FnPrepareEFEMTimeout, STATE.Ready_For_EFEM);
  167. Transition(STATE.Prepare_For_EFEM, MSG.Abort, FnAbortPrepareEFEM, STATE.Idle);
  168. Transition(STATE.Ready_For_EFEM, MSG.EFEM_Exchange_Ready, null, STATE.Idle);
  169. Transition(STATE.Ready_For_EFEM, MSG.Prepare_EFEM, null, STATE.Ready_For_EFEM);
  170. Transition(STATE.Ready_For_EFEM, MSG.Abort, null, STATE.Idle);
  171. Transition(STATE.Ready_For_EFEM, MSG.AutoPump, FnTryAutoPump, STATE.Pumping);
  172. //AnyStateTransition(FSM_MSG.TIMER, LLControlPressureTimer_Elapsed, FSM_STATE.SAME);
  173. Running = true;
  174. }
  175. public int Invoke(string function, params object[] args)
  176. {
  177. switch (function)
  178. {
  179. case "Home":
  180. CheckToPostMessage((int)MSG.Home);
  181. return (int)MSG.Home;
  182. }
  183. return (int)FSM_MSG.NONE;
  184. }
  185. public bool CheckAcked(int msg)
  186. {
  187. return fsm.CheckExecuted(msg);
  188. }
  189. public bool CheckToPostMessage(int msg, params object[] args)
  190. {
  191. if (!fsm.FindTransition(fsm.State, msg))
  192. {
  193. LOG.Write(eEvent.WARN_FSM_WARN, Module, $"{Module} is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
  194. return false;
  195. }
  196. Running = true;
  197. fsm.PostMsg(msg, args);
  198. return true;
  199. }
  200. public (int processed, int unprocessed) GetWaferProcessStatus()
  201. {
  202. int processedCount = 0;
  203. int unprocessCount = 0;
  204. for (int i = 0; i < _slotNumber; i++)
  205. {
  206. var wafer = WaferManager.Instance.GetWafer(Module, i);
  207. if (!wafer.IsEmpty)
  208. {
  209. if (wafer.ProcessState == Aitex.Core.Common.EnumWaferProcessStatus.Completed)
  210. {
  211. processedCount++;
  212. }
  213. else
  214. {
  215. unprocessCount++;
  216. }
  217. }
  218. }
  219. return (processedCount, unprocessCount);
  220. }
  221. private bool fnEnterTMReady(object[] param)
  222. {
  223. if (RouteManager.IsATMMode)
  224. {
  225. Status = LLStatus.Ready_For_TM;
  226. return true;
  227. }
  228. startControlPressureFlag = false;
  229. _controlPressureCheckPoint = SC.GetValue<int>($"{Module}.ControlPressureCheckPoint");
  230. _controlPressureSetPoint = SC.GetValue<int>($"{Module}.ControlPressureSetPoint");
  231. _controlFlowSetPoint = SC.GetValue<int>($"{Module}.{Module}_MFC1.DefaultSetPoint");
  232. _JetTM.TurnFastPumpValve(Module, true);
  233. _JetTM.TurnPurgeValve(Module, true);
  234. if (Module == ModuleName.LLA)
  235. {
  236. _JetTM.SwitchLLAPressureMode(true);
  237. _JetTM.SetLLAPressure(_controlPressureSetPoint);
  238. }
  239. else if (Module == ModuleName.LLB)
  240. {
  241. _JetTM.SwitchLLBPressureMode(true);
  242. _JetTM.SetLLBPressure(_controlPressureSetPoint);
  243. }
  244. Status = LLStatus.Ready_For_TM;
  245. return true;
  246. }
  247. private bool fnExitTMReady(object[] param)
  248. {
  249. if (RouteManager.IsATMMode)
  250. {
  251. Status = LLStatus.Not_Ready;
  252. return true;
  253. }
  254. _JetTM.TurnFastPumpValve(Module, false);
  255. _JetTM.TurnPurgeValve(Module, false);
  256. if (Module == ModuleName.LLA)
  257. {
  258. _JetTM.SwitchLLAPressureMode(false);
  259. _JetTM.SetLLAPressure(0);
  260. }
  261. else if (Module == ModuleName.LLB)
  262. {
  263. _JetTM.SwitchLLBPressureMode(false);
  264. _JetTM.SetLLBPressure(0);
  265. }
  266. Status = LLStatus.Not_Ready;
  267. return true;
  268. }
  269. private bool fnEnterEFEMReady(object[] param)
  270. {
  271. Status = LLStatus.Ready_For_EFEM;
  272. return true;
  273. }
  274. private bool fnExitEFEMReady(object[] param)
  275. {
  276. Status = LLStatus.Not_Ready;
  277. return true;
  278. }
  279. private bool fnMonitor(object[] param)
  280. {
  281. _debugRoutine();
  282. return true;
  283. }
  284. private bool fnError(object[] param)
  285. {
  286. IsOnline = false;
  287. return true;
  288. }
  289. private bool fnOnline(object[] param)
  290. {
  291. IsOnline = true;
  292. return true;
  293. }
  294. private bool fnOffline(object[] param)
  295. {
  296. IsOnline = false;
  297. return true;
  298. }
  299. private bool fnAbort(object[] param)
  300. {
  301. return true;
  302. }
  303. private bool fnHome(object[] param)
  304. {
  305. IsOnline = true;
  306. return true;
  307. }
  308. private bool fnHoming(object[] param)
  309. {
  310. return true;
  311. }
  312. private bool FnStartVent(object[] param)
  313. {
  314. return _ventingRoutine.Start() == RState.Running;
  315. }
  316. private bool FnTryAutoVent(object[] param)
  317. {
  318. if (RouteManager.IsATMMode)
  319. {
  320. PostMsg(MSG.TM_Exchange_Ready);
  321. return false;
  322. }
  323. return _ventingRoutine.Start() == RState.Running;
  324. }
  325. private bool FnVentTimeout(object[] param)
  326. {
  327. RState ret = _ventingRoutine.Monitor();
  328. if (ret == RState.Failed || ret == RState.Timeout)
  329. {
  330. PostMsg(MSG.Error);
  331. return false;
  332. }
  333. return ret == RState.End;
  334. }
  335. private bool FnAbortVent(object[] param)
  336. {
  337. _ventingRoutine.Abort();
  338. return true;
  339. }
  340. private bool FnStartPump(object[] param)
  341. {
  342. return _pumpingRoutine.Start() == RState.Running;
  343. }
  344. private bool FnPumpTimeout(object[] param)
  345. {
  346. RState ret = _pumpingRoutine.Monitor();
  347. if (ret == RState.Failed || ret == RState.Timeout)
  348. {
  349. PostMsg(MSG.Error);
  350. return false;
  351. }
  352. return ret == RState.End;
  353. }
  354. private bool FnAbortPump(object[] param)
  355. {
  356. _pumpingRoutine.Abort();
  357. return true;
  358. }
  359. private bool FnTryAutoPump(object[] param)
  360. {
  361. if (_JetTM.LLPumpStatus != JetTM.LLPumpState.Idle || RouteManager.IsATMMode)
  362. {
  363. PostMsg(MSG.EFEM_Exchange_Ready);
  364. return false;
  365. }
  366. return _pumpingRoutine.Start() == RState.Running;
  367. }
  368. private bool FnStartPurge(object[] param)
  369. {
  370. return _purgeRoutine.Start() == RState.Running;
  371. }
  372. private bool FnPurgeTimeout(object[] param)
  373. {
  374. RState ret = _purgeRoutine.Monitor();
  375. if (ret == RState.Failed || ret == RState.Timeout)
  376. {
  377. PostMsg(MSG.Error);
  378. return false;
  379. }
  380. return ret == RState.End;
  381. }
  382. private bool FnAbortPurge(object[] param)
  383. {
  384. _purgeRoutine.Abort();
  385. return true;
  386. }
  387. private bool FnStartLeakCheck(object[] param)
  388. {
  389. return _leakCheckRoutine.Start() == RState.Running;
  390. }
  391. private bool FnLeakCheckTimeout(object[] param)
  392. {
  393. RState ret = _leakCheckRoutine.Monitor();
  394. if (ret == RState.Failed || ret == RState.Timeout)
  395. {
  396. PostMsg(MSG.Error);
  397. return false;
  398. }
  399. return ret == RState.End;
  400. }
  401. private bool FnAbortLeakCheck(object[] param)
  402. {
  403. _leakCheckRoutine.Abort();
  404. return true;
  405. }
  406. private bool FnStartPrepareTM(object[] param)
  407. {
  408. if (RouteManager.IsATMMode)
  409. return true;
  410. return _pumpingRoutine.Start() == RState.Running;
  411. }
  412. private bool FnPreparaTMTimeout(object[] param)
  413. {
  414. if (RouteManager.IsATMMode)
  415. {
  416. if (fsm.ElapsedTime > 10000)
  417. {
  418. LOG.Write(eEvent.ERR_TM, Module, $"Cannot transfer wafer as {Module} is not ATM.");
  419. PostMsg(MSG.Error);
  420. return true;
  421. }
  422. return _JetTM.IsModuleATM(Module);
  423. }
  424. RState ret = _pumpingRoutine.Monitor();
  425. if (ret == RState.Failed || ret == RState.Timeout)
  426. {
  427. PostMsg(MSG.Error);
  428. return false;
  429. }
  430. return ret == RState.End;
  431. }
  432. private bool FnAbortPreparaTM(object[] param)
  433. {
  434. _pumpingRoutine.Abort();
  435. return true;
  436. }
  437. private bool FnStartPrepareEFEM(object[] param)
  438. {
  439. if (RouteManager.IsATMMode)
  440. return true;
  441. return _ventingRoutine.Start() == RState.Running;
  442. }
  443. private bool FnPrepareEFEMTimeout(object[] param)
  444. {
  445. if (RouteManager.IsATMMode)
  446. {
  447. if (fsm.ElapsedTime > 10000)
  448. {
  449. LOG.Write(eEvent.ERR_TM, Module, $"Cannot transfer wafer as {Module} is not ATM.");
  450. PostMsg(MSG.Error);
  451. return true;
  452. }
  453. return _JetTM.IsModuleATM(Module);
  454. }
  455. RState ret = _ventingRoutine.Monitor();
  456. if (ret == RState.Failed || ret == RState.Timeout)
  457. {
  458. PostMsg(MSG.Error);
  459. return false;
  460. }
  461. return ret == RState.End;
  462. }
  463. private bool FnAbortPrepareEFEM(object[] param)
  464. {
  465. _ventingRoutine.Abort();
  466. return true;
  467. }
  468. private void _debugRoutine()
  469. {
  470. int flag = 0;
  471. // Test Home routine
  472. if (flag == 1)
  473. {
  474. PostMsg(MSG.Home);
  475. }
  476. else if (flag == 2)
  477. {
  478. PostMsg(MSG.Vent);
  479. }
  480. else if (flag == 3)
  481. {
  482. PostMsg(MSG.Pump);
  483. }
  484. //else if (flag == 4)
  485. //{
  486. // PostMsg(MSG.PumpLoadLock);
  487. //}
  488. //else if (flag == 5)
  489. //{
  490. // PostMsg(MSG.VentLoadLock);
  491. //}
  492. //else if (flag == 6)
  493. //{
  494. // PostMsg(MSG.PurgeLoadLock);
  495. //}
  496. //else if (flag == 7)
  497. //{
  498. // PostMsg(MSG.LaunchPump);
  499. //}
  500. //else if (flag == 8)
  501. //{
  502. // PostMsg(MSG.LaunchTurboPump);
  503. //}
  504. //else if (flag == 9)
  505. //{
  506. // PostMsg(MSG.LoadLockLeakCheck);
  507. //}
  508. else if (flag == 10)
  509. {
  510. PostMsg(MSG.CyclePurge);
  511. }
  512. //else if (flag == 11)
  513. //{
  514. // PostMsg(MSG.GasLinePurge);
  515. //}
  516. //else if (flag == 12)
  517. //{
  518. // PostMsg(MSG.LeakCheck);
  519. //}
  520. //else if (flag == 13)
  521. //{
  522. // PostMsg(MSG.GasLeakCheck);
  523. //}
  524. //else if (flag == 14)
  525. //{
  526. // PostMsg(MSG.LLPlace);
  527. //}
  528. //else if (flag == 15)
  529. //{
  530. // PostMsg(MSG.LLPick);
  531. //}
  532. //else if (flag == 16)
  533. //{
  534. // PostMsg(MSG.RunRecipe, "7777");
  535. //}
  536. //else if (flag == 17)
  537. //{
  538. // PostMsg(MSG.MFCVerification, "MFC2", (double)50, 10);
  539. //}
  540. }
  541. }
  542. }