PlatingCellRunRecipeRoutine.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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.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 System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. namespace PunkHPX8_RT.Modules.PlatingCell
  18. {
  19. public class PlatingCellRunRecipeRoutine : RoutineBase, IRoutine
  20. {
  21. private enum RunRecipeStep
  22. {
  23. Delay,
  24. InterRinse,
  25. CheckInterRinse,
  26. Vertical,
  27. CheckVertical,
  28. End
  29. }
  30. #region 常量
  31. private const int ALL_DAY_MILLOSECONDS = 24 * 60 * 60 * 1000;
  32. #endregion
  33. #region 内部变量
  34. /// <summary>
  35. /// recipe
  36. /// </summary>
  37. private DepRecipe _recipe;
  38. /// <summary>
  39. /// Platingcell device
  40. /// </summary>
  41. private PlatingCellDevice _device;
  42. /// <summary>
  43. /// Rotation axis
  44. /// </summary>
  45. private JetAxisBase _rotationAxis;
  46. /// <summary>
  47. ///rotation Provider对象
  48. /// </summary>
  49. private BeckhoffProviderAxis _rotationProviderAxis;
  50. /// cycle次数
  51. /// </summary>
  52. private int _cycle;
  53. /// <summary>
  54. /// 当前完成的Cycle次数
  55. /// </summary>
  56. private int _currentCycle;
  57. private PlatingCellInterRinseRoutine _interRinseRoutine;
  58. private PlatingCellVerticalEntity _verticalEntity;
  59. #endregion
  60. /// <summary>
  61. /// 构造函数
  62. /// </summary>
  63. /// <param name="module"></param>
  64. public PlatingCellRunRecipeRoutine(string module) : base(module)
  65. {
  66. _interRinseRoutine = new PlatingCellInterRinseRoutine(module);
  67. }
  68. /// <summary>
  69. /// 中止
  70. /// </summary>
  71. public void Abort()
  72. {
  73. Runner.Stop("Manual Abort");
  74. }
  75. /// <summary>
  76. /// 监控
  77. /// </summary>
  78. /// <returns></returns>
  79. public RState Monitor()
  80. {
  81. Runner.Delay(RunRecipeStep.Delay, 5000)
  82. .Run(RunRecipeStep.InterRinse, () => { return _interRinseRoutine.Start() == RState.Running; })
  83. .WaitWithStopCondition(RunRecipeStep.CheckInterRinse, () => CommonFunction.CheckRoutineEndState(_interRinseRoutine),
  84. () => CommonFunction.CheckRoutineStopState(_interRinseRoutine))
  85. .Run(RunRecipeStep.Vertical, StartVertical)
  86. .WaitWithStopCondition(RunRecipeStep.CheckVertical, CheckVerticalEnd, CheckVerticalError)
  87. .End(RunRecipeStep.End, NullFun);
  88. return Runner.Status;
  89. }
  90. /// <summary>
  91. /// 垂直电机运行(仅示例只做参考)
  92. /// </summary>
  93. /// <returns></returns>
  94. private bool StartVertical()
  95. {
  96. double position = 101;
  97. return _verticalEntity.CheckToPostMessage<PlatingCellVerticalState, PlatingCellVerticalEntity.VerticalMsg>(Aitex.Core.RT.Log.eEvent.INFO_PLATINGCELL,
  98. Module, (int)PlatingCellVerticalEntity.VerticalMsg.Position, position);
  99. }
  100. /// <summary>
  101. /// 检验垂直电机是否运动完成
  102. /// </summary>
  103. /// <returns></returns>
  104. private bool CheckVerticalEnd()
  105. {
  106. return _verticalEntity.IsIdle;
  107. }
  108. /// <summary>
  109. /// 检验垂直是否出现错误
  110. /// </summary>
  111. /// <returns></returns>
  112. private bool CheckVerticalError()
  113. {
  114. return _verticalEntity.IsError;
  115. }
  116. /// <summary>
  117. /// 启动
  118. /// </summary>
  119. /// <param name="objs"></param>
  120. /// <returns></returns>
  121. public RState Start(params object[] objs)
  122. {
  123. _recipe = objs[0] as DepRecipe;
  124. if (_recipe == null)
  125. {
  126. LOG.WriteLog(eEvent.ERR_METAL, Module, "recipe is null");
  127. return RState.Failed;
  128. }
  129. if (objs.Length > 1)
  130. {
  131. _cycle = (int)objs[1];
  132. }
  133. _device = DEVICE.GetDevice<PlatingCellDevice>(Module);
  134. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  135. _rotationProviderAxis = BeckhoffAxisProviderManager.Instance.GetAxisProvider($"{Module}.Rotation");
  136. if (_rotationProviderAxis == null)
  137. {
  138. NotifyError(eEvent.ERR_PLATINGCELL, $"{Module}.Rotation Provider is not exist", 0);
  139. return RState.Failed;
  140. }
  141. string vertical = ModuleMatcherManager.Instance.GetPlatingVerticalByCell(Module);
  142. _verticalEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellVerticalEntity>(vertical);
  143. if (!CheckPreCondition())
  144. {
  145. return RState.Failed;
  146. }
  147. _currentCycle = 0;
  148. return Runner.Start(Module, "Run Recipe");
  149. }
  150. /// <summary>
  151. /// 检验前置条件
  152. /// </summary>
  153. /// <returns></returns>
  154. private bool CheckPreCondition()
  155. {
  156. if (_recipe == null)
  157. {
  158. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Recipe is null");
  159. return false;
  160. }
  161. if (_recipe.DepSteps.Count == 0)
  162. {
  163. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Recipe DepSteps count is 0");
  164. return false;
  165. }
  166. CheckAxisHome();
  167. CheckFacility();
  168. return true;
  169. }
  170. /// <summary>
  171. /// 检查马达是否上电且home
  172. /// </summary>
  173. /// <returns></returns>
  174. private bool CheckAxisHome()
  175. {
  176. if (!_rotationAxis.IsSwitchOn)
  177. {
  178. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Rotation Axis is off");
  179. return false;
  180. }
  181. if (!_rotationAxis.IsHomed)
  182. {
  183. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Rotation Axis is not home");
  184. return false;
  185. }
  186. if (!_verticalEntity.IsIdle)
  187. {
  188. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Vertical Axis is not home");
  189. return false;
  190. }
  191. return true;
  192. }
  193. /// <summary>
  194. /// 检查facility
  195. /// </summary>
  196. /// <returns></returns>
  197. private bool CheckFacility()
  198. {
  199. return true;
  200. }
  201. }
  202. }