TMEntity.cs 31 KB

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