TMEntity.cs 29 KB

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