EfemModule.cs 30 KB

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