TMEntity.cs 32 KB

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