PlatingCellRunRecipeRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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, CheckInterRinseEndStatus,
  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. private bool CheckInterRinseEndStatus()
  102. {
  103. bool result = CommonFunction.CheckRoutineEndState(_interRinseRoutine);
  104. SubRoutineStep = _interRinseRoutine.CurrentStep;
  105. return result;
  106. }
  107. /// <summary>
  108. /// 垂直电机运行(仅示例只做参考)
  109. /// </summary>
  110. /// <returns></returns>
  111. private bool StartVertical()
  112. {
  113. double position = 101;
  114. return _verticalEntity.CheckToPostMessage<PlatingCellVerticalState, PlatingCellVerticalEntity.VerticalMsg>(Aitex.Core.RT.Log.eEvent.INFO_PLATINGCELL,
  115. Module, (int)PlatingCellVerticalEntity.VerticalMsg.Position, position);
  116. }
  117. /// <summary>
  118. /// 检验垂直电机是否运动完成
  119. /// </summary>
  120. /// <returns></returns>
  121. private bool CheckVerticalEnd()
  122. {
  123. return _verticalEntity.IsIdle;
  124. }
  125. /// <summary>
  126. /// 检验垂直是否出现错误
  127. /// </summary>
  128. /// <returns></returns>
  129. private bool CheckVerticalError()
  130. {
  131. return _verticalEntity.IsError;
  132. }
  133. /// <summary>
  134. /// 启动
  135. /// </summary>
  136. /// <param name="objs"></param>
  137. /// <returns></returns>
  138. public RState Start(params object[] objs)
  139. {
  140. _recipe = objs[0] as DepRecipe;
  141. if (_recipe == null)
  142. {
  143. LOG.WriteLog(eEvent.ERR_METAL, Module, "recipe is null");
  144. return RState.Failed;
  145. }
  146. if (objs.Length > 1)
  147. {
  148. _cycle = (int)objs[1];
  149. }
  150. _device = DEVICE.GetDevice<PlatingCellDevice>(Module);
  151. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  152. _rotationProviderAxis = BeckhoffAxisProviderManager.Instance.GetAxisProvider($"{Module}.Rotation");
  153. if (_rotationProviderAxis == null)
  154. {
  155. NotifyError(eEvent.ERR_PLATINGCELL, $"{Module}.Rotation Provider is not exist", 0);
  156. return RState.Failed;
  157. }
  158. //获取vertical entity
  159. string vertical = ModuleMatcherManager.Instance.GetPlatingVerticalByCell(Module);
  160. _verticalEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellVerticalEntity>(vertical);
  161. //获取platingcell eneity
  162. _platingCellEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(Module);
  163. //获取对应reservoir eneity
  164. string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module);
  165. _reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(reservoir);
  166. if (!CheckPreCondition())
  167. {
  168. return RState.Failed;
  169. }
  170. _currentCycle = 0;
  171. return Runner.Start(Module, "Run Recipe");
  172. }
  173. /// <summary>
  174. /// 检验前置条件
  175. /// </summary>
  176. /// <returns></returns>
  177. private bool CheckPreCondition()
  178. {
  179. if (_recipe == null)
  180. {
  181. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Recipe is null");
  182. return false;
  183. }
  184. //if (_recipe.DepSteps.Count == 0)
  185. //{
  186. // LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Recipe DepSteps count is 0");
  187. // return false;
  188. //}
  189. CheckAxisHome();
  190. CheckFacility();
  191. CheckModuleAndReservoir();
  192. return true;
  193. }
  194. private bool CheckModuleAndReservoir()
  195. {
  196. if (!_platingCellEntity.IsIdle)
  197. {
  198. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"{Module} is not initialized");
  199. return false;
  200. }
  201. if (!_reservoirEntity.IsIdle)
  202. {
  203. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Releated reseroivr is not initialized");
  204. return false;
  205. }
  206. if (!_reservoirEntity.TemperatureReached)
  207. {
  208. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Releated reseroivr temperature is not reached");
  209. return false;
  210. }
  211. if ("Manual".Equals(_reservoirEntity.PersistentValue.OperatingMode))
  212. {
  213. // 要增加又wafer的判定,待修正
  214. }
  215. return true;
  216. }
  217. /// <summary>
  218. /// 检查马达是否上电且home
  219. /// </summary>
  220. /// <returns></returns>
  221. private bool CheckAxisHome()
  222. {
  223. if (!_rotationAxis.IsSwitchOn)
  224. {
  225. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Rotation Axis is off");
  226. return false;
  227. }
  228. if (!_rotationAxis.IsHomed)
  229. {
  230. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Rotation Axis is not home");
  231. return false;
  232. }
  233. if (!_verticalEntity.IsIdle)
  234. {
  235. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Vertical Axis is not home");
  236. return false;
  237. }
  238. return true;
  239. }
  240. /// <summary>
  241. /// 检查facility
  242. /// </summary>
  243. /// <returns></returns>
  244. private bool CheckFacility()
  245. {
  246. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  247. if (systemFacilities == null)
  248. {
  249. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility is null");
  250. return false;
  251. }
  252. if (!systemFacilities.CDAEnable)
  253. {
  254. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility CDA is off");
  255. return false;
  256. }
  257. if (!systemFacilities.N2Enable)
  258. {
  259. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility N2 is off");
  260. return false;
  261. }
  262. if (!systemFacilities.DIFillEnable)
  263. {
  264. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility DIW is off");
  265. return false;
  266. }
  267. if (systemFacilities.FacilitiesDataDic["CDA1Pressure"].IsError || systemFacilities.FacilitiesDataDic["CDA2Pressure"].IsError)
  268. {
  269. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility CDA Data is in errro range");
  270. return false;
  271. }
  272. if (systemFacilities.FacilitiesDataDic["Nitrogen1APressure"].IsError ||
  273. systemFacilities.FacilitiesDataDic["Nitrogen1BPressure"].IsError ||
  274. systemFacilities.FacilitiesDataDic["Nitrogen2APressure"].IsError ||
  275. systemFacilities.FacilitiesDataDic["Nitrogen2BPressure"].IsError)
  276. {
  277. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility N2 Data is in errro range");
  278. return false;
  279. }
  280. if (systemFacilities.FacilitiesDataDic["DiWaterPressure"].IsError)
  281. {
  282. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility Diw Pressure value is in errro range");
  283. return false;
  284. }
  285. return true;
  286. }
  287. }
  288. }