PlatingCellEntryRoutine.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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.Station;
  6. using MECF.Framework.Common.CommonData.PowerSupplier;
  7. using MECF.Framework.Common.RecipeCenter;
  8. using MECF.Framework.Common.Routine;
  9. using MECF.Framework.Common.Utilities;
  10. using PunkHPX8_Core;
  11. using PunkHPX8_RT.Devices.AXIS;
  12. using PunkHPX8_RT.Devices.PlatingCell;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. namespace PunkHPX8_RT.Modules.PlatingCell
  19. {
  20. public class PlatingCellEntryRoutine : RoutineBase, IRoutine
  21. {
  22. private enum RunRecipeStep
  23. {
  24. RotationStartEntry,
  25. RotationChangeToEntrySpeed,
  26. AngleTilt,
  27. VerticalGotoPlate,
  28. WaitEntryCurrentProtectedFromRinse,
  29. WaitEntryCurrentProtectedFromHome,
  30. RunPowerStepWithEntryProtect,
  31. CheckVerticalGotoPlate,
  32. AngleVertical,
  33. WaitPlatingDelay,
  34. End
  35. }
  36. #region 常量
  37. /// <summary>
  38. /// ROTATION电机转速比例
  39. /// </summary>
  40. private const int SPEED_RATIO = 1;
  41. #endregion
  42. /// <summary>
  43. /// recipe
  44. /// </summary>
  45. private DepRecipe _recipe;
  46. /// <summary>
  47. /// Rotation axis
  48. /// </summary>
  49. private JetAxisBase _rotationAxis;
  50. /// <summary>
  51. /// Vertical axis
  52. /// </summary>
  53. private JetAxisBase _verticalAxis;
  54. /// <summary>
  55. /// Platingcell device
  56. /// </summary>
  57. private PlatingCellDevice _device;
  58. /// <summary>
  59. /// rotation运动的目的地
  60. /// </summary>
  61. private int _rotationgTargetPosition;
  62. /// <summary>
  63. /// vertical axis entity
  64. /// </summary>
  65. private PlatingCellVerticalEntity _verticalEntity;
  66. /// <summary>
  67. /// Power step集合
  68. /// </summary>
  69. List<PowerSupplierStepPeriodData> _powerSupplierStepPeriodDatas = new List<PowerSupplierStepPeriodData>();
  70. /// <summary>
  71. /// Plating启动时间
  72. /// </summary>
  73. private DateTime _platingStartTime;
  74. /// <summary>
  75. /// 构造函数
  76. /// </summary>
  77. /// <param name="module"></param>
  78. public PlatingCellEntryRoutine(string module) : base(module)
  79. {
  80. }
  81. /// <summary>
  82. /// 中止
  83. /// </summary>
  84. public void Abort()
  85. {
  86. Runner.Stop("Manual Abort");
  87. }
  88. /// <summary>
  89. /// 监控
  90. /// </summary>
  91. /// <returns></returns>
  92. public RState Monitor()
  93. { //启动Rotation/Rotation 设置为entry 转速 (没有intercal rinse 在entry开始的时候启动rotation)
  94. Runner.RunIf(RunRecipeStep.RotationStartEntry, !_recipe.RinseBeforeEntryEnable, RotationStartEntry, _delay_1ms)
  95. //有intercal rinse 直接变速 (rotation在interval rinse的时候已经启动了)
  96. .RunIf(RunRecipeStep.RotationChangeToEntrySpeed, _recipe.RinseBeforeEntryEnable, () => { return ChangeSpeed(_recipe.EntrySpinSpeed); }, _delay_1ms)
  97. //Angle tilt 操作
  98. .Run(RunRecipeStep.AngleTilt, _device.HeadtTiltAction, () => { return _device.PlatingCellDeviceData.IsHeadTilt; }, _delay_1s)
  99. //vertical goto plate
  100. .Run(RunRecipeStep.VerticalGotoPlate, () => { return StartVertical("Plate", _recipe.DepSteps[0].PlatingZoffset); }, _delay_1ms)
  101. //vertical 到达entry位置前110ms (多10ms)
  102. .Delay(RunRecipeStep.WaitEntryCurrentProtectedFromRinse, CalculatePowerDelayTime())
  103. //有上电保护,此刻给电
  104. .RunIf(RunRecipeStep.RunPowerStepWithEntryProtect, !_recipe.IsEntryTypeCold, StartPowerStep, _delay_1ms)
  105. //检查vertical到达plate位置
  106. .WaitWithStopCondition(RunRecipeStep.CheckVerticalGotoPlate, CheckVerticalEnd, CheckVerticalError)
  107. //Angle vertical操作
  108. .Run(RunRecipeStep.AngleVertical, _device.HeadtVerticalAction, () => { return _device.PlatingCellDeviceData.IsHeadVertical; }, _delay_1s)
  109. //如果不需要上电保护,执行plating delay
  110. .DelayIf(RunRecipeStep.WaitPlatingDelay, _recipe.IsEntryTypeCold, _recipe.PlatingDelay * 1000)
  111. .End(RunRecipeStep.End, NullFun);
  112. return Runner.Status;
  113. }
  114. /// <summary>
  115. /// 计算出上电前需要delay的时间
  116. /// </summary>
  117. /// <returns> 返回值单位ms</returns>
  118. private int CalculatePowerDelayTime()
  119. {
  120. int delayTime = 0;
  121. if (_recipe.RinseBeforeEntryEnable)
  122. {
  123. delayTime = _verticalAxis.CalculateVerticaMoveTime($"{_verticalAxis.Module}.Vertical", "Rinse", "Entry", 0 ,_recipe.EntryZoffset) - 110;
  124. }
  125. else
  126. {
  127. delayTime = _verticalAxis.CalculateVerticaMoveTime($"{_verticalAxis.Module}.Vertical", "Load", "Entry", 0, _recipe.EntryZoffset) - 110;
  128. }
  129. return delayTime;
  130. }
  131. /// <summary>
  132. /// 启动PowerSupplier
  133. /// </summary>
  134. /// <returns></returns>
  135. private bool StartPowerStep()
  136. {
  137. bool result = _device.PowerSupplier.StartSetStepPeriodNoWaitEnd(_powerSupplierStepPeriodDatas);
  138. if (!result)
  139. {
  140. _device.PowerSupplier.DisableOperation("", null);
  141. return false;
  142. }
  143. _platingStartTime = DateTime.Now;
  144. return true;
  145. }
  146. /// <summary>
  147. /// rotation 从entry步骤开始旋转
  148. /// </summary>
  149. /// <returns></returns>
  150. private bool RotationStartEntry()
  151. {
  152. bool result = _rotationAxis.ProfilePosition(_rotationgTargetPosition, _recipe.EntrySpinSpeed * SPEED_RATIO, 0, 0);
  153. if (!result)
  154. {
  155. NotifyError(eEvent.ERR_PLATINGCELL, "Start Rotation is failed", 0);
  156. return false;
  157. }
  158. return true;
  159. }
  160. /// <summary>
  161. /// change speed
  162. /// </summary>
  163. /// <returns></returns>
  164. private bool ChangeSpeed(int speed) //参数speed单位是rmp
  165. {
  166. double realSpeed = BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(speed);
  167. bool result = _rotationAxis.ChangeSpeed((int)realSpeed);
  168. if (!result)
  169. {
  170. NotifyError(eEvent.ERR_PLATINGCELL, "Change Speed failed", 0);
  171. return false;
  172. }
  173. return true;
  174. }
  175. /// <summary>
  176. /// vertical 运行
  177. /// </summary>
  178. /// <param name="positionName"></param> 目标位置名称
  179. /// <param name="offset"></param> 偏移量
  180. /// <returns></returns>
  181. private bool StartVertical(string positionName, double offset)
  182. {
  183. return _verticalEntity.CheckToPostMessage<PlatingCellVerticalState, PlatingCellVerticalEntity.VerticalMsg>(Aitex.Core.RT.Log.eEvent.INFO_PLATINGCELL,
  184. Module, (int)PlatingCellVerticalEntity.VerticalMsg.Position, positionName, offset);
  185. }
  186. /// <summary>
  187. /// 检验垂直电机是否运动完成
  188. /// </summary>
  189. /// <returns></returns>
  190. private bool CheckVerticalEnd()
  191. {
  192. return _verticalEntity.IsIdle;
  193. }
  194. /// <summary>
  195. /// 检验垂直是否出现错误
  196. /// </summary>
  197. /// <returns></returns>
  198. private bool CheckVerticalError()
  199. {
  200. return _verticalEntity.IsError;
  201. }
  202. /// <summary>
  203. /// 启动
  204. /// </summary>
  205. /// <param name="objs"></param>
  206. /// <returns></returns>
  207. public RState Start(params object[] objs)
  208. {
  209. _recipe = (DepRecipe)objs[0];
  210. _rotationgTargetPosition = (int)objs[1];
  211. _powerSupplierStepPeriodDatas = (List<PowerSupplierStepPeriodData>)objs[2];
  212. _platingStartTime = (DateTime)objs[3];
  213. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  214. _device = DEVICE.GetDevice<PlatingCellDevice>(Module);
  215. //获取vertical entity
  216. string vertical = ModuleMatcherManager.Instance.GetPlatingVerticalByCell(Module);
  217. _verticalEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellVerticalEntity>(vertical);
  218. _verticalAxis = DEVICE.GetDevice<JetAxisBase>($"{vertical}.Vertical");//不能用来移动,移动用vertical entity来操作
  219. return Runner.Start(Module, "start Entry routine");
  220. }
  221. }
  222. }