TMEntity.cs 28 KB

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