SRDUnloadRoutine.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using CyberX8_Core;
  5. using CyberX8_RT.Devices.AXIS;
  6. using CyberX8_RT.Devices.SRD;
  7. using MECF.Framework.Common.Routine;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Runtime.InteropServices;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using static CyberX8_RT.Modules.SRD.UnloadingStateMachine;
  15. namespace CyberX8_RT.Modules.SRD
  16. {
  17. public class SRDUnloadRoutine : RoutineBase, IRoutine
  18. {
  19. private enum UnloadStep
  20. {
  21. Unloading_Start,
  22. Unloading_CheckArmHomed,
  23. Unloading_CheckRotationHomed,
  24. Unloading_WaferPresent,
  25. Unloading_OpenDoor,
  26. Unloading_CheckDoorOpened,
  27. Unloading_ReleaseChuckVacuum,
  28. Unloading_CheckVacuum,
  29. Test,
  30. End
  31. }
  32. #region 常量
  33. /// <summary>
  34. /// Arm Home最大retry次数
  35. /// </summary>
  36. private const int MAX_ARM_HOME_RETRIES = 3;
  37. /// <summary>
  38. /// Rotation Home最大retry次数
  39. /// </summary>
  40. private const int MAX_ROTATION_HOME_RETRIES = 3;
  41. /// <summary>
  42. /// 旋转增加时长
  43. /// </summary>
  44. private const int ROTATION_PLUS_TIME = 10;
  45. #endregion
  46. #region 内部变量
  47. /// <summary>
  48. /// SRD Common
  49. /// </summary>
  50. private SrdCommonDevice _srdCommon;
  51. /// <summary>
  52. /// Arm Axis
  53. /// </summary>
  54. private JetAxisBase _armAxis;
  55. /// <summary>
  56. /// Rotation Axis
  57. /// </summary>
  58. private JetAxisBase _rotationAxis;
  59. /// <summary>
  60. /// Arm重试次数
  61. /// </summary>
  62. private int _armRetryTimes = 0;
  63. /// <summary>
  64. /// Rotation重试次数
  65. /// </summary>
  66. private int _rotationRetryTimes = 0;
  67. #endregion
  68. /// <summary>
  69. /// 构造函数
  70. /// </summary>
  71. /// <param name="module"></param>
  72. public SRDUnloadRoutine(string module) : base(module)
  73. {
  74. }
  75. /// <summary>
  76. /// 中止
  77. /// </summary>
  78. public void Abort()
  79. {
  80. Runner.Stop("SRD Unloading Abort");
  81. }
  82. /// <summary>
  83. /// 监控
  84. /// </summary>
  85. /// <returns></returns>
  86. public RState Monitor()
  87. {
  88. Runner.Run(UnloadStep.Unloading_Start, NullFun, _delay_1ms)
  89. .WaitWithStopCondition(UnloadStep.Unloading_CheckArmHomed, CheckArmEndStatus, CheckArmStopStatus)
  90. .WaitWithStopCondition(UnloadStep.Unloading_CheckRotationHomed, CheckRotationEndStatus, CheckRotationStopStatus)
  91. .Run(UnloadStep.Unloading_WaferPresent, CheckWaferPresent, _delay_1ms)
  92. .Run(UnloadingState.Unloading_OpenDoor, OpenDoor, _delay_1ms)
  93. .WaitWithStopCondition(UnloadingState.Unloading_CheckDoorOpened, CheckDoorOpenedEndStatus, CheckDoorOpenedStopStatus)
  94. .Run(UnloadingState.Unloading_ReleaseChuckVacuum, ReleaseChuckVacuum, _delay_1ms)
  95. .WaitWithStopCondition(UnloadStep.Unloading_CheckVacuum, CheckReleaseChuckEndStatus, CheckReleaseChuckStopStatus)
  96. .End(UnloadStep.End, NullFun, _delay_1ms);
  97. return Runner.Status;
  98. }
  99. /// <summary>
  100. /// 检验Arm home结束状态
  101. /// </summary>
  102. /// <returns></returns>
  103. private bool CheckArmEndStatus()
  104. {
  105. if (_armAxis.IsHomed && _armAxis.Status == RState.End)
  106. {
  107. _armRetryTimes = 0;
  108. return true;
  109. }
  110. return false;
  111. }
  112. /// <summary>
  113. /// 检验Arm停止状态
  114. /// </summary>
  115. /// <returns></returns>
  116. private bool CheckArmStopStatus()
  117. {
  118. if (_armAxis.Status == RState.Failed || _armAxis.Status == RState.Timeout)
  119. {
  120. if (_armRetryTimes < MAX_ARM_HOME_RETRIES)
  121. {
  122. _armAxis.Home(false);
  123. _armRetryTimes++;
  124. }
  125. else
  126. {
  127. NotifyError(eEvent.ERR_SRD, $"Arm Home Retry Home {_armRetryTimes + 1} times is over {MAX_ARM_HOME_RETRIES}", 0);
  128. return true;
  129. }
  130. }
  131. return false;
  132. }
  133. /// <summary>
  134. /// 检验Rotation home结束状态
  135. /// </summary>
  136. /// <returns></returns>
  137. private bool CheckRotationEndStatus()
  138. {
  139. if (_rotationAxis.IsHomed && _rotationAxis.Status == RState.End)
  140. {
  141. _rotationRetryTimes = 0;
  142. return true;
  143. }
  144. return false;
  145. }
  146. /// <summary>
  147. /// 检验Rotation停止状态
  148. /// </summary>
  149. /// <returns></returns>
  150. private bool CheckRotationStopStatus()
  151. {
  152. if (_rotationAxis.Status == RState.Failed || _rotationAxis.Status == RState.Timeout)
  153. {
  154. if (_rotationRetryTimes < MAX_ROTATION_HOME_RETRIES)
  155. {
  156. _rotationAxis.Home(false);
  157. _rotationRetryTimes++;
  158. }
  159. else
  160. {
  161. NotifyError(eEvent.ERR_SRD, $"Rotation Home Retry Home {_rotationRetryTimes + 1} times is over {MAX_ROTATION_HOME_RETRIES}", 0);
  162. return true;
  163. }
  164. }
  165. return false;
  166. }
  167. /// <summary>
  168. /// Check Wafer Present
  169. /// </summary>
  170. /// <param name="param"></param>
  171. /// <returns></returns>
  172. private bool CheckWaferPresent()
  173. {
  174. if (_srdCommon.IsWaferPresence)
  175. {
  176. if (_srdCommon.WaferPresence != "WellPlaced")
  177. {
  178. NotifyError(eEvent.ERR_SRD, "Wafer Presence is not WellPlaced",0);
  179. return false;
  180. }
  181. }
  182. else
  183. {
  184. LOG.WriteLog(eEvent.INFO_SRD, Module, "CheckWaferPresent has been ignored");
  185. }
  186. return true;
  187. }
  188. /// <summary>
  189. /// Open Door
  190. /// </summary>
  191. /// <param name="param"></param>
  192. /// <returns></returns>
  193. private bool OpenDoor()
  194. {
  195. return _srdCommon.DoorOpenAction("", null);
  196. }
  197. /// <summary>
  198. /// 检验DoorOpened
  199. /// </summary>
  200. /// <param name="param"></param>
  201. /// <returns></returns>
  202. private bool CheckDoorOpenedEndStatus()
  203. {
  204. bool result = _srdCommon.Status == RState.End;
  205. if (result)
  206. {
  207. if (_srdCommon.CommonData.DoorOpened && !_srdCommon.CommonData.DoorClosed)
  208. {
  209. return true;
  210. }
  211. else
  212. {
  213. NotifyError(eEvent.ERR_SRD, $"Opened {_srdCommon.CommonData.DoorOpened}&&Closed {_srdCommon.CommonData.DoorClosed}", 0);
  214. return false;
  215. }
  216. }
  217. return false;
  218. }
  219. /// <summary>
  220. /// 检验Door
  221. /// </summary>
  222. /// <returns></returns>
  223. private bool CheckDoorOpenedStopStatus()
  224. {
  225. return _srdCommon.Status == RState.Failed || _srdCommon.Status == RState.Timeout;
  226. }
  227. /// <summary>
  228. /// 关闭Chuck Vacuum,并检查Vacuum Level
  229. /// </summary>
  230. /// <param name="param"></param>
  231. /// <returns></returns>
  232. private bool ReleaseChuckVacuum()
  233. {
  234. return _srdCommon.ChuckVacuumOffAction("", null);
  235. }
  236. /// <summary>
  237. /// 检验Release Chuck结束状态
  238. /// </summary>
  239. /// <returns></returns>
  240. private bool CheckReleaseChuckEndStatus()
  241. {
  242. return _srdCommon.Status==RState.End;
  243. }
  244. /// <summary>
  245. /// 检验Release Chuck停止状态
  246. /// </summary>
  247. /// <returns></returns>
  248. private bool CheckReleaseChuckStopStatus()
  249. {
  250. return _srdCommon.Status == RState.Failed||_srdCommon.Status==RState.Timeout;
  251. }
  252. /// <summary>
  253. /// 启动
  254. /// </summary>
  255. /// <param name="objs"></param>
  256. /// <returns></returns>
  257. public RState Start(params object[] objs)
  258. {
  259. _armAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Arm");
  260. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  261. _srdCommon = DEVICE.GetDevice<SrdCommonDevice>($"{Module}.Common");
  262. return Runner.Start(Module, "Start Unload Wafer");
  263. }
  264. }
  265. }