PufGotoRobotForPickRoutine.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using MECF.Framework.Common.Routine;
  5. using MECF.Framework.Common.Utilities;
  6. using CyberX8_Core;
  7. using CyberX8_RT.Devices.AXIS;
  8. using CyberX8_RT.Devices.PUF;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace CyberX8_RT.Modules.PUF
  15. {
  16. public class PufGotoRobotForPickRoutine : RoutineBase, IRoutine
  17. {
  18. private enum GotoRobotStep
  19. {
  20. ChuckIn,
  21. WaitChuck,
  22. RotationFlip,
  23. RotationFlipWait,
  24. FlipGotoSide,
  25. FlipGotoSideWait,
  26. RotationGotoRobot,
  27. RotationWait,
  28. End
  29. }
  30. #region 常量
  31. private const string WAFER_PRESENT = "WaferPresent";
  32. #endregion
  33. #region 内部变量
  34. /// <summary>
  35. /// Side
  36. /// </summary>
  37. private string _side = "";
  38. /// <summary>
  39. /// Flip Axis
  40. /// </summary>
  41. private JetAxisBase _flipAxis;
  42. /// <summary>
  43. /// Rotation Axis
  44. /// </summary>
  45. private JetAxisBase _rotationAxis;
  46. /// <summary>
  47. /// Puf Vacuum
  48. /// </summary>
  49. private PufVacuum _pufVacuum;
  50. /// <summary>
  51. /// chuck routine
  52. /// </summary>
  53. private PufChuckRoutine _chuckRoutine;
  54. /// <summary>
  55. /// Flip Side
  56. /// </summary>
  57. private string _flipSide;
  58. /// <summary>
  59. /// 是否需要翻转
  60. /// </summary>
  61. private bool _needFlip;
  62. #endregion
  63. /// <summary>
  64. /// 构造函数
  65. /// </summary>
  66. /// <param name="module"></param>
  67. public PufGotoRobotForPickRoutine(string module) : base(module)
  68. {
  69. _chuckRoutine = new PufChuckRoutine(module);
  70. }
  71. /// <summary>
  72. /// 中止
  73. /// </summary>
  74. public void Abort()
  75. {
  76. Runner.Stop("Manual Abort");
  77. }
  78. /// <summary>
  79. /// 监控
  80. /// </summary>
  81. /// <returns></returns>
  82. public RState Monitor()
  83. {
  84. Runner.Run(GotoRobotStep.ChuckIn, () => _chuckRoutine.Start(false) == RState.Running, _delay_1ms)
  85. .WaitWithStopCondition(GotoRobotStep.WaitChuck, () => CommonFunction.CheckRoutineEndState(_chuckRoutine),
  86. CheckChuckStopStatus)
  87. .Run(GotoRobotStep.RotationFlip, RotationGotoFlip, _delay_1ms)
  88. .WaitWithStopCondition(GotoRobotStep.RotationFlipWait, CheckRotationGotoFlipStatus, CheckRotationGotoFlipStopStatus)
  89. .Run(GotoRobotStep.FlipGotoSide, () => { return _flipAxis.PositionStation(_flipSide, false); }, _delay_1ms)
  90. .WaitWithStopCondition(GotoRobotStep.FlipGotoSideWait, CheckFlipPositionStatus, CheckFlipPositionRunStop)
  91. .Run(GotoRobotStep.RotationGotoRobot, () => { return _rotationAxis.PositionStation("Robot", false); }, _delay_1ms)
  92. .WaitWithStopCondition(GotoRobotStep.RotationWait, CheckRotationPositionStatus, CheckRotationPositionRunStop)
  93. .End(GotoRobotStep.End, NullFun, _delay_1ms);
  94. return Runner.Status;
  95. }
  96. /// <summary>
  97. /// 检验chuck routine停止状态
  98. /// </summary>
  99. /// <returns></returns>
  100. private bool CheckChuckStopStatus()
  101. {
  102. bool result = CommonFunction.CheckRoutineStopState(_chuckRoutine);
  103. if (!result)
  104. {
  105. NotifyError(eEvent.ERR_PUF, _chuckRoutine.ErrorMsg, 0);
  106. }
  107. return result;
  108. }
  109. /// <summary>
  110. /// Rotation Goto Flip
  111. /// </summary>
  112. /// <returns></returns>
  113. private bool RotationGotoFlip()
  114. {
  115. if (_needFlip)
  116. {
  117. return _rotationAxis.PositionStation("Flip", false);
  118. }
  119. else
  120. {
  121. return true;
  122. }
  123. }
  124. /// <summary>
  125. /// 检验Rotation Goto Flip状态
  126. /// </summary>
  127. /// <returns></returns>
  128. private bool CheckRotationGotoFlipStatus()
  129. {
  130. if (_needFlip)
  131. {
  132. return _rotationAxis.Status == RState.End;
  133. }
  134. else
  135. {
  136. return true;
  137. }
  138. }
  139. /// <summary>
  140. /// 检验Rotation Goto Flip停止状态
  141. /// </summary>
  142. /// <returns></returns>
  143. private bool CheckRotationGotoFlipStopStatus()
  144. {
  145. if (_needFlip)
  146. {
  147. return _rotationAxis.Status == RState.End;
  148. }
  149. else
  150. {
  151. return false;
  152. }
  153. }
  154. /// <summary>
  155. /// 检验Rotation移动状态
  156. /// </summary>
  157. /// <returns></returns>
  158. private bool CheckRotationPositionStatus()
  159. {
  160. return _rotationAxis.Status == RState.End;
  161. }
  162. /// <summary>
  163. /// 检验Rotation是否还在运动
  164. /// </summary>
  165. /// <returns></returns>
  166. private bool CheckRotationPositionRunStop()
  167. {
  168. return _rotationAxis.Status == RState.Failed;
  169. }
  170. /// <summary>
  171. /// 检验Flip移动状态
  172. /// </summary>
  173. /// <returns></returns>
  174. private bool CheckFlipPositionStatus()
  175. {
  176. return _flipAxis.Status == RState.End;
  177. }
  178. /// <summary>
  179. /// 检验Flip是否还在运动
  180. /// </summary>
  181. /// <returns></returns>
  182. private bool CheckFlipPositionRunStop()
  183. {
  184. return _flipAxis.Status == RState.Failed;
  185. }
  186. /// <summary>
  187. /// 启动
  188. /// </summary>
  189. /// <param name="objs"></param>
  190. /// <returns></returns>
  191. public RState Start(params object[] objs)
  192. {
  193. _side = objs[0].ToString();
  194. if(_side=="SideA")
  195. {
  196. _flipSide = "SideB";//Flip 运动至Side相反位置,即使用SideA,则Flip运动至SideB
  197. }
  198. else
  199. {
  200. _flipSide = "SideA";
  201. }
  202. _flipAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Flip");
  203. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  204. _pufVacuum = DEVICE.GetDevice<PufVacuum>($"{Module}.Vacuum");
  205. _needFlip = !_flipAxis.CheckPositionIsInStation(_flipAxis.MotionData.MotorPosition, _flipSide);
  206. if (!CheckPreCondition())
  207. {
  208. return RState.Failed;
  209. }
  210. return Runner.Start(Module, "Go to Robot");
  211. }
  212. /// <summary>
  213. /// 前置条件
  214. /// </summary>
  215. /// <returns></returns>
  216. private bool CheckPreCondition()
  217. {
  218. if(!_flipAxis.IsHomed)
  219. {
  220. LOG.WriteLog(eEvent.ERR_PUF, Module, "Flip Axis is not homed");
  221. return false;
  222. }
  223. if (!_rotationAxis.IsHomed)
  224. {
  225. LOG.WriteLog(eEvent.ERR_PUF, Module, "Rotation Axis is not homed");
  226. return false;
  227. }
  228. if (_side == "SideA")
  229. {
  230. if(_pufVacuum.ChuckAVacuumStatus!=WAFER_PRESENT)
  231. {
  232. LOG.WriteLog(eEvent.ERR_PUF, Module, "Side A is not wafer present");
  233. return false;
  234. }
  235. }
  236. else if(_side=="SideB")
  237. {
  238. if (_pufVacuum.ChuckBVacuumStatus != WAFER_PRESENT)
  239. {
  240. LOG.WriteLog(eEvent.ERR_PUF, Module, "Side B is not wafer present");
  241. return false;
  242. }
  243. }
  244. if(!_rotationAxis.CheckGotoPosition("Robot"))
  245. {
  246. return false;
  247. }
  248. return true;
  249. }
  250. }
  251. }