TMEntity.cs 29 KB

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