TMEntity.cs 21 KB

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