PlatingCellRunRecipeRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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.ToolLayout;
  9. using MECF.Framework.Common.Utilities;
  10. using PunkHPX8_Core;
  11. using PunkHPX8_RT.Devices.AXIS;
  12. using PunkHPX8_RT.Devices.Facilities;
  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 PlatingCellRunRecipeRoutine : RoutineBase, IRoutine
  23. {
  24. private enum RunRecipeStep
  25. {
  26. Delay,
  27. InterRinse,
  28. CheckInterRinse,
  29. Vertical,
  30. CheckVertical,
  31. End
  32. }
  33. #region 常量
  34. private const int ALL_DAY_MILLOSECONDS = 24 * 60 * 60 * 1000;
  35. #endregion
  36. #region 内部变量
  37. /// <summary>
  38. /// recipe
  39. /// </summary>
  40. private DepRecipe _recipe;
  41. /// <summary>
  42. /// Platingcell device
  43. /// </summary>
  44. private PlatingCellDevice _device;
  45. /// <summary>
  46. /// Rotation axis
  47. /// </summary>
  48. private JetAxisBase _rotationAxis;
  49. /// <summary>
  50. ///rotation Provider对象
  51. /// </summary>
  52. private BeckhoffProviderAxis _rotationProviderAxis;
  53. /// cycle次数
  54. /// </summary>
  55. private int _cycle;
  56. /// <summary>
  57. /// 当前完成的Cycle次数
  58. /// </summary>
  59. private int _currentCycle;
  60. /// <summary>
  61. /// platingcell entity
  62. /// </summary>
  63. private PlatingCellEntity _platingCellEntity;
  64. /// <summary>
  65. /// 对应reservoir entity
  66. /// </summary>
  67. private ReservoirEntity _reservoirEntity;
  68. private PlatingCellInterRinseRoutine _interRinseRoutine;
  69. private PlatingCellVerticalEntity _verticalEntity;
  70. #endregion
  71. /// <summary>
  72. /// 构造函数
  73. /// </summary>
  74. /// <param name="module"></param>
  75. public PlatingCellRunRecipeRoutine(string module) : base(module)
  76. {
  77. _interRinseRoutine = new PlatingCellInterRinseRoutine(module);
  78. }
  79. /// <summary>
  80. /// 中止
  81. /// </summary>
  82. public void Abort()
  83. {
  84. Runner.Stop("Manual Abort");
  85. }
  86. /// <summary>
  87. /// 监控
  88. /// </summary>
  89. /// <returns></returns>
  90. public RState Monitor()
  91. {
  92. Runner.Delay(RunRecipeStep.Delay, 5000)
  93. .Run(RunRecipeStep.InterRinse, () => { return _interRinseRoutine.Start() == RState.Running; })
  94. .WaitWithStopCondition(RunRecipeStep.CheckInterRinse, () => CommonFunction.CheckRoutineEndState(_interRinseRoutine),
  95. () => CommonFunction.CheckRoutineStopState(_interRinseRoutine))
  96. .Run(RunRecipeStep.Vertical, StartVertical)
  97. .WaitWithStopCondition(RunRecipeStep.CheckVertical, CheckVerticalEnd, CheckVerticalError)
  98. .End(RunRecipeStep.End, NullFun);
  99. return Runner.Status;
  100. }
  101. /// <summary>
  102. /// 垂直电机运行(仅示例只做参考)
  103. /// </summary>
  104. /// <returns></returns>
  105. private bool StartVertical()
  106. {
  107. double position = 101;
  108. return _verticalEntity.CheckToPostMessage<PlatingCellVerticalState, PlatingCellVerticalEntity.VerticalMsg>(Aitex.Core.RT.Log.eEvent.INFO_PLATINGCELL,
  109. Module, (int)PlatingCellVerticalEntity.VerticalMsg.Position, position);
  110. }
  111. /// <summary>
  112. /// 检验垂直电机是否运动完成
  113. /// </summary>
  114. /// <returns></returns>
  115. private bool CheckVerticalEnd()
  116. {
  117. return _verticalEntity.IsIdle;
  118. }
  119. /// <summary>
  120. /// 检验垂直是否出现错误
  121. /// </summary>
  122. /// <returns></returns>
  123. private bool CheckVerticalError()
  124. {
  125. return _verticalEntity.IsError;
  126. }
  127. /// <summary>
  128. /// 启动
  129. /// </summary>
  130. /// <param name="objs"></param>
  131. /// <returns></returns>
  132. public RState Start(params object[] objs)
  133. {
  134. _recipe = objs[0] as DepRecipe;
  135. if (_recipe == null)
  136. {
  137. LOG.WriteLog(eEvent.ERR_METAL, Module, "recipe is null");
  138. return RState.Failed;
  139. }
  140. if (objs.Length > 1)
  141. {
  142. _cycle = (int)objs[1];
  143. }
  144. _device = DEVICE.GetDevice<PlatingCellDevice>(Module);
  145. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  146. _rotationProviderAxis = BeckhoffAxisProviderManager.Instance.GetAxisProvider($"{Module}.Rotation");
  147. if (_rotationProviderAxis == null)
  148. {
  149. NotifyError(eEvent.ERR_PLATINGCELL, $"{Module}.Rotation Provider is not exist", 0);
  150. return RState.Failed;
  151. }
  152. //获取vertical entity
  153. string vertical = ModuleMatcherManager.Instance.GetPlatingVerticalByCell(Module);
  154. _verticalEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellVerticalEntity>(vertical);
  155. //获取platingcell eneity
  156. _platingCellEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(Module);
  157. //获取对应reservoir eneity
  158. string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module);
  159. _reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(reservoir);
  160. if (!CheckPreCondition())
  161. {
  162. return RState.Failed;
  163. }
  164. _currentCycle = 0;
  165. return Runner.Start(Module, "Run Recipe");
  166. }
  167. /// <summary>
  168. /// 检验前置条件
  169. /// </summary>
  170. /// <returns></returns>
  171. private bool CheckPreCondition()
  172. {
  173. if (_recipe == null)
  174. {
  175. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Recipe is null");
  176. return false;
  177. }
  178. if (_recipe.DepSteps.Count == 0)
  179. {
  180. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Recipe DepSteps count is 0");
  181. return false;
  182. }
  183. CheckAxisHome();
  184. CheckFacility();
  185. CheckModuleAndReservoir();
  186. return true;
  187. }
  188. private bool CheckModuleAndReservoir()
  189. {
  190. if (!_platingCellEntity.IsIdle)
  191. {
  192. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"{Module} is not initialized");
  193. return false;
  194. }
  195. if (!_reservoirEntity.IsIdle)
  196. {
  197. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Releated reseroivr is not initialized");
  198. return false;
  199. }
  200. if (!_reservoirEntity.TemperatureReached)
  201. {
  202. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Releated reseroivr temperature is not reached");
  203. return false;
  204. }
  205. if ("Manual".Equals(_reservoirEntity.PersistentValue.OperatingMode))
  206. {
  207. // 要增加又wafer的判定,待修正
  208. }
  209. return true;
  210. }
  211. /// <summary>
  212. /// 检查马达是否上电且home
  213. /// </summary>
  214. /// <returns></returns>
  215. private bool CheckAxisHome()
  216. {
  217. if (!_rotationAxis.IsSwitchOn)
  218. {
  219. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Rotation Axis is off");
  220. return false;
  221. }
  222. if (!_rotationAxis.IsHomed)
  223. {
  224. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Rotation Axis is not home");
  225. return false;
  226. }
  227. if (!_verticalEntity.IsIdle)
  228. {
  229. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Vertical Axis is not home");
  230. return false;
  231. }
  232. return true;
  233. }
  234. /// <summary>
  235. /// 检查facility
  236. /// </summary>
  237. /// <returns></returns>
  238. private bool CheckFacility()
  239. {
  240. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  241. if (systemFacilities == null)
  242. {
  243. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility is null");
  244. return false;
  245. }
  246. if (!systemFacilities.CDAEnable)
  247. {
  248. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility CDA is off");
  249. return false;
  250. }
  251. if (!systemFacilities.N2Enable)
  252. {
  253. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility N2 is off");
  254. return false;
  255. }
  256. if (!systemFacilities.DIFillEnable)
  257. {
  258. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility DIW is off");
  259. return false;
  260. }
  261. if (systemFacilities.FacilitiesDataDic["CDA1Pressure"].IsError || systemFacilities.FacilitiesDataDic["CDA2Pressure"].IsError)
  262. {
  263. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility CDA Data is in errro range");
  264. return false;
  265. }
  266. if (systemFacilities.FacilitiesDataDic["Nitrogen1APressure"].IsError ||
  267. systemFacilities.FacilitiesDataDic["Nitrogen1BPressure"].IsError ||
  268. systemFacilities.FacilitiesDataDic["Nitrogen2APressure"].IsError ||
  269. systemFacilities.FacilitiesDataDic["Nitrogen2BPressure"].IsError)
  270. {
  271. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility N2 Data is in errro range");
  272. return false;
  273. }
  274. if (systemFacilities.FacilitiesDataDic["DiWaterPressure"].IsError)
  275. {
  276. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility Diw Pressure value is in errro range");
  277. return false;
  278. }
  279. return true;
  280. }
  281. }
  282. }