DummyRinseRunRecipeRoutine.cs 18 KB

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