PufReadyForRobotPickRoutine.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 CyberX8_RT.Devices.PUF;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Aitex.Core.RT.Log;
  13. using MECF.Framework.Common.Utilities;
  14. namespace CyberX8_RT.Modules.PUF
  15. {
  16. public class PufReadyForRobotPickRoutine : RoutineBase, IRoutine
  17. {
  18. private enum ReadyForPickPlaceStep
  19. {
  20. RotationRobot,
  21. WaitRotationRobot,
  22. //ChuckAVacuumOff,
  23. End
  24. }
  25. #region 内部变量
  26. private JetAxisBase _rotationAxis;
  27. private PufVacuum _vacuum;
  28. #endregion
  29. /// <summary>
  30. /// 构造函数
  31. /// </summary>
  32. /// <param name="module"></param>
  33. public PufReadyForRobotPickRoutine(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(ReadyForPickPlaceStep.RotationRobot, () => AxisGotoPosition(_rotationAxis,"Robot",0), _delay_1ms)
  50. .WaitWithStopCondition(ReadyForPickPlaceStep.WaitRotationRobot, CheckRotationPositionStatus, ()=>CheckRotationStopStatus(0))
  51. //.Run(ReadyForPickPlaceStep.ChuckAVacuumOff,SideAVacuumOff, _delay_1ms)
  52. .End(ReadyForPickPlaceStep.End, NullFun, _delay_1ms);
  53. return Runner.Status;
  54. }
  55. /// <summary>
  56. /// Axis goto position
  57. /// </summary>
  58. /// <param name="axis"></param>
  59. /// <param name="position"></param>
  60. /// <param name="index"></param>
  61. /// <returns></returns>
  62. private bool AxisGotoPosition(JetAxisBase axis, string position, int index)
  63. {
  64. bool result = axis.PositionStation(position);
  65. if (!result)
  66. {
  67. NotifyError(eEvent.ERR_PUF, $"{axis.Module} goto {position} failed", index);
  68. }
  69. return result;
  70. }
  71. /// <summary>
  72. /// 检验Rotation移动状态
  73. /// </summary>
  74. /// <returns></returns>
  75. private bool CheckRotationPositionStatus()
  76. {
  77. return _rotationAxis.Status == RState.End;
  78. }
  79. /// <summary>
  80. /// 检验Rotation异常状态
  81. /// </summary>
  82. /// <returns></returns>
  83. private bool CheckRotationStopStatus(int index)
  84. {
  85. bool result = _rotationAxis.Status == RState.Failed || _rotationAxis.Status == RState.Timeout;
  86. if (result)
  87. {
  88. NotifyError(eEvent.ERR_PUF, "rotation motion failed", index);
  89. }
  90. return result;
  91. }
  92. /// <summary>
  93. /// 启动
  94. /// </summary>
  95. /// <param name="objs"></param>
  96. /// <returns></returns>
  97. public RState Start(params object[] objs)
  98. {
  99. InitializeParameters();
  100. return Runner.Start(Module, "start ready for robot place");
  101. }
  102. /// <summary>
  103. /// 初始化参数
  104. /// </summary>
  105. private void InitializeParameters()
  106. {
  107. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  108. _vacuum = DEVICE.GetDevice<PufVacuum>($"{Module}.Vacuum");
  109. }
  110. /// <summary>
  111. /// 重试
  112. /// </summary>
  113. /// <param name="step"></param>
  114. public RState Retry(int step)
  115. {
  116. InitializeParameters();
  117. List<Enum> preStepIds = new List<Enum>();
  118. return Runner.Retry(ReadyForPickPlaceStep.RotationRobot, preStepIds, Module, "ReadyForPick Retry");
  119. }
  120. /// <summary>
  121. /// 检验完成情况
  122. /// </summary>
  123. /// <returns></returns>
  124. public bool CheckCompleteCondition()
  125. {
  126. double rotationPosition = _rotationAxis.MotionData.MotorPosition;
  127. if (!_rotationAxis.CheckPositionIsInStation(rotationPosition, "Robot"))
  128. {
  129. NotifyError(eEvent.ERR_PUF, $"rotation {rotationPosition} not in Robot", 0);
  130. return false;
  131. }
  132. return true;
  133. }
  134. }
  135. }