TMEntity.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  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. Transition(STATE.Init, MSG.Home, fnHome, STATE.Initializing);
  215. Transition(STATE.Error, MSG.Home, fnHome, STATE.Initializing);
  216. Transition(STATE.Idle, MSG.Home, fnHome, STATE.Initializing);
  217. // Home
  218. Transition(STATE.Initializing, FSM_MSG.TIMER, fnHoming, STATE.Idle);
  219. Transition(STATE.Initializing, MSG.Abort, FnAbortHome, STATE.Idle);
  220. // Robot Home
  221. Transition(STATE.Idle, MSG.RobotHome, fnHome, STATE.InitializingRB);
  222. Transition(STATE.InitializingRB, FSM_MSG.TIMER, fnHoming, STATE.Idle);
  223. Transition(STATE.InitializingRB, MSG.Abort, FnAbortHome, STATE.Idle);
  224. //Transition(STATE.Idle, FSM_MSG.TIMER, fnMonitor, STATE.Idle);
  225. //Transition(STATE.Init, FSM_MSG.TIMER, fnMonitor, STATE.Init);
  226. // Vent sequence
  227. Transition(STATE.Idle, MSG.Vent, FnStartVent, STATE.Venting);
  228. Transition(STATE.Venting, FSM_MSG.TIMER, FnVentTimeout, STATE.Idle);
  229. Transition(STATE.Venting, MSG.Abort, FnAbortVent, STATE.Idle);
  230. // Pump sequence
  231. Transition(STATE.Idle, MSG.Pump, FnStartPump, STATE.Pumping);
  232. Transition(STATE.Pumping, FSM_MSG.TIMER, FnPumpTimeout, STATE.Idle);
  233. Transition(STATE.Pumping, MSG.Abort, FnAbortPump, STATE.Idle);
  234. // Purge sequence
  235. Transition(STATE.Idle, MSG.Purge, FnStartPurge, STATE.Purging);
  236. Transition(STATE.Purging, FSM_MSG.TIMER, FnPurgeTimeout, STATE.Idle);
  237. Transition(STATE.Purging, MSG.Abort, FnAbortPurge, STATE.Idle);
  238. // Leak check sequence
  239. Transition(STATE.Idle, MSG.LeakCheck, FnStartLeakCheck, STATE.Leakchecking);
  240. Transition(STATE.Leakchecking, FSM_MSG.TIMER, FnLeakCheckTimeout, STATE.Idle);
  241. Transition(STATE.Leakchecking, MSG.Abort, FnAbortLeakCheck, STATE.Idle);
  242. // Pick wafer from LL sequence
  243. Transition(STATE.Idle, MSG.Pick, FnStartPick, STATE.Picking);
  244. Transition(STATE.Picking, FSM_MSG.TIMER, FnPickTimeout, STATE.Idle);
  245. Transition(STATE.Picking, MSG.Abort, FnAbortPick, STATE.Idle);
  246. // Place wafer to LL sequence
  247. Transition(STATE.Idle, MSG.Place, FnStartPlace, STATE.Placing);
  248. Transition(STATE.Placing, FSM_MSG.TIMER, FnPlaceTimeout, STATE.Idle);
  249. Transition(STATE.Placing, MSG.Abort, FnAbortPlace, STATE.Idle);
  250. // Swap wafer with LL sequence
  251. Transition(STATE.Idle, MSG.Swap, FnStartSwap, STATE.Swaping);
  252. Transition(STATE.Swaping, FSM_MSG.TIMER, FnSwapTimeout, STATE.Idle);
  253. Transition(STATE.Swaping, MSG.Abort, FnAbortSwap, STATE.Idle);
  254. // Pick wafer from PM sequence
  255. Transition(STATE.Idle, MSG.PMPick, FnStartPMPick, STATE.PMPicking);
  256. Transition(STATE.PMPicking, FSM_MSG.TIMER, FnPMPickTimeout, STATE.Idle);
  257. Transition(STATE.PMPicking, MSG.Abort, FnAbortPMPick, STATE.Idle);
  258. // Place wafer to PM sequence
  259. Transition(STATE.Idle, MSG.PMPlace, FnStartPMPlace, STATE.PMPlacing);
  260. Transition(STATE.PMPlacing, FSM_MSG.TIMER, FnPMPlaceTimeout, STATE.Idle);
  261. Transition(STATE.PMPlacing, MSG.Abort, FnAbortPMPlace, STATE.Idle);
  262. // Swap wafer with PM sequence
  263. Transition(STATE.Idle, MSG.PMSwap, FnStartPMSwap, STATE.PMSwaping);
  264. Transition(STATE.PMSwaping, FSM_MSG.TIMER, FnPMSwapTimeout, STATE.Idle);
  265. Transition(STATE.PMSwaping, MSG.Abort, FnAbortPMSwap, STATE.Idle);
  266. //Retract
  267. Transition(STATE.Idle, MSG.Retract, FnStartRetract, STATE.Retracting);
  268. Transition(STATE.Retracting, FSM_MSG.TIMER, FnRetract, STATE.Idle);
  269. Transition(STATE.Retracting, MSG.Abort, FnAbortRetract, STATE.Idle);
  270. //Extend
  271. Transition(STATE.Idle, MSG.Extend, FnStartExtend, STATE.Extending);
  272. Transition(STATE.Extending, FSM_MSG.TIMER, FnExtend, STATE.Idle);
  273. Transition(STATE.Extending, MSG.Abort, FnAbortExtend, STATE.Idle);
  274. //Transition(RtState.Init, MSG.TMCycle, FsmStartTMCycle, RtState.TMCycle);
  275. //Transition(RtState.TMCycle, FSM_MSG.TIMER, FsmMonitorTMCycle, RtState.Idle);
  276. //Extend
  277. //Control Pressure
  278. AnyStateTransition(FSM_MSG.TIMER, ControlPressureTimer_Elapsed, FSM_STATE.SAME);
  279. Running = true;
  280. }
  281. private bool fnMonitor(object[] param)
  282. {
  283. _debugRoutine();
  284. return true;
  285. }
  286. private bool fnError(object[] param)
  287. {
  288. IsOnline = false;
  289. return true;
  290. }
  291. private bool fnOnline(object[] param)
  292. {
  293. //controlPressureTimer.Start();
  294. IsOnline = true;
  295. return true;
  296. }
  297. private bool fnOffline(object[] param)
  298. {
  299. //controlPressureTimer.Stop();
  300. IsOnline = false;
  301. return true;
  302. }
  303. private bool fnAbort(object[] param)
  304. {
  305. _robot.Halt();
  306. return true;
  307. }
  308. private bool fnHome(object[] param)
  309. {
  310. if (fsm.State == (int)STATE.Init && param.Length > 0)//带参home
  311. {
  312. return false;
  313. }
  314. else
  315. return _homeRoutine.Start(param) == RState.Running;
  316. }
  317. private bool fnHoming(object[] param)
  318. {
  319. RState ret = _homeRoutine.Monitor();
  320. if (ret == RState.Failed || ret == RState.Timeout)
  321. {
  322. PostMsg(MSG.Error);
  323. return false;
  324. }
  325. return ret == RState.End;
  326. }
  327. private bool FnStartVent(object[] param)
  328. {
  329. return _ventingRoutine.Start(false) == RState.Running;
  330. }
  331. private bool FnVentTimeout(object[] param)
  332. {
  333. RState ret = _ventingRoutine.Monitor();
  334. if (ret == RState.Failed || ret == RState.Timeout)
  335. {
  336. _ventingRoutine.Abort();
  337. PostMsg(MSG.Error);
  338. return false;
  339. }
  340. return ret == RState.End;
  341. }
  342. private bool FnAbortVent(object[] param)
  343. {
  344. _ventingRoutine.Abort();
  345. return true;
  346. }
  347. private bool FnStartPump(object[] param)
  348. {
  349. return _pumpingRoutine.Start() == RState.Running;
  350. }
  351. private bool FnPumpTimeout(object[] param)
  352. {
  353. RState ret = _pumpingRoutine.Monitor();
  354. if (ret == RState.Failed || ret == RState.Timeout)
  355. {
  356. _pumpingRoutine.Abort();
  357. PostMsg(MSG.Error);
  358. return false;
  359. }
  360. return ret == RState.End;
  361. }
  362. private bool FnAbortPump(object[] param)
  363. {
  364. _pumpingRoutine.Abort();
  365. return true;
  366. }
  367. private bool FnStartPurge(object[] param)
  368. {
  369. return _purgeRoutine.Start() == RState.Running;
  370. }
  371. private bool FnPurgeTimeout(object[] param)
  372. {
  373. RState ret = _purgeRoutine.Monitor();
  374. if (ret == RState.Failed || ret == RState.Timeout)
  375. {
  376. PostMsg(MSG.Error);
  377. return false;
  378. }
  379. return ret == RState.End;
  380. }
  381. private bool FnAbortPurge(object[] param)
  382. {
  383. _purgeRoutine.Abort();
  384. return true;
  385. }
  386. private bool FnStartLeakCheck(object[] param)
  387. {
  388. return _leakCheckRoutine.Start() == RState.Running;
  389. }
  390. private bool FnLeakCheckTimeout(object[] param)
  391. {
  392. RState ret = _leakCheckRoutine.Monitor();
  393. if (ret == RState.Failed || ret == RState.Timeout)
  394. {
  395. PostMsg(MSG.Error);
  396. return false;
  397. }
  398. return ret == RState.End;
  399. }
  400. private bool FnAbortLeakCheck(object[] param)
  401. {
  402. _leakCheckRoutine.Abort();
  403. return true;
  404. }
  405. private bool FnStartPick(object[] param)
  406. {
  407. return _pickRoutine.Start(param) == RState.Running;
  408. }
  409. private bool FnPickTimeout(object[] param)
  410. {
  411. RState ret = _pickRoutine.Monitor();
  412. if (ret == RState.Failed || ret == RState.Timeout)
  413. {
  414. PostMsg(MSG.Error);
  415. return false;
  416. }
  417. return ret == RState.End;
  418. }
  419. private bool FnAbortPick(object[] param)
  420. {
  421. _pickRoutine.Abort();
  422. return true;
  423. }
  424. private bool FnStartPlace(object[] param)
  425. {
  426. return _placeRoutine.Start(param) == RState.Running;
  427. }
  428. private bool FnPlaceTimeout(object[] param)
  429. {
  430. RState ret = _placeRoutine.Monitor();
  431. if (ret == RState.Failed || ret == RState.Timeout)
  432. {
  433. PostMsg(MSG.Error);
  434. return false;
  435. }
  436. return ret == RState.End;
  437. }
  438. private bool FnAbortPlace(object[] param)
  439. {
  440. _placeRoutine.Abort();
  441. return true;
  442. }
  443. private bool FnStartSwap(object[] param)
  444. {
  445. return _swapRoutine.Start(param) == RState.Running;
  446. }
  447. private bool FnSwapTimeout(object[] param)
  448. {
  449. RState ret = _swapRoutine.Monitor();
  450. if (ret == RState.Failed || ret == RState.Timeout)
  451. {
  452. PostMsg(MSG.Error);
  453. return false;
  454. }
  455. return ret == RState.End;
  456. }
  457. private bool FnAbortSwap(object[] param)
  458. {
  459. _swapRoutine.Abort();
  460. return true;
  461. }
  462. private bool FnStartPMPick(object[] param)
  463. {
  464. return _pmPickRoutine.Start(param) == RState.Running;
  465. }
  466. private bool FnPMPickTimeout(object[] param)
  467. {
  468. RState ret = _pmPickRoutine.Monitor();
  469. if (ret == RState.Failed || ret == RState.Timeout)
  470. {
  471. PostMsg(MSG.Error);
  472. return false;
  473. }
  474. return ret == RState.End;
  475. }
  476. private bool FnAbortPMPick(object[] param)
  477. {
  478. _pmPickRoutine.Abort();
  479. return true;
  480. }
  481. private bool FnStartPMPlace(object[] param)
  482. {
  483. return _pmPlaceRoutine.Start(param) == RState.Running;
  484. }
  485. private bool FnPMPlaceTimeout(object[] param)
  486. {
  487. RState ret = _pmPlaceRoutine.Monitor();
  488. if (ret == RState.Failed || ret == RState.Timeout)
  489. {
  490. PostMsg(MSG.Error);
  491. return false;
  492. }
  493. return ret == RState.End;
  494. }
  495. private bool FnAbortPMPlace(object[] param)
  496. {
  497. _pmPlaceRoutine.Abort();
  498. return true;
  499. }
  500. private bool FnStartPMSwap(object[] param)
  501. {
  502. return _pmSwapRoutine.Start(param) == RState.Running;
  503. }
  504. private bool FnPMSwapTimeout(object[] param)
  505. {
  506. RState ret = _pmSwapRoutine.Monitor();
  507. if (ret == RState.Failed || ret == RState.Timeout)
  508. {
  509. PostMsg(MSG.Error);
  510. return false;
  511. }
  512. return ret == RState.End;
  513. }
  514. private bool FnAbortPMSwap(object[] param)
  515. {
  516. _pmSwapRoutine.Abort();
  517. return true;
  518. }
  519. private bool FnStartRetract(object[] param)
  520. {
  521. return _pmRetractRoutine.Start(param) == RState.Running;
  522. }
  523. private bool FnRetract(object[] param)
  524. {
  525. RState ret = _pmRetractRoutine.Monitor();
  526. if (ret == RState.Failed || ret == RState.Timeout)
  527. {
  528. PostMsg(MSG.Error);
  529. return false;
  530. }
  531. return ret == RState.End;
  532. }
  533. private bool FnAbortRetract(object[] param)
  534. {
  535. _pmRetractRoutine.Abort();
  536. return true;
  537. }
  538. private bool FnStartExtend(object[] param)
  539. {
  540. return _pmExtendRoutine.Start(param) == RState.Running;
  541. }
  542. private bool FnExtend(object[] param)
  543. {
  544. RState ret = _pmExtendRoutine.Monitor();
  545. if (ret == RState.Failed || ret == RState.Timeout)
  546. {
  547. PostMsg(MSG.Error);
  548. return false;
  549. }
  550. return ret == RState.End;
  551. }
  552. private bool FnAbortHome(object[] param)
  553. {
  554. _homeRoutine.Abort();
  555. return true;
  556. }
  557. private bool FnAbortHomeRB(object[] param)
  558. {
  559. _homeRoutine.Abort();
  560. return true;
  561. }
  562. private bool FnAbortExtend(object[] param)
  563. {
  564. _pmExtendRoutine.Abort();
  565. return true;
  566. }
  567. private bool RobotGoto(object[] param)
  568. {
  569. return _robot.Goto((ModuleName)param[0], (int)param[1], (Hand)param[2]);
  570. }
  571. private bool ControlPressureTimer_Elapsed(object[] param)
  572. {
  573. // robot idle check
  574. _robotIdleTrigger.CLK = _robot.Status != RState.Running;
  575. if (_robotIdleTrigger.Q)
  576. {
  577. _robotWatch.Restart();
  578. }
  579. if (RouteManager.IsATMMode)
  580. {
  581. return true;
  582. }
  583. if (IsOnline == true)
  584. {
  585. //if (_tm.AllPMSlitDoorClosed != _allPMSlitDoorClosed)
  586. //{
  587. // startControlPressureFlag = true;
  588. //}
  589. //_allPMSlitDoorClosed = _tm.AllPMSlitDoorClosed;
  590. if (startControlPressureFlag == true)
  591. {
  592. //_tmControlPressureRoutine.Start(param);
  593. _controlPressureCheckPoint = SC.GetValue<int>($"TM.ControlPressureCheckPoint");
  594. _controlPressureSetPoint = SC.GetValue<int>($"TM.ControlPressureSetPoint");
  595. _controlFlowSetPoint = SC.GetValue<int>($"TM.TM_MFC1.DefaultSetPoint");
  596. startControlPressureFlag = false;
  597. stopControlPressureFlag = false;
  598. _pumpingRoutine.Start();
  599. }
  600. RState ret = _pumpingRoutine.Monitor();
  601. if (ret == RState.End && _tm.ChamberPressure <= _controlPressureCheckPoint)
  602. {
  603. if (stopControlPressureFlag == false)
  604. {
  605. stopControlPressureFlag = true;
  606. //_tm.TurnFastPumpValve(ModuleName.TM, true);
  607. _tm.TurnSoftPumpValve(ModuleName.TM, true);
  608. _tm.TurnN2Valve(true);
  609. _tm.TurnPurgeValve(ModuleName.TM, true);
  610. if (_tm.AllPMSlitDoorClosed)
  611. {
  612. _tm.SetTMFlow(0);
  613. _tm.SwitchTMPressureMode(true);
  614. _tm.SetTMPressure(_controlPressureSetPoint);
  615. }
  616. else
  617. {
  618. _tm.SetTMPressure(0);
  619. _tm.SwitchTMPressureMode(false);
  620. _tm.SetTMFlow(_controlFlowSetPoint);
  621. }
  622. //if (_tm.PMASlitDoorClosed == false || _tm.PMBSlitDoorClosed == false || _tm.PMCSlitDoorClosed == false || _tm.PMDSlitDoorClosed == false)
  623. //{
  624. // _tm.SwitchTMPressureMode(false);
  625. //}
  626. //else
  627. //{
  628. // _tm.SwitchTMPressureMode(true);
  629. //}
  630. }
  631. }
  632. }
  633. else
  634. {
  635. if (stopControlPressureFlag == true)
  636. {
  637. //_tm.TurnFastPumpValve(ModuleName.TM, false);
  638. _tm.TurnSoftPumpValve(ModuleName.TM, false);
  639. //_tm.TurnN2Valve(false);
  640. _tm.TurnPurgeValve(ModuleName.TM, false);
  641. _tm.SetTMPressure(0);
  642. _tm.SetTMFlow(0);
  643. }
  644. startControlPressureFlag = true;
  645. stopControlPressureFlag = false;
  646. }
  647. return true;
  648. }
  649. public bool Check(int msg, out string reason, params object[] args)
  650. {
  651. reason = "";
  652. return true;
  653. }
  654. public int Invoke(string function, params object[] args)
  655. {
  656. switch (function)
  657. {
  658. case "Home":
  659. CheckToPostMessage((int)MSG.Home);
  660. return (int)MSG.Home;
  661. }
  662. return (int)FSM_MSG.NONE;
  663. }
  664. public bool CheckAcked(int msg)
  665. {
  666. return fsm.CheckExecuted(msg);
  667. }
  668. public bool CheckToPostMessage(int msg, params object[] args)
  669. {
  670. if (!fsm.FindTransition(fsm.State, msg))
  671. {
  672. LOG.Write(eEvent.WARN_FSM_WARN, ModuleName.TM, $"TM is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
  673. return false;
  674. }
  675. Running = true;
  676. fsm.PostMsg(msg, args);
  677. return true;
  678. }
  679. public bool TurnEFEMSlitDoor(ModuleName loadlock, bool open, out string reason)
  680. {
  681. return _tm.TurnEFEMSlitDoor(loadlock, open, out reason);
  682. }
  683. public bool TMRobotNotExtendModule(ModuleName moduleName)
  684. {
  685. return _tm.TMRobotNotExtendModule(moduleName);
  686. }
  687. public bool EFEMRobotNotExtendModule(ModuleName moduleName)
  688. {
  689. return _tm.EFEMRobotNotExtendModule(moduleName);
  690. }
  691. //private bool FsmStartTMCycle(object[] objs)
  692. //{
  693. // return _TMCycle.Start(objs) == RState.Running;
  694. //}
  695. //private bool FsmMonitorTMCycle(object[] objs)
  696. //{
  697. // RState ret = _TMCycle.Monitor();
  698. // if (ret == RState.Failed || ret == RState.Timeout)
  699. // {
  700. // PostMsg(MSG.Error);
  701. // return false;
  702. // }
  703. // return ret == RState.End;
  704. //}
  705. private void _debugRoutine()
  706. {
  707. int flag = 0;
  708. // Test Home routine
  709. if (flag == 1)
  710. {
  711. PostMsg(MSG.Home);
  712. }
  713. else if (flag == 2)
  714. {
  715. PostMsg(MSG.Vent);
  716. }
  717. else if (flag == 3)
  718. {
  719. PostMsg(MSG.Pump);
  720. }
  721. else if (flag == 4)
  722. {
  723. PostMsg(MSG.Pick, ModuleName.LLA, 0, 0);
  724. }
  725. else if (flag == 5)
  726. {
  727. PostMsg(MSG.Place, ModuleName.LLA, 0, 0);
  728. }
  729. else if (flag == 6)
  730. {
  731. Queue<MoveItem> items = new Queue<MoveItem>();
  732. items.Enqueue(new MoveItem(ModuleName.TMRobot, 0, ModuleName.LLA, 0, Hand.Blade1));
  733. items.Enqueue(new MoveItem(ModuleName.TMRobot, 1, ModuleName.LLA, 1, Hand.Blade2));
  734. items.Enqueue(new MoveItem(ModuleName.LLA, 0, ModuleName.TMRobot, 0, Hand.Blade1));
  735. items.Enqueue(new MoveItem(ModuleName.LLA, 1, ModuleName.TMRobot, 1, Hand.Blade2));
  736. PostMsg(MSG.Swap, items);
  737. }
  738. else if (flag == 7)
  739. {
  740. PostMsg(MSG.PMPick, ModuleName.PMA, 0, 0);
  741. }
  742. else if (flag == 8)
  743. {
  744. PostMsg(MSG.PMPlace, ModuleName.PMA, 0, 0);
  745. }
  746. else if (flag == 9)
  747. {
  748. PostMsg(MSG.PMSwap, ModuleName.PMA, 0, 0, 0, 0);
  749. }
  750. //else if (flag == 4)
  751. //{
  752. // PostMsg(MSG.PumpLoadLock);
  753. //}
  754. //else if (flag == 5)
  755. //{
  756. // PostMsg(MSG.VentLoadLock);
  757. //}
  758. //else if (flag == 6)
  759. //{
  760. // PostMsg(MSG.PurgeLoadLock);
  761. //}
  762. //else if (flag == 7)
  763. //{
  764. // PostMsg(MSG.LaunchPump);
  765. //}
  766. //else if (flag == 8)
  767. //{
  768. // PostMsg(MSG.LaunchTurboPump);
  769. //}
  770. //else if (flag == 9)
  771. //{
  772. // PostMsg(MSG.LoadLockLeakCheck);
  773. //}
  774. //else if (flag == 10)
  775. //{
  776. // PostMsg(MSG.CyclePurge);
  777. //}
  778. //else if (flag == 11)
  779. //{
  780. // PostMsg(MSG.GasLinePurge);
  781. //}
  782. //else if (flag == 12)
  783. //{
  784. // PostMsg(MSG.LeakCheck);
  785. //}
  786. //else if (flag == 13)
  787. //{
  788. // PostMsg(MSG.GasLeakCheck);
  789. //}
  790. //else if (flag == 14)
  791. //{
  792. // PostMsg(MSG.LLPlace);
  793. //}
  794. //else if (flag == 15)
  795. //{
  796. // PostMsg(MSG.LLPick);
  797. //}
  798. //else if (flag == 16)
  799. //{
  800. // PostMsg(MSG.RunRecipe, "7777");
  801. //}
  802. //else if (flag == 17)
  803. //{
  804. // PostMsg(MSG.MFCVerification, "MFC2", (double)50, 10);
  805. //}
  806. }
  807. }
  808. }