PlatingCellReclaimRoutine.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Util;
  6. using MECF.Framework.Common.RecipeCenter;
  7. using MECF.Framework.Common.Routine;
  8. using MECF.Framework.Common.Utilities;
  9. using PunkHPX8_Core;
  10. using PunkHPX8_RT.Devices.AXIS;
  11. using PunkHPX8_RT.Devices.PlatingCell;
  12. using PunkHPX8_RT.Devices.PowerSupplier;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using System.Windows.Navigation;
  19. namespace PunkHPX8_RT.Modules.PlatingCell
  20. {
  21. public class PlatingCellReclaimRoutine : RoutineBase, IRoutine
  22. {
  23. private enum RunRecipeStep
  24. {
  25. SetCurrentProtect,
  26. SetCurrentProtectWait,
  27. VerticalGotoReclaim,
  28. CheckVerticalGotoReclaim,
  29. PowerDisable,
  30. ChangeRotation,
  31. RotationDelay,
  32. End
  33. }
  34. #region 常量
  35. #endregion
  36. /// <summary>
  37. /// recipe
  38. /// </summary>
  39. private DepRecipe _recipe;
  40. /// <summary>
  41. /// Rotation axis
  42. /// </summary>
  43. private JetAxisBase _rotationAxis;
  44. /// <summary>
  45. /// Platingcell device
  46. /// </summary>
  47. private PlatingCellDevice _device;
  48. /// <summary>
  49. /// vertical axis entity
  50. /// </summary>
  51. private PlatingCellVerticalEntity _verticalEntity;
  52. /// <summary>
  53. /// 片子是否电镀
  54. /// </summary>
  55. private bool _isZeroCurrent = false;
  56. /// <summary>
  57. /// reclaim过程是否启用电流保护
  58. /// </summary>
  59. private bool _isCurrentProtectEnable = false;
  60. /// <summary>
  61. ///reclaim过程vertical运动速度
  62. /// </summary>
  63. private int _verticalReclaimSpeed = 0;
  64. /// <summary>
  65. /// reclaim过程vertical加速度
  66. /// </summary>
  67. private int _verticalReclaimAcceleration = 0;
  68. /// <summary>
  69. /// reclaim过程电流保护的电流数值
  70. /// </summary>
  71. private double _reclaimCurrentSetPoint = 0;
  72. /// <summary>
  73. /// 设置电流并启动routine
  74. /// </summary>
  75. private PowerSupplierSetCurrentRoutine _enablePowerRoutine;
  76. /// <summary>
  77. /// PowerSupplier
  78. /// </summary>
  79. protected CellPowerSupplier _powerSupplier;
  80. /// <summary>
  81. /// 构造函数
  82. /// </summary>
  83. /// <param name="module"></param>
  84. public PlatingCellReclaimRoutine(string module) : base(module)
  85. {
  86. }
  87. /// <summary>
  88. /// 中止
  89. /// </summary>
  90. public void Abort()
  91. {
  92. Runner.Stop("Manual Abort");
  93. }
  94. /// <summary>
  95. /// 监控
  96. /// </summary>
  97. /// <returns></returns>
  98. public RState Monitor()
  99. {
  100. Runner.RunIf(RunRecipeStep.SetCurrentProtect, !_isZeroCurrent && _isCurrentProtectEnable, () => {return _enablePowerRoutine.Start(_reclaimCurrentSetPoint) == RState.Running; }, _delay_1ms)
  101. .WaitWithStopConditionIf(RunRecipeStep.SetCurrentProtectWait, !_isZeroCurrent && _isCurrentProtectEnable,
  102. () => CommonFunction.CheckRoutineEndState(_enablePowerRoutine),
  103. () => CommonFunction.CheckRoutineStopState(_enablePowerRoutine))
  104. .Run(RunRecipeStep.VerticalGotoReclaim, () => StartVertical("Reclaim",_recipe.ReclaimZoffset, _verticalReclaimSpeed, _verticalReclaimAcceleration), _delay_1ms)
  105. .WaitWithStopCondition(RunRecipeStep.CheckVerticalGotoReclaim, CheckVerticalEnd, CheckVerticalError)
  106. .RunIf(RunRecipeStep.PowerDisable, !_isZeroCurrent && _isCurrentProtectEnable, DisablePower, _delay_1ms)
  107. .Run(RunRecipeStep.ChangeRotation, () => ChangeRotationSpeed(_recipe.ReclaimSpeed), _delay_1ms)
  108. .Delay(RunRecipeStep.RotationDelay, _recipe.ReclaimTime*1000)
  109. .End(RunRecipeStep.End, NullFun);
  110. return Runner.Status;
  111. }
  112. /// <summary>
  113. /// 停止电源输出
  114. /// </summary>
  115. /// <returns></returns>
  116. private bool DisablePower()
  117. {
  118. return _device.PowerSupplier.DisableOperation("", null);
  119. }
  120. /// <summary>
  121. /// rotation改变速度
  122. /// </summary>
  123. /// <param name="speed"></param>
  124. /// <returns></returns>
  125. private bool ChangeRotationSpeed(int speed)
  126. {
  127. double _scale = _rotationAxis.ScaleFactor;
  128. speed = (int)Math.Round(_scale * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(speed), 0);
  129. return _rotationAxis.ChangeSpeed(speed);
  130. }
  131. /// <summary>
  132. /// vertical 运行
  133. /// </summary>
  134. /// <param name="positionName"></param> 目标位置名称
  135. /// <param name="offset"></param> 偏移量
  136. /// <returns></returns>
  137. private bool StartVertical(string positionName, double offset,int speed,int accelerate)
  138. {
  139. return _verticalEntity.CheckToPostMessage<PlatingCellVerticalState, PlatingCellVerticalEntity.VerticalMsg>(Aitex.Core.RT.Log.eEvent.INFO_PLATINGCELL,
  140. Module, (int)PlatingCellVerticalEntity.VerticalMsg.Position, positionName, offset, speed, accelerate);
  141. }
  142. /// <summary>
  143. /// 检验垂直电机是否运动完成
  144. /// </summary>
  145. /// <returns></returns>
  146. private bool CheckVerticalEnd()
  147. {
  148. return _verticalEntity.IsIdle;
  149. }
  150. /// <summary>
  151. /// 检验垂直是否出现错误
  152. /// </summary>
  153. /// <returns></returns>
  154. private bool CheckVerticalError()
  155. {
  156. return _verticalEntity.IsError;
  157. }
  158. /// <summary>
  159. /// 启动
  160. /// </summary>
  161. /// <param name="objs"></param>
  162. /// <returns></returns>
  163. public RState Start(params object[] objs)
  164. {
  165. _recipe = (DepRecipe)objs[0];
  166. _isZeroCurrent = (bool)objs[1];
  167. _powerSupplier = (CellPowerSupplier)objs[2];
  168. if (_powerSupplier != null)
  169. {
  170. _enablePowerRoutine = new PowerSupplierSetCurrentRoutine(_powerSupplier.DeviceID);
  171. }
  172. _isCurrentProtectEnable = SC.GetValue<bool>("PlatingCell.PostProcessCurrentEnable");
  173. _verticalReclaimSpeed = SC.GetValue<int>("PlatingCell.ReclaimSpeed");
  174. _verticalReclaimAcceleration = SC.GetValue<int>("PlatingCell.ReclaimAcceleration");
  175. _reclaimCurrentSetPoint = SC.GetValue<double>("PlatingCell.PostProcessCurrentSetPoint");
  176. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  177. _device = DEVICE.GetDevice<PlatingCellDevice>(Module);
  178. //获取vertical entity
  179. string vertical = ModuleMatcherManager.Instance.GetPlatingVerticalByCell(Module);
  180. _verticalEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellVerticalEntity>(vertical);
  181. return Runner.Start(Module, "start Reclaim routine");
  182. }
  183. }
  184. }