TMEntity.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. using System;
  2. using Aitex.Core.RT.Fsm;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.Util;
  5. using Venus_Core;
  6. using Aitex.Sorter.Common;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.SubstrateTrackings;
  9. using Venus_RT.Devices;
  10. using Venus_RT.Modules.TM;
  11. namespace Venus_RT.Modules
  12. {
  13. class TMEntity : Entity, IModuleEntity
  14. {
  15. public enum STATE
  16. {
  17. Unknown,
  18. Init,
  19. Initializing,
  20. Idle,
  21. Error,
  22. Pumping,
  23. Venting,
  24. Purging,
  25. Leakchecking,
  26. Picking,
  27. Placing,
  28. Swaping,
  29. PMPicking,
  30. PMPlacing,
  31. PMSwaping,
  32. Aligning,
  33. Mapping,
  34. Extending,
  35. Retracting,
  36. Swapping,
  37. Gotoing,
  38. }
  39. public enum MSG
  40. {
  41. Home,
  42. Online,
  43. Offline,
  44. Pump,
  45. Vent,
  46. Purge,
  47. CyclePurge,
  48. LeakCheck,
  49. Pick,
  50. Place,
  51. Swap,
  52. PMPick,
  53. PMPlace,
  54. PMSwap,
  55. Extend,
  56. Retract,
  57. Error,
  58. Abort,
  59. }
  60. public bool IsIdle
  61. {
  62. get { return fsm.State == (int)STATE.Idle; }
  63. }
  64. public bool IsError
  65. {
  66. get { return fsm.State == (int)STATE.Error; }
  67. }
  68. public bool IsInit
  69. {
  70. get { return fsm.State == (int)STATE.Unknown || fsm.State == (int)STATE.Init; }
  71. }
  72. public bool IsBusy
  73. {
  74. get { return !IsInit && !IsError && !IsIdle; }
  75. }
  76. public bool IsOnline { get; internal set; }
  77. private readonly JetTM _tm;
  78. private readonly ITransferRobot _robot;
  79. private readonly MFHomeRoutine _homeRoutine;
  80. private readonly MFPumpRoutine _pumpingRoutine;
  81. private readonly MFVentRoutine _ventingRoutine;
  82. private readonly MFLeakCheckRoutine _leakCheckRoutine;
  83. private readonly MFPurgeRoutine _purgeRoutine;
  84. private readonly MFPickRoutine _pickRoutine;
  85. private readonly MFPlaceRoutine _placeRoutine;
  86. private readonly MFSwapRoutine _swapRoutine;
  87. private readonly MFPMPickRoutine _pmPickRoutine;
  88. private readonly MFPMPlaceRoutine _pmPlaceRoutine;
  89. private readonly MFPMSwapRoutine _pmSwapRoutine;
  90. public TMEntity()
  91. {
  92. _tm = Singleton<JetTM>.Instance;
  93. _robot = new SIASUNRobot();
  94. _homeRoutine = new MFHomeRoutine(_tm, _robot);
  95. _pickRoutine = new MFPickRoutine(_tm, _robot);
  96. _placeRoutine = new MFPlaceRoutine(_tm, _robot);
  97. _swapRoutine = new MFSwapRoutine(_tm, _robot);
  98. _pmPickRoutine = new MFPMPickRoutine(_tm, _robot);
  99. _pmPlaceRoutine = new MFPMPlaceRoutine(_tm, _robot);
  100. _pmSwapRoutine = new MFPMSwapRoutine(_tm, _robot);
  101. _pumpingRoutine = new MFPumpRoutine(_tm, ModuleName.TM);
  102. _ventingRoutine = new MFVentRoutine(_tm, ModuleName.TM);
  103. _leakCheckRoutine = new MFLeakCheckRoutine(_tm, ModuleName.TM);
  104. _purgeRoutine = new MFPurgeRoutine(_tm, ModuleName.TM);
  105. WaferManager.Instance.SubscribeLocation(ModuleName.TM, 2);
  106. InitFsmMap();
  107. }
  108. protected override bool Init()
  109. {
  110. return true;
  111. }
  112. private void InitFsmMap()
  113. {
  114. fsm = new StateMachine<TMEntity>("TM", (int)STATE.Init, 50);
  115. //AnyStateTransition(FSM_MSG.TIMER, fnMonitor, FSM_STATE.SAME);
  116. AnyStateTransition(MSG.Error, fnError, STATE.Error);
  117. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  118. AnyStateTransition(MSG.Offline, fnOffline, FSM_STATE.SAME);
  119. AnyStateTransition(MSG.Home, fnHome, STATE.Initializing);
  120. // Home
  121. Transition(STATE.Initializing, FSM_MSG.TIMER, fnHoming, STATE.Idle);
  122. Transition(STATE.Idle, FSM_MSG.TIMER, fnMonitor, STATE.Idle);
  123. Transition(STATE.Init, FSM_MSG.TIMER, fnMonitor, STATE.Init);
  124. // Vent sequence
  125. Transition(STATE.Idle, MSG.Vent, FnStartVent, STATE.Venting);
  126. Transition(STATE.Venting, FSM_MSG.TIMER, FnVentTimeout, STATE.Idle);
  127. Transition(STATE.Venting, MSG.Abort, FnAbortVent, STATE.Idle);
  128. // Pump sequence
  129. Transition(STATE.Idle, MSG.Pump, FnStartPump, STATE.Pumping);
  130. Transition(STATE.Pumping, FSM_MSG.TIMER, FnPumpTimeout, STATE.Idle);
  131. Transition(STATE.Pumping, MSG.Abort, FnAbortPump, STATE.Idle);
  132. // Purge sequence
  133. Transition(STATE.Idle, MSG.CyclePurge, FnStartPurge, STATE.Purging);
  134. Transition(STATE.Purging, FSM_MSG.TIMER, FnPurgeTimeout, STATE.Idle);
  135. Transition(STATE.Purging, MSG.Abort, FnAbortPurge, STATE.Idle);
  136. // Leak check sequence
  137. Transition(STATE.Idle, MSG.LeakCheck, FnStartLeakCheck, STATE.Leakchecking);
  138. Transition(STATE.Leakchecking, FSM_MSG.TIMER, FnLeakCheckTimeout, STATE.Idle);
  139. Transition(STATE.Leakchecking, MSG.Abort, FnAbortLeakCheck, STATE.Idle);
  140. // Pick wafer from LL sequence
  141. Transition(STATE.Idle, MSG.Pick, FnStartPick, STATE.Picking);
  142. Transition(STATE.Picking, FSM_MSG.TIMER, FnPickTimeout, STATE.Idle);
  143. Transition(STATE.Picking, MSG.Abort, FnAbortPick, STATE.Idle);
  144. // Place wafer to LL sequence
  145. Transition(STATE.Idle, MSG.Place, FnStartPlace, STATE.Placing);
  146. Transition(STATE.Placing, FSM_MSG.TIMER, FnPlaceTimeout, STATE.Idle);
  147. Transition(STATE.Placing, MSG.Abort, FnAbortPlace, STATE.Idle);
  148. // Swap wafer with LL sequence
  149. Transition(STATE.Idle, MSG.Swap, FnStartSwap, STATE.Swaping);
  150. Transition(STATE.Swaping, FSM_MSG.TIMER, FnSwapTimeout, STATE.Idle);
  151. Transition(STATE.Swaping, MSG.Abort, FnAbortSwap, STATE.Idle);
  152. // Pick wafer from PM sequence
  153. Transition(STATE.Idle, MSG.PMPick, FnStartPMPick, STATE.PMPicking);
  154. Transition(STATE.PMPicking, FSM_MSG.TIMER, FnPMPickTimeout, STATE.Idle);
  155. Transition(STATE.PMPicking, MSG.Abort, FnAbortPMPick, STATE.Idle);
  156. // Place wafer to PM sequence
  157. Transition(STATE.Idle, MSG.PMPlace, FnStartPMPlace, STATE.PMPlacing);
  158. Transition(STATE.PMPlacing, FSM_MSG.TIMER, FnPMPlaceTimeout, STATE.Idle);
  159. Transition(STATE.PMPlacing, MSG.Abort, FnAbortPMPlace, STATE.Idle);
  160. // Swap wafer with PM sequence
  161. Transition(STATE.Idle, MSG.PMSwap, FnStartPMSwap, STATE.PMSwaping);
  162. Transition(STATE.PMSwaping, FSM_MSG.TIMER, FnPMSwapTimeout, STATE.Idle);
  163. Transition(STATE.PMSwaping, MSG.Abort, FnAbortPMSwap, STATE.Idle);
  164. Running = true;
  165. }
  166. private bool fnMonitor(object[] param)
  167. {
  168. _debugRoutine();
  169. return true;
  170. }
  171. private bool fnError(object[] param)
  172. {
  173. IsOnline = false;
  174. return true;
  175. }
  176. private bool fnOnline(object[] param)
  177. {
  178. return true;
  179. }
  180. private bool fnOffline(object[] param)
  181. {
  182. IsOnline = false;
  183. return true;
  184. }
  185. private bool fnAbort(object[] param)
  186. {
  187. _robot.Halt();
  188. return true;
  189. }
  190. private bool fnHome(object[] param)
  191. {
  192. return _homeRoutine.Start() == RState.Running;
  193. }
  194. private bool fnHoming(object[] param)
  195. {
  196. RState ret = _homeRoutine.Monitor();
  197. if (ret == RState.Failed || ret == RState.Timeout)
  198. {
  199. PostMsg(MSG.Error);
  200. return false;
  201. }
  202. return ret == RState.End;
  203. }
  204. private bool FnStartVent(object[] param)
  205. {
  206. return _ventingRoutine.Start() == RState.Running ;
  207. }
  208. private bool FnVentTimeout(object[] param)
  209. {
  210. RState ret = _ventingRoutine.Monitor();
  211. if (ret == RState.Failed || ret == RState.Timeout)
  212. {
  213. _ventingRoutine.Abort();
  214. PostMsg(MSG.Error);
  215. return false;
  216. }
  217. return ret == RState.End;
  218. }
  219. private bool FnAbortVent(object[] param)
  220. {
  221. _ventingRoutine.Abort();
  222. return true;
  223. }
  224. private bool FnStartPump(object[] param)
  225. {
  226. return _pumpingRoutine.Start() == RState.Running;
  227. }
  228. private bool FnPumpTimeout(object[] param)
  229. {
  230. RState ret = _pumpingRoutine.Monitor();
  231. if (ret == RState.Failed || ret == RState.Timeout)
  232. {
  233. _pumpingRoutine.Abort();
  234. PostMsg(MSG.Error);
  235. return false;
  236. }
  237. return ret == RState.End;
  238. }
  239. private bool FnAbortPump(object[] param)
  240. {
  241. _pumpingRoutine.Abort();
  242. return true;
  243. }
  244. private bool FnStartPurge(object[] param)
  245. {
  246. return _purgeRoutine.Start() == RState.Running;
  247. }
  248. private bool FnPurgeTimeout(object[] param)
  249. {
  250. RState ret = _purgeRoutine.Monitor();
  251. if (ret == RState.Failed || ret == RState.Timeout)
  252. {
  253. PostMsg(MSG.Error);
  254. return false;
  255. }
  256. return ret == RState.End;
  257. }
  258. private bool FnAbortPurge(object[] param)
  259. {
  260. _purgeRoutine.Abort();
  261. return true;
  262. }
  263. private bool FnStartLeakCheck(object[] param)
  264. {
  265. return _leakCheckRoutine.Start() == RState.Running;
  266. }
  267. private bool FnLeakCheckTimeout(object[] param)
  268. {
  269. RState ret = _leakCheckRoutine.Monitor();
  270. if (ret == RState.Failed || ret == RState.Timeout)
  271. {
  272. PostMsg(MSG.Error);
  273. return false;
  274. }
  275. return ret == RState.End;
  276. }
  277. private bool FnAbortLeakCheck(object[] param)
  278. {
  279. _leakCheckRoutine.Abort();
  280. return true;
  281. }
  282. private bool FnStartPick(object[] param)
  283. {
  284. return _pickRoutine.Start(param) == RState.Running;
  285. }
  286. private bool FnPickTimeout(object[] param)
  287. {
  288. RState ret = _pickRoutine.Monitor();
  289. if (ret == RState.Failed || ret == RState.Timeout)
  290. {
  291. PostMsg(MSG.Error);
  292. return false;
  293. }
  294. return ret == RState.End;
  295. }
  296. private bool FnAbortPick(object[] param)
  297. {
  298. _pickRoutine.Abort();
  299. return true;
  300. }
  301. private bool FnStartPlace(object[] param)
  302. {
  303. return _placeRoutine.Start(param) == RState.Running;
  304. }
  305. private bool FnPlaceTimeout(object[] param)
  306. {
  307. RState ret = _placeRoutine.Monitor();
  308. if (ret == RState.Failed || ret == RState.Timeout)
  309. {
  310. PostMsg(MSG.Error);
  311. return false;
  312. }
  313. return ret == RState.End;
  314. }
  315. private bool FnAbortPlace(object[] param)
  316. {
  317. _placeRoutine.Abort();
  318. return true;
  319. }
  320. private bool FnStartSwap(object[] param)
  321. {
  322. return _swapRoutine.Start(param) == RState.Running;
  323. }
  324. private bool FnSwapTimeout(object[] param)
  325. {
  326. RState ret = _swapRoutine.Monitor();
  327. if (ret == RState.Failed || ret == RState.Timeout)
  328. {
  329. PostMsg(MSG.Error);
  330. return false;
  331. }
  332. return ret == RState.End;
  333. }
  334. private bool FnAbortSwap(object[] param)
  335. {
  336. _swapRoutine.Abort();
  337. return true;
  338. }
  339. private bool FnStartPMPick(object[] param)
  340. {
  341. return _pmPickRoutine.Start(param) == RState.Running;
  342. }
  343. private bool FnPMPickTimeout(object[] param)
  344. {
  345. RState ret = _pmPickRoutine.Monitor();
  346. if (ret == RState.Failed || ret == RState.Timeout)
  347. {
  348. PostMsg(MSG.Error);
  349. return false;
  350. }
  351. return ret == RState.End;
  352. }
  353. private bool FnAbortPMPick(object[] param)
  354. {
  355. _pmPickRoutine.Abort();
  356. return true;
  357. }
  358. private bool FnStartPMPlace(object[] param)
  359. {
  360. return _pmPlaceRoutine.Start(param) == RState.Running;
  361. }
  362. private bool FnPMPlaceTimeout(object[] param)
  363. {
  364. RState ret = _pmPlaceRoutine.Monitor();
  365. if (ret == RState.Failed || ret == RState.Timeout)
  366. {
  367. PostMsg(MSG.Error);
  368. return false;
  369. }
  370. return ret == RState.End;
  371. }
  372. private bool FnAbortPMPlace(object[] param)
  373. {
  374. _pmPlaceRoutine.Abort();
  375. return true;
  376. }
  377. private bool FnStartPMSwap(object[] param)
  378. {
  379. return _pmSwapRoutine.Start(param) == RState.Running;
  380. }
  381. private bool FnPMSwapTimeout(object[] param)
  382. {
  383. RState ret = _pmSwapRoutine.Monitor();
  384. if (ret == RState.Failed || ret == RState.Timeout)
  385. {
  386. PostMsg(MSG.Error);
  387. return false;
  388. }
  389. return ret == RState.End;
  390. }
  391. private bool FnAbortPMSwap(object[] param)
  392. {
  393. _pmSwapRoutine.Abort();
  394. return true;
  395. }
  396. public bool Check(int msg, out string reason, params object[] args)
  397. {
  398. reason = "";
  399. return true;
  400. }
  401. public int Invoke(string function, params object[] args)
  402. {
  403. switch (function)
  404. {
  405. case "Home":
  406. CheckToPostMessage((int)MSG.Home);
  407. return (int)MSG.Home;
  408. }
  409. return (int)FSM_MSG.NONE;
  410. }
  411. public bool CheckAcked(int msg)
  412. {
  413. return fsm.CheckExecuted(msg);
  414. }
  415. public bool CheckToPostMessage(int msg, params object[] args)
  416. {
  417. if (!fsm.FindTransition(fsm.State, msg))
  418. {
  419. LOG.Write(eEvent.WARN_FSM_WARN, ModuleName.TM, $"TM is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
  420. return false;
  421. }
  422. Running = true;
  423. fsm.PostMsg(msg, args);
  424. return true;
  425. }
  426. private void _debugRoutine()
  427. {
  428. int flag = 0;
  429. // Test Home routine
  430. if (flag == 1)
  431. {
  432. PostMsg(MSG.Home);
  433. }
  434. else if (flag == 2)
  435. {
  436. PostMsg(MSG.Vent);
  437. }
  438. else if (flag == 3)
  439. {
  440. PostMsg(MSG.Pump);
  441. }
  442. else if(flag == 4)
  443. {
  444. PostMsg(MSG.Pick, ModuleName.LLA, 0, 0);
  445. }
  446. else if(flag == 5)
  447. {
  448. PostMsg(MSG.Place, ModuleName.LLA, 0, 0);
  449. }
  450. else if(flag == 6)
  451. {
  452. PostMsg(MSG.Swap, ModuleName.LLA, 0, 2, 0);
  453. }
  454. else if(flag == 7)
  455. {
  456. PostMsg(MSG.PMPick, ModuleName.PMA, 0, 0);
  457. }
  458. else if(flag == 8)
  459. {
  460. PostMsg(MSG.PMPlace, ModuleName.PMA, 0, 0);
  461. }
  462. else if(flag == 9)
  463. {
  464. PostMsg(MSG.PMSwap, ModuleName.PMA, 0, 0, 0, 0);
  465. }
  466. //else if (flag == 4)
  467. //{
  468. // PostMsg(MSG.PumpLoadLock);
  469. //}
  470. //else if (flag == 5)
  471. //{
  472. // PostMsg(MSG.VentLoadLock);
  473. //}
  474. //else if (flag == 6)
  475. //{
  476. // PostMsg(MSG.PurgeLoadLock);
  477. //}
  478. //else if (flag == 7)
  479. //{
  480. // PostMsg(MSG.LaunchPump);
  481. //}
  482. //else if (flag == 8)
  483. //{
  484. // PostMsg(MSG.LaunchTurboPump);
  485. //}
  486. //else if (flag == 9)
  487. //{
  488. // PostMsg(MSG.LoadLockLeakCheck);
  489. //}
  490. //else if (flag == 10)
  491. //{
  492. // PostMsg(MSG.CyclePurge);
  493. //}
  494. //else if (flag == 11)
  495. //{
  496. // PostMsg(MSG.GasLinePurge);
  497. //}
  498. //else if (flag == 12)
  499. //{
  500. // PostMsg(MSG.LeakCheck);
  501. //}
  502. //else if (flag == 13)
  503. //{
  504. // PostMsg(MSG.GasLeakCheck);
  505. //}
  506. //else if (flag == 14)
  507. //{
  508. // PostMsg(MSG.LLPlace);
  509. //}
  510. //else if (flag == 15)
  511. //{
  512. // PostMsg(MSG.LLPick);
  513. //}
  514. //else if (flag == 16)
  515. //{
  516. // PostMsg(MSG.RunRecipe, "7777");
  517. //}
  518. //else if (flag == 17)
  519. //{
  520. // PostMsg(MSG.MFCVerification, "MFC2", (double)50, 10);
  521. //}
  522. }
  523. }
  524. }