EfemEntity.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. using System;
  2. using System.Collections.Generic;
  3. using Aitex.Core.Common;
  4. using Aitex.Core.RT.DataCenter;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.Fsm;
  7. using Aitex.Core.RT.OperationCenter;
  8. using Aitex.Core.RT.SCCore;
  9. using Aitex.Core.Utilities;
  10. using Aitex.Sorter.Common;
  11. using MECF.Framework.Common.Equipment;
  12. using MECF.Framework.Common.Schedulers;
  13. using MECF.Framework.Common.SubstrateTrackings;
  14. using Venus_Core;
  15. using Venus_RT;
  16. using Venus_RT.Devices;
  17. using Venus_RT.Devices.YASKAWA;
  18. using Venus_RT.Devices.EFEM;
  19. using Venus_RT.Modules.LPs;
  20. using Venus_RT.Modules.EFEM;
  21. namespace Venus_RT.Modules
  22. {
  23. class EfemEntity : Entity, IEntity, IModuleEntity
  24. {
  25. //private int _bigWafer = 0;
  26. //private int _midWafer = 0;
  27. //private int _smallWafer = 0;
  28. public enum STATE
  29. {
  30. Unknown, // 0
  31. Initializing, // 1
  32. Idle, // 2
  33. Error, // 3
  34. Picking, // 4
  35. Placing, // 5
  36. Aligning, // 6
  37. Mapping, // 7
  38. Init, // 8
  39. Orgshing, // 9
  40. Lifting, // 10
  41. InitingAL, // 11
  42. InitingRB, // 12
  43. Extending, // 13
  44. Retracting, // 14
  45. //SettingLamp, // 15
  46. Swapping,
  47. Gotoing,
  48. Gripping,
  49. Ungripping,
  50. Fliping,
  51. }
  52. public enum MSG
  53. {
  54. HomeAll, // 0
  55. Pick, // 1
  56. Place, // 2
  57. Align, // 3
  58. ActionDone, // 4
  59. MoveCmd, // 6
  60. Recover, // 8
  61. Goto, // 9
  62. Error, // 10
  63. Online, // 11
  64. CommReady, // 12
  65. Lift, // 13
  66. HomeAL, // 14
  67. HomeRB, // 15
  68. Extend, // 16
  69. Retract, // 17
  70. PMLiftPinUp, // 18
  71. PMLiftPinDown, // 19
  72. TurnOffBuzzer,
  73. Abort,
  74. Map,
  75. ToInit,
  76. Cool,
  77. Swap,
  78. Grip,
  79. Ungrip,
  80. Flip,
  81. LiftActionDone,
  82. }
  83. public enum EfemType
  84. {
  85. FutureEfem = 1,
  86. JetEfem = 2,
  87. BrooksEFEM = 3,
  88. }
  89. public bool IsIdle
  90. {
  91. get { return fsm.State == (int)STATE.Idle; }
  92. }
  93. public bool IsError
  94. {
  95. get { return fsm.State == (int)STATE.Error; }
  96. }
  97. public bool IsInit
  98. {
  99. get { return fsm.State == (int)STATE.Unknown || fsm.State == (int)STATE.Init; }
  100. }
  101. public bool IsBusy
  102. {
  103. get { return !IsInit && !IsError && !IsIdle; }
  104. }
  105. public bool IsOnline { get; internal set; }
  106. public bool Check(int msg, out string reason, params object[] args)
  107. {
  108. throw new NotImplementedException();
  109. }
  110. // Fields
  111. //
  112. private readonly string Name;
  113. private readonly EfemBase _efem;
  114. private readonly LoadPortModule[] _lpms = new LoadPortModule[2];
  115. private readonly EfemType _efemType;
  116. public EfemBase EfemDevice => _efem;
  117. public EfemType EFEMType => _efemType;
  118. // routine
  119. private readonly EfemPickRoutine _pickRoutine;
  120. private readonly EfemPlaceRoutine _placeRoutine;
  121. private readonly EfemSwapRoutine _swapRoutine;
  122. private readonly EfemHomeRoutine _homeRoutine;
  123. // Constructor
  124. //
  125. public EfemEntity()
  126. {
  127. _efemType = (EfemType)SC.GetValue<int>($"EFEM.EfemType");
  128. _efem = new JetEfem();
  129. Name = ModuleName.EFEM.ToString();
  130. _homeRoutine = new EfemHomeRoutine(_efem);
  131. _pickRoutine = new EfemPickRoutine(_efem);
  132. _placeRoutine = new EfemPlaceRoutine(_efem);
  133. _swapRoutine = new EfemSwapRoutine(_efem);
  134. InitFsmMap();
  135. }
  136. public void NotifyLP(ModuleName mod, LoadportEntity.MSG msg)
  137. {
  138. _lpms[mod - ModuleName.LP1].PostMsg(msg);
  139. }
  140. public void NotifyLPError(ModuleName mod )
  141. {
  142. _lpms[mod - ModuleName.LP1].PostMsg(LoadportEntity.MSG.ActionDone);
  143. //_lpms[mod - ModuleName.LP1]..OnError();
  144. }
  145. protected override bool Init()
  146. {
  147. _lpms[0] = new LoadPortModule(ModuleName.LP1, _efem);
  148. _lpms[1] = new LoadPortModule(ModuleName.LP2, _efem);
  149. _lpms[0].Initialize();
  150. _lpms[1].Initialize();
  151. OP.Subscribe($"{ModuleName.EFEM}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeAll); return true; });
  152. OP.Subscribe($"{ModuleName.EFEM}.{EfemOperation.ClearError}", (cmd, args) => { PostMsg(MSG.Recover); return true; });
  153. OP.Subscribe($"{ModuleName.EFEM}.{EfemOperation.TurnOffBuzzer}", (cmd, args) => { PostMsg(MSG.TurnOffBuzzer); return true; });
  154. //OP.Subscribe($"{ModuleName.EFEM}.{EfemOperation.SwitchOnBuzzerAndRed}", (cmd, args) => { PostMsg(MSG.SwitchOnBuzzerAndRed); return true; });
  155. OP.Subscribe($"{ModuleName.EFEM}.Online", (cmd, args) => { PostMsg(MSG.Online); return true; });
  156. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Pick}", (cmd, args) => { PostMsg(MSG.Pick, args[0], args[1], args[3], args[2]); return true; });
  157. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Place}", (cmd, args) => { PostMsg(MSG.Place, args[0], args[1], args[3], args[2]); return true; });
  158. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Abort}", (cmd, args) => { PostMsg(MSG.Abort); return true; });
  159. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeRB); return true; });
  160. OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Grip}", (cmd, args) =>
  161. {
  162. bool isGrip = ((string)args[0]).ToLower() == "on";
  163. PostMsg(isGrip ? MSG.Grip : MSG.Ungrip, args[1]);
  164. return true;
  165. });
  166. //OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Flip}", (cmd, args) => { PostMsg(MSG.Flip, args[0]); return true; });
  167. OP.Subscribe($"{ModuleName.Aligner1}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeAL, ModuleName.Aligner1); return true; });
  168. OP.Subscribe($"{ModuleName.Aligner2}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeAL, ModuleName.Aligner2); return true; });
  169. OP.Subscribe($"{ModuleName.Cooling1}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeAL, ModuleName.Cooling1); return true; });
  170. OP.Subscribe($"{ModuleName.Cooling2}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeAL, ModuleName.Cooling2); return true; });
  171. OP.Subscribe($"{ModuleName.Aligner1}.{EfemOperation.Align}", (cmd, args) => { PostMsg(MSG.Align, ModuleName.Aligner1, args[0]); return true; });
  172. OP.Subscribe($"{ModuleName.Aligner2}.{EfemOperation.Align}", (cmd, args) => { PostMsg(MSG.Align, ModuleName.Aligner2, args[0]); return true; });
  173. OP.Subscribe($"{ModuleName.Cooling1}.{EfemOperation.Align}", (cmd, args) => { PostMsg(MSG.Align, ModuleName.Cooling1, args[0]); return true; });
  174. OP.Subscribe($"{ModuleName.Cooling2}.{EfemOperation.Align}", (cmd, args) => { PostMsg(MSG.Align, ModuleName.Cooling2, args[0]); return true; });
  175. OP.Subscribe($"{ModuleName.Aligner1}.{EfemOperation.Lift}", (cmd, args) => { PostMsg(MSG.Lift, ModuleName.Aligner1); return true; });
  176. OP.Subscribe($"{ModuleName.Aligner2}.{EfemOperation.Lift}", (cmd, args) => { PostMsg(MSG.Lift, ModuleName.Aligner2); return true; });
  177. OP.Subscribe($"{ModuleName.Cooling1}.{EfemOperation.Lift}", (cmd, args) => { PostMsg(MSG.Lift, ModuleName.Cooling1); return true; });
  178. OP.Subscribe($"{ModuleName.Cooling2}.{EfemOperation.Lift}", (cmd, args) => { PostMsg(MSG.Lift, ModuleName.Cooling2); return true; });
  179. DATA.Subscribe($"{Name}.FsmState", () => ((STATE)fsm.State).ToString());
  180. DATA.Subscribe($"{Name}.FsmPrevState", () => ((STATE)fsm.PrevState).ToString());
  181. DATA.Subscribe($"{Name}.FsmLastMessage", GetFsmLastMessage);
  182. return true;
  183. }
  184. private void InitFsmMap()
  185. {
  186. fsm = new StateMachine<EfemEntity>("EFEM", (int)STATE.Unknown, 50);
  187. fsm.EnableRepeatedMsg(true);
  188. //AnyStateTransition(FSM_MSG.TIMER, fnMonitor, FSM_STATE.SAME);
  189. AnyStateTransition(MSG.TurnOffBuzzer, fnTurnOffBuzzer, FSM_STATE.SAME);
  190. AnyStateTransition(MSG.Recover, fnRecover, STATE.Idle);
  191. AnyStateTransition(MSG.Error, fnError, STATE.Error);
  192. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  193. AnyStateTransition(MSG.Abort, fnAbortRobot, STATE.Idle);
  194. AnyStateTransition(MSG.ToInit, fnToInit, STATE.Init);
  195. AnyStateTransition(MSG.CommReady, fnCommReady, STATE.Init);
  196. Transition(STATE.Init, FSM_MSG.TIMER, fnMonitor, STATE.Init);
  197. Transition(STATE.Idle, FSM_MSG.TIMER, fnMonitor, STATE.Idle);
  198. Transition(STATE.Error, FSM_MSG.TIMER, fnMonitor, STATE.Error);
  199. // Home
  200. Transition(STATE.Init, MSG.HomeAll, fnHomeAll, STATE.Initializing);
  201. Transition(STATE.Idle, MSG.HomeAll, fnHomeAll, STATE.Initializing);
  202. Transition(STATE.Error, MSG.HomeAll, fnHomeAll, STATE.Initializing);
  203. Transition(STATE.Initializing, FSM_MSG.TIMER, fnHomingTimeout, STATE.Idle);
  204. // Home Robot
  205. Transition(STATE.Idle, MSG.HomeRB, fnHomeRobot, STATE.InitingRB);
  206. Transition(STATE.InitingRB, FSM_MSG.TIMER, fnHomingTimeout, STATE.Idle);
  207. // Home Aligner
  208. Transition(STATE.Idle, MSG.HomeAL, fnHomeAligner, STATE.InitingAL);
  209. Transition(STATE.InitingAL, FSM_MSG.TIMER, fnHomingTimeout, STATE.Idle);
  210. // Pick wafer
  211. Transition(STATE.Idle, MSG.Pick, FnStartPick, STATE.Picking);
  212. Transition(STATE.Picking, FSM_MSG.TIMER, FnPickTimeout, STATE.Idle);
  213. Transition(STATE.Picking, MSG.Abort, FnAbortPick, STATE.Idle);
  214. // Place wafer
  215. Transition(STATE.Idle, MSG.Place, FnStartPlace, STATE.Placing);
  216. Transition(STATE.Placing, FSM_MSG.TIMER, FnPlaceTimeout, STATE.Idle);
  217. Transition(STATE.Placing, MSG.Abort, FnAbortPlace, STATE.Idle);
  218. // Swap wafer with LL sequence
  219. Transition(STATE.Idle, MSG.Swap, FnStartSwap, STATE.Swapping);
  220. Transition(STATE.Swapping, FSM_MSG.TIMER, FnSwapTimeout, STATE.Idle);
  221. Transition(STATE.Swapping, MSG.Abort, FnAbortSwap, STATE.Idle);
  222. // Goto
  223. Transition(STATE.Idle, MSG.Goto, fnGoto, STATE.Gotoing);
  224. Transition(STATE.Gotoing, MSG.ActionDone, fnActionDone, STATE.Idle);
  225. // Map
  226. Transition(STATE.Idle, MSG.Map, fnMap, STATE.Mapping);
  227. Transition(STATE.Mapping, MSG.ActionDone, fnActionDone, STATE.Idle);
  228. // Grip
  229. Transition(STATE.Idle, MSG.Grip, fnGrip, STATE.Gripping);
  230. Transition(STATE.Gripping, MSG.ActionDone, fnActionDone, STATE.Idle);
  231. // Ungrip
  232. Transition(STATE.Idle, MSG.Ungrip, fnUngrip, STATE.Ungripping);
  233. Transition(STATE.Ungripping, MSG.ActionDone, fnActionDone, STATE.Idle);
  234. // Aligner
  235. Transition(STATE.Idle, MSG.Lift, fnLift, STATE.Lifting);
  236. Transition(STATE.Lifting, MSG.LiftActionDone, fnActionDone, STATE.Idle);
  237. Transition(STATE.Idle, MSG.Align, fnAlign, STATE.Aligning);
  238. Transition(STATE.Aligning, MSG.ActionDone, fnActionDone, STATE.Idle);
  239. EnumLoop<STATE>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  240. EnumLoop<MSG>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  241. Running = true;
  242. }
  243. private bool fnCommReady(object[] param)
  244. {
  245. return true;
  246. }
  247. private bool fnHomeAll(object[] param)
  248. {
  249. return _homeRoutine.Start(ModuleName.EFEM) == RState.Running;
  250. }
  251. private bool fnHomingTimeout(object[] param)
  252. {
  253. RState ret = _homeRoutine.Monitor();
  254. if (ret == RState.Failed || ret == RState.Timeout)
  255. {
  256. PostMsg(MSG.Error);
  257. return false;
  258. }
  259. return ret == RState.End;
  260. }
  261. private bool fnHomeRobot(object[] param)
  262. {
  263. return _homeRoutine.Start(ModuleName.EfemRobot) == RState.Running;
  264. }
  265. private bool fnHomeAligner(object[] param)
  266. {
  267. // module
  268. ModuleName unit = ModuleName.EFEM;
  269. if (param[0] is string s1)
  270. unit = ModuleNameString.ToEnum(s1);
  271. else if (param[0] is ModuleName mod)
  272. unit = mod;
  273. else
  274. throw new ArgumentException("Argument error");
  275. return _homeRoutine.Start(unit) == RState.Running;
  276. }
  277. private bool fnActionDone(object[] param)
  278. {
  279. return false;
  280. }
  281. public bool CheckToPostMessage(int msg, params object[] args)
  282. {
  283. if (!fsm.FindTransition(fsm.State, msg))
  284. {
  285. EV.PostWarningLog(Name, $"{Name} is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
  286. return false;
  287. }
  288. Running = true;
  289. fsm.PostMsg(msg, args);
  290. return true;
  291. }
  292. private bool fnMonitor(object[] param)
  293. {
  294. _efem.Monitor();
  295. _debugRoutine();
  296. return true;
  297. }
  298. private bool fnOnline(object[] param)
  299. {
  300. bool bOnlineFlag = (bool)param[0];
  301. if (_efem is EfemBase efem)
  302. {
  303. efem.SetOnline(bOnlineFlag);
  304. }
  305. return true;
  306. }
  307. private string GetFsmLastMessage()
  308. {
  309. int msg = fsm.LastMsg;
  310. if (msg >= (int)MSG.HomeAll && msg <= (int)MSG.Error)
  311. return ((MSG)msg).ToString();
  312. if (msg == (int)FSM_MSG.TIMER)
  313. return "Timer";
  314. return msg.ToString();
  315. }
  316. private bool fnError(object[] param)
  317. {
  318. return true;
  319. }
  320. private bool fnToInit(object[] param)
  321. {
  322. return true;
  323. }
  324. private bool fnRecover(object[] param)
  325. {
  326. _efem.ClearError();
  327. //_efem.ExecuteAction();
  328. return true;
  329. }
  330. private bool fnAbortRobot(object[] param)
  331. {
  332. //_efem.ExecuteAction();
  333. return true;
  334. }
  335. private bool fnSetLED(object[] param)
  336. {
  337. LightType light = (LightType)param[0];
  338. LightStatus st = (LightStatus)param[1];
  339. _efem.SetLamp(light, st);
  340. return true;
  341. }
  342. private bool fnTurnOffBuzzer(object[] param)
  343. {
  344. return false;
  345. }
  346. private bool FnStartPick(object[] param)
  347. {
  348. return _pickRoutine.Start(param) == RState.Running;
  349. }
  350. private bool FnPickTimeout(object[] param)
  351. {
  352. RState ret = _pickRoutine.Monitor();
  353. if (ret == RState.Failed || ret == RState.Timeout)
  354. {
  355. PostMsg(MSG.Error);
  356. return false;
  357. }
  358. return ret == RState.End;
  359. }
  360. private bool FnAbortPick(object[] param)
  361. {
  362. _pickRoutine.Abort();
  363. return true;
  364. }
  365. private bool FnStartPlace(object[] param)
  366. {
  367. return _placeRoutine.Start(param) == RState.Running;
  368. }
  369. private bool FnPlaceTimeout(object[] param)
  370. {
  371. RState ret = _placeRoutine.Monitor();
  372. if (ret == RState.Failed || ret == RState.Timeout)
  373. {
  374. PostMsg(MSG.Error);
  375. return false;
  376. }
  377. return ret == RState.End;
  378. }
  379. private bool FnAbortPlace(object[] param)
  380. {
  381. _placeRoutine.Abort();
  382. return true;
  383. }
  384. private bool FnStartSwap(object[] param)
  385. {
  386. return _swapRoutine.Start(param) == RState.Running;
  387. }
  388. private bool FnSwapTimeout(object[] param)
  389. {
  390. RState ret = _swapRoutine.Monitor();
  391. if (ret == RState.Failed || ret == RState.Timeout)
  392. {
  393. PostMsg(MSG.Error);
  394. return false;
  395. }
  396. return ret == RState.End;
  397. }
  398. private bool FnAbortSwap(object[] param)
  399. {
  400. _swapRoutine.Abort();
  401. return true;
  402. }
  403. private bool fnGoto(object[] param)
  404. {
  405. // module
  406. ModuleName unit = ModuleName.EFEM;
  407. if (param[0] is string s1)
  408. unit = ModuleNameString.ToEnum(s1);
  409. else if (param[0] is ModuleName mod)
  410. unit = mod;
  411. else
  412. throw new ArgumentException("Argument error");
  413. _efem.Goto(unit, Hand.Blade1);
  414. return true;
  415. }
  416. private bool fnLift(object[] param)
  417. {
  418. // module
  419. ModuleName unit = ModuleName.EFEM;
  420. if (param[0] is string s1)
  421. unit = ModuleNameString.ToEnum(s1);
  422. else if (param[0] is ModuleName mod)
  423. unit = mod;
  424. else
  425. throw new ArgumentException("Argument error");
  426. bool isUp = true;
  427. if (param.Length > 1)
  428. {
  429. isUp = (bool) param[1];
  430. }
  431. if (isUp)
  432. {
  433. if (!_efem.SetPinUp(unit))
  434. return false;
  435. }
  436. else
  437. {
  438. if (!_efem.SetPinDown(unit))
  439. return false;
  440. }
  441. return true;
  442. }
  443. private bool fnAlign(object[] param)
  444. {
  445. // module
  446. ModuleName unit = ModuleName.EFEM;
  447. if (param[0] is string s1)
  448. unit = ModuleNameString.ToEnum(s1);
  449. else if (param[0] is ModuleName mod)
  450. unit = mod;
  451. else
  452. throw new ArgumentException("Argument error");
  453. // wafer size
  454. WaferSize ws1 = WaferSize.WS0;
  455. if (param[1] is string s2)
  456. {
  457. if (Enum.TryParse(s2, out WaferSize p5))
  458. ws1 = p5;
  459. }
  460. else if (param[1] is WaferSize p6)
  461. {
  462. ws1 = p6;
  463. }
  464. if (!_efem.Align(unit, 1000, ws1))
  465. return false;
  466. return true;
  467. }
  468. private bool fnMap(object[] param)
  469. {
  470. // module
  471. ModuleName unit = ModuleName.EFEM;
  472. if (param[0] is string s1)
  473. unit = ModuleNameString.ToEnum(s1);
  474. else if (param[0] is ModuleName mod)
  475. unit = mod;
  476. else
  477. throw new ArgumentException("Argument error");
  478. if (!_efem.Map(unit))
  479. return false;
  480. return true;
  481. }
  482. private bool fnGrip(object[] param)
  483. {
  484. Hand arm = (Hand)Enum.Parse(typeof(Hand), (string)param[0]);
  485. if (!_efem.Grip(arm, true))
  486. return false;
  487. return true;
  488. }
  489. private bool fnUngrip(object[] param)
  490. {
  491. Hand arm = (Hand)Enum.Parse(typeof(Hand), (string)param[0]);
  492. if (!_efem.Grip(arm, false))
  493. return false;
  494. return true;
  495. }
  496. public int Invoke(string function, params object[] args)
  497. {
  498. switch (function)
  499. {
  500. case "Home":
  501. CheckToPostMessage((int)MSG.HomeAll);
  502. return (int)MSG.HomeAll;
  503. }
  504. return (int)FSM_MSG.NONE;
  505. }
  506. public bool CheckAcked(int msg)
  507. {
  508. return fsm.CheckExecuted(msg);
  509. }
  510. internal void InvokeReset()
  511. {
  512. if (fsm.State == (int) STATE.Error)
  513. {
  514. PostMsg((int)MSG.Recover);
  515. }
  516. }
  517. public int InvokeAlign(string module, float time)
  518. {
  519. if (CheckToPostMessage((int)MSG.Align, module, time))
  520. return (int)MSG.Align;
  521. return (int)FSM_MSG.NONE;
  522. }
  523. public int InvokeLiftDown(string module)
  524. {
  525. if (CheckToPostMessage((int)MSG.Lift, module, false))
  526. return (int)MSG.Lift;
  527. return (int)FSM_MSG.NONE;
  528. }
  529. public int InvokePick(ModuleName source, int slot, Hand hand, WaferSize size)
  530. {
  531. if (CheckToPostMessage((int)MSG.Pick, source, slot, hand, size))
  532. return (int)MSG.Pick;
  533. return (int)FSM_MSG.NONE;
  534. }
  535. public int InvokeGoto(ModuleName source, int slot)
  536. {
  537. if (CheckToPostMessage((int)MSG.Goto, source, slot))
  538. return (int)MSG.Goto;
  539. return (int)FSM_MSG.NONE;
  540. }
  541. public int InvokePlace(ModuleName target, int slot, Hand hand, WaferSize size)
  542. {
  543. if (CheckToPostMessage((int)MSG.Place, target, slot, hand, size))
  544. return (int)MSG.Place;
  545. return (int)FSM_MSG.NONE;
  546. }
  547. public int InvokePickAndPlace(ModuleName targetModule, Hand pickHand, int pickSlot, Hand placeHand, int placeSlot, WaferSize size)
  548. {
  549. if (CheckToPostMessage((int)MSG.Swap, targetModule, pickSlot, pickHand, placeHand, placeSlot, size))
  550. return (int)MSG.Swap;
  551. return (int)FSM_MSG.NONE;
  552. }
  553. public int InvokeMap(string target )
  554. {
  555. if (CheckToPostMessage((int)MSG.Map, target ))
  556. return (int)MSG.Map;
  557. return (int)FSM_MSG.NONE;
  558. }
  559. public int InvokeFlip(Hand hand)
  560. {
  561. if (CheckToPostMessage((int)MSG.Flip, hand))
  562. return (int)MSG.Flip;
  563. return (int)FSM_MSG.NONE;
  564. }
  565. public bool IsPrepareTransferReady(ModuleName module, EnumTransferType type, int slot)
  566. {
  567. //if (type == EnumTransferType.Pick)
  568. //{
  569. // //需要补充:判断LP 放好了,而且已经map过。
  570. // return _efem[module].HasCassette && _efem[module].IsMapped;
  571. //}
  572. //else if (type == EnumTransferType.Place)
  573. //{
  574. // //需要补充:判断LP 放好了,而且已经map过。
  575. // return _efem[module].HasCassette && _efem[module].IsMapped;
  576. //}
  577. return false;
  578. }
  579. internal bool CheckReadyRunNewJob(ModuleName module)
  580. {
  581. //???
  582. return true;
  583. }
  584. internal bool CheckReadyTransfer(ModuleName module)
  585. {
  586. //return _efem[module].HasCassette && _efem[module].IsMapped;
  587. return true;
  588. }
  589. internal bool CheckPlaced(ModuleName module)
  590. {
  591. //return _efem[module].HasCassette;
  592. return true;
  593. }
  594. internal void NoteJobStart(ModuleName module)
  595. {
  596. //_efem[module].NoteJobStart();
  597. }
  598. internal void NoteJobComplete(ModuleName module)
  599. {
  600. //_efem[module].NoteJobComplete();
  601. }
  602. private void _debugRoutine()
  603. {
  604. int flag = 0;
  605. // Test Home routine
  606. if (flag == 1)
  607. {
  608. PostMsg(MSG.HomeAll);
  609. }
  610. else if (flag == 2)
  611. {
  612. WaferManager.Instance.CreateWafer(ModuleName.Aligner1, 0, WaferStatus.Normal);
  613. WaferManager.Instance.DeleteWafer(ModuleName.EfemRobot, 0);
  614. var item = new MoveItem(ModuleName.Aligner1, 0, ModuleName.EfemRobot, 0, Hand.Blade1);
  615. var items = new Queue<MoveItem>();
  616. items.Enqueue(item);
  617. PostMsg(MSG.Pick, items);
  618. }
  619. else if (flag == 3)
  620. {
  621. var item = new MoveItem( ModuleName.EfemRobot, 0, ModuleName.Aligner1, 0, Hand.Blade1);
  622. var items = new Queue<MoveItem>();
  623. items.Enqueue(item);
  624. PostMsg(MSG.Place, items);
  625. }
  626. else if (flag == 4)
  627. {
  628. WaferManager.Instance.CreateWafer(ModuleName.LLA, 0, WaferStatus.Normal);
  629. WaferManager.Instance.CreateWafer(ModuleName.LLA, 1, WaferStatus.Normal);
  630. WaferManager.Instance.DeleteWafer(ModuleName.LLA, 2);
  631. WaferManager.Instance.DeleteWafer(ModuleName.LLA, 3);
  632. WaferManager.Instance.CreateWafer(ModuleName.EfemRobot, 0, WaferStatus.Normal);
  633. WaferManager.Instance.CreateWafer(ModuleName.EfemRobot, 1, WaferStatus.Normal);
  634. var item = new MoveItem(ModuleName.EfemRobot, 0, ModuleName.LLA, 2, Hand.Blade1);
  635. var items = new Queue<MoveItem>();
  636. items.Enqueue(item);
  637. item = new MoveItem(ModuleName.EfemRobot, 1, ModuleName.LLA, 3, Hand.Blade2);
  638. items.Enqueue(item);
  639. item = new MoveItem(ModuleName.LLA, 0, ModuleName.EfemRobot, 0, Hand.Blade1);
  640. items.Enqueue(item);
  641. item = new MoveItem(ModuleName.LLA, 1, ModuleName.EfemRobot, 1, Hand.Blade2);
  642. items.Enqueue(item);
  643. PostMsg(MSG.Swap, items);
  644. }
  645. else if (flag == 5)
  646. {
  647. PostMsg(MSG.HomeRB);
  648. }
  649. else if (flag == 6)
  650. {
  651. PostMsg(MSG.HomeAL, ModuleName.Aligner1);
  652. }
  653. }
  654. }
  655. /// <summary>
  656. /// LP entity
  657. /// </summary>
  658. class LoadportEntity : Entity, IEntity
  659. {
  660. private enum STATE
  661. {
  662. Unknown,
  663. Idle, // 1
  664. Initializing, // 2
  665. Initialized, // 3
  666. Mapping, // 4
  667. Mapped, // 5
  668. }
  669. public enum MSG
  670. {
  671. Home, // 0
  672. Map, // 1
  673. ActionDone, // 2
  674. RecHwMsg, // 3
  675. Recover, // 4
  676. Abort, // 5
  677. Online, // 6
  678. Error // 7
  679. }
  680. private readonly EfemBase _efem;
  681. private ModuleName Module { get; }
  682. public LoadportEntity(ModuleName mod, EfemBase efem)
  683. {
  684. this.Module = mod;
  685. _efem = efem;
  686. InitFsmMap();
  687. OP.Subscribe($"{Module}.Home", (cmd, args) => { PostMsg(MSG.Home); return true; });
  688. OP.Subscribe($"{Module}.Abort", (cmd, args) => { PostMsg(MSG.Abort); return true; });
  689. //OP.Subscribe($"{Module}.Map", (cmd, args) => { PostMsg(MSG.Map); return true; });
  690. OP.Subscribe($"{Module}.Online", (cmd, args) => { PostMsg(MSG.Online); return true; });
  691. DATA.Subscribe($"{Module}.Status", () => ((STATE)fsm.State).ToString());
  692. DATA.Subscribe($"{Module}.FsmState", () => ((STATE)fsm.State).ToString());
  693. DATA.Subscribe($"{Module}.FsmPrevState", () => ((STATE)fsm.PrevState).ToString());
  694. DATA.Subscribe($"{Module}.FsmLastMessage", GetFsmLastMessage);
  695. }
  696. private string GetFsmLastMessage()
  697. {
  698. int msg = fsm.LastMsg;
  699. if (msg >= (int)MSG.Home && msg <= (int)MSG.Error)
  700. return ((MSG)msg).ToString();
  701. if (msg == (int)FSM_MSG.TIMER)
  702. return "Timer";
  703. return msg.ToString();
  704. }
  705. private void InitFsmMap()
  706. {
  707. fsm = new StateMachine<LoadportEntity>($"LPM_{Module}", (int)STATE.Idle, 500);
  708. AnyStateTransition(FSM_MSG.TIMER, fnMonitor, FSM_STATE.SAME);
  709. //AnyStateTransition(MSG.RecHwMsg, fnRecMsg, FSM_STATE.SAME);
  710. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  711. AnyStateTransition(MSG.Recover, fnRecover, STATE.Idle);
  712. AnyStateTransition(MSG.Abort, fnRecover, STATE.Idle);
  713. EnterExitTransition<STATE, FSM_MSG>(STATE.Initializing, fnEnterExecute, FSM_MSG.NONE, fnExitExecute);
  714. // Home
  715. AnyStateTransition(MSG.Home, fnHome, STATE.Initializing);
  716. Transition(STATE.Initializing, MSG.ActionDone, fnActionDone, STATE.Idle);
  717. }
  718. private bool fnOnline(object[] param)
  719. {
  720. bool online = (bool)param[0];
  721. //_efem.SetOnline(Module, online);
  722. return true;
  723. }
  724. private bool fnRecover(object[] param)
  725. {
  726. return true;
  727. }
  728. private bool fnMonitor(object[] param)
  729. {
  730. STATE curSt = (STATE)fsm.State;
  731. if (curSt == STATE.Initializing || curSt == STATE.Mapping)
  732. {
  733. if (fsm.ElapsedTime > 20 * 1000)
  734. {
  735. PostMsg(MSG.Recover);
  736. }
  737. }
  738. return true;
  739. }
  740. private bool fnEnterExecute(object[] param)
  741. {
  742. return true;
  743. }
  744. private bool fnExitExecute(object[] param)
  745. {
  746. return true;
  747. }
  748. private bool fnActionDone(object[] param)
  749. {
  750. return true;
  751. }
  752. private bool fnHome(object[] param)
  753. {
  754. _efem.Home(Module);
  755. return true;
  756. }
  757. public bool Check(int msg, out string reason, params object[] args)
  758. {
  759. throw new NotImplementedException();
  760. }
  761. }
  762. }