DummyRinseRunRecipeRoutine.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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.Beckhoff.Station;
  7. using MECF.Framework.Common.RecipeCenter;
  8. using MECF.Framework.Common.Routine;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using MECF.Framework.Common.ToolLayout;
  11. using MECF.Framework.Common.Utilities;
  12. using PunkHPX8_Core;
  13. using PunkHPX8_RT.Devices.AXIS;
  14. using PunkHPX8_RT.Devices.Facilities;
  15. using PunkHPX8_RT.Devices.PlatingCell;
  16. using PunkHPX8_RT.Modules.Reservoir;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. namespace PunkHPX8_RT.Modules.PlatingCell
  23. {
  24. public class DummyRinseRunRecipeRoutine : RoutineBase, IRoutine
  25. {
  26. private enum RunRecipeStep
  27. {
  28. LoopStart,
  29. //interval rinse
  30. LoopCheckVerticalIntervalRinseStation,
  31. IntervalRinseOpenRinseValve,
  32. StartRotation,
  33. WaitRotation,
  34. IntervalRinseCloseRinseValve,
  35. //reclaim
  36. LoopCheckVerticalRelciamStation,
  37. ReclaimChangeRotationSpeed,
  38. ReclaimRotationDelay,
  39. //rinse
  40. LoopCheckVerticalRinseStation,
  41. RinseOpenRinseValve,
  42. RinseChangeRotationSpeed,
  43. RinseRotationDelay,
  44. RinseCloseRinseValve,
  45. //Dry
  46. LoopCheckVerticalDryStation,
  47. DryChangeRotationSpeed,
  48. DryRotationDelay,
  49. RotationStop,
  50. CheckRotationStoped,
  51. LoopEnd,
  52. End
  53. }
  54. #region 常量
  55. private const int ALL_DAY_MILLOSECONDS = 24 * 60 * 60 * 1000;
  56. /// <summary>
  57. /// ROTATION电机转速比例
  58. /// </summary>
  59. private const int SPEED_RATIO = 1;
  60. /// <summary>
  61. /// 电机以500rmp 运行12个小时的位置
  62. /// </summary>
  63. private const int LARGETARGETPOSITION = 12 * 60 * 60 * 500 * 6;
  64. #endregion
  65. #region 内部变量
  66. /// <summary>
  67. /// recipe
  68. /// </summary>
  69. private DqdrRecipe _recipe;
  70. /// <summary>
  71. /// 匹配的platingcell的dep recipe
  72. /// </summary>
  73. private DepRecipe _matchPlatingCellDepDeprecipe;
  74. /// <summary>
  75. /// Platingcell device
  76. /// </summary>
  77. private PlatingCellDevice _device;
  78. /// <summary>
  79. /// Rotation axis
  80. /// </summary>
  81. private JetAxisBase _rotationAxis;
  82. /// <summary>
  83. ///rotation Provider对象
  84. /// </summary>
  85. private BeckhoffProviderAxis _rotationProviderAxis;
  86. /// cycle次数
  87. /// </summary>
  88. private int _cycle;
  89. /// <summary>
  90. /// 当前完成的Cycle次数
  91. /// </summary>
  92. private int _currentCycle;
  93. /// <summary>
  94. /// platingcell entity
  95. /// </summary>
  96. private PlatingCellEntity _platingCellEntity;
  97. /// <summary>
  98. /// 另一边的platingcell entity
  99. /// </summary>
  100. private PlatingCellEntity _matchPlatingCellEntity;
  101. /// <summary>
  102. /// 对应reservoir entity
  103. /// </summary>
  104. private ReservoirEntity _reservoirEntity;
  105. /// <summary>
  106. /// vertical axis entity
  107. /// </summary>
  108. private PlatingCellVerticalEntity _verticalEntity;
  109. /// <summary>
  110. /// run recipe 过程中电机会停的位置(需要根据recipe计算出来)
  111. /// </summary>
  112. #region 属性
  113. #endregion
  114. #endregion
  115. /// <summary>
  116. /// 构造函数
  117. /// </summary>
  118. /// <param name="module"></param>
  119. public DummyRinseRunRecipeRoutine(string module) : base(module)
  120. {
  121. }
  122. /// <summary>
  123. /// 中止
  124. /// </summary>
  125. public void Abort()
  126. {
  127. Runner.Stop("Manual Abort");
  128. }
  129. /// <summary>
  130. /// 监控
  131. /// </summary>
  132. /// <returns></returns>
  133. public RState Monitor()
  134. {
  135. Runner.LoopStart(RunRecipeStep.LoopStart, "Loop Start Cycle Run DummyRinse Recipe Routine", _cycle, NullFun, _delay_1ms)
  136. //interval risne
  137. .LoopRunIfWithStopStatus(RunRecipeStep.LoopCheckVerticalIntervalRinseStation, _matchPlatingCellEntity.IsInRecipe && _recipe.RinseBeforeEntryEnable,
  138. () => CheckVerticalInStation("Rinse", _matchPlatingCellDepDeprecipe.IntervalRinseZoffset), () => { return _matchPlatingCellEntity.IsError; })
  139. .LoopRunIf(RunRecipeStep.IntervalRinseOpenRinseValve, _matchPlatingCellEntity.IsInRecipe && _recipe.RinseBeforeEntryEnable, _device.RinseEnableAction, _delay_1ms)
  140. .LoopRunIf(RunRecipeStep.StartRotation, _matchPlatingCellEntity.IsInRecipe && _recipe.RinseBeforeEntryEnable, () => { return StartRotation(LARGETARGETPOSITION); }, _delay_1ms)
  141. .LoopDelayIf(RunRecipeStep.WaitRotation, _matchPlatingCellEntity.IsInRecipe && _recipe.RinseBeforeEntryEnable, _recipe.IntervalRinseTime * 1000)
  142. .LoopRunIf(RunRecipeStep.IntervalRinseCloseRinseValve, _matchPlatingCellEntity.IsInRecipe && _recipe.RinseBeforeEntryEnable, _device.RinseDisableAction, _delay_1ms)
  143. //Reclaim
  144. .LoopRunIfWithStopStatus(RunRecipeStep.LoopCheckVerticalIntervalRinseStation, _matchPlatingCellEntity.IsInRecipe,
  145. () => CheckVerticalInStation("Reclaim", _matchPlatingCellDepDeprecipe.ReclaimZoffset), () => { return _matchPlatingCellEntity.IsError; })
  146. .LoopRunIf(RunRecipeStep.ReclaimChangeRotationSpeed, _matchPlatingCellEntity.IsInRecipe , () => { return ChangeRotationSpeed(_recipe.ReclaimSpeed); }, _delay_1ms)
  147. .LoopDelayIf(RunRecipeStep.ReclaimRotationDelay, _matchPlatingCellEntity.IsInRecipe , _recipe.ReclaimTime * 1000)
  148. //Rinse
  149. .LoopRunIfWithStopStatus(RunRecipeStep.LoopCheckVerticalRinseStation, _matchPlatingCellEntity.IsInRecipe,
  150. () => CheckVerticalInStation("Rinse", _matchPlatingCellDepDeprecipe.RinseZoffset), () => { return _matchPlatingCellEntity.IsError; })
  151. .LoopRunIf(RunRecipeStep.RinseOpenRinseValve, _matchPlatingCellEntity.IsInRecipe, _device.RinseEnableAction, _delay_1ms)
  152. .LoopRunIf(RunRecipeStep.RinseChangeRotationSpeed, _matchPlatingCellEntity.IsInRecipe, () => { return ChangeRotationSpeed(_recipe.RinseSpeed); }, _delay_1ms)
  153. .LoopDelayIf(RunRecipeStep.RinseRotationDelay, _matchPlatingCellEntity.IsInRecipe, _recipe.RinseTime * 1000)
  154. .LoopRunIf(RunRecipeStep.RinseCloseRinseValve, _matchPlatingCellEntity.IsInRecipe, _device.RinseDisableAction, _delay_1ms)
  155. //Dry
  156. .LoopRunIfWithStopStatus(RunRecipeStep.LoopCheckVerticalDryStation, _matchPlatingCellEntity.IsInRecipe && _matchPlatingCellDepDeprecipe.RinseZoffset != _matchPlatingCellDepDeprecipe.DryZoffset,
  157. () => CheckVerticalInStation("Rinse", _matchPlatingCellDepDeprecipe.DryZoffset), () => { return _matchPlatingCellEntity.IsError; })
  158. .LoopRunIf(RunRecipeStep.DryChangeRotationSpeed, _matchPlatingCellEntity.IsInRecipe, () => { return ChangeRotationSpeed(_recipe.DrySpeed); }, _delay_1ms)
  159. .LoopDelayIf(RunRecipeStep.DryRotationDelay, _matchPlatingCellEntity.IsInRecipe, _recipe.DryTime * 1000)
  160. .LoopRun(RunRecipeStep.RotationStop, _rotationAxis.StopPositionOperation, _delay_1ms)
  161. .LoopRunWithStopStatus(RunRecipeStep.CheckRotationStoped, CheckRotationPositionStatus, CheckRotationPositionRunStop)
  162. .LoopEnd(RunRecipeStep.LoopEnd, UpdateCycleCount, _delay_1ms)
  163. .End(RunRecipeStep.End, NullFun);
  164. return Runner.Status;
  165. }
  166. /// <summary>
  167. /// 查询vertical是否到达某个位置
  168. /// </summary>
  169. /// <returns></returns>
  170. private bool CheckVerticalInStation(string station,double offset)
  171. {
  172. return _verticalEntity.ChecVerticalInPosition(station, offset);
  173. }
  174. /// <summary>
  175. /// rotation开始旋转
  176. /// </summary>
  177. /// <param name="param"></param>
  178. /// <returns></returns>
  179. private bool StartRotation(int targetPosition)
  180. {
  181. bool result = _rotationAxis.ProfilePosition(targetPosition, _recipe.IntervalRinseSpeed * SPEED_RATIO * 6, 0, 0); //rpm->deg/s
  182. if (!result)
  183. {
  184. NotifyError(eEvent.ERR_PLATINGCELL, "Start Rotation is failed", 0);
  185. return false;
  186. }
  187. return true;
  188. }
  189. /// <summary>
  190. /// rotation改变速度
  191. /// </summary>
  192. /// <param name="speed"></param>
  193. /// <returns></returns>
  194. private bool ChangeRotationSpeed(int speed)
  195. {
  196. double _scale = _rotationAxis.ScaleFactor;
  197. speed = (int)Math.Round(_scale * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(speed), 0);
  198. return _rotationAxis.ChangeSpeed(speed);
  199. }
  200. /// <summary>
  201. /// 检验Rotation移动状态
  202. /// </summary>
  203. /// <returns></returns>
  204. private bool CheckRotationPositionStatus()
  205. {
  206. return _rotationAxis.Status == RState.End;
  207. }
  208. /// <summary>
  209. /// 检验Rotation是否运动失败
  210. /// </summary>
  211. /// <returns></returns>
  212. private bool CheckRotationPositionRunStop()
  213. {
  214. return _rotationAxis.Status == RState.Failed || _rotationAxis.Status == RState.Timeout;
  215. }
  216. /// 统计完成的Cycle次数
  217. /// </summary>
  218. /// <returns></returns>
  219. private bool UpdateCycleCount()
  220. {
  221. _currentCycle += 1;
  222. return true;
  223. }
  224. /// <summary>
  225. /// 获取当前Cycle次数
  226. /// </summary>
  227. /// <returns></returns>
  228. public int GetCurrentCycle()
  229. {
  230. return _currentCycle;
  231. }
  232. /// <summary>
  233. /// 启动
  234. /// </summary>
  235. /// <param name="objs"></param>
  236. /// <returns></returns>
  237. public RState Start(params object[] objs)
  238. {
  239. _recipe = objs[0] as DqdrRecipe;
  240. if (_recipe == null)
  241. {
  242. LOG.WriteLog(eEvent.ERR_METAL, Module, "recipe is null");
  243. return RState.Failed;
  244. }
  245. if (objs.Length > 1)
  246. {
  247. _cycle = (int)objs[1];
  248. }
  249. _device = DEVICE.GetDevice<PlatingCellDevice>(Module);
  250. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  251. _rotationProviderAxis = BeckhoffAxisProviderManager.Instance.GetAxisProvider($"{Module}.Rotation");
  252. if (_rotationProviderAxis == null)
  253. {
  254. NotifyError(eEvent.ERR_PLATINGCELL, $"{Module}.Rotation Provider is not exist", 0);
  255. return RState.Failed;
  256. }
  257. //获取相匹配的platingcell 的 vertical entity
  258. string MatchModule = ModuleMatcherManager.Instance.GetMatcherByModule(Module);
  259. string vertical = ModuleMatcherManager.Instance.GetPlatingVerticalByCell(MatchModule);
  260. _verticalEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellVerticalEntity>(vertical);
  261. //获取platingcell eneity
  262. _platingCellEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(Module);
  263. //获取match的platingcell的dep recipe
  264. _matchPlatingCellEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(MatchModule);
  265. _matchPlatingCellDepDeprecipe = _matchPlatingCellEntity.CurrentRecipe;
  266. //获取对应reservoir eneity
  267. string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module);
  268. _reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(reservoir);
  269. if (!CheckPreCondition())
  270. {
  271. return RState.Failed;
  272. }
  273. _currentCycle = 0;
  274. return Runner.Start(Module, "PlatingCell Run DummyRecipe Recipe");
  275. }
  276. /// <summary>
  277. /// 检验前置条件
  278. /// </summary>
  279. /// <returns></returns>
  280. private bool CheckPreCondition()
  281. {
  282. if (_recipe == null)
  283. {
  284. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Recipe is null");
  285. return false;
  286. }
  287. if (!CheckAxisHome())
  288. {
  289. NotifyError(eEvent.ERR_PLATINGCELL, "Check Axis home error", 0);
  290. return false;
  291. }
  292. if (!CheckFacility())
  293. {
  294. NotifyError(eEvent.ERR_PLATINGCELL, "Check facility error", 0);
  295. return false;
  296. }
  297. if (!CheckModuleAndReservoir())
  298. {
  299. NotifyError(eEvent.ERR_PLATINGCELL, "Check ModuleAndReservoir error", 0);
  300. return false;
  301. }
  302. return true;
  303. }
  304. private bool CheckModuleAndReservoir()
  305. {
  306. if (!_platingCellEntity.IsIdle)
  307. {
  308. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"{Module} is not initialized");
  309. return false;
  310. }
  311. if (!_reservoirEntity.IsIdle)
  312. {
  313. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Releated reseroivr is not initialized");
  314. return false;
  315. }
  316. if (!_reservoirEntity.TemperatureReached)
  317. {
  318. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Releated reseroivr temperature is not reached");
  319. return false;
  320. }
  321. if ("Manual".Equals(_reservoirEntity.PersistentValue.OperatingMode) && !WaferManager.Instance.CheckHasWafer(Module, 0))
  322. {
  323. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Run recipe in manual must has wafer!");
  324. return false;
  325. }
  326. return true;
  327. }
  328. /// <summary>
  329. /// 检查马达是否上电且home
  330. /// </summary>
  331. /// <returns></returns>
  332. private bool CheckAxisHome()
  333. {
  334. if (!_rotationAxis.IsSwitchOn)
  335. {
  336. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Rotation Axis is off");
  337. return false;
  338. }
  339. if (!_rotationAxis.IsHomed)
  340. {
  341. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Rotation Axis is not home");
  342. return false;
  343. }
  344. if (!_verticalEntity.AxisIsHome)
  345. {
  346. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Vertical Axis is not home");
  347. return false;
  348. }
  349. return true;
  350. }
  351. /// <summary>
  352. /// 检查facility
  353. /// </summary>
  354. /// <returns></returns>
  355. private bool CheckFacility()
  356. {
  357. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  358. if (systemFacilities == null)
  359. {
  360. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility is null");
  361. return false;
  362. }
  363. if (!systemFacilities.CDAEnable)
  364. {
  365. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility CDA is off");
  366. return false;
  367. }
  368. if (!systemFacilities.N2Enable)
  369. {
  370. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility N2 is off");
  371. return false;
  372. }
  373. if (!systemFacilities.DIFillEnable)
  374. {
  375. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility DIW is off");
  376. return false;
  377. }
  378. if (systemFacilities.FacilitiesDataDic["CDA1Pressure"].IsError || systemFacilities.FacilitiesDataDic["CDA2Pressure"].IsError)
  379. {
  380. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility CDA Data is in error range");
  381. return false;
  382. }
  383. if (systemFacilities.FacilitiesDataDic["Nitrogen1APressure"].IsError ||
  384. systemFacilities.FacilitiesDataDic["Nitrogen1BPressure"].IsError ||
  385. systemFacilities.FacilitiesDataDic["Nitrogen2APressure"].IsError ||
  386. systemFacilities.FacilitiesDataDic["Nitrogen2BPressure"].IsError)
  387. {
  388. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility N2 Data is in error range");
  389. return false;
  390. }
  391. if (systemFacilities.FacilitiesDataDic["DiWaterPressure"].IsError)
  392. {
  393. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility Diw Pressure value is in error range");
  394. return false;
  395. }
  396. return true;
  397. }
  398. }
  399. }