TMEntity.cs 32 KB

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