PufBackToParkRoutine.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Routine;
  3. using MECF.Framework.Common.Routine;
  4. using CyberX8_Core;
  5. using CyberX8_RT.Devices.AXIS;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using Aitex.Core.RT.Log;
  12. using System.Windows.Media.Animation;
  13. using MECF.Framework.Common.Utilities;
  14. using MECF.Framework.Common.Equipment;
  15. using CyberX8_RT.Devices.PUF;
  16. namespace CyberX8_RT.Modules.PUF
  17. {
  18. public class PufBackToParkRoutine : RoutineBase, IRoutine
  19. {
  20. private enum BackToParkStep
  21. {
  22. ChuckIn,
  23. WaitChuck,
  24. RotationHomeStation,
  25. WaitRotationHomeStation,
  26. FlipSideA,
  27. WaitFlipSideA,
  28. End
  29. }
  30. #region 内部变量
  31. private JetAxisBase _flipAxis;
  32. private JetAxisBase _rotationAxis;
  33. private PufVacuum _pufVacuum;
  34. private PufChuckRoutine _chuckRoutine;
  35. #endregion
  36. /// <summary>
  37. /// 构造函数
  38. /// </summary>
  39. /// <param name="module"></param>
  40. public PufBackToParkRoutine(string module) : base(module)
  41. {
  42. _chuckRoutine=new PufChuckRoutine(module);
  43. _pufVacuum = DEVICE.GetDevice<PufVacuum>($"{Module}.Vacuum");
  44. }
  45. /// <summary>
  46. /// 中止
  47. /// </summary>
  48. public void Abort()
  49. {
  50. Runner.Stop("manual abort");
  51. }
  52. /// <summary>
  53. /// 监控
  54. /// </summary>
  55. /// <returns></returns>
  56. public RState Monitor()
  57. {
  58. Runner.Run(BackToParkStep.ChuckIn, () => _chuckRoutine.Start(false)==RState.Running, _delay_1ms)
  59. .WaitWithStopCondition(BackToParkStep.WaitChuck, ()=>CommonFunction.CheckRoutineEndState(_chuckRoutine),
  60. CheckChuckStopStatus)
  61. .Run(BackToParkStep.RotationHomeStation, () => AxisGotoPosition(_rotationAxis, "Home", 0), _delay_1ms)
  62. .WaitWithStopCondition(BackToParkStep.WaitRotationHomeStation, CheckRotationPositionStatus, CheckRotationStopStatus)
  63. .RunIf(BackToParkStep.FlipSideA,Module==ModuleName.PUF1.ToString(),() => AxisGotoPosition(_flipAxis,"SideA", 0), _delay_1ms)
  64. .WaitWithStopConditionIf(BackToParkStep.WaitFlipSideA, Module == ModuleName.PUF1.ToString(), CheckFlipPositionStatus, CheckFlipStopStatus)
  65. .End(BackToParkStep.End, NullFun, _delay_1ms);
  66. return Runner.Status;
  67. }
  68. /// <summary>
  69. /// 检验chuck routine停止状态
  70. /// </summary>
  71. /// <returns></returns>
  72. private bool CheckChuckStopStatus()
  73. {
  74. bool result=CommonFunction.CheckRoutineStopState(_chuckRoutine);
  75. if (result)
  76. {
  77. NotifyError(eEvent.ERR_PUF, _chuckRoutine.ErrorMsg, 0);
  78. }
  79. return result;
  80. }
  81. /// <summary>
  82. /// 检验Rotation移动状态
  83. /// </summary>
  84. /// <returns></returns>
  85. private bool CheckRotationPositionStatus()
  86. {
  87. return _rotationAxis.Status == RState.End;
  88. }
  89. /// <summary>
  90. /// 检验Flip移动状态
  91. /// </summary>
  92. /// <returns></returns>
  93. private bool CheckFlipPositionStatus()
  94. {
  95. return _flipAxis.Status == RState.End;
  96. }
  97. /// <summary>
  98. /// 检验Flip异常状态
  99. /// </summary>
  100. /// <returns></returns>
  101. private bool CheckFlipStopStatus()
  102. {
  103. bool result = _flipAxis.Status == RState.Failed || _flipAxis.Status == RState.Timeout;
  104. if (result)
  105. {
  106. NotifyError(eEvent.ERR_PUF, "flip motion failed", 0);
  107. }
  108. return result;
  109. }
  110. /// <summary>
  111. /// 检验Rotation异常状态
  112. /// </summary>
  113. /// <returns></returns>
  114. private bool CheckRotationStopStatus()
  115. {
  116. bool result = _rotationAxis.Status == RState.Failed || _rotationAxis.Status == RState.Timeout;
  117. if (result)
  118. {
  119. NotifyError(eEvent.ERR_PUF, "rotation motion failed", 0);
  120. }
  121. return result;
  122. }
  123. /// <summary>
  124. /// Axis goto position
  125. /// </summary>
  126. /// <param name="axis"></param>
  127. /// <param name="position"></param>
  128. /// <param name="index"></param>
  129. /// <returns></returns>
  130. private bool AxisGotoPosition(JetAxisBase axis, string position, int index)
  131. {
  132. bool result = axis.PositionStation(position);
  133. if (!result)
  134. {
  135. NotifyError(eEvent.ERR_PUF, $"{axis.Module} goto {position} failed", index);
  136. }
  137. return result;
  138. }
  139. /// <summary>
  140. /// 启动
  141. /// </summary>
  142. /// <param name="objs"></param>
  143. /// <returns></returns>
  144. public RState Start(params object[] objs)
  145. {
  146. InitializeParameters();
  147. return Runner.Start(Module, "start back to park station");
  148. }
  149. /// <summary>
  150. /// 初始化参数
  151. /// </summary>
  152. private void InitializeParameters()
  153. {
  154. _flipAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Flip");
  155. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  156. }
  157. /// <summary>
  158. /// 重试
  159. /// </summary>
  160. /// <param name="step"></param>
  161. public RState Retry(int step)
  162. {
  163. InitializeParameters();
  164. List<Enum> preStepIds = new List<Enum>();
  165. return Runner.Retry(BackToParkStep.ChuckIn, preStepIds, Module, "Back to park Retry");
  166. }
  167. /// <summary>
  168. /// 检验完成情况
  169. /// </summary>
  170. /// <returns></returns>
  171. public bool CheckCompleteCondition()
  172. {
  173. double rotationPosition = _rotationAxis.MotionData.MotorPosition;
  174. if (!_rotationAxis.CheckPositionIsInStation(rotationPosition, "Home"))
  175. {
  176. NotifyError(eEvent.ERR_PUF, $"rotation {rotationPosition} not in Home", 0);
  177. return false;
  178. }
  179. double flipPosition = _flipAxis.MotionData.MotorPosition;
  180. if (!_flipAxis.CheckPositionIsInStation(flipPosition, "SideA"))
  181. {
  182. NotifyError(eEvent.ERR_PUF, $"flip {flipPosition} not in SideA", 0);
  183. return false;
  184. }
  185. if (!_pufVacuum.CheckChuckIn())
  186. {
  187. NotifyError(eEvent.ERR_PUF, $"Chuck status is not chuck in", 0);
  188. return false;
  189. }
  190. return true;
  191. }
  192. }
  193. }