EfemModule.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  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 FutureEfemLib.Aligners;
  11. using FutureEfemLib.LPs;
  12. using FutureEfemLib.SignalTowers;
  13. using MECF.Framework.Common.Equipment;
  14. using MECF.Framework.Common.Event;
  15. using MECF.Framework.Common.SubstrateTrackings;
  16. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
  17. using MECF.Framework.RT.ModuleLibrary.EfemModules;
  18. namespace FutureEfemLib.Efems
  19. {
  20. public class EfemModule : EfemModuleBase
  21. {
  22. public enum STATE
  23. {
  24. NotInstall,
  25. Init,
  26. Idle,
  27. Homing,
  28. HomingAll,
  29. Picking,
  30. Placing,
  31. RobotGoto,
  32. Swapping,
  33. Mapping,
  34. Load,
  35. Unload,
  36. Error,
  37. NotConnect,
  38. Extending,
  39. Retracting,
  40. }
  41. public enum MSG
  42. {
  43. Home,
  44. HomeAll,
  45. Connected,
  46. Disconnected,
  47. Map,
  48. Pick,
  49. PickAndPlace,
  50. Place,
  51. Goto,
  52. Reset,
  53. Abort,
  54. Error,
  55. ToInit,
  56. Extend,
  57. Retract,
  58. }
  59. public override bool IsReady
  60. {
  61. get { return FsmState == (int)STATE.Idle && CheckAllMessageProcessed(); }
  62. }
  63. public override bool IsError
  64. {
  65. get { return FsmState == (int)STATE.Error; }
  66. }
  67. public override bool IsInit
  68. {
  69. get { return FsmState == (int)STATE.Init; }
  70. }
  71. public bool IsBusy
  72. {
  73. get { return !IsInit && !IsError && !IsReady; }
  74. }
  75. public event Action<string> OnEnterError;
  76. public bool IsEfemRobotHomed { get; set; }
  77. public FutureEfemRobot RobotDevice { get; set; }
  78. public FutureEfem EfemDevice { get; set; }
  79. public FutureSignalTower SignalTowerDevice { get; set; }
  80. public FutureEfemLoadPort LP1Device { get; set; }
  81. public FutureEfemLoadPort LP2Device { get; set; }
  82. public FutureEfemLoadPort LP3Device { get; set; }
  83. public FutureBuffer BufADevice { get; set; }
  84. public FutureBuffer BufBDevice { get; set; }
  85. public FutureAligner AlignerDevice { get; set; }
  86. private EfemHomeRoutine _homeRoutine;
  87. private EfemHomeAllRoutine _homeAllRoutine;
  88. private EfemPickRoutine _pickRoutine;
  89. private EfemPlaceRoutine _placeRoutine;
  90. private EfemGotoRoutine _gotoRoutine;
  91. private EfemMapRoutine _mapRoutine;
  92. private EfemPickAndPlaceRoutine _pickAndPlaceRoutine;
  93. private EfemExtendRoutine _extendRoutine;
  94. private EfemRetractRoutine _retractRoutine;
  95. //private EfemPickPMRoutine _pickPMRoutine;
  96. //private EfemPlacePMRoutine _placePMRoutine;
  97. //private EfemPickAndPlacePMRoutine _pickAndPlacePMRoutine;
  98. private bool _isInit;
  99. public EfemModule(ModuleName module) : base(2)
  100. {
  101. Module = module.ToString();
  102. Name = module.ToString();
  103. IsOnline = true;
  104. }
  105. public override bool Initialize()
  106. {
  107. InitDevice();
  108. InitRoutine();
  109. InitFsm();
  110. InitOp();
  111. InitData();
  112. return base.Initialize();
  113. }
  114. private void InitRoutine()
  115. {
  116. _homeRoutine = new EfemHomeRoutine(this);
  117. _homeAllRoutine = new EfemHomeAllRoutine(this);
  118. _pickRoutine = new EfemPickRoutine(this);
  119. _placeRoutine = new EfemPlaceRoutine(this);
  120. _gotoRoutine = new EfemGotoRoutine(this);
  121. _mapRoutine = new EfemMapRoutine(this);
  122. _pickAndPlaceRoutine = new EfemPickAndPlaceRoutine(this);
  123. _extendRoutine = new EfemExtendRoutine(this);
  124. _retractRoutine = new EfemRetractRoutine(this);
  125. //_pickPMRoutine = new EfemPickPMRoutine(this);
  126. //_placePMRoutine = new EfemPlacePMRoutine(this);
  127. //_pickAndPlacePMRoutine = new EfemPickAndPlacePMRoutine(this);
  128. }
  129. public void InitDevice()
  130. {
  131. RobotDevice = DEVICE.GetDevice<FutureEfemRobot>($"{ModuleName.EfemRobot}.{ModuleName.EfemRobot}");
  132. SignalTowerDevice = DEVICE.GetDevice<FutureSignalTower>($"{ModuleName.System}.{ModuleName.SignalTower}");
  133. //for (int i = 1; i <= 3; i++)
  134. //{
  135. // FutureEfemLoadPort lp = DEVICE.GetDevice<FutureEfemLoadPort>($"LP{i}.LP{i}");
  136. // //lp.SetRobot(RobotDevice);
  137. //}
  138. BufADevice = DEVICE.GetDevice<FutureBuffer>($"{ModuleName.LLA}");
  139. BufBDevice = DEVICE.GetDevice<FutureBuffer>($"{ModuleName.LLB}");
  140. LP1Device = DEVICE.GetDevice<FutureEfemLoadPort>($"{ModuleName.LP1}");
  141. LP2Device = DEVICE.GetDevice<FutureEfemLoadPort>($"{ModuleName.LP2}");
  142. LP3Device = DEVICE.GetDevice<FutureEfemLoadPort>($"{ModuleName.LP3}");
  143. AlignerDevice= DEVICE.GetDevice<FutureAligner>($"{ModuleName.Aligner}.{ModuleName.Aligner}");
  144. EfemDevice = DEVICE.GetDevice<FutureEfem>($"{ModuleName.System}.{ModuleName.EFEM}");
  145. EfemDevice.Connection.OnConnected += Connection_OnConnected;
  146. EfemDevice.Connection.OnDisconnected += Connection_OnDisconnected;
  147. EfemDevice.Connection.OnError += Connection_OnError;
  148. EfemDevice.OnDeviceAlarmStateChanged += EfemDevice_OnDeviceAlarmStateChanged;
  149. }
  150. private void InitData()
  151. {
  152. DATA.Subscribe($"{Module}.Status", () => StringFsmStatus);
  153. DATA.Subscribe($"{Module}.IsOnline", () => IsOnline);
  154. DATA.Subscribe($"{Module}.IsHomed", () => IsEfemRobotHomed);
  155. DATA.Subscribe($"{Module}.IsError", () => IsError);
  156. DATA.Subscribe($"{Module}.IsConnected", () => EfemDevice?.Connection.IsConnected);
  157. DATA.Subscribe($"{Module}.WaferSize", () => WaferManager.Instance.GetWaferSize(ModuleHelper.Converter(Module), 0).ToString());
  158. }
  159. private void InitOp()
  160. {
  161. OP.Subscribe($"{Name}.Connect", (string cmd, object[] args) =>
  162. {
  163. if (EfemDevice.Connection != null && !EfemDevice.Connection.IsConnected)
  164. {
  165. EfemDevice.Connect();
  166. }
  167. return true;
  168. });
  169. OP.Subscribe($"{Name}.Disconnect", (string cmd, object[] args) =>
  170. {
  171. if (EfemDevice.Connection != null && EfemDevice.Connection.IsConnected)
  172. {
  173. EfemDevice.Disconnect();
  174. }
  175. return true;
  176. });
  177. OP.Subscribe($"{Name}.SetOnline", (string cmd, object[] args) =>
  178. {
  179. IsOnline = true;
  180. return true;
  181. });
  182. OP.Subscribe($"{Name}.SetOffline", (string cmd, object[] args) =>
  183. {
  184. IsOnline = false;
  185. return true;
  186. });
  187. OP.Subscribe($"{Name}.Home", (string cmd, object[] args) =>
  188. {
  189. return CheckToPostMessage((int)MSG.Home);
  190. });
  191. OP.Subscribe($"{Name}.HomeAll", (string cmd, object[] args) =>
  192. {
  193. return CheckToPostMessage((int)MSG.HomeAll);
  194. });
  195. OP.Subscribe($"{Name}.Abort", (string cmd, object[] args) =>
  196. {
  197. return CheckToPostMessage((int)MSG.Abort);
  198. });
  199. OP.Subscribe($"{Name}.Reset", (string cmd, object[] args) =>
  200. {
  201. return CheckToPostMessage((int)MSG.Reset);
  202. });
  203. OP.Subscribe($"{Name}.Pick", (string cmd, object[] args) =>
  204. {
  205. return CheckToPostMessage((int)MSG.Pick, args);
  206. });
  207. OP.Subscribe($"{Name}.Place", (string cmd, object[] args) =>
  208. {
  209. return CheckToPostMessage((int)MSG.Place, args);
  210. });
  211. OP.Subscribe($"{Name}.Extend", (string cmd, object[] args) =>
  212. {
  213. return CheckToPostMessage((int)MSG.Extend, args[0], args[1], args[2], args[3]);
  214. });
  215. OP.Subscribe($"{Name}.Retract", (string cmd, object[] args) =>
  216. {
  217. return CheckToPostMessage((int)MSG.Retract, args[0], args[1], args[2], args[3]);
  218. });
  219. OP.Subscribe($"{Name}.Goto", (string cmd, object[] args) =>
  220. {
  221. return CheckToPostMessage((int)MSG.Goto, args[0]);
  222. });
  223. OP.Subscribe($"{Name}.Map", (string cmd, object[] args) =>
  224. {
  225. return CheckToPostMessage((int)MSG.Map, args[0]);
  226. });
  227. }
  228. private void InitFsm()
  229. {
  230. EnumLoop<STATE>.ForEach((item) =>
  231. {
  232. MapState((int)item, item.ToString());
  233. });
  234. EnumLoop<MSG>.ForEach((item) =>
  235. {
  236. MapMessage((int)item, item.ToString());
  237. });
  238. EnableFsm(50, IsInstalled ? STATE.Init : STATE.NotInstall);
  239. //Error
  240. AnyStateTransition(MSG.Error, FsmOnError, STATE.Error);
  241. Transition(STATE.Error, MSG.Reset, FsmReset, STATE.Idle);
  242. EnterExitTransition<STATE, FSM_MSG>(STATE.Error, FsmEnterError, FSM_MSG.NONE, FsmExitError);
  243. AnyStateTransition(FSM_MSG.WARNING, fWarning, FSM_STATE.SAME);
  244. AnyStateTransition((int)FSM_MSG.ALARM, fAlarm, (int)STATE.Error);
  245. //connection
  246. AnyStateTransition(MSG.Disconnected, FsmOnDisconnected, STATE.NotConnect);
  247. Transition(STATE.NotConnect, MSG.Connected, FsmOnConnected, STATE.Init);
  248. Transition(STATE.NotConnect, MSG.Reset, FsmResetConnect, STATE.NotConnect);
  249. //Init
  250. Transition(STATE.Init, MSG.Home, FsmStartHome, STATE.Homing);
  251. Transition(STATE.Error, MSG.Home, FsmStartHome, STATE.Homing);
  252. Transition(STATE.Idle, MSG.Home, FsmStartHome, STATE.Homing);
  253. Transition(STATE.Homing, FSM_MSG.TIMER, FsmMonitorHomeTask, STATE.Idle);
  254. Transition(STATE.Homing, MSG.Error, null, STATE.Init);
  255. Transition(STATE.Homing, MSG.Abort, FsmAbortTask, STATE.Init);
  256. AnyStateTransition(MSG.ToInit, FsmToInit, STATE.Init);
  257. //idle
  258. EnterExitTransition<STATE, FSM_MSG>(STATE.Idle, FsmEnterIdle, FSM_MSG.NONE, FsmExitIdle);
  259. //robot home all
  260. Transition(STATE.Init, MSG.HomeAll, FsmStartHomeAll, STATE.HomingAll);
  261. Transition(STATE.Error, MSG.HomeAll, FsmStartHomeAll, STATE.HomingAll);
  262. Transition(STATE.Idle, MSG.HomeAll, FsmStartHomeAll, STATE.HomingAll);
  263. Transition(STATE.HomingAll, FSM_MSG.TIMER, FsmMonitorHomingAllTask, STATE.Idle);
  264. Transition(STATE.HomingAll, MSG.Error, null, STATE.Init);
  265. Transition(STATE.HomingAll, MSG.Abort, FsmAbortTask, STATE.Init);
  266. //robot map
  267. Transition(STATE.Idle, MSG.Map, FsmStartMap, STATE.Mapping);
  268. Transition(STATE.Mapping, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  269. Transition(STATE.Mapping, MSG.Abort, FsmAbortTask, STATE.Idle);
  270. //robot pick
  271. Transition(STATE.Idle, MSG.Pick, FsmStartRobotPick, STATE.Picking);
  272. Transition(STATE.Picking, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  273. Transition(STATE.Picking, MSG.Abort, FsmAbortTask, STATE.Idle);
  274. //robot pickAndplace
  275. Transition(STATE.Idle, MSG.PickAndPlace, FsmStartPickAndPlace, STATE.Swapping);
  276. Transition(STATE.Swapping, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  277. Transition(STATE.Swapping, MSG.Abort, FsmAbortTask, STATE.Idle);
  278. //robot place
  279. Transition(STATE.Idle, MSG.Place, FsmStartRobotPlace, STATE.Placing);
  280. Transition(STATE.Placing, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  281. Transition(STATE.Placing, MSG.Abort, FsmAbortTask, STATE.Idle);
  282. //robot Extend
  283. Transition(STATE.Idle, MSG.Extend, FsmStartRobotExtend, STATE.Extending);
  284. Transition(STATE.Extending, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  285. Transition(STATE.Extending, MSG.Abort, FsmAbortTask, STATE.Idle);
  286. //robot Retract
  287. Transition(STATE.Idle, MSG.Retract, FsmStartRobotRetract, STATE.Retracting);
  288. Transition(STATE.Retracting, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  289. Transition(STATE.Retracting, MSG.Abort, FsmAbortTask, STATE.Idle);
  290. //robot goto
  291. Transition(STATE.Idle, MSG.Goto, FsmStartRobotGoto, STATE.RobotGoto);
  292. Transition(STATE.RobotGoto, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  293. Transition(STATE.RobotGoto, MSG.Abort, FsmAbortTask, STATE.Idle);
  294. }
  295. private bool FsmToInit(object[] param)
  296. {
  297. return true;
  298. }
  299. private bool FsmResetConnect(object[] param)
  300. {
  301. //if (!EfemDevice.Connection.IsConnected)
  302. //{
  303. // EfemDevice.Connect();
  304. // return false;
  305. //}
  306. //if (!EfemDevice.EmoAlarm.IsAcknowledged)
  307. //{
  308. // EfemDevice.ClearError();
  309. // return false;
  310. //}
  311. return true;
  312. }
  313. private bool FsmOnConnected(object[] param)
  314. {
  315. //SignalTowerDevice.ResetData();
  316. //LP1Device.ResetData();
  317. //LP2Device.ResetData();
  318. //LP3Device.ResetData();
  319. //LP4Device.ResetData();
  320. //EfemDevice.ResetData();
  321. return true;
  322. }
  323. private bool FsmOnDisconnected(object[] param)
  324. {
  325. return true;
  326. }
  327. private bool FsmExitIdle(object[] param)
  328. {
  329. return true;
  330. }
  331. private bool FsmEnterIdle(object[] param)
  332. {
  333. return true;
  334. }
  335. private bool FsmExitError(object[] param)
  336. {
  337. return true;
  338. }
  339. private bool fWarning(object[] objs)
  340. {
  341. //IsWarning = false;
  342. return true;
  343. }
  344. private bool fAlarm(object[] objs)
  345. {
  346. if (FsmState == (int)STATE.Init)
  347. return false;
  348. return true;
  349. }
  350. private bool FsmEnterError(object[] param)
  351. {
  352. if (OnEnterError != null)
  353. OnEnterError(Module);
  354. return true;
  355. }
  356. private bool FsmStartHome(object[] param)
  357. {
  358. Result ret = StartRoutine(_homeRoutine);
  359. if (ret == Result.FAIL || ret == Result.DONE)
  360. return false;
  361. _isInit = false;
  362. IsEfemRobotHomed = false;
  363. return ret == Result.RUN;
  364. }
  365. private bool FsmStartHomeAll(object[] param)
  366. {
  367. Result ret = StartRoutine(_homeAllRoutine);
  368. if (ret == Result.FAIL || ret == Result.DONE)
  369. return false;
  370. _isInit = false;
  371. IsEfemRobotHomed = false;
  372. return ret == Result.RUN;
  373. }
  374. private bool FsmStartRobotPick(object[] param)
  375. {
  376. //if (!param[0].ToString().Contains("PM"))
  377. //{
  378. if (param.Length == 3)
  379. {
  380. _pickRoutine.Init(ModuleHelper.Converter((string)param[0]), (int)param[1], (Hand)param[2]);
  381. }
  382. else
  383. {
  384. _pickRoutine.Init(ModuleHelper.Converter((string)param[0]), (int)param[1]);
  385. }
  386. Result ret = StartRoutine(_pickRoutine);
  387. if (ret == Result.FAIL || ret == Result.DONE)
  388. return false;
  389. return ret == Result.RUN;
  390. //}
  391. //else;
  392. //{
  393. // if (param.Length == 3)
  394. // {
  395. // _pickPMRoutine.Init(ModuleHelper.Converter((string)param[0]), (int)param[1], (Hand)param[2]);
  396. // }
  397. // else
  398. // {
  399. // _pickPMRoutine.Init(ModuleHelper.Converter((string)param[0]), (int)param[1]);
  400. // }
  401. // Result ret = StartRoutine(_pickPMRoutine);
  402. // if (ret == Result.FAIL || ret == Result.DONE)
  403. // return false;
  404. // return ret == Result.RUN;
  405. //}
  406. }
  407. private bool FsmStartPickAndPlace(object[] param)
  408. {
  409. //if (!param[0].ToString().Contains("PM"))
  410. //{
  411. _pickAndPlaceRoutine.Init(ModuleHelper.Converter((string)param[0]), (Hand)param[1], (int)param[2], (Hand)param[3], (int)param[4]);
  412. Result ret = StartRoutine(_pickAndPlaceRoutine);
  413. if (ret == Result.FAIL || ret == Result.DONE)
  414. return false;
  415. return ret == Result.RUN;
  416. //}
  417. //else
  418. //{
  419. // _pickAndPlacePMRoutine.Init(ModuleHelper.Converter((string)param[0]), (Hand)param[1], (int)param[2], (Hand)param[3], (int)param[4]);
  420. // Result ret = StartRoutine(_pickAndPlacePMRoutine);
  421. // if (ret == Result.FAIL || ret == Result.DONE)
  422. // return false;
  423. // return ret == Result.RUN;
  424. //}
  425. }
  426. private bool FsmStartRobotPlace(object[] param)
  427. {
  428. //if (!param[0].ToString().Contains("PM"))
  429. //{
  430. if (param.Length == 3)
  431. {
  432. _placeRoutine.Init(ModuleHelper.Converter((string)param[0]), (int)param[1], (Hand)param[2]);
  433. }
  434. else
  435. {
  436. _placeRoutine.Init(ModuleHelper.Converter((string)param[0]), (int)param[1]);
  437. }
  438. Result ret = StartRoutine(_placeRoutine);
  439. if (ret == Result.FAIL || ret == Result.DONE)
  440. return false;
  441. return ret == Result.RUN;
  442. //}
  443. //else
  444. //{
  445. // if (param.Length == 3)
  446. // {
  447. // _placePMRoutine.Init(ModuleHelper.Converter((string)param[0]), (int)param[1], (Hand)param[2]);
  448. // }
  449. // else
  450. // {
  451. // _placePMRoutine.Init(ModuleHelper.Converter((string)param[0]), (int)param[1]);
  452. // }
  453. // Result ret = StartRoutine(_placePMRoutine);
  454. // if (ret == Result.FAIL || ret == Result.DONE)
  455. // return false;
  456. // return ret == Result.RUN;
  457. //}
  458. }
  459. private bool FsmStartRobotExtend(object[] param)
  460. {
  461. _extendRoutine.Init(ModuleHelper.Converter((string)param[0]), (int)param[1], param[2].ToString(), param[3].ToString()); ;
  462. Result ret = StartRoutine(_extendRoutine);
  463. if (ret == Result.FAIL || ret == Result.DONE)
  464. return false;
  465. return ret == Result.RUN;
  466. }
  467. private bool FsmStartRobotRetract(object[] param)
  468. {
  469. _retractRoutine.Init(ModuleHelper.Converter((string)param[0]), (int)param[1], param[2].ToString(), param[3].ToString());
  470. Result ret = StartRoutine(_retractRoutine);
  471. if (ret == Result.FAIL || ret == Result.DONE)
  472. return false;
  473. return ret == Result.RUN;
  474. }
  475. private bool FsmStartRobotGoto(object[] param)
  476. {
  477. _gotoRoutine.Init(ModuleHelper.Converter((string)param[0]), (int)param[1], (Hand)param[2]);
  478. Result ret = StartRoutine(_gotoRoutine);
  479. if (ret == Result.FAIL || ret == Result.DONE)
  480. return false;
  481. return ret == Result.RUN;
  482. }
  483. private bool FsmStartMap(object[] param)
  484. {
  485. _mapRoutine.Init(ModuleHelper.Converter((string)param[0]));
  486. Result ret = StartRoutine(_mapRoutine);
  487. if (ret == Result.FAIL || ret == Result.DONE)
  488. return false;
  489. return ret == Result.RUN;
  490. }
  491. private bool FsmAbortTask(object[] param)
  492. {
  493. AbortRoutine();
  494. return true;
  495. }
  496. private bool FsmMonitorHomeTask(object[] param)
  497. {
  498. Result ret = MonitorRoutine();
  499. if (ret == Result.FAIL)
  500. {
  501. PostMsg(MSG.Error);
  502. return false;
  503. }
  504. if (ret == Result.DONE)
  505. {
  506. _isInit = true;
  507. IsEfemRobotHomed = true;
  508. OP.DoOperation($"{Module}.ResetTask");
  509. return true;
  510. }
  511. return false;
  512. }
  513. private bool FsmMonitorHomingAllTask(object[] param)
  514. {
  515. Result ret = MonitorRoutine();
  516. if (ret == Result.FAIL)
  517. {
  518. PostMsg(MSG.Error);
  519. return false;
  520. }
  521. if (ret == Result.DONE)
  522. {
  523. _isInit = true;
  524. IsEfemRobotHomed = true;
  525. OP.DoOperation($"{Module}.ResetTask");
  526. return true;
  527. }
  528. return false;
  529. }
  530. private bool FsmMonitorTask(object[] param)
  531. {
  532. Result ret = MonitorRoutine();
  533. if (ret == Result.FAIL)
  534. {
  535. PostMsg(MSG.Error);
  536. return false;
  537. }
  538. return ret == Result.DONE;
  539. }
  540. private bool FsmOnError(object[] param)
  541. {
  542. if (FsmState == (int)STATE.Error)
  543. {
  544. return false;
  545. }
  546. if (FsmState == (int)STATE.Picking)
  547. {
  548. _pickRoutine.Abort();
  549. }
  550. if (FsmState == (int)STATE.Placing)
  551. {
  552. _placeRoutine.Abort();
  553. }
  554. if (FsmState == (int)STATE.RobotGoto)
  555. {
  556. _gotoRoutine.Abort();
  557. }
  558. if (FsmState == (int)STATE.Init)
  559. return false;
  560. return true;
  561. }
  562. private bool FsmReset(object[] param)
  563. {
  564. //if (!EfemDevice.Connection.IsConnected)
  565. //{
  566. // EfemDevice.Connect();
  567. // return false;
  568. //}
  569. //if (!EfemDevice.EmoAlarm.IsAcknowledged)
  570. //{
  571. // EfemDevice.ClearError();
  572. // return false;
  573. //}
  574. if (!_isInit)
  575. {
  576. PostMsg(MSG.ToInit);
  577. return false;
  578. }
  579. if (RobotDevice.IsError)
  580. {
  581. EV.PostWarningLog(Module, $"Robot in error, home to recover");
  582. PostMsg(MSG.ToInit);
  583. return false;
  584. }
  585. return true;
  586. }
  587. #region Service functions
  588. public override bool Home(out string reason)
  589. {
  590. if (!CheckToPostMessage((int)MSG.Home))
  591. {
  592. reason = $"Can not home in {StringFsmStatus} status";
  593. return false;
  594. }
  595. reason = string.Empty;
  596. return true;
  597. }
  598. public override void Reset()
  599. {
  600. SignalTowerDevice.Reset();
  601. if (IsError)
  602. {
  603. if (RobotDevice.IsError)
  604. {
  605. RobotDevice.Reset();
  606. }
  607. else if (RobotDevice.RobotState != RobotStateEnum.Idle && RobotDevice.RobotState != RobotStateEnum.Init)
  608. {
  609. EV.PostWarningLog(Module, $"Robot in {RobotDevice.RobotState}, need home to reset error");
  610. return;
  611. }
  612. CheckToPostMessage((int)MSG.Reset);
  613. }
  614. }
  615. private bool CheckDeviceHasError()
  616. {
  617. if (RobotDevice.IsError)
  618. return true;
  619. return false;
  620. }
  621. public override bool Pick(ModuleName target, Hand blade, int targetSlot, out string reason)
  622. {
  623. CheckToPostMessage((int)MSG.Pick, target.ToString(), targetSlot, blade);
  624. reason = string.Empty;
  625. return true;
  626. }
  627. public override bool Place(ModuleName target, Hand blade, int targetSlot, out string reason)
  628. {
  629. CheckToPostMessage((int)MSG.Place, target.ToString(), targetSlot, blade);
  630. reason = string.Empty;
  631. return true;
  632. }
  633. public override bool PickAndPlace(ModuleName pickTarget, Hand pickHand, int pickSlot, ModuleName placeTarget, Hand placeHand,
  634. int placeSlot, out string reason)
  635. {
  636. CheckToPostMessage((int)MSG.PickAndPlace, pickTarget.ToString(), pickHand, pickSlot, placeHand, placeSlot);
  637. reason = string.Empty;
  638. return true;
  639. }
  640. public override bool Goto(ModuleName target, Hand blade, int targetSlot, out string reason)
  641. {
  642. CheckToPostMessage((int)MSG.Goto, target.ToString(), targetSlot, blade);
  643. reason = string.Empty;
  644. return true;
  645. }
  646. //public override bool GotoRE(ModuleName target, Hand blade, int targetSlot, RobotPostionEnum postiontype, out string reason)
  647. //{
  648. // if(postiontype.ToString().Contains("Extend"))
  649. // CheckToPostMessage((int)MSG.Extend, target.ToString(), targetSlot, blade, postiontype);
  650. // else if(postiontype.ToString().Contains("Retract"))
  651. // CheckToPostMessage((int)MSG.Retract, target.ToString(), targetSlot, blade, postiontype);
  652. // reason = string.Empty;
  653. // return true;
  654. //}
  655. public override bool Map(ModuleName target, out string reason)
  656. {
  657. if (!CheckToPostMessage((int)MSG.Map, target.ToString()))
  658. {
  659. reason = $"Can not support map in {StringFsmStatus}";
  660. return false;
  661. }
  662. reason = string.Empty;
  663. return true;
  664. }
  665. private void EfemDevice_OnDeviceAlarmStateChanged(string module, AlarmEventItem alarmItem)
  666. {
  667. if (IsInit)
  668. return;
  669. if (!alarmItem.IsAcknowledged)
  670. {
  671. if (alarmItem.Level == EventLevel.Warning)
  672. {
  673. EV.PostWarningLog(Module, alarmItem.Description);
  674. }
  675. else
  676. {
  677. EV.PostAlarmLog(Module, alarmItem.Description);
  678. }
  679. //if (alarmItem.EventEnum == EfemDevice.IsMaintain.EventEnum
  680. //|| alarmItem.EventEnum == EfemDevice.EmoAlarm.EventEnum
  681. //|| alarmItem.EventEnum == EfemDevice.DoorOpen.EventEnum )
  682. //{
  683. // _isInit = false;
  684. // PostMsg(MSG.Error);
  685. //}
  686. //else
  687. if (alarmItem.Level == EventLevel.Alarm)
  688. {
  689. PostMsg(MSG.Error);
  690. }
  691. }
  692. else
  693. {
  694. if (IsError)
  695. CheckToPostMessage((int)MSG.Reset);
  696. }
  697. }
  698. private void Connection_OnError(string obj)
  699. {
  700. PostMsg(MSG.Disconnected);
  701. }
  702. private void Connection_OnDisconnected()
  703. {
  704. PostMsg(MSG.Disconnected);
  705. }
  706. private void Connection_OnConnected()
  707. {
  708. PostMsg(MSG.Connected);
  709. }
  710. #endregion
  711. }
  712. }