TMEntity.cs 30 KB

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