PlatingCellInterRinseRoutine.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.Util;
  5. using MECF.Framework.Common.Beckhoff.AxisProvider;
  6. using MECF.Framework.Common.Beckhoff.Station;
  7. using MECF.Framework.Common.RecipeCenter;
  8. using MECF.Framework.Common.Routine;
  9. using MECF.Framework.Common.ToolLayout;
  10. using MECF.Framework.Common.Utilities;
  11. using PunkHPX8_Core;
  12. using PunkHPX8_RT.Devices.AXIS;
  13. using PunkHPX8_RT.Devices.PlatingCell;
  14. using PunkHPX8_RT.Modules.Reservoir;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. namespace PunkHPX8_RT.Modules.PlatingCell
  21. {
  22. public class PlatingCellInterRinseRoutine : RoutineBase, IRoutine
  23. {
  24. private enum RunRecipeStep
  25. {
  26. VerticalGotoRinse,
  27. CheckVerticalGotoRinse,
  28. OpenRinseValve,
  29. StartRotation,
  30. WaitRotation,
  31. CloseRinseValve,
  32. End
  33. }
  34. #region 常量
  35. /// <summary>
  36. /// ROTATION电机转速比例
  37. /// </summary>
  38. private const int SPEED_RATIO = 1;
  39. #endregion
  40. /// <summary>
  41. /// recipe
  42. /// </summary>
  43. private DepRecipe _recipe;
  44. /// <summary>
  45. /// Rotation axis
  46. /// </summary>
  47. private JetAxisBase _rotationAxis;
  48. /// <summary>
  49. /// Platingcell device
  50. /// </summary>
  51. private PlatingCellDevice _device;
  52. /// <summary>
  53. /// rotation运动的目的地
  54. /// </summary>
  55. private int _rotationgTargetPosition;
  56. /// <summary>
  57. /// vertical axis entity
  58. /// </summary>
  59. private PlatingCellVerticalEntity _verticalEntity;
  60. /// <summary>
  61. /// 构造函数
  62. /// </summary>
  63. /// <param name="module"></param>
  64. public PlatingCellInterRinseRoutine(string module) : base(module)
  65. {
  66. }
  67. /// <summary>
  68. /// 中止
  69. /// </summary>
  70. public void Abort()
  71. {
  72. Runner.Stop("Manual Abort");
  73. }
  74. /// <summary>
  75. /// 监控
  76. /// </summary>
  77. /// <returns></returns>
  78. public RState Monitor()
  79. {
  80. Runner.Run(RunRecipeStep.VerticalGotoRinse, () => { return StartVertical("Rinse", _recipe.IntervalRinseZoffset); }, _delay_1ms)
  81. .WaitWithStopCondition(RunRecipeStep.CheckVerticalGotoRinse, CheckVerticalEnd, CheckVerticalError)
  82. .Run(RunRecipeStep.OpenRinseValve, _device.RinseEnableAction, _delay_1ms)
  83. .Run(RunRecipeStep.StartRotation, () => { return StartRotation(_rotationgTargetPosition); }, _delay_1ms)
  84. .Delay(RunRecipeStep.WaitRotation, _recipe.IntervalRinseTime*1000)
  85. .Run(RunRecipeStep.CloseRinseValve, _device.RinseDisableAction, _delay_1ms)
  86. .End(RunRecipeStep.End, NullFun);
  87. return Runner.Status;
  88. }
  89. /// <summary>
  90. /// rotation开始旋转
  91. /// </summary>
  92. /// <param name="param"></param>
  93. /// <returns></returns>
  94. private bool StartRotation(int targetPosition)
  95. {
  96. bool result = _rotationAxis.ProfilePosition(targetPosition, _recipe.IntervalRinseSpeed * SPEED_RATIO * 6, 0, 0); //rpm->deg/s
  97. if (!result)
  98. {
  99. NotifyError(eEvent.ERR_PLATINGCELL, "Start Rotation is failed", 0);
  100. return false;
  101. }
  102. return true;
  103. }
  104. /// <summary>
  105. /// vertical 运行
  106. /// </summary>
  107. /// <param name="positionName"></param> 目标位置名称
  108. /// <param name="offset"></param> 偏移量
  109. /// <returns></returns>
  110. private bool StartVertical(string positionName, double offset)
  111. {
  112. return _verticalEntity.CheckToPostMessage<PlatingCellVerticalState, PlatingCellVerticalEntity.VerticalMsg>(Aitex.Core.RT.Log.eEvent.INFO_PLATINGCELL,
  113. Module, (int)PlatingCellVerticalEntity.VerticalMsg.Position, positionName, offset);
  114. }
  115. /// <summary>
  116. /// 检验垂直电机是否运动完成
  117. /// </summary>
  118. /// <returns></returns>
  119. private bool CheckVerticalEnd()
  120. {
  121. return _verticalEntity.IsIdle;
  122. }
  123. /// <summary>
  124. /// 检验垂直是否出现错误
  125. /// </summary>
  126. /// <returns></returns>
  127. private bool CheckVerticalError()
  128. {
  129. return _verticalEntity.IsError;
  130. }
  131. /// <summary>
  132. /// 启动
  133. /// </summary>
  134. /// <param name="objs"></param>
  135. /// <returns></returns>
  136. public RState Start(params object[] objs)
  137. {
  138. _recipe = (DepRecipe)objs[0];
  139. _rotationgTargetPosition = (int)objs[1];
  140. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  141. _device = DEVICE.GetDevice<PlatingCellDevice>(Module);
  142. //获取vertical entity
  143. string vertical = ModuleMatcherManager.Instance.GetPlatingVerticalByCell(Module);
  144. _verticalEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellVerticalEntity>(vertical);
  145. return Runner.Start(Module, "start intervale rinse");
  146. }
  147. }
  148. }