EfemHomeRoutine.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. using System;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using MECF.Framework.Common.Equipment;
  6. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Efems;
  7. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Efems.Rorzes;
  8. namespace FutureEfemLib.Efems
  9. {
  10. class EfemHomeRoutine : ModuleRoutine, IRoutine
  11. {
  12. enum RoutineStep
  13. {
  14. InitEfem,
  15. ClearEfemError,
  16. InitRobot,
  17. HomeRobot,
  18. CheckRobotWafer,
  19. ResetSignalTowerData,
  20. }
  21. private int _timeout = 0;
  22. private bool _needInitEfem;
  23. private IEfemController _efem = null;
  24. private EfemModule _efemModule;
  25. public EfemHomeRoutine(EfemModule module)
  26. {
  27. Module = ModuleName.EfemRobot.ToString();
  28. Name = "Home";
  29. _efem = module.EfemDevice;
  30. _efemModule = module;
  31. }
  32. public Result Start(params object[] objs)
  33. {
  34. Reset();
  35. _timeout = SC.GetValue<int>("EFEM.EfemRobot.HomeTimeout");
  36. _needInitEfem = !_efem.IsInitialized;
  37. Notify($"Start");
  38. return Result.RUN;
  39. }
  40. public Result Monitor()
  41. {
  42. try
  43. {
  44. if (_needInitEfem)
  45. {
  46. InitEfem((int)RoutineStep.InitEfem, _timeout);
  47. }
  48. ClearEfemError((int)RoutineStep.ClearEfemError, _timeout);
  49. InitRobot((int)RoutineStep.InitRobot, _timeout);
  50. HomeRobot((int)RoutineStep.HomeRobot, _timeout);
  51. CheckRobotWafer((int)RoutineStep.CheckRobotWafer, _timeout);
  52. ResetSignalTowerData((int)RoutineStep.ResetSignalTowerData);
  53. }
  54. catch (RoutineBreakException)
  55. {
  56. return Result.RUN;
  57. }
  58. catch (RoutineFaildException)
  59. {
  60. return Result.FAIL;
  61. }
  62. Notify("Finished");
  63. return Result.DONE;
  64. }
  65. public void InitEfem(int id, int timeout)
  66. {
  67. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  68. {
  69. Notify($"Start initialize EFEM status");
  70. string reason;
  71. if (!_efem.Home(out reason))
  72. {
  73. Stop(reason);
  74. return false;
  75. }
  76. return true;
  77. }, () =>
  78. {
  79. if (!_efem.IsInitialized)
  80. return false;
  81. if (_efem.CheckIsBusy(ModuleName.System))
  82. return false;
  83. return true;
  84. }, timeout * 1000);
  85. if (ret.Item1)
  86. {
  87. if (ret.Item2 == Result.FAIL)
  88. {
  89. Stop(string.Format("Home failed."));
  90. throw (new RoutineFaildException());
  91. }
  92. else if (ret.Item2 == Result.TIMEOUT) //timeout
  93. {
  94. Stop(string.Format("Home timeout, can not complete in {0} seconds", timeout));
  95. throw (new RoutineFaildException());
  96. }
  97. else
  98. throw (new RoutineBreakException());
  99. }
  100. }
  101. public void ClearEfemError(int id, int timeout)
  102. {
  103. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  104. {
  105. Notify($"Start clear EFEM error");
  106. //string reason;
  107. (_efem as RorzeEfem).ClearError();
  108. return true;
  109. }, () =>
  110. {
  111. if (_efem.CheckIsBusy(ModuleName.System))
  112. return false;
  113. //if ((_efem as StripEfem).HasAlarm)
  114. // return false;
  115. return true;
  116. }, timeout * 1000);
  117. if (ret.Item1)
  118. {
  119. if (ret.Item2 == Result.FAIL)
  120. {
  121. Stop(string.Format("Home failed."));
  122. throw (new RoutineFaildException());
  123. }
  124. else if (ret.Item2 == Result.TIMEOUT) //timeout
  125. {
  126. Stop(string.Format("Home timeout, can not clear error in {0} seconds", timeout));
  127. throw (new RoutineFaildException());
  128. }
  129. else
  130. throw (new RoutineBreakException());
  131. }
  132. }
  133. public void InitRobot(int id, int timeout)
  134. {
  135. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  136. {
  137. Notify($"Start initialize robot status");
  138. _efemModule.RobotDevice.Abort();
  139. if (!_efemModule.RobotDevice.Home(out string reason))
  140. {
  141. Stop(reason);
  142. return false;
  143. }
  144. return true;
  145. }, () =>
  146. {
  147. if (!_efemModule.RobotDevice.IsIdle)
  148. return false;
  149. return true;
  150. }, timeout * 1000);
  151. if (ret.Item1)
  152. {
  153. if (ret.Item2 == Result.FAIL)
  154. {
  155. Stop(string.Format("Home failed."));
  156. throw (new RoutineFaildException());
  157. }
  158. else if (ret.Item2 == Result.TIMEOUT) //timeout
  159. {
  160. Stop(string.Format("Home timeout, can not complete in {0} seconds", timeout));
  161. throw (new RoutineFaildException());
  162. }
  163. else
  164. throw (new RoutineBreakException());
  165. }
  166. }
  167. public void HomeRobot(int id, int timeout)
  168. {
  169. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  170. {
  171. Notify($"Start home robot");
  172. if (!_efemModule.RobotDevice.HomeAllAxes(out string reason))
  173. {
  174. Stop(reason);
  175. return false;
  176. }
  177. return true;
  178. }, () =>
  179. {
  180. if (_efemModule.RobotDevice.IsError)
  181. {
  182. return null;
  183. }
  184. if (!_efemModule.RobotDevice.IsIdle)
  185. return false;
  186. return true;
  187. }, timeout * 1000);
  188. if (ret.Item1)
  189. {
  190. if (ret.Item2 == Result.FAIL)
  191. {
  192. Stop(string.Format("Home failed."));
  193. throw (new RoutineFaildException());
  194. }
  195. else if (ret.Item2 == Result.TIMEOUT) //timeout
  196. {
  197. Stop(string.Format("Home timeout, can not complete in {0} seconds", timeout));
  198. throw (new RoutineFaildException());
  199. }
  200. else
  201. throw (new RoutineBreakException());
  202. }
  203. }
  204. public void ResetSignalTowerData(int id )
  205. {
  206. Tuple<bool, Result> ret = Execute(id, () =>
  207. {
  208. Notify($"reset signal tower");
  209. //_efemModule.SignalTowerDevice.ResetData();
  210. return true;
  211. } );
  212. if (ret.Item1)
  213. {
  214. if (ret.Item2 == Result.FAIL)
  215. {
  216. Stop(string.Format("Home failed."));
  217. throw (new RoutineFaildException());
  218. }
  219. else
  220. throw (new RoutineBreakException());
  221. }
  222. }
  223. public void CheckRobotWafer(int id, int timeout)
  224. {
  225. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  226. {
  227. Notify($"Start check robot wafer present");
  228. string reason;
  229. if (!_efem.QueryRobotWaferPresence(out _, out reason))
  230. {
  231. Stop(reason);
  232. return false;
  233. }
  234. return true;
  235. }, () =>
  236. {
  237. if (_efem.CheckIsBusy(ModuleName.System))
  238. return false;
  239. return true;
  240. }, timeout * 1000);
  241. if (ret.Item1)
  242. {
  243. if (ret.Item2 == Result.FAIL)
  244. {
  245. Stop(string.Format("Home failed."));
  246. throw (new RoutineFaildException());
  247. }
  248. else if (ret.Item2 == Result.TIMEOUT) //timeout
  249. {
  250. Stop(string.Format("Home timeout, can not complete in {0} seconds", timeout));
  251. throw (new RoutineFaildException());
  252. }
  253. else
  254. throw (new RoutineBreakException());
  255. }
  256. }
  257. public void Abort()
  258. {
  259. }
  260. }
  261. }