LoadPortModule.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Fsm;
  3. using Aitex.Core.RT.OperationCenter;
  4. using Aitex.Core.RT.Routine;
  5. using Aitex.Core.Utilities;
  6. using Aitex.Core.Util;
  7. using Aitex.Sorter.Common;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.Common.Schedulers;
  10. using MECF.Framework.RT.ModuleLibrary.LPModules;
  11. using System;
  12. using Aitex.Core.RT.SCCore;
  13. using Venus_RT.Devices;
  14. using Venus_RT.Devices.EFEM;
  15. using Venus_Core;
  16. namespace Venus_RT.Modules.LPs
  17. {
  18. /// <summary>
  19. /// LP entity
  20. /// </summary>
  21. sealed class LoadPortModule : LoadPortModuleBase
  22. {
  23. public event Action<string> OnEnterError;
  24. private enum STATE
  25. {
  26. Unknown,
  27. Idle, // 1
  28. Init,
  29. Error,
  30. Homing, // 2
  31. Mapping, // 4
  32. Loading,
  33. ReadingCarrierId,
  34. Unloading,
  35. Docking,
  36. Undocking,
  37. Clamping,
  38. Unclamping,
  39. WritingCarrierId,
  40. ReadingTagData,
  41. WritingTagData,
  42. }
  43. public enum MSG
  44. {
  45. Home, // 0
  46. Map, // 1
  47. ActionDone, // 2
  48. Abort, // 5
  49. Online, // 6
  50. Error, // 7
  51. Reset,
  52. ReadCarrierId,
  53. WriteCarrierID,
  54. Load,
  55. Unload,
  56. Dock,
  57. Undock,
  58. Clamp,
  59. Unclamp,
  60. ToInit,
  61. ToIdle,
  62. ReadTagData,
  63. WriteTagData,
  64. CloseDoor,
  65. OpenDoor,
  66. }
  67. private readonly EfemBase _efem;
  68. private Loadport _lpDevice;
  69. public Loadport LPDevice
  70. {
  71. get
  72. {
  73. return _lpDevice;
  74. }
  75. }
  76. public override bool IsReady
  77. {
  78. get { return FsmState == (int)STATE.Idle && CheckAllMessageProcessed(); }
  79. }
  80. public override bool IsError
  81. {
  82. get { return FsmState == (int)STATE.Error; }
  83. }
  84. public override bool IsInit
  85. {
  86. get { return FsmState == (int)STATE.Init; }
  87. }
  88. public bool IsRobotIdle
  89. {
  90. get { return Singleton<RouteManager>.Instance.EFEM.RobotStatus == RState.End; }
  91. }
  92. private LoadPortHomeRoutine _home;
  93. //private LoadPortCloseDoorRoutine _closeDoor;
  94. private LoadPortClampRoutine _clamp;
  95. private LoadPortReadCarrierIdRoutine _readCarrierId;
  96. private LoadPortWriteCarrierIdRoutine _writeCarrierId;
  97. private LoadPortReadTagDataRoutine _readTag;
  98. private LoadPortWriteTagDataRoutine _writeTag;
  99. private LoadPortUnclampRoutine _unclamp;
  100. private LoadPortDockRoutine _dock;
  101. private LoadPortUnDockRoutine _undock;
  102. private LoadPortLoadRoutine _load;
  103. private LoadPortUnloadRoutine _unload;
  104. private bool _isInit;
  105. public LoadPortModule(ModuleName module, EfemBase efem) : base(SC.GetValue<int>("EFEM.LoadPort.SlotNumber"))
  106. {
  107. Name = module.ToString();
  108. Module = module.ToString();
  109. _efem = efem;
  110. InitFsmMap();
  111. OP.Subscribe($"{Module}.ReadCarrierId", (cmd, args) => { PostMsg(MSG.ReadCarrierId); return true; });
  112. OP.Subscribe($"{Module}.WriteCarrierID", (cmd, args) => { PostMsg(MSG.WriteCarrierID, args[0]); return true; });
  113. OP.Subscribe($"{Module}.ReadTagData", (cmd, args) => { PostMsg(MSG.ReadTagData); return true; });
  114. OP.Subscribe($"{Module}.WriteTagData", (cmd, args) => { PostMsg(MSG.WriteTagData, args[0]); return true; });
  115. OP.Subscribe($"{Module}.Load", (cmd, args) => { PostMsg(MSG.Load); return true; });
  116. OP.Subscribe($"{Module}.Unload", (cmd, args) => { PostMsg(MSG.Unload); return true; });
  117. OP.Subscribe($"{Module}.Clamp", (cmd, args) => { PostMsg(MSG.Clamp); return true; });
  118. OP.Subscribe($"{Module}.Unclamp", (cmd, args) => { PostMsg(MSG.Unclamp); return true; });
  119. OP.Subscribe($"{Module}.Dock", (cmd, args) => { PostMsg(MSG.Dock); return true; });
  120. OP.Subscribe($"{Module}.Undock", (cmd, args) => { PostMsg(MSG.Undock); return true; });
  121. OP.Subscribe($"{Module}.Home", (cmd, args) => { PostMsg(MSG.Home); return true; });
  122. OP.Subscribe($"{Module}.Abort", (cmd, args) => { PostMsg(MSG.Abort); return true; });
  123. OP.Subscribe($"{Module}.Online", (cmd, args) => { PostMsg(MSG.Online); return true; });
  124. OP.Subscribe($"{Name}.OpenDoor", (string cmd, object[] args) =>{return CheckToPostMessage((int)MSG.OpenDoor);});
  125. OP.Subscribe($"{Name}.CloseDoor", (string cmd, object[] args) =>{return CheckToPostMessage((int)MSG.CloseDoor);});
  126. OP.Subscribe($"{Module}.ReSet", (cmd, args) => { PostMsg(MSG.Reset); return true; });
  127. DATA.Subscribe($"{Module}.Status", () => ((STATE)FsmState).ToString(), Aitex.Core.Util.SubscriptionAttribute.FLAG.IgnoreSaveDB);
  128. DATA.Subscribe($"{Module}.FsmState", () => ((STATE)FsmState).ToString(), Aitex.Core.Util.SubscriptionAttribute.FLAG.IgnoreSaveDB);
  129. DATA.Subscribe($"{Module}.FsmPrevState", () => ((STATE)FsmPreviousState).ToString(), Aitex.Core.Util.SubscriptionAttribute.FLAG.IgnoreSaveDB);
  130. DATA.Subscribe($"{Module}.FsmLastMessage", GetFsmLastMessage, Aitex.Core.Util.SubscriptionAttribute.FLAG.IgnoreSaveDB);
  131. _lpDevice = efem[module] as Loadport;
  132. InitRoutine();
  133. }
  134. private void InitRoutine()
  135. {
  136. _home = new LoadPortHomeRoutine(this);
  137. //_closeDoor = new LoadPortCloseDoorRoutine(this);
  138. _clamp = new LoadPortClampRoutine(this);
  139. _dock = new LoadPortDockRoutine(this);
  140. //_map = new LoadPortMapRoutine(this);
  141. //_openDoor = new LoadPortOpenDoorRoutine(this);
  142. _readCarrierId = new LoadPortReadCarrierIdRoutine(this);
  143. _writeCarrierId = new LoadPortWriteCarrierIdRoutine(this);
  144. _readTag = new LoadPortReadTagDataRoutine(this);
  145. _writeTag = new LoadPortWriteTagDataRoutine(this);
  146. _unclamp = new LoadPortUnclampRoutine(this);
  147. _undock = new LoadPortUnDockRoutine(this);
  148. //_MapDT = new LoadPortGetMapInfoRoutine(this);
  149. _load = new LoadPortLoadRoutine(this);
  150. _unload = new LoadPortUnloadRoutine(this);
  151. }
  152. private string GetFsmLastMessage()
  153. {
  154. int msg = FsmLastMessage;
  155. if (msg >= (int)MSG.Home && msg <= (int)MSG.Error)
  156. return ((MSG)msg).ToString();
  157. if (msg == (int)FSM_MSG.TIMER)
  158. return "Timer";
  159. return msg.ToString();
  160. }
  161. private void InitFsmMap()
  162. {
  163. EnableFsm(50, STATE.Idle);
  164. //online
  165. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  166. //Error
  167. AnyStateTransition(MSG.Error, FsmOnError, STATE.Error);
  168. Transition(STATE.Error, MSG.Reset, FsmReset, STATE.Idle);
  169. EnterExitTransition<STATE, FSM_MSG>(STATE.Error, FsmEnterError, FSM_MSG.NONE, FsmExitError);
  170. //Init
  171. Transition(STATE.Init, MSG.Home, FsmStartHome, STATE.Homing);
  172. Transition(STATE.Error, MSG.Home, FsmStartHome, STATE.Homing);
  173. Transition(STATE.Idle, MSG.Home, FsmStartHome, STATE.Homing);
  174. Transition(STATE.Homing, FSM_MSG.TIMER, FsmMonitorHomeTask, STATE.Idle);
  175. Transition(STATE.Homing, MSG.Error, null, STATE.Init);
  176. Transition(STATE.Homing, MSG.Abort, FsmAbortTask, STATE.Init);
  177. //load
  178. Transition(STATE.Idle, MSG.Load, FsmStartLoad, STATE.Loading);
  179. Transition(STATE.Loading, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  180. Transition(STATE.Loading, MSG.Abort, FsmAbortTask, STATE.Idle);
  181. //unload
  182. Transition(STATE.Idle, MSG.Unload, FsmStartUnload, STATE.Unloading);
  183. Transition(STATE.Unloading, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  184. Transition(STATE.Unloading, MSG.Abort, FsmAbortTask, STATE.Idle);
  185. //read carrier id
  186. Transition(STATE.Idle, MSG.ReadCarrierId, FsmStartReadCarrierId, STATE.ReadingCarrierId);
  187. Transition(STATE.ReadingCarrierId, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  188. Transition(STATE.ReadingCarrierId, MSG.Abort, FsmAbortTask, STATE.Idle);
  189. //clamp
  190. Transition(STATE.Idle, MSG.Clamp, FsmStartClamp, STATE.Clamping);
  191. Transition(STATE.Clamping, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  192. Transition(STATE.Clamping, MSG.Abort, FsmAbortTask, STATE.Idle);
  193. //unclamp
  194. Transition(STATE.Idle, MSG.Unclamp, FsmStartUnclamp, STATE.Unclamping);
  195. Transition(STATE.Unclamping, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  196. Transition(STATE.Unclamping, MSG.Abort, FsmAbortTask, STATE.Idle);
  197. //dock
  198. Transition(STATE.Idle, MSG.Dock, FsmStartDock, STATE.Docking);
  199. Transition(STATE.Docking, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  200. Transition(STATE.Docking, MSG.Abort, FsmAbortTask, STATE.Idle);
  201. //undock
  202. Transition(STATE.Idle, MSG.Undock, FsmStartUndock, STATE.Undocking);
  203. Transition(STATE.Undocking, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  204. Transition(STATE.Undocking, MSG.Abort, FsmAbortTask, STATE.Idle);
  205. //write carrier id
  206. Transition(STATE.Idle, MSG.WriteCarrierID, FsmStartWriteCarrierId, STATE.WritingCarrierId);
  207. Transition(STATE.WritingCarrierId, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  208. Transition(STATE.WritingCarrierId, MSG.Abort, FsmAbortTask, STATE.Idle);
  209. //read tag data
  210. Transition(STATE.Idle, MSG.ReadTagData, FsmStartReadTagData, STATE.ReadingTagData);
  211. Transition(STATE.ReadingTagData, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  212. Transition(STATE.ReadingTagData, MSG.Abort, FsmAbortTask, STATE.Idle);
  213. //write tag data
  214. Transition(STATE.Idle, MSG.WriteTagData, FsmStartWriteTagData, STATE.WritingTagData);
  215. Transition(STATE.WritingTagData, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  216. Transition(STATE.WritingTagData, MSG.Abort, FsmAbortTask, STATE.Idle);
  217. EnumLoop<STATE>.ForEach((item) =>
  218. {
  219. MapState((int)item, item.ToString());
  220. });
  221. EnumLoop<MSG>.ForEach((item) =>
  222. {
  223. MapMessage((int)item, item.ToString());
  224. });
  225. }
  226. private bool FsmAbortTask(object[] param)
  227. {
  228. return true;
  229. }
  230. private bool FsmReset(object[] param)
  231. {
  232. if (!_isInit)
  233. {
  234. PostMsg(MSG.ToInit);
  235. return false;
  236. }
  237. return true;
  238. }
  239. private bool FsmOnError(object[] param)
  240. {
  241. if (FsmState == (int)STATE.Error)
  242. {
  243. return false;
  244. }
  245. AbortRoutine();
  246. if (FsmState == (int)STATE.Init)
  247. return false;
  248. return true;
  249. }
  250. private bool FsmExitError(object[] param)
  251. {
  252. return true;
  253. }
  254. private bool FsmEnterError(object[] param)
  255. {
  256. if (OnEnterError != null)
  257. OnEnterError(Module);
  258. return true;
  259. }
  260. private bool FsmMonitorTask(object[] param)
  261. {
  262. RState ret = MonitorRoutine();
  263. if (ret == RState.Failed || ret == RState.Timeout)
  264. {
  265. PostMsg(MSG.Error);
  266. return false;
  267. }
  268. return ret == RState.End;
  269. }
  270. private bool FsmStartHome(object[] param)
  271. {
  272. RState ret = StartRoutine(_home);
  273. if (ret == RState.Failed || ret == RState.End)
  274. return false;
  275. _isInit = false;
  276. return ret == RState.Running;
  277. }
  278. private bool FsmMonitorHomeTask(object[] param)
  279. {
  280. RState ret = MonitorRoutine();
  281. if (ret == RState.Failed)
  282. {
  283. PostMsg(MSG.Error);
  284. return false;
  285. }
  286. if (ret == RState.End)
  287. {
  288. _isInit = true;
  289. return true;
  290. }
  291. return false;
  292. }
  293. private bool FsmStartUndock(object[] param)
  294. {
  295. RState ret = StartRoutine(_undock);
  296. if (ret == RState.Failed || ret == RState.End)
  297. {
  298. return false;
  299. }
  300. return ret == RState.Running;
  301. }
  302. private bool FsmStartDock(object[] param)
  303. {
  304. RState ret = StartRoutine(_dock);
  305. if (ret == RState.Failed || ret == RState.End)
  306. {
  307. return false;
  308. }
  309. return ret == RState.Running;
  310. }
  311. private bool FsmStartUnclamp(object[] param)
  312. {
  313. RState ret = StartRoutine(_unclamp);
  314. if (ret == RState.Failed || ret == RState.End)
  315. return false;
  316. return ret == RState.Running;
  317. }
  318. private bool FsmStartClamp(object[] param)
  319. {
  320. _clamp.IsUnloadClamp = false;
  321. RState ret = StartRoutine(_clamp);
  322. if (ret == RState.Failed || ret == RState.End)
  323. return false;
  324. return ret == RState.Running;
  325. }
  326. private bool FsmStartReadCarrierId(object[] param)
  327. {
  328. RState ret = StartRoutine(_readCarrierId);
  329. if (ret == RState.Failed || ret == RState.End)
  330. return false;
  331. return ret == RState.Running;
  332. }
  333. private bool FsmStartWriteCarrierId(object[] param)
  334. {
  335. _writeCarrierId.CarrierIdSetPoint = (string) param[0];
  336. RState ret = StartRoutine(_writeCarrierId);
  337. if (ret == RState.Failed || ret == RState.End)
  338. return false;
  339. return ret == RState.Running;
  340. }
  341. private bool FsmStartReadTagData(object[] param)
  342. {
  343. RState ret = StartRoutine(_readTag);
  344. if (ret == RState.Failed || ret == RState.End)
  345. return false;
  346. return ret == RState.Running;
  347. }
  348. private bool FsmStartWriteTagData(object[] param)
  349. {
  350. _writeTag.TagDataSetPoint = (string)param[0];
  351. RState ret = StartRoutine(_writeTag);
  352. if (ret == RState.Failed || ret == RState.End)
  353. return false;
  354. return ret == RState.Running;
  355. }
  356. private bool FsmStartUnload(object[] param)
  357. {
  358. RState ret = StartRoutine(_unload);
  359. if (ret == RState.Failed || ret == RState.End)
  360. return false;
  361. if(ret == RState.Running)
  362. {
  363. _lpDevice.UnloadStart();
  364. }
  365. return ret == RState.Running;
  366. }
  367. private bool FsmStartLoad(object[] param)
  368. {
  369. RState ret = StartRoutine(_load);
  370. if (ret == RState.Failed || ret == RState.End)
  371. return false;
  372. if (ret == RState.Running)
  373. {
  374. _lpDevice.LoadStart();
  375. }
  376. return ret == RState.Running;
  377. }
  378. private bool fnOnline(object[] param)
  379. {
  380. bool online = (bool)param[0];
  381. //_efem.SetOnline(ModuleHelper.Converter(Module), online);
  382. return true;
  383. }
  384. public bool IsPrepareTransferReady(ModuleName module, EnumTransferType type, int slot)
  385. {
  386. if (type == EnumTransferType.Pick)
  387. {
  388. //需要补充:判断LP 放好了,而且已经map过。
  389. //return _efem[module].HasCassette && _efem[module].IsMapped && _efem[module].IsThicknessValid;
  390. }
  391. else if (type == EnumTransferType.Place)
  392. {
  393. //需要补充:判断LP 放好了,而且已经map过。
  394. //return _efem[module].HasCassette && _efem[module].IsMapped && _efem[module].IsThicknessValid;
  395. }
  396. return false;
  397. }
  398. internal bool CheckReadyRunNewJob(ModuleName module)
  399. {
  400. return _efem[module].HasCassette && _efem[module].IsMapped && _efem[module].IsThicknessValid;
  401. }
  402. internal bool CheckReadyTransfer(ModuleName module)
  403. {
  404. return _efem[module].HasCassette && _efem[module].IsMapped && _efem[module].IsThicknessValid;
  405. }
  406. public override bool Home(out string reason)
  407. {
  408. throw new NotImplementedException();
  409. }
  410. public override void NoteJobStart()
  411. {
  412. throw new NotImplementedException();
  413. }
  414. public override void NoteJobComplete()
  415. {
  416. throw new NotImplementedException();
  417. }
  418. public override bool PrepareTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
  419. {
  420. throw new NotImplementedException();
  421. }
  422. public override bool TransferHandoff(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
  423. {
  424. throw new NotImplementedException();
  425. }
  426. public override bool PostTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
  427. {
  428. throw new NotImplementedException();
  429. }
  430. public override bool CheckReadyForTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType,
  431. out string reason)
  432. {
  433. throw new NotImplementedException();
  434. }
  435. public override void NoteTransferStart(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType)
  436. {
  437. throw new NotImplementedException();
  438. }
  439. public override void NoteTransferStop(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType)
  440. {
  441. throw new NotImplementedException();
  442. }
  443. public override bool CheckReadyForMap(ModuleName robot, Hand blade, out string reason)
  444. {
  445. throw new NotImplementedException();
  446. }
  447. }
  448. }