TMHomeRoutine.cs 8.4 KB

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