TMEntity.cs 31 KB

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