TMEntity.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  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. using Aitex.Core.RT.Device;
  17. using System.Timers;
  18. using Aitex.Core.RT.SCCore;
  19. using Aitex.Core.Backend;
  20. using System.Windows.Controls;
  21. namespace Venus_RT.Modules
  22. {
  23. class TMEntity : Entity, IModuleEntity
  24. {
  25. public enum STATE
  26. {
  27. Unknown,
  28. Init,
  29. Initializing,
  30. Idle,
  31. Error,
  32. Pumping,
  33. Venting,
  34. Purging,
  35. Leakchecking,
  36. Picking,
  37. Placing,
  38. Swaping,
  39. PMPicking,
  40. PMPlacing,
  41. PMSwaping,
  42. Aligning,
  43. Mapping,
  44. Extending,
  45. Retracting,
  46. Swapping,
  47. Gotoing,
  48. ControllingPressure
  49. }
  50. public enum MSG
  51. {
  52. Home,
  53. Online,
  54. Offline,
  55. Pump,
  56. Vent,
  57. Purge,
  58. CyclePurge,
  59. LeakCheck,
  60. Pick,
  61. Place,
  62. Swap,
  63. DoublePick,
  64. DoublePlace,
  65. DoubleSwap,
  66. PMPick,
  67. PMPlace,
  68. PMSwap,
  69. Extend,
  70. Retract,
  71. TMCycle,
  72. ControlPressure,
  73. Error,
  74. Abort,
  75. AbortControlPressure
  76. }
  77. public bool IsIdle
  78. {
  79. get { return fsm.State == (int)STATE.Idle; }
  80. }
  81. public bool IsError
  82. {
  83. get { return fsm.State == (int)STATE.Error; }
  84. }
  85. public bool IsInit
  86. {
  87. get { return fsm.State == (int)STATE.Unknown || fsm.State == (int)STATE.Init; }
  88. }
  89. public bool IsBusy
  90. {
  91. get { return !IsInit && !IsError && !IsIdle; }
  92. }
  93. public bool IsLLSlitDoorClosed(ModuleName ll) => ll == ModuleName.LLA ? _tm.IsLLAESlitDoorClosed : _tm.IsLLBESlitDoorClosed;
  94. public bool IsLLSlitDoorOpen(ModuleName ll) => ll == ModuleName.LLA ? _tm.IsLLAESlitDoorOpen : _tm.IsLLBESlitDoorOpen;
  95. public bool IsOnline { get; internal set; }
  96. public bool IsTMVac => _tm.IsTMVac;
  97. public bool IsTMATM => _tm.IsTMATM;
  98. public double TMPressure { get { return _tm.TMPressure; } }
  99. private readonly JetTM _tm;
  100. private readonly ITransferRobot _robot;
  101. private readonly MFHomeRoutine _homeRoutine;
  102. private readonly MFPumpRoutine _pumpingRoutine;
  103. private readonly MFVentRoutine _ventingRoutine;
  104. private readonly MFLeakCheckRoutine _leakCheckRoutine;
  105. private readonly MFPurgeRoutine _purgeRoutine;
  106. private readonly MFPickRoutine _pickRoutine;
  107. private readonly MFPlaceRoutine _placeRoutine;
  108. private readonly MFSwapRoutine _swapRoutine;
  109. private readonly MFPMPickRoutine _pmPickRoutine;
  110. private readonly MFPMPlaceRoutine _pmPlaceRoutine;
  111. private readonly MFPMSwapRoutine _pmSwapRoutine;
  112. private readonly MFPMRetractRoutine _pmRetractRoutine;
  113. private readonly MFPMExtendRoutine _pmExtendRoutine;
  114. private readonly MFControlPressureRoutine _tmControlPressureRoutine;
  115. //private readonly Timer controlPressureTimer;
  116. public TMEntity()
  117. {
  118. //_tm = Singleton<JetTM>.Instance;
  119. _tm = DEVICE.GetDevice<JetTM>("TM");
  120. _robot = new SIASUNRobot();
  121. _pickRoutine = new MFPickRoutine(_tm, _robot);
  122. _placeRoutine = new MFPlaceRoutine(_tm, _robot);
  123. _swapRoutine = new MFSwapRoutine(_tm, _robot);
  124. _pmPickRoutine = new MFPMPickRoutine(_tm, _robot);
  125. _pmPlaceRoutine = new MFPMPlaceRoutine(_tm, _robot);
  126. _pmSwapRoutine = new MFPMSwapRoutine(_tm, _robot);
  127. _pumpingRoutine = new MFPumpRoutine(_tm, ModuleName.TM);
  128. _homeRoutine = new MFHomeRoutine(_tm, _robot, _pumpingRoutine);
  129. _ventingRoutine = new MFVentRoutine(_tm, ModuleName.TM);
  130. _leakCheckRoutine = new MFLeakCheckRoutine(_tm, ModuleName.TM);
  131. _purgeRoutine = new MFPurgeRoutine(_tm, ModuleName.TM);
  132. _pmRetractRoutine = new MFPMRetractRoutine(_tm, _robot);
  133. _pmExtendRoutine = new MFPMExtendRoutine(_tm, _robot);
  134. _tmControlPressureRoutine = new MFControlPressureRoutine(_tm, _pumpingRoutine);
  135. WaferManager.Instance.SubscribeLocation(ModuleName.TMRobot, 2);
  136. InitFsmMap();
  137. //controlPressureTimer = new Timer(50);
  138. //controlPressureTimer.Elapsed += ControlPressureTimer_Elapsed;
  139. }
  140. protected override bool Init()
  141. {
  142. OP.Subscribe("TM.Home", (cmd, args) => CheckToPostMessage((int)MSG.Home));
  143. OP.Subscribe($"TM.{RtOperation.LLPick}", (cmd, args) => CheckToPostMessage((int)MSG.Pick, args));
  144. OP.Subscribe($"TM.{RtOperation.LLPlace}", (cmd, args) => CheckToPostMessage((int)MSG.Place, args));
  145. OP.Subscribe($"TM.{RtOperation.PMPick}", (cmd, args) => CheckToPostMessage((int)MSG.PMPick, args));
  146. OP.Subscribe($"TM.{RtOperation.PMPlace}", (cmd, args) => CheckToPostMessage((int)MSG.PMPlace, args));
  147. OP.Subscribe($"TM.{RtOperation.Extend}", (cmd, args) => CheckToPostMessage((int)MSG.Extend, args));
  148. OP.Subscribe($"TM.{RtOperation.Retract}", (cmd, args) => CheckToPostMessage((int)MSG.Retract, args));
  149. OP.Subscribe($"TM.{RtOperation.Cycle}", (cmd, args) => CheckToPostMessage((int)MSG.Swap, args));
  150. //OP.Subscribe($"TM.{RtOperation.LLPlace}", (cmd, args) => CheckToPostMessage((int)MSG.Place, args));
  151. OP.Subscribe($"TM.{RtOperation.Pump}", (cmd, args) => CheckToPostMessage((int)MSG.Pump));
  152. OP.Subscribe($"TM.{RtOperation.Vent}", (cmd, args) => CheckToPostMessage((int)MSG.Vent));
  153. OP.Subscribe($"TM.{RtOperation.LeakCheck}", (cmd, args) => CheckToPostMessage((int)MSG.LeakCheck));
  154. OP.Subscribe($"TM.{RtOperation.Purge}", (cmd, args) => CheckToPostMessage((int)MSG.Purge));
  155. OP.Subscribe($"TM.{RtOperation.Abort}", (cmd, args) => CheckToPostMessage((int)MSG.Abort));
  156. OP.Subscribe($"TM.{RtOperation.Online}", (cmd, args) => CheckToPostMessage((int)MSG.Online));
  157. OP.Subscribe($"TM.{RtOperation.Offline}", (cmd, args) => CheckToPostMessage((int)MSG.Offline));
  158. OP.Subscribe($"TM.{RtOperation.ControlPressure}", (cmd, args) => CheckToPostMessage((int)MSG.ControlPressure));
  159. OP.Subscribe($"TM.{RtOperation.AbortControlPressure}", (cmd, args) => CheckToPostMessage((int)MSG.AbortControlPressure));
  160. DATA.Subscribe("TM.FsmState", () => (((STATE)fsm.State).ToString()));
  161. DATA.Subscribe("TM.FsmPrevState", () => (((PMState)fsm.PrevState).ToString()));
  162. DATA.Subscribe("TM.FsmLastMessage", () => (((MSG)fsm.LastMsg).ToString()));
  163. DATA.Subscribe("TM.RobotMoveAction", () => _robot.TMRobotMoveInfo);
  164. DATA.Subscribe("TM.RobotMoveAction.ArmTarget", () => _robot.TMRobotMoveInfo.ArmTarget.ToString()) ;
  165. DATA.Subscribe("TM.RobotMoveAction.BladeTarget", () => _robot.TMRobotMoveInfo.BladeTarget);
  166. DATA.Subscribe("TM.RobotMoveAction.RobotAction", () => _robot.TMRobotMoveInfo.Action.ToString());
  167. DATA.Subscribe("TM.IsOnline", () => IsOnline);
  168. DATA.Subscribe("TM.Home.StepNo", () => _homeRoutine.currentStepNo);
  169. return true;
  170. }
  171. private void InitFsmMap()
  172. {
  173. fsm = new StateMachine<TMEntity>("TM", (int)STATE.Init, 50);
  174. //AnyStateTransition(FSM_MSG.TIMER, fnMonitor, FSM_STATE.SAME);
  175. AnyStateTransition(MSG.Error, fnError, STATE.Error);
  176. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  177. AnyStateTransition(MSG.Offline, fnOffline, FSM_STATE.SAME);
  178. AnyStateTransition(MSG.Home, fnHome, STATE.Initializing);
  179. // Home
  180. Transition(STATE.Initializing, FSM_MSG.TIMER, fnHoming, STATE.Idle);
  181. Transition(STATE.Idle, FSM_MSG.TIMER, fnMonitor, STATE.Idle);
  182. Transition(STATE.Init, FSM_MSG.TIMER, fnMonitor, STATE.Init);
  183. // Vent sequence
  184. Transition(STATE.Idle, MSG.Vent, FnStartVent, STATE.Venting);
  185. Transition(STATE.Venting, FSM_MSG.TIMER, FnVentTimeout, STATE.Idle);
  186. Transition(STATE.Venting, MSG.Abort, FnAbortVent, STATE.Idle);
  187. // Pump sequence
  188. Transition(STATE.Idle, MSG.Pump, FnStartPump, STATE.Pumping);
  189. Transition(STATE.Pumping, FSM_MSG.TIMER, FnPumpTimeout, STATE.Idle);
  190. Transition(STATE.Pumping, MSG.Abort, FnAbortPump, STATE.Idle);
  191. // Purge sequence
  192. Transition(STATE.Idle, MSG.Purge, FnStartPurge, STATE.Purging);
  193. Transition(STATE.Purging, FSM_MSG.TIMER, FnPurgeTimeout, STATE.Idle);
  194. Transition(STATE.Purging, MSG.Abort, FnAbortPurge, STATE.Idle);
  195. // Leak check sequence
  196. Transition(STATE.Idle, MSG.LeakCheck, FnStartLeakCheck, STATE.Leakchecking);
  197. Transition(STATE.Leakchecking, FSM_MSG.TIMER, FnLeakCheckTimeout, STATE.Idle);
  198. Transition(STATE.Leakchecking, MSG.Abort, FnAbortLeakCheck, STATE.Idle);
  199. // Pick wafer from LL sequence
  200. Transition(STATE.Idle, MSG.Pick, FnStartPick, STATE.Picking);
  201. Transition(STATE.Picking, FSM_MSG.TIMER, FnPickTimeout, STATE.Idle);
  202. Transition(STATE.Picking, MSG.Abort, FnAbortPick, STATE.Idle);
  203. // Place wafer to LL sequence
  204. Transition(STATE.Idle, MSG.Place, FnStartPlace, STATE.Placing);
  205. Transition(STATE.Placing, FSM_MSG.TIMER, FnPlaceTimeout, STATE.Idle);
  206. Transition(STATE.Placing, MSG.Abort, FnAbortPlace, STATE.Idle);
  207. // Swap wafer with LL sequence
  208. Transition(STATE.Idle, MSG.Swap, FnStartSwap, STATE.Swaping);
  209. Transition(STATE.Swaping, FSM_MSG.TIMER, FnSwapTimeout, STATE.Idle);
  210. Transition(STATE.Swaping, MSG.Abort, FnAbortSwap, STATE.Idle);
  211. // Pick wafer from PM sequence
  212. Transition(STATE.Idle, MSG.PMPick, FnStartPMPick, STATE.PMPicking);
  213. Transition(STATE.PMPicking, FSM_MSG.TIMER, FnPMPickTimeout, STATE.Idle);
  214. Transition(STATE.PMPicking, MSG.Abort, FnAbortPMPick, STATE.Idle);
  215. // Place wafer to PM sequence
  216. Transition(STATE.Idle, MSG.PMPlace, FnStartPMPlace, STATE.PMPlacing);
  217. Transition(STATE.PMPlacing, FSM_MSG.TIMER, FnPMPlaceTimeout, STATE.Idle);
  218. Transition(STATE.PMPlacing, MSG.Abort, FnAbortPMPlace, STATE.Idle);
  219. // Swap wafer with PM sequence
  220. Transition(STATE.Idle, MSG.PMSwap, FnStartPMSwap, STATE.PMSwaping);
  221. Transition(STATE.PMSwaping, FSM_MSG.TIMER, FnPMSwapTimeout, STATE.Idle);
  222. Transition(STATE.PMSwaping, MSG.Abort, FnAbortPMSwap, STATE.Idle);
  223. //Retract
  224. Transition(STATE.Idle, MSG.Retract, FnStartRetract, STATE.Retracting);
  225. Transition(STATE.Retracting, FSM_MSG.TIMER, FnRetract, STATE.Idle);
  226. Transition(STATE.Retracting, MSG.Abort, FnAbortRetract, STATE.Idle);
  227. //Extend
  228. Transition(STATE.Idle, MSG.Extend, FnStartExtend, STATE.Extending);
  229. Transition(STATE.Extending, FSM_MSG.TIMER, FnExtend, STATE.Idle);
  230. Transition(STATE.Extending, MSG.Abort, FnAbortExtend, STATE.Idle);
  231. //Transition(RtState.Init, MSG.TMCycle, FsmStartTMCycle, RtState.TMCycle);
  232. //Transition(RtState.TMCycle, FSM_MSG.TIMER, FsmMonitorTMCycle, RtState.Idle);
  233. //Extend
  234. //Control Pressure
  235. AnyStateTransition(MSG.ControlPressure, FnStartControlPressure, FSM_STATE.SAME, ControlPressureTimer_Elapsed);
  236. //Transition(STATE.ControllingPressure, FSM_MSG.TIMER, FnControlPressure, STATE.Idle);
  237. AnyStateTransition(MSG.AbortControlPressure, FnAbortControlPressure, FSM_STATE.SAME);
  238. Running = true;
  239. }
  240. private bool fnMonitor(object[] param)
  241. {
  242. _debugRoutine();
  243. return true;
  244. }
  245. private bool fnError(object[] param)
  246. {
  247. IsOnline = false;
  248. return true;
  249. }
  250. private bool fnOnline(object[] param)
  251. {
  252. //controlPressureTimer.Start();
  253. IsOnline = true;
  254. return true;
  255. }
  256. private bool fnOffline(object[] param)
  257. {
  258. //controlPressureTimer.Stop();
  259. IsOnline = false;
  260. return true;
  261. }
  262. private bool fnAbort(object[] param)
  263. {
  264. _robot.Halt();
  265. return true;
  266. }
  267. private bool fnHome(object[] param)
  268. {
  269. return _homeRoutine.Start() == RState.Running;
  270. }
  271. private bool fnHoming(object[] param)
  272. {
  273. RState ret = _homeRoutine.Monitor();
  274. if (ret == RState.Failed || ret == RState.Timeout)
  275. {
  276. PostMsg(MSG.Error);
  277. return false;
  278. }
  279. return ret == RState.End;
  280. }
  281. private bool FnStartVent(object[] param)
  282. {
  283. return _ventingRoutine.Start() == RState.Running ;
  284. }
  285. private bool FnVentTimeout(object[] param)
  286. {
  287. RState ret = _ventingRoutine.Monitor();
  288. if (ret == RState.Failed || ret == RState.Timeout)
  289. {
  290. _ventingRoutine.Abort();
  291. PostMsg(MSG.Error);
  292. return false;
  293. }
  294. return ret == RState.End;
  295. }
  296. private bool FnAbortVent(object[] param)
  297. {
  298. _ventingRoutine.Abort();
  299. return true;
  300. }
  301. private bool FnStartPump(object[] param)
  302. {
  303. return _pumpingRoutine.Start() == RState.Running;
  304. }
  305. private bool FnPumpTimeout(object[] param)
  306. {
  307. RState ret = _pumpingRoutine.Monitor();
  308. if (ret == RState.Failed || ret == RState.Timeout)
  309. {
  310. _pumpingRoutine.Abort();
  311. PostMsg(MSG.Error);
  312. return false;
  313. }
  314. return ret == RState.End;
  315. }
  316. private bool FnAbortPump(object[] param)
  317. {
  318. _pumpingRoutine.Abort();
  319. return true;
  320. }
  321. private bool FnStartPurge(object[] param)
  322. {
  323. return _purgeRoutine.Start() == RState.Running;
  324. }
  325. private bool FnPurgeTimeout(object[] param)
  326. {
  327. RState ret = _purgeRoutine.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 FnAbortPurge(object[] param)
  336. {
  337. _purgeRoutine.Abort();
  338. return true;
  339. }
  340. private bool FnStartLeakCheck(object[] param)
  341. {
  342. return _leakCheckRoutine.Start() == RState.Running;
  343. }
  344. private bool FnLeakCheckTimeout(object[] param)
  345. {
  346. RState ret = _leakCheckRoutine.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 FnAbortLeakCheck(object[] param)
  355. {
  356. _leakCheckRoutine.Abort();
  357. return true;
  358. }
  359. private bool FnStartPick(object[] param)
  360. {
  361. return _pickRoutine.Start(param) == RState.Running;
  362. }
  363. private bool FnPickTimeout(object[] param)
  364. {
  365. RState ret = _pickRoutine.Monitor();
  366. if (ret == RState.Failed || ret == RState.Timeout)
  367. {
  368. PostMsg(MSG.Error);
  369. return false;
  370. }
  371. return ret == RState.End;
  372. }
  373. private bool FnAbortPick(object[] param)
  374. {
  375. _pickRoutine.Abort();
  376. return true;
  377. }
  378. private bool FnStartPlace(object[] param)
  379. {
  380. return _placeRoutine.Start(param) == RState.Running;
  381. }
  382. private bool FnPlaceTimeout(object[] param)
  383. {
  384. RState ret = _placeRoutine.Monitor();
  385. if (ret == RState.Failed || ret == RState.Timeout)
  386. {
  387. PostMsg(MSG.Error);
  388. return false;
  389. }
  390. return ret == RState.End;
  391. }
  392. private bool FnAbortPlace(object[] param)
  393. {
  394. _placeRoutine.Abort();
  395. return true;
  396. }
  397. private bool FnStartSwap(object[] param)
  398. {
  399. return _swapRoutine.Start(param) == RState.Running;
  400. }
  401. private bool FnSwapTimeout(object[] param)
  402. {
  403. RState ret = _swapRoutine.Monitor();
  404. if (ret == RState.Failed || ret == RState.Timeout)
  405. {
  406. PostMsg(MSG.Error);
  407. return false;
  408. }
  409. return ret == RState.End;
  410. }
  411. private bool FnAbortSwap(object[] param)
  412. {
  413. _swapRoutine.Abort();
  414. return true;
  415. }
  416. private bool FnStartPMPick(object[] param)
  417. {
  418. return _pmPickRoutine.Start(param) == RState.Running;
  419. }
  420. private bool FnPMPickTimeout(object[] param)
  421. {
  422. RState ret = _pmPickRoutine.Monitor();
  423. if (ret == RState.Failed || ret == RState.Timeout)
  424. {
  425. PostMsg(MSG.Error);
  426. return false;
  427. }
  428. return ret == RState.End;
  429. }
  430. private bool FnAbortPMPick(object[] param)
  431. {
  432. _pmPickRoutine.Abort();
  433. return true;
  434. }
  435. private bool FnStartPMPlace(object[] param)
  436. {
  437. return _pmPlaceRoutine.Start(param) == RState.Running;
  438. }
  439. private bool FnPMPlaceTimeout(object[] param)
  440. {
  441. RState ret = _pmPlaceRoutine.Monitor();
  442. if (ret == RState.Failed || ret == RState.Timeout)
  443. {
  444. PostMsg(MSG.Error);
  445. return false;
  446. }
  447. return ret == RState.End;
  448. }
  449. private bool FnAbortPMPlace(object[] param)
  450. {
  451. _pmPlaceRoutine.Abort();
  452. return true;
  453. }
  454. private bool FnStartPMSwap(object[] param)
  455. {
  456. return _pmSwapRoutine.Start(param) == RState.Running;
  457. }
  458. private bool FnPMSwapTimeout(object[] param)
  459. {
  460. RState ret = _pmSwapRoutine.Monitor();
  461. if (ret == RState.Failed || ret == RState.Timeout)
  462. {
  463. PostMsg(MSG.Error);
  464. return false;
  465. }
  466. return ret == RState.End;
  467. }
  468. private bool FnAbortPMSwap(object[] param)
  469. {
  470. _pmSwapRoutine.Abort();
  471. return true;
  472. }
  473. private bool FnStartRetract(object[] param)
  474. {
  475. return _pmRetractRoutine.Start(param) == RState.Running;
  476. }
  477. private bool FnRetract(object[] param)
  478. {
  479. RState ret = _pmRetractRoutine.Monitor();
  480. if (ret == RState.Failed || ret == RState.Timeout)
  481. {
  482. PostMsg(MSG.Error);
  483. return false;
  484. }
  485. return ret == RState.End;
  486. }
  487. private bool FnAbortRetract(object[] param)
  488. {
  489. _pmRetractRoutine.Abort();
  490. return true;
  491. }
  492. private bool FnStartExtend(object[] param)
  493. {
  494. return _pmExtendRoutine.Start(param) == RState.Running;
  495. }
  496. private bool FnExtend(object[] param)
  497. {
  498. RState ret = _pmExtendRoutine.Monitor();
  499. if (ret == RState.Failed || ret == RState.Timeout)
  500. {
  501. PostMsg(MSG.Error);
  502. return false;
  503. }
  504. return ret == RState.End;
  505. }
  506. private bool FnAbortExtend(object[] param)
  507. {
  508. _pmExtendRoutine.Abort();
  509. return true;
  510. }
  511. private bool FnStartControlPressure(object[] param)
  512. {
  513. return _tmControlPressureRoutine.Start(param) == RState.Running;
  514. }
  515. private bool ControlPressureTimer_Elapsed(object[] param)
  516. {
  517. if (IsOnline == true)
  518. {
  519. RState ret = _tmControlPressureRoutine.Monitor();
  520. if (ret == RState.End)
  521. {
  522. if (_tm.PMASlitDoorClosed == false || _tm.PMBSlitDoorClosed == false || _tm.PMCSlitDoorClosed == false || _tm.PMDSlitDoorClosed == false)
  523. {
  524. _tm.SwitchTMPressureMode(true);
  525. }
  526. else
  527. {
  528. _tm.SwitchTMPressureMode(false);
  529. }
  530. }
  531. }
  532. return true;
  533. }
  534. private bool FnControlPressure(object[] param)
  535. {
  536. RState ret = _tmControlPressureRoutine.Monitor();
  537. if (ret == RState.Failed)
  538. {
  539. PostMsg(MSG.Error);
  540. return false;
  541. }
  542. return ret == RState.End;
  543. }
  544. private bool FnAbortControlPressure(object[] param)
  545. {
  546. _tmControlPressureRoutine.Abort();
  547. return true;
  548. }
  549. public bool Check(int msg, out string reason, params object[] args)
  550. {
  551. reason = "";
  552. return true;
  553. }
  554. public int Invoke(string function, params object[] args)
  555. {
  556. switch (function)
  557. {
  558. case "Home":
  559. CheckToPostMessage((int)MSG.Home);
  560. return (int)MSG.Home;
  561. }
  562. return (int)FSM_MSG.NONE;
  563. }
  564. public bool CheckAcked(int msg)
  565. {
  566. return fsm.CheckExecuted(msg);
  567. }
  568. public bool CheckToPostMessage(int msg, params object[] args)
  569. {
  570. if (!fsm.FindTransition(fsm.State, msg))
  571. {
  572. LOG.Write(eEvent.WARN_FSM_WARN, ModuleName.TM, $"TM is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
  573. return false;
  574. }
  575. Running = true;
  576. fsm.PostMsg(msg, args);
  577. return true;
  578. }
  579. public bool TurnEFEMSlitDoor(ModuleName loadlock, bool open, out string reason)
  580. {
  581. return _tm.TurnEFEMSlitDoor(loadlock, open, out reason);
  582. }
  583. //private bool FsmStartTMCycle(object[] objs)
  584. //{
  585. // return _TMCycle.Start(objs) == RState.Running;
  586. //}
  587. //private bool FsmMonitorTMCycle(object[] objs)
  588. //{
  589. // RState ret = _TMCycle.Monitor();
  590. // if (ret == RState.Failed || ret == RState.Timeout)
  591. // {
  592. // PostMsg(MSG.Error);
  593. // return false;
  594. // }
  595. // return ret == RState.End;
  596. //}
  597. private void _debugRoutine()
  598. {
  599. int flag = 0;
  600. // Test Home routine
  601. if (flag == 1)
  602. {
  603. PostMsg(MSG.Home);
  604. }
  605. else if (flag == 2)
  606. {
  607. PostMsg(MSG.Vent);
  608. }
  609. else if (flag == 3)
  610. {
  611. PostMsg(MSG.Pump);
  612. }
  613. else if(flag == 4)
  614. {
  615. PostMsg(MSG.Pick, ModuleName.LLA, 0, 0);
  616. }
  617. else if(flag == 5)
  618. {
  619. PostMsg(MSG.Place, ModuleName.LLA, 0, 0);
  620. }
  621. else if(flag == 6)
  622. {
  623. Queue<MoveItem> items = new Queue<MoveItem>();
  624. items.Enqueue(new MoveItem(ModuleName.TMRobot, 0, ModuleName.LLA, 0, Hand.Blade1));
  625. items.Enqueue(new MoveItem(ModuleName.TMRobot, 1, ModuleName.LLA, 1, Hand.Blade2));
  626. items.Enqueue(new MoveItem(ModuleName.LLA, 0, ModuleName.TMRobot, 0, Hand.Blade1));
  627. items.Enqueue(new MoveItem(ModuleName.LLA, 1, ModuleName.TMRobot, 1, Hand.Blade2));
  628. PostMsg(MSG.Swap,items);
  629. }
  630. else if(flag == 7)
  631. {
  632. PostMsg(MSG.PMPick, ModuleName.PMA, 0, 0);
  633. }
  634. else if(flag == 8)
  635. {
  636. PostMsg(MSG.PMPlace, ModuleName.PMA, 0, 0);
  637. }
  638. else if(flag == 9)
  639. {
  640. PostMsg(MSG.PMSwap, ModuleName.PMA, 0, 0, 0, 0);
  641. }
  642. //else if (flag == 4)
  643. //{
  644. // PostMsg(MSG.PumpLoadLock);
  645. //}
  646. //else if (flag == 5)
  647. //{
  648. // PostMsg(MSG.VentLoadLock);
  649. //}
  650. //else if (flag == 6)
  651. //{
  652. // PostMsg(MSG.PurgeLoadLock);
  653. //}
  654. //else if (flag == 7)
  655. //{
  656. // PostMsg(MSG.LaunchPump);
  657. //}
  658. //else if (flag == 8)
  659. //{
  660. // PostMsg(MSG.LaunchTurboPump);
  661. //}
  662. //else if (flag == 9)
  663. //{
  664. // PostMsg(MSG.LoadLockLeakCheck);
  665. //}
  666. //else if (flag == 10)
  667. //{
  668. // PostMsg(MSG.CyclePurge);
  669. //}
  670. //else if (flag == 11)
  671. //{
  672. // PostMsg(MSG.GasLinePurge);
  673. //}
  674. //else if (flag == 12)
  675. //{
  676. // PostMsg(MSG.LeakCheck);
  677. //}
  678. //else if (flag == 13)
  679. //{
  680. // PostMsg(MSG.GasLeakCheck);
  681. //}
  682. //else if (flag == 14)
  683. //{
  684. // PostMsg(MSG.LLPlace);
  685. //}
  686. //else if (flag == 15)
  687. //{
  688. // PostMsg(MSG.LLPick);
  689. //}
  690. //else if (flag == 16)
  691. //{
  692. // PostMsg(MSG.RunRecipe, "7777");
  693. //}
  694. //else if (flag == 17)
  695. //{
  696. // PostMsg(MSG.MFCVerification, "MFC2", (double)50, 10);
  697. //}
  698. }
  699. }
  700. }