TMEntity.cs 31 KB

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