PufReadyForRobotPlaceRoutine.cs 5.0 KB

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