TMEntity.cs 30 KB

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