PlatingCellRunRecipeRoutine.cs 11 KB

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