TMEntity.cs 15 KB

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