AlignerModule.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. using System;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.Fsm;
  6. using Aitex.Core.RT.OperationCenter;
  7. using Aitex.Core.RT.Routine;
  8. using Aitex.Core.Utilities;
  9. using Aitex.Sorter.Common;
  10. using MECF.Framework.Common.Equipment;
  11. using MECF.Framework.Common.Schedulers;
  12. using MECF.Framework.Common.SubstrateTrackings;
  13. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Efems.Rorzes;
  14. using MECF.Framework.RT.ModuleLibrary.AlignerModules;
  15. namespace JetEfemLib.Aligners
  16. {
  17. public class AlignerModule : AlignerModuleBase
  18. {
  19. private FutureAligner _alignerDevice;
  20. public enum STATE
  21. {
  22. NotInstall,
  23. Init,
  24. Idle,
  25. Homing,
  26. MapWaferPresence,
  27. Error,
  28. NotConnect,
  29. InTransfer,
  30. Aligning,
  31. Lifting,
  32. }
  33. public enum MSG
  34. {
  35. Home,
  36. Connected,
  37. Disconnected,
  38. MapWaferPresence,
  39. Align,
  40. Reset,
  41. Abort,
  42. Error,
  43. ToInit,
  44. InTransfer,
  45. TransferComplete,
  46. Lift
  47. }
  48. public event Action<string> OnEnterError;
  49. public override bool IsReady
  50. {
  51. get { return FsmState == (int)STATE.Idle && CheckAllMessageProcessed() && !_alignerDevice.IsBusy; }
  52. }
  53. public override bool IsError
  54. {
  55. get { return FsmState == (int)STATE.Error; }
  56. }
  57. private bool _isInit;
  58. public override bool IsInit
  59. {
  60. get { return _isInit; }
  61. }
  62. private AlignerHomeRoutine _home;
  63. private AlignerAlignRoutine _align;
  64. private AlignerLiftRoutine _lift;
  65. public AlignerModule(ModuleName module) : base(1)
  66. {
  67. Name = module.ToString();
  68. Module = module.ToString();
  69. IsOnline = true;
  70. }
  71. public override bool Initialize()
  72. {
  73. InitRoutine();
  74. InitDevice();
  75. InitFsm();
  76. InitOp();
  77. InitData();
  78. return base.Initialize();
  79. }
  80. private void InitRoutine()
  81. {
  82. _home = new AlignerHomeRoutine(this);
  83. _align = new AlignerAlignRoutine(this);
  84. _lift = new AlignerLiftRoutine(this);
  85. }
  86. public void InitDevice()
  87. {
  88. _alignerDevice = DEVICE.GetDevice<FutureAligner>($"{ModuleName.Aligner1}.{ModuleName.Aligner1}");
  89. }
  90. private void InitData()
  91. {
  92. DATA.Subscribe($"{Module}.Status", () => StringFsmStatus);
  93. DATA.Subscribe($"{Module}.IsOnline", () => IsOnline);
  94. DATA.Subscribe($"{Module}.WaferSize", () => WaferManager.Instance.GetWaferSize(ModuleHelper.Converter(Module), 0).ToString());
  95. }
  96. private void InitOp()
  97. {
  98. OP.Subscribe($"{Module}.Home", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Home));
  99. OP.Subscribe($"{Module}.Reset", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Reset));
  100. OP.Subscribe($"{Module}.Align", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Align,args));
  101. OP.Subscribe($"{Module}.Lift", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Lift, args));
  102. }
  103. private void InitFsm()
  104. {
  105. EnumLoop<STATE>.ForEach((item) =>
  106. {
  107. MapState((int)item, item.ToString());
  108. });
  109. EnumLoop<MSG>.ForEach((item) =>
  110. {
  111. MapMessage((int)item, item.ToString());
  112. });
  113. EnableFsm(50, IsInstalled ? STATE.Init : STATE.NotInstall);
  114. //Error
  115. AnyStateTransition(MSG.Error, FsmOnError, STATE.Error);
  116. Transition(STATE.Error, MSG.Reset, FsmReset, STATE.Idle);
  117. EnterExitTransition<STATE, FSM_MSG>(STATE.Error, FsmEnterError, FSM_MSG.NONE, FsmExitError);
  118. //Init
  119. Transition(STATE.Init, MSG.Home, FsmStartHome, STATE.Homing);
  120. Transition(STATE.Error, MSG.Home, FsmStartHome, STATE.Homing);
  121. Transition(STATE.Idle, MSG.Home, FsmStartHome, STATE.Homing);
  122. Transition(STATE.Homing, FSM_MSG.TIMER, FsmMonitorHomeTask, STATE.Idle);
  123. Transition(STATE.Homing, MSG.Error, null, STATE.Init);
  124. Transition(STATE.Homing, MSG.Abort, FsmAbortTask, STATE.Init);
  125. AnyStateTransition(MSG.ToInit, FsmToInit, STATE.Init);
  126. //idle
  127. EnterExitTransition<STATE, FSM_MSG>(STATE.Idle, FsmEnterIdle, FSM_MSG.NONE, FsmExitIdle);
  128. //align
  129. Transition(STATE.Idle, MSG.Align, FsmStartAlign, STATE.Aligning);
  130. Transition(STATE.Aligning, FSM_MSG.TIMER, FsmMonitorAlignTask, STATE.Idle);
  131. Transition(STATE.Aligning, MSG.Error, null, STATE.Init);
  132. Transition(STATE.Aligning, MSG.Abort, FsmAbortTask, STATE.Init);
  133. //lift
  134. Transition(STATE.Idle, MSG.Lift, FsmStartLift, STATE.Lifting);
  135. Transition(STATE.Lifting, FSM_MSG.TIMER, FsmMonitorLiftTask, STATE.Idle);
  136. Transition(STATE.Lifting, MSG.Error, null, STATE.Init);
  137. Transition(STATE.Lifting, MSG.Abort, FsmAbortTask, STATE.Init);
  138. }
  139. #region Service Functions
  140. public override bool Align(double angle)
  141. {
  142. return CheckToPostMessage((int)MSG.Align,angle);
  143. }
  144. public override bool Lift(bool isUp)
  145. {
  146. return CheckToPostMessage((int)MSG.Lift, isUp);
  147. }
  148. public override bool Home(out string reason)
  149. {
  150. if (!CheckToPostMessage((int)MSG.Home))
  151. {
  152. reason = $"Can not home in {StringFsmStatus} status";
  153. return false;
  154. }
  155. reason = string.Empty;
  156. return true;
  157. }
  158. public override void Reset()
  159. {
  160. if (IsError)
  161. {
  162. if (_alignerDevice.IsError)
  163. {
  164. _alignerDevice.Reset();
  165. }
  166. CheckToPostMessage((int)MSG.Reset);
  167. }
  168. }
  169. public override bool PrepareTransfer(ModuleName robot, Hand blade, int[] targetSlot, EnumTransferType transferType, out string reason)
  170. {
  171. reason = string.Empty;
  172. return true;
  173. }
  174. public override bool TransferHandoff(ModuleName robot, Hand blade, int[] targetSlot, EnumTransferType transferType, out string reason)
  175. {
  176. reason = string.Empty;
  177. return true;
  178. }
  179. public override bool PostTransfer(ModuleName robot, Hand blade, int[] targetSlot, EnumTransferType transferType, out string reason)
  180. {
  181. reason = string.Empty;
  182. return true;
  183. }
  184. public override bool CheckReadyForTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType,
  185. out string reason)
  186. {
  187. reason = string.Empty;
  188. if (transferType == EnumTransferType.Pick)
  189. {
  190. return IsReady&&WaferManager.Instance.CheckHasWafer(Module, targetSlot);
  191. }
  192. if (transferType == EnumTransferType.Place)
  193. {
  194. return IsReady&&WaferManager.Instance.CheckNoWafer(Module, targetSlot);
  195. }
  196. return false;
  197. }
  198. public override void NoteTransferStart(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType)
  199. {
  200. //CheckToPostMessage(MSG.InTransfer);
  201. }
  202. public override void NoteTransferStop(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType)
  203. {
  204. //if (FsmState == (int)STATE.InTransfer)
  205. // CheckToPostMessage(MSG.TransferComplete);
  206. }
  207. private bool FsmReset(object[] param)
  208. {
  209. if (!_isInit)
  210. {
  211. PostMsg(MSG.ToInit);
  212. return false;
  213. }
  214. if (_alignerDevice.IsError)
  215. {
  216. EV.PostWarningLog(Module, $"{Module} in error, home to recover");
  217. PostMsg(MSG.ToInit);
  218. return false;
  219. }
  220. return true;
  221. }
  222. private bool FsmOnError(object[] param)
  223. {
  224. if (FsmState == (int)STATE.Error)
  225. {
  226. return false;
  227. }
  228. AbortRoutine();
  229. if (FsmState == (int)STATE.Init)
  230. return false;
  231. return true;
  232. }
  233. private bool FsmExitIdle(object[] param)
  234. {
  235. return true;
  236. }
  237. private bool FsmEnterIdle(object[] param)
  238. {
  239. return true;
  240. }
  241. private bool FsmExitError(object[] param)
  242. {
  243. return true;
  244. }
  245. private bool FsmEnterError(object[] param)
  246. {
  247. if (OnEnterError != null)
  248. OnEnterError(Module);
  249. return true;
  250. }
  251. private bool FsmAbortTask(object[] param)
  252. {
  253. AbortRoutine();
  254. return true;
  255. }
  256. private bool FsmStartHome(object[] param)
  257. {
  258. RState ret = StartRoutine(_home);
  259. if (ret == RState.Failed || ret == RState.End)
  260. return false;
  261. _isInit = false;
  262. return ret == RState.Running;
  263. }
  264. private bool FsmMonitorHomeTask(object[] param)
  265. {
  266. RState ret = MonitorRoutine();
  267. if (ret == RState.Failed || ret == RState.Timeout)
  268. {
  269. PostMsg(MSG.Error);
  270. return false;
  271. }
  272. if (ret == RState.End)
  273. {
  274. _isInit = true;
  275. return true;
  276. }
  277. return false;
  278. }
  279. private bool FsmStartAlign(object[] param)
  280. {
  281. _align.Init(Convert.ToDouble(param[0]));
  282. RState ret = StartRoutine(_align);
  283. if (ret == RState.Failed || ret == RState.End)
  284. return false;
  285. _isInit = false;
  286. return ret == RState.Running;
  287. }
  288. private bool FsmStartLift(object[] param)
  289. {
  290. _lift.Init((bool)param[0]);
  291. RState ret = StartRoutine(_lift);
  292. if (ret == RState.Failed || ret == RState.End)
  293. return false;
  294. _isInit = false;
  295. return ret == RState.Running;
  296. }
  297. private bool FsmMonitorAlignTask(object[] param)
  298. {
  299. RState ret = MonitorRoutine();
  300. if (ret == RState.Failed)
  301. {
  302. PostMsg(MSG.Error);
  303. return false;
  304. }
  305. if (ret == RState.End)
  306. {
  307. _isInit = true;
  308. return true;
  309. }
  310. return false;
  311. }
  312. private bool FsmMonitorLiftTask(object[] param)
  313. {
  314. RState ret = MonitorRoutine();
  315. if (ret == RState.Failed)
  316. {
  317. PostMsg(MSG.Error);
  318. return false;
  319. }
  320. if (ret == RState.End)
  321. {
  322. _isInit = true;
  323. return true;
  324. }
  325. return false;
  326. }
  327. private bool FsmToInit(object[] param)
  328. {
  329. return true;
  330. }
  331. private bool FsmToIdle(object[] param)
  332. {
  333. return true;
  334. }
  335. #endregion
  336. }
  337. }