DummyRinseRunRecipeRoutine.cs 18 KB

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