VceEntity.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Fsm;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.Utilities;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.Schedulers;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using MECF.Framework.RT.ModuleLibrary.VceModules;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Reflection;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using Venus_Core;
  19. using Venus_RT.Devices;
  20. using Venus_RT.Devices.VCE;
  21. using Venus_RT.Modules.PMs;
  22. using Venus_RT.Modules.TM;
  23. using Venus_RT.Modules.TM.VenusEntity;
  24. namespace Venus_RT.Modules.VCE
  25. {
  26. #region 状态和消息
  27. public enum VceMSG
  28. {
  29. Home,
  30. Error,
  31. DoorOpen,
  32. DoorClose,
  33. Map,
  34. ReadMap,
  35. Load,
  36. UnLoad,
  37. LoadPrepare,
  38. LoadWithoutSMIF,
  39. Reset,
  40. Goto,
  41. GotoLP,
  42. SafeLoad,
  43. SafeUnload,
  44. Pump,
  45. Vent,
  46. Abort,
  47. None
  48. }
  49. #endregion
  50. public class VceEntity : Entity, IEntity, IModuleEntity
  51. {
  52. private ModuleName _modulename;
  53. private readonly VceModuleBase _vce;
  54. public bool IsIdle => fsm.State == (int)VceSTATE.Idle;
  55. public bool IsInit => fsm.State == (int)VceSTATE.Init || fsm.State == (int)VceSTATE.Unknown;
  56. public bool IsBusy => !IsInit && !IsError && !IsIdle;
  57. public bool IsError => fsm.State == (int)VceSTATE.Error;
  58. public bool VCEOutDoorClosed => !_vce.OutDoorIsOpen;
  59. private int currentSlot;
  60. private int targetSlot;
  61. private LoadRoutine _loadRoutine;
  62. private LoadPrepareRoutine _prepareRoutine;
  63. private UnloadRoutine _unloadRoutine;
  64. private readonly SEMFPumpRoutine _pumpRoutine;
  65. private readonly SEMFVentRoutine _ventRoutine;
  66. public VceEntity(ModuleName moduleName)
  67. {
  68. currentSlot = 0;
  69. _modulename = moduleName;
  70. _vce = new HongHuVce(25, _modulename);
  71. _loadRoutine = new LoadRoutine(_modulename,_vce);
  72. _prepareRoutine = new LoadPrepareRoutine(_modulename,_vce);
  73. _unloadRoutine = new UnloadRoutine(_modulename, _vce);
  74. _pumpRoutine = new SEMFPumpRoutine(DEVICE.GetDevice<HongHuTM>("SETM"), _modulename);
  75. _ventRoutine = new SEMFVentRoutine(DEVICE.GetDevice<HongHuTM>("SETM"), _modulename);
  76. InitFsmMap();
  77. }
  78. protected override bool Init()
  79. {
  80. DATA.Subscribe($"{_modulename}.VCEOutDoorClosed", () => !VCEOutDoorClosed);
  81. DATA.Subscribe($"{_modulename}.CurrentSlot", () => currentSlot);
  82. DATA.Subscribe($"{_modulename}.FsmState", () => ((VceSTATE)fsm.State).ToString());
  83. //DATA.Subscribe($"{_modulename}.IsRunning", () => IsIdle);
  84. //DATA.Subscribe($"{_modulename}.IsRunning", () => IsIdle);
  85. OP.Subscribe($"{_modulename}.HOME", (cmd,args) => { PostMsg(VceMSG.Home);return true; });
  86. OP.Subscribe($"{_modulename}.DoorOpen", (cmd,args) => { PostMsg(VceMSG.DoorOpen);return true; });
  87. OP.Subscribe($"{_modulename}.DoorClose", (cmd,args) => { PostMsg(VceMSG.DoorClose);return true; });
  88. OP.Subscribe($"{_modulename}.Map", (cmd,args) => { PostMsg(VceMSG.Map);return true; });
  89. OP.Subscribe($"{_modulename}.ReadMap", (cmd,args) => { PostMsg(VceMSG.ReadMap);return true; });
  90. OP.Subscribe($"{_modulename}.Load", (cmd,args) => { PostMsg(VceMSG.Load);return true; });
  91. OP.Subscribe($"{_modulename}.UnLoad", (cmd,args) => { PostMsg(VceMSG.UnLoad);return true; });
  92. OP.Subscribe($"{_modulename}.Reset", (cmd,args) => { PostMsg(VceMSG.Reset);return true; });
  93. OP.Subscribe($"{_modulename}.Goto", (cmd,args) => { PostMsg(VceMSG.Goto, args[0]);return true; });
  94. OP.Subscribe($"{_modulename}.GotoLP", (cmd, args) => { PostMsg(VceMSG.GotoLP); return true; });
  95. OP.Subscribe($"{_modulename}.Abort", (cmd, args) => { PostMsg(VceMSG.Abort); return true; });
  96. OP.Subscribe($"{_modulename}.PumpDown", (cmd, args) => { PostMsg(VceMSG.Pump); return true; });
  97. OP.Subscribe($"{_modulename}.Vent", (cmd, args) => { PostMsg(VceMSG.Vent); return true; });
  98. OP.Subscribe($"{_modulename}.LoadPrepare", (cmd, args) => { PostMsg(VceMSG.LoadPrepare); return true; });
  99. OP.Subscribe($"{_modulename}.SafeLoad", (cmd, args) => { PostMsg(VceMSG.SafeLoad); return true; });
  100. OP.Subscribe($"{_modulename}.SafeUnload", (cmd, args) => { PostMsg(VceMSG.SafeUnload); return true; });
  101. return true;
  102. }
  103. /// <summary>
  104. /// 定义状态机的迁移表
  105. /// </summary>
  106. private void InitFsmMap()
  107. {
  108. fsm = new StateMachine<VceEntity>(_modulename.ToString(), (int)VceSTATE.Init, 50);
  109. fsm.EnableRepeatedMsg(true);
  110. AnyStateTransition(VceMSG.Error, fnError, VceSTATE.Error);
  111. AnyStateTransition(VceMSG.Abort, fnAbort, VceSTATE.Idle);
  112. AnyStateTransition(VceMSG.Home, fnStartHome, VceSTATE.Homing);
  113. //HOME init->homing idle->homing
  114. Transition(VceSTATE.Init, VceMSG.Home, fnStartHome, VceSTATE.Homing);
  115. Transition(VceSTATE.Idle, VceMSG.Home, fnStartHome, VceSTATE.Homing);
  116. Transition(VceSTATE.Error, VceMSG.Home, fnStartHome, VceSTATE.Homing);
  117. Transition(VceSTATE.Homing, FSM_MSG.TIMER, fnHomeTimeout, VceSTATE.Idle);
  118. //Open Door 开门
  119. Transition(VceSTATE.Idle, VceMSG.DoorOpen, fnStartOpenDoor, VceSTATE.DoorOpenning);
  120. Transition(VceSTATE.DoorOpenning, FSM_MSG.TIMER, fnOpenDoorTimeout, VceSTATE.Idle);
  121. //Close Door 关门
  122. Transition(VceSTATE.Idle, VceMSG.DoorClose, fnStartCloseDoor, VceSTATE.DoorClosing);
  123. Transition(VceSTATE.DoorClosing, FSM_MSG.TIMER, fnCloseDoorTimeout, VceSTATE.Idle);
  124. //Map 扫片
  125. Transition(VceSTATE.Idle, VceMSG.Map, fnStartMapping, VceSTATE.Mapping);
  126. Transition(VceSTATE.Mapping, FSM_MSG.TIMER, fnMappingTimeout, VceSTATE.Idle);
  127. //Load 取cassette
  128. Transition(VceSTATE.Idle, VceMSG.Load, fnStartLoading, VceSTATE.Loading);
  129. Transition(VceSTATE.Loading, FSM_MSG.TIMER, fnLoadingTimeout, VceSTATE.Idle);
  130. //UnLoad 放cassette
  131. Transition(VceSTATE.Idle, VceMSG.UnLoad, fnStartUnLoading, VceSTATE.UnLoading);
  132. Transition(VceSTATE.UnLoading, FSM_MSG.TIMER, fnUnLoadingTimeout, VceSTATE.Idle);
  133. //Goto 指定槽对准窗口
  134. Transition(VceSTATE.Idle, VceMSG.Goto, fnStartGoto, VceSTATE.Goting);
  135. Transition(VceSTATE.Goting, FSM_MSG.TIMER, fnGotingTimeout, VceSTATE.Idle);
  136. //ReadMap
  137. Transition(VceSTATE.Idle, VceMSG.ReadMap, fnStartReadingMap, VceSTATE.ReadingMap);
  138. Transition(VceSTATE.ReadingMap, FSM_MSG.TIMER, fnReadingMapTimeout, VceSTATE.Idle);
  139. //Load Prepare
  140. Transition(VceSTATE.Idle, VceMSG.LoadPrepare,fnStartLoadPrepare,VceSTATE.LoadPreparing) ;
  141. Transition(VceSTATE.LoadPreparing, FSM_MSG.TIMER, fnLoadingPrepareTimeout,VceSTATE.Idle) ;
  142. //Safe Load
  143. Transition(VceSTATE.Idle,VceMSG.SafeLoad,fnStartSafeLoad,VceSTATE.SafeLoading) ;
  144. Transition(VceSTATE.SafeLoading, FSM_MSG.TIMER,fnSafeLoadTimeout,VceSTATE.Idle);
  145. //Safe UnLoad
  146. Transition(VceSTATE.Idle, VceMSG.SafeUnload, fnStartSafeUnLoad, VceSTATE.SafeUnloading);
  147. Transition(VceSTATE.SafeUnloading, FSM_MSG.TIMER, fnSafeUnLoadTimeout, VceSTATE.Idle);
  148. //Goto LP
  149. Transition(VceSTATE.Idle, VceMSG.GotoLP, fnStartGotoLP, VceSTATE.GotingLP);
  150. Transition(VceSTATE.GotingLP, FSM_MSG.TIMER, fnGotoLPTimeout, VceSTATE.Idle);
  151. //Pump down
  152. //Pump
  153. Transition(VceSTATE.Idle, VceMSG.Pump, fnStartPump, VceSTATE.Pumping);
  154. Transition(VceSTATE.Pumping, FSM_MSG.TIMER, fnPumpTimeout, VceSTATE.Idle);
  155. Transition(VceSTATE.Pumping, VceMSG.Abort, fnAbortPump, VceSTATE.Idle);
  156. //Vent
  157. Transition(VceSTATE.Idle, VceMSG.Vent, fnStartVent, VceSTATE.Venting);
  158. Transition(VceSTATE.Venting, FSM_MSG.TIMER, fnVentTimeout, VceSTATE.Idle);
  159. Transition(VceSTATE.Venting, VceMSG.Abort, fnAbortVent, VceSTATE.Idle);
  160. EnumLoop<VceSTATE>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  161. EnumLoop<VceMSG>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  162. Running = true;
  163. }
  164. private bool fnAbortVent(object[] param)
  165. {
  166. _ventRoutine.Abort();
  167. return true;
  168. }
  169. private bool fnVentTimeout(object[] param)
  170. {
  171. RState ret = _ventRoutine.Monitor();
  172. if (ret == RState.Timeout || ret == RState.Failed)
  173. {
  174. PostMsg(VceMSG.Error);
  175. return false;
  176. }
  177. return ret == RState.End;
  178. }
  179. private bool fnStartVent(object[] param)
  180. {
  181. return _ventRoutine.Start(param) == RState.Running;
  182. }
  183. private bool fnAbortPump(object[] param)
  184. {
  185. _pumpRoutine.Abort();
  186. return true;
  187. }
  188. private bool fnPumpTimeout(object[] param)
  189. {
  190. RState ret = _pumpRoutine.Monitor();
  191. if (ret == RState.Timeout || ret == RState.Failed)
  192. {
  193. PostMsg(VceMSG.Error);
  194. return false;
  195. }
  196. return ret == RState.End;
  197. }
  198. private bool fnStartPump(object[] param)
  199. {
  200. return _pumpRoutine.Start(param) == RState.Running;
  201. }
  202. private bool fnGotoLPTimeout(object[] param)
  203. {
  204. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  205. {
  206. PostMsg(VceMSG.Error);
  207. return false;
  208. }
  209. if (_vce.Status == RState.End)
  210. {
  211. currentSlot = targetSlot;
  212. }
  213. return _vce.Status == RState.End;
  214. }
  215. private bool fnStartGotoLP(object[] param)
  216. {
  217. if (_vce.GotoLP())
  218. {
  219. targetSlot = -1;
  220. return true;
  221. }
  222. else
  223. return false;
  224. }
  225. private bool fnSafeUnLoadTimeout(object[] param)
  226. {
  227. RState ret = _unloadRoutine.Monitor();
  228. if (ret == RState.Timeout || ret == RState.Failed)
  229. {
  230. PostMsg(VceMSG.Error);
  231. return false;
  232. }
  233. return ret == RState.End;
  234. }
  235. private bool fnStartSafeUnLoad(object[] param)
  236. {
  237. return _unloadRoutine.Start(param) == RState.Running;
  238. }
  239. private bool fnSafeLoadTimeout(object[] param)
  240. {
  241. RState ret = _loadRoutine.Monitor();
  242. if (ret == RState.Timeout || ret == RState.Failed)
  243. {
  244. PostMsg(VceMSG.Error);
  245. return false;
  246. }
  247. return ret == RState.End;
  248. }
  249. private bool fnStartSafeLoad(object[] param)
  250. {
  251. return _loadRoutine.Start(param) == RState.Running;
  252. }
  253. private bool fnLoadingPrepareTimeout(object[] param)
  254. {
  255. RState ret = _prepareRoutine.Monitor();
  256. if (ret == RState.Timeout || ret == RState.Failed)
  257. {
  258. PostMsg(VceMSG.Error);
  259. return false;
  260. }
  261. return ret == RState.End;
  262. }
  263. private bool fnStartLoadPrepare(object[] param)
  264. {
  265. return _prepareRoutine.Start(param) == RState.Running;
  266. }
  267. private bool fnReadingMapTimeout(object[] param)
  268. {
  269. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  270. {
  271. PostMsg(VceMSG.Error);
  272. return false;
  273. }
  274. return _vce.Status == RState.End;
  275. }
  276. private bool fnStartReadingMap(object[] param)
  277. {
  278. return _vce.ReadMap();
  279. }
  280. //急停
  281. private bool fnAbort(object[] param)
  282. {
  283. return true;
  284. }
  285. //升降到槽位
  286. private bool fnStartGoto(object[] param)
  287. {
  288. if (_vce.Goto(Convert.ToInt32(param[0])))
  289. {
  290. targetSlot = Convert.ToInt32(param[0]);
  291. return true;
  292. }
  293. else
  294. return false;
  295. }
  296. private bool fnGotingTimeout(object[] param)
  297. {
  298. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  299. {
  300. PostMsg(VceMSG.Error);
  301. return false;
  302. }
  303. if(_vce.Status == RState.End)
  304. currentSlot = targetSlot;
  305. return _vce.Status == RState.End;
  306. }
  307. private bool fnError(object[] param)
  308. {
  309. return true;
  310. }
  311. private bool fnStartHome(object[] param)
  312. {
  313. return _vce.HomeALL();
  314. }
  315. private bool fnHomeTimeout(object[] param)
  316. {
  317. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  318. {
  319. PostMsg(VceMSG.Error);
  320. return false;
  321. }
  322. return _vce.Status == RState.End;
  323. }
  324. private bool fnStartOpenDoor(object[] param)
  325. {
  326. return _vce.OpenDoor();
  327. }
  328. private bool fnOpenDoorTimeout(object[] param)
  329. {
  330. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  331. {
  332. PostMsg(VceMSG.Error);
  333. return false;
  334. }
  335. return _vce.Status == RState.End;
  336. }
  337. private bool fnStartCloseDoor(object[] param)
  338. {
  339. return _vce.CloseDoor();
  340. }
  341. private bool fnCloseDoorTimeout(object[] param)
  342. {
  343. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  344. {
  345. PostMsg(VceMSG.Error);
  346. return false;
  347. }
  348. return _vce.Status == RState.End;
  349. }
  350. private bool fnStartMapping(object[] param)
  351. {
  352. return _vce.Map();
  353. }
  354. private bool fnMappingTimeout(object[] param)
  355. {
  356. if(_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  357. {
  358. PostMsg(VceMSG.Error);
  359. return false;
  360. }
  361. return _vce.Status == RState.End;
  362. }
  363. private bool fnStartLoading(object[] param)
  364. {
  365. return _vce.Load();
  366. }
  367. private bool fnLoadingTimeout(object[] param)
  368. {
  369. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  370. {
  371. PostMsg(VceMSG.Error);
  372. return false;
  373. }
  374. return _vce.Status == RState.End;
  375. }
  376. private bool fnStartUnLoading(object[] param)
  377. {
  378. return _vce.UnLoad();
  379. }
  380. private bool fnUnLoadingTimeout(object[] param)
  381. {
  382. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  383. {
  384. PostMsg(VceMSG.Error);
  385. return false;
  386. }
  387. return _vce.Status == RState.End;
  388. }
  389. public bool Check(int msg, out string reason, params object[] args)
  390. {
  391. reason = "";
  392. return true;
  393. }
  394. public int Invoke(string function, params object[] args)
  395. {
  396. switch (function)
  397. {
  398. case "Home":
  399. CheckToPostMessage((int)VceMSG.Home);
  400. return (int)VceMSG.Home;
  401. }
  402. return (int)VceMSG.None;
  403. }
  404. public bool CheckToPostMessage(int msg, params object[] args)
  405. {
  406. if (!fsm.FindTransition(fsm.State, msg))
  407. {
  408. LOG.Write(eEvent.WARN_FSM_WARN, _modulename, $"{_modulename} is in {(VceSTATE)fsm.State} state,can not do {(VceMSG)msg}");
  409. return false;
  410. }
  411. Running = true;
  412. fsm.PostMsg(msg, args);
  413. return true;
  414. }
  415. public bool CheckAcked(int msg)
  416. {
  417. return fsm.CheckExecuted(msg);
  418. }
  419. public bool IsPrepareTransferReady(ModuleName module, EnumTransferType transferType, int slot)
  420. {
  421. return false;
  422. }
  423. }
  424. }