PufReadyForRobotPlaceRoutine.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. namespace CyberX8_RT.Modules.PUF
  13. {
  14. public class PufReadyForRobotPlaceRoutine : RoutineBase, IRoutine
  15. {
  16. private enum ReadyForRobotPlaceStep
  17. {
  18. RotationRobot,
  19. WaitRotationRobot,
  20. FlipSideA,
  21. WaitFlipSideA,
  22. End
  23. }
  24. #region 内部变量
  25. private JetAxisBase _flipAxis;
  26. private JetAxisBase _rotationAxis;
  27. #endregion
  28. /// <summary>
  29. /// 构造函数
  30. /// </summary>
  31. /// <param name="module"></param>
  32. public PufReadyForRobotPlaceRoutine(string module) : base(module)
  33. {
  34. }
  35. /// <summary>
  36. /// 中止
  37. /// </summary>
  38. public void Abort()
  39. {
  40. Runner.Stop("manual abort");
  41. }
  42. /// <summary>
  43. /// 监控
  44. /// </summary>
  45. /// <returns></returns>
  46. public RState Monitor()
  47. {
  48. Runner.Run(ReadyForRobotPlaceStep.RotationRobot, () => _rotationAxis.PositionStation("Robot"), _delay_1ms)
  49. .WaitWithStopCondition(ReadyForRobotPlaceStep.WaitRotationRobot, CheckRotationPositionStatus, CheckRotationPositionRunStop)
  50. .Run(ReadyForRobotPlaceStep.FlipSideA, () => _flipAxis.PositionStation("SideA"), _delay_1ms)
  51. .WaitWithStopCondition(ReadyForRobotPlaceStep.WaitFlipSideA, CheckFlipPositionStatus, CheckFlipPositionRunStop)
  52. .End(ReadyForRobotPlaceStep.End, NullFun, _delay_1ms);
  53. return Runner.Status;
  54. }
  55. /// <summary>
  56. /// 检验Rotation移动状态
  57. /// </summary>
  58. /// <returns></returns>
  59. private bool CheckRotationPositionStatus()
  60. {
  61. return _rotationAxis.Status == RState.End;
  62. }
  63. /// <summary>
  64. /// 检验Rotation是否还在运动
  65. /// </summary>
  66. /// <returns></returns>
  67. private bool CheckRotationPositionRunStop()
  68. {
  69. bool result= _rotationAxis.Status == RState.Failed||_rotationAxis.Status==RState.Timeout;
  70. if (result)
  71. {
  72. NotifyError(eEvent.ERR_PUF, "rotation motion failed", 0);
  73. }
  74. return result;
  75. }
  76. /// <summary>
  77. /// 检验Flip移动状态
  78. /// </summary>
  79. /// <returns></returns>
  80. private bool CheckFlipPositionStatus()
  81. {
  82. return _flipAxis.Status == RState.End;
  83. }
  84. /// <summary>
  85. /// 检验Flip是否还在运动
  86. /// </summary>
  87. /// <returns></returns>
  88. private bool CheckFlipPositionRunStop()
  89. {
  90. bool result = _flipAxis.Status == RState.Failed || _flipAxis.Status == RState.Timeout ;
  91. if (result)
  92. {
  93. NotifyError(eEvent.ERR_PUF, "flip motion failed", 0);
  94. }
  95. return result;
  96. }
  97. /// <summary>
  98. /// 启动
  99. /// </summary>
  100. /// <param name="objs"></param>
  101. /// <returns></returns>
  102. public RState Start(params object[] objs)
  103. {
  104. InitializeParameters();
  105. return Runner.Start(Module, "start ready for robot place");
  106. }
  107. /// <summary>
  108. /// 初始化参数
  109. /// </summary>
  110. private void InitializeParameters()
  111. {
  112. _flipAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Flip");
  113. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  114. }
  115. /// <summary>
  116. /// 重试
  117. /// </summary>
  118. /// <param name="step"></param>
  119. public RState Retry(int step)
  120. {
  121. InitializeParameters();
  122. List<Enum> preStepIds = new List<Enum>();
  123. return Runner.Retry(ReadyForRobotPlaceStep.RotationRobot, preStepIds, Module, "ReadyForRobotPlace Retry");
  124. }
  125. /// <summary>
  126. /// 检验完成情况
  127. /// </summary>
  128. /// <returns></returns>
  129. public bool CheckCompleteCondition()
  130. {
  131. double rotationPosition = _rotationAxis.MotionData.MotorPosition;
  132. if(!_rotationAxis.CheckPositionIsInStation(rotationPosition, "Robot"))
  133. {
  134. NotifyError(eEvent.ERR_PUF, $"rotation {rotationPosition} not in Robot", 0);
  135. return false;
  136. }
  137. double flipPosition = _flipAxis.MotionData.MotorPosition;
  138. if (!_flipAxis.CheckPositionIsInStation(flipPosition, "SideA"))
  139. {
  140. NotifyError(eEvent.ERR_PUF, $"flip {flipPosition} not in SideA", 0);
  141. return false;
  142. }
  143. return true;
  144. }
  145. }
  146. }