TMEntity.cs 32 KB

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