PlatingCellRunRecipeRoutine.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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.CommonData.PowerSupplier;
  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.Devices.PowerSupplier;
  18. using PunkHPX8_RT.Modules.Reservoir;
  19. using SecsGem.Core.ItemModel;
  20. using System;
  21. using System.Collections.Generic;
  22. using System.Diagnostics;
  23. using System.Linq;
  24. using System.Text;
  25. using System.Threading.Tasks;
  26. using static Mono.Security.X509.X520;
  27. namespace PunkHPX8_RT.Modules.PlatingCell
  28. {
  29. public class PlatingCellRunRecipeRoutine : RoutineBase, IRoutine
  30. {
  31. private enum RunRecipeStep
  32. {
  33. LoopStart,
  34. InterRinse,
  35. CheckInterRinse,
  36. Entry,
  37. CheckEntry,
  38. Deposition,
  39. CheckDeposition,
  40. Reclaim,
  41. CheckReclaim,
  42. Rinse,
  43. CheckRinse,
  44. Dry,
  45. CheckDry,
  46. LoopEnd,
  47. End
  48. }
  49. #region 常量
  50. private const int ALL_DAY_MILLOSECONDS = 24 * 60 * 60 * 1000;
  51. /// <summary>
  52. /// ROTATION电机转速比例
  53. /// </summary>
  54. private const int SPEED_RATIO = 1;
  55. #endregion
  56. #region 内部变量
  57. /// <summary>
  58. /// recipe
  59. /// </summary>
  60. private DepRecipe _recipe;
  61. /// <summary>
  62. /// Platingcell device
  63. /// </summary>
  64. private PlatingCellDevice _device;
  65. /// <summary>
  66. /// Rotation axis
  67. /// </summary>
  68. private JetAxisBase _rotationAxis;
  69. /// <summary>
  70. ///rotation Provider对象
  71. /// </summary>
  72. private BeckhoffProviderAxis _rotationProviderAxis;
  73. ///是否选中dummy load
  74. /// </summary>
  75. private bool _isDummyLoad;
  76. /// cycle次数
  77. /// </summary>
  78. private int _cycle;
  79. /// <summary>
  80. /// 当前完成的Cycle次数
  81. /// </summary>
  82. private int _currentCycle;
  83. /// <summary>
  84. /// platingcell entity
  85. /// </summary>
  86. private PlatingCellEntity _platingCellEntity;
  87. /// <summary>
  88. /// 对应reservoir entity
  89. /// </summary>
  90. private ReservoirEntity _reservoirEntity;
  91. /// <summary>
  92. /// vertical axis entity
  93. /// </summary>
  94. private PlatingCellVerticalEntity _verticalEntity;
  95. /// <summary>
  96. /// vertical 轴的位置数据
  97. /// </summary>
  98. private BeckhoffStationAxis _verticalBeckhoffStation;
  99. /// <summary>
  100. /// recipe中是否存在电机反转
  101. /// </summary>
  102. private bool _isRecipeContainsRevserseRotation = false;
  103. /// <summary>
  104. /// run recipe 过程中电机会停的位置(需要根据recipe计算出来)
  105. /// </summary>
  106. private List<int> _targetPositionList = new List<int>();
  107. #region 电镀通电相关
  108. /// <summary>
  109. /// 不通电
  110. /// </summary>
  111. private bool _isZeroCurrent = false;
  112. /// <summary>
  113. /// Power step集合
  114. /// </summary>
  115. List<PowerSupplierStepPeriodData> _powerSupplierStepPeriodDatas = new List<PowerSupplierStepPeriodData>();
  116. /// <summary>
  117. /// 记录dep recipe中出现的最大电流,用于启动电源前切换挡位
  118. /// </summary>
  119. private double _maxCurrent = 0;
  120. /// <summary>
  121. /// 通电总时长
  122. /// </summary>
  123. private int _totalMicrosecond = 0;
  124. /// <summary>
  125. /// Plating启动时间
  126. /// </summary>
  127. private DateTime _platingStartTime;
  128. #endregion
  129. #region routine
  130. /// <summary>
  131. /// interbal rinse routien
  132. /// </summary>
  133. private PlatingCellInterRinseRoutine _interRinseRoutine;
  134. /// <summary>
  135. /// entry routien
  136. /// </summary>
  137. private PlatingCellEntryRoutine _entryRoutine;
  138. /// <summary>
  139. /// entry routien
  140. /// </summary>
  141. private PlatingCellDepositionRoutine _depositionRoutine;
  142. /// <summary>
  143. /// reclaim routien
  144. /// </summary>
  145. private PlatingCellReclaimRoutine _reclaimRoutine;
  146. /// <summary>
  147. /// Rinse routien
  148. /// </summary>
  149. private PlatingCellRinseRoutine _rinseRoutine;
  150. /// <summary>
  151. /// Dry routien
  152. /// </summary>
  153. private PlatingCellDryRoutine _dryRoutine;
  154. #endregion
  155. #region 属性
  156. #endregion
  157. #endregion
  158. /// <summary>
  159. /// 构造函数
  160. /// </summary>
  161. /// <param name="module"></param>
  162. public PlatingCellRunRecipeRoutine(string module) : base(module)
  163. {
  164. _interRinseRoutine = new PlatingCellInterRinseRoutine(module);
  165. _entryRoutine = new PlatingCellEntryRoutine(module);
  166. _depositionRoutine = new PlatingCellDepositionRoutine(module);
  167. _reclaimRoutine = new PlatingCellReclaimRoutine(module);
  168. _rinseRoutine = new PlatingCellRinseRoutine(module);
  169. _dryRoutine = new PlatingCellDryRoutine(module);
  170. }
  171. /// <summary>
  172. /// 中止
  173. /// </summary>
  174. public void Abort()
  175. {
  176. Runner.Stop("Manual Abort");
  177. }
  178. /// <summary>
  179. /// 监控
  180. /// </summary>
  181. /// <returns></returns>
  182. public RState Monitor()
  183. {
  184. Runner.LoopStart(RunRecipeStep.LoopStart, "Loop Start Cycle Run Platingcell Recipe Routine", _cycle, NullFun, _delay_1ms)
  185. //interval rinse
  186. .LoopRunIf(RunRecipeStep.InterRinse, _recipe.RinseBeforeEntryEnable, () => { return _interRinseRoutine.Start(_recipe, _targetPositionList[0]) == RState.Running; })
  187. .LoopRunIfWithStopStatus(RunRecipeStep.CheckInterRinse, _recipe.RinseBeforeEntryEnable, CheckInterRinseEndStatus,
  188. () => CommonFunction.CheckRoutineStopState(_interRinseRoutine))
  189. //entry
  190. .LoopRun(RunRecipeStep.Entry, () => { return _entryRoutine.Start(_recipe, _targetPositionList[0], _powerSupplierStepPeriodDatas,_platingStartTime) == RState.Running; })
  191. .LoopRunWithStopStatus(RunRecipeStep.CheckEntry, CheckEntryEndStatus,
  192. () => CommonFunction.CheckRoutineStopState(_entryRoutine))
  193. //Deposition
  194. .LoopRun(RunRecipeStep.Deposition, () => { return _depositionRoutine.Start(_recipe, _isZeroCurrent, _isRecipeContainsRevserseRotation,_powerSupplierStepPeriodDatas, _platingStartTime) == RState.Running; })
  195. .LoopRunWithStopStatus(RunRecipeStep.CheckDeposition, CheckDepositionEndStatus,
  196. () => CommonFunction.CheckRoutineStopState(_depositionRoutine))
  197. //Reclaim
  198. .LoopRun(RunRecipeStep.Reclaim, () => { return _reclaimRoutine.Start(_recipe, _isZeroCurrent) == RState.Running; })
  199. .LoopRunWithStopStatus(RunRecipeStep.CheckReclaim, CheckReclaimEndStatus,
  200. () => CommonFunction.CheckRoutineStopState(_reclaimRoutine))
  201. //Rinse
  202. .LoopRun(RunRecipeStep.Rinse, () => { return _rinseRoutine.Start(_recipe) == RState.Running; })
  203. .LoopRunWithStopStatus(RunRecipeStep.CheckRinse, CheckRinseEndStatus,
  204. () => CommonFunction.CheckRoutineStopState(_rinseRoutine))
  205. //Dry
  206. .LoopRun(RunRecipeStep.Dry, () => { return _dryRoutine.Start(_recipe) == RState.Running; })
  207. .LoopRunWithStopStatus(RunRecipeStep.CheckDry, CheckDryEndStatus,
  208. () => CommonFunction.CheckRoutineStopState(_dryRoutine))
  209. .LoopEnd(RunRecipeStep.LoopEnd, UpdateCycleCount, _delay_1ms)
  210. .End(RunRecipeStep.End, NullFun);
  211. return Runner.Status;
  212. }
  213. /// 统计完成的Cycle次数
  214. /// </summary>
  215. /// <returns></returns>
  216. private bool UpdateCycleCount()
  217. {
  218. _currentCycle += 1;
  219. return true;
  220. }
  221. /// <summary>
  222. /// 获取当前Cycle次数
  223. /// </summary>
  224. /// <returns></returns>
  225. public int GetCurrentCycle()
  226. {
  227. return _currentCycle;
  228. }
  229. /// <summary>
  230. /// 检查interval rinse是否完成
  231. /// </summary>
  232. /// <returns></returns>
  233. private bool CheckInterRinseEndStatus()
  234. {
  235. bool result = CommonFunction.CheckRoutineEndState(_interRinseRoutine);
  236. SubRoutineStep = _interRinseRoutine.CurrentStep;
  237. return result;
  238. }
  239. /// <summary>
  240. /// 检查entry是否完成
  241. /// </summary>
  242. /// <returns></returns>
  243. private bool CheckEntryEndStatus()
  244. {
  245. bool result = CommonFunction.CheckRoutineEndState(_entryRoutine);
  246. SubRoutineStep = _entryRoutine.CurrentStep;
  247. return result;
  248. }
  249. /// <summary>
  250. /// 检查Deposition是否完成
  251. /// </summary>
  252. /// <returns></returns>
  253. private bool CheckDepositionEndStatus()
  254. {
  255. bool result = CommonFunction.CheckRoutineEndState(_depositionRoutine);
  256. SubRoutineStep = _depositionRoutine.CurrentStep;
  257. return result;
  258. }
  259. /// <summary>
  260. /// 检查Reclaim是否完成
  261. /// </summary>
  262. /// <returns></returns>
  263. private bool CheckReclaimEndStatus()
  264. {
  265. bool result = CommonFunction.CheckRoutineEndState(_reclaimRoutine);
  266. SubRoutineStep = _reclaimRoutine.CurrentStep;
  267. return result;
  268. }
  269. /// <summary>
  270. /// 检查Rinse是否完成
  271. /// </summary>
  272. /// <returns></returns>
  273. private bool CheckRinseEndStatus()
  274. {
  275. bool result = CommonFunction.CheckRoutineEndState(_rinseRoutine);
  276. SubRoutineStep = _rinseRoutine.CurrentStep;
  277. return result;
  278. }
  279. /// <summary>
  280. /// 检查Dry是否完成
  281. /// </summary>
  282. /// <returns></returns>
  283. private bool CheckDryEndStatus()
  284. {
  285. bool result = CommonFunction.CheckRoutineEndState(_dryRoutine);
  286. SubRoutineStep = _dryRoutine.CurrentStep;
  287. return result;
  288. }
  289. /// <summary>
  290. /// 启动
  291. /// </summary>
  292. /// <param name="objs"></param>
  293. /// <returns></returns>
  294. public RState Start(params object[] objs)
  295. {
  296. _recipe = objs[0] as DepRecipe;
  297. if (_recipe == null)
  298. {
  299. LOG.WriteLog(eEvent.ERR_METAL, Module, "recipe is null");
  300. return RState.Failed;
  301. }
  302. if (objs.Length > 1)
  303. {
  304. _isDummyLoad = (bool)objs[1];
  305. }
  306. if (objs.Length > 2)
  307. {
  308. _cycle = (int)objs[2];
  309. }
  310. _device = DEVICE.GetDevice<PlatingCellDevice>(Module);
  311. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  312. _rotationProviderAxis = BeckhoffAxisProviderManager.Instance.GetAxisProvider($"{Module}.Rotation");
  313. if (_rotationProviderAxis == null)
  314. {
  315. NotifyError(eEvent.ERR_PLATINGCELL, $"{Module}.Rotation Provider is not exist", 0);
  316. return RState.Failed;
  317. }
  318. //获取vertical entity
  319. string vertical = ModuleMatcherManager.Instance.GetPlatingVerticalByCell(Module);
  320. _verticalEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellVerticalEntity>(vertical);
  321. //获取platingcell eneity
  322. _platingCellEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(Module);
  323. //获取对应reservoir eneity
  324. string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module);
  325. _reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(reservoir);
  326. //获取vertical station信息对象
  327. _verticalBeckhoffStation = BeckhoffStationLocationManager.Instance.GetStationAxis($"{_verticalEntity.Module}", "Vertical");
  328. if (!CheckPreCondition())
  329. {
  330. return RState.Failed;
  331. }
  332. CalculatVerticalPosition(_recipe);
  333. if (!UpdatePowerStepDatas())
  334. {
  335. NotifyError(eEvent.ERR_PLATINGCELL, $"Update Power StepDatas Failed!", 0);
  336. return RState.Failed;
  337. }
  338. _currentCycle = 0;
  339. return Runner.Start(Module, "PlatingCell Run Recipe");
  340. }
  341. /// <summary>
  342. /// 初始化Power step步骤
  343. /// </summary>
  344. private bool UpdatePowerStepDatas()
  345. {
  346. _isZeroCurrent = false;
  347. _isRecipeContainsRevserseRotation = false;
  348. double current = 0;
  349. _totalMicrosecond = 0;
  350. _powerSupplierStepPeriodDatas.Clear();
  351. if (!_recipe.IsEntryTypeCold)//如果entry带上电保护,那么把上电保护的部分加到步阶电流的第一步
  352. {
  353. PowerSupplierStepPeriodData step = new PowerSupplierStepPeriodData(); //上电保护时间(提前上电时间+延迟时间)
  354. step.Hour = 0;
  355. step.Minute = (ushort)((_recipe.PlatingDelay) / 60);
  356. step.Second = (ushort)(_recipe.PlatingDelay % 60);
  357. step.Microsecond = 110; //到达entry位置提前100ms上电,提前一丢丢
  358. step.Voltage = _recipe.DepMaxVoltageWarning;
  359. _powerSupplierStepPeriodDatas.Add(step);
  360. }
  361. foreach (var item in _recipe.DepSteps)
  362. {
  363. PowerSupplierStepPeriodData step = new PowerSupplierStepPeriodData();
  364. step.Current = item.CurrentValue;
  365. if(item.CurrentValue > _maxCurrent)
  366. {
  367. _maxCurrent = item.CurrentValue;
  368. }
  369. step.Hour = (ushort)(item.DurartionSeconds / 3600);
  370. step.Minute = (ushort)((item.DurartionSeconds - step.Hour * 3600) / 60);
  371. step.Second = (ushort)(item.DurartionSeconds % 60);
  372. step.Microsecond = 0;
  373. step.Voltage = _recipe.DepMaxVoltageWarning;
  374. _powerSupplierStepPeriodDatas.Add(step);
  375. current += step.Current;
  376. _totalMicrosecond += item.DurartionSeconds * 1000;
  377. }
  378. if (current == 0)
  379. {
  380. _isZeroCurrent = true;
  381. }
  382. if(_maxCurrent > 0.6) //设置电源挡位,有超过0.6A的电流则用高档,否则用中挡
  383. {
  384. return _device.PowerSupplier.SetPowerGrade("set power grade high", new object[] { (byte)2 });
  385. }
  386. else
  387. {
  388. return _device.PowerSupplier.SetPowerGrade("set power grade middle", new object[] { (byte)1 });
  389. }
  390. }
  391. /// <summary>
  392. /// 根据dep recipe计算出整个电镀过程中Rotation profile position可能去到的位置
  393. /// </summary>
  394. private void CalculatVerticalPosition(DepRecipe recipe)
  395. {
  396. foreach(var item in recipe.DepSteps)
  397. {
  398. if (item.BiDireaction)
  399. {
  400. _isRecipeContainsRevserseRotation = true;
  401. }
  402. else
  403. {
  404. continue;
  405. }
  406. }
  407. _targetPositionList.Add(12 * 60 * 60 * 500 * 6); //以500rmp 运行12个小时的位置
  408. }
  409. /// <summary>
  410. /// 检验前置条件
  411. /// </summary>
  412. /// <returns></returns>
  413. private bool CheckPreCondition()
  414. {
  415. if (_recipe == null)
  416. {
  417. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Recipe is null");
  418. return false;
  419. }
  420. //if (_recipe.DepSteps.Count == 0)
  421. //{
  422. // LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Recipe DepSteps count is 0");
  423. // return false;
  424. //}
  425. if (!CheckAxisHome())
  426. {
  427. NotifyError(eEvent.ERR_PLATINGCELL, "Check Axis home error",0);
  428. return false;
  429. }
  430. if (!CheckFacility())
  431. {
  432. NotifyError(eEvent.ERR_PLATINGCELL, "Check facility error", 0);
  433. return false;
  434. }
  435. if (!CheckModuleAndReservoir())
  436. {
  437. NotifyError(eEvent.ERR_PLATINGCELL, "Check ModuleAndReservoir error", 0);
  438. return false;
  439. }
  440. return true;
  441. }
  442. private bool CheckModuleAndReservoir()
  443. {
  444. if (!_platingCellEntity.IsIdle)
  445. {
  446. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"{Module} is not initialized");
  447. return false;
  448. }
  449. if (!_reservoirEntity.IsIdle)
  450. {
  451. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Releated reseroivr is not initialized");
  452. return false;
  453. }
  454. if (!_reservoirEntity.TemperatureReached)
  455. {
  456. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Releated reseroivr temperature is not reached");
  457. return false;
  458. }
  459. if ("Manual".Equals(_reservoirEntity.PersistentValue.OperatingMode) && !WaferManager.Instance.CheckHasWafer(Module, 0))
  460. {
  461. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Run recipe in manual must has wafer!");
  462. return false;
  463. }
  464. return true;
  465. }
  466. /// <summary>
  467. /// 检查马达是否上电且home
  468. /// </summary>
  469. /// <returns></returns>
  470. private bool CheckAxisHome()
  471. {
  472. if (!_rotationAxis.IsSwitchOn)
  473. {
  474. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Rotation Axis is off");
  475. return false;
  476. }
  477. if (!_rotationAxis.IsHomed)
  478. {
  479. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Rotation Axis is not home");
  480. return false;
  481. }
  482. if (!_verticalEntity.IsIdle)
  483. {
  484. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Vertical Axis is not home");
  485. return false;
  486. }
  487. return true;
  488. }
  489. /// <summary>
  490. /// 检查facility
  491. /// </summary>
  492. /// <returns></returns>
  493. private bool CheckFacility()
  494. {
  495. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  496. if (systemFacilities == null)
  497. {
  498. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility is null");
  499. return false;
  500. }
  501. if (!systemFacilities.CDAEnable)
  502. {
  503. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility CDA is off");
  504. return false;
  505. }
  506. if (!systemFacilities.N2Enable)
  507. {
  508. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility N2 is off");
  509. return false;
  510. }
  511. if (!systemFacilities.DIFillEnable)
  512. {
  513. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility DIW is off");
  514. return false;
  515. }
  516. if (systemFacilities.FacilitiesDataDic["CDA1Pressure"].IsError || systemFacilities.FacilitiesDataDic["CDA2Pressure"].IsError)
  517. {
  518. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility CDA Data is in error range");
  519. return false;
  520. }
  521. if (systemFacilities.FacilitiesDataDic["Nitrogen1APressure"].IsError ||
  522. systemFacilities.FacilitiesDataDic["Nitrogen1BPressure"].IsError ||
  523. systemFacilities.FacilitiesDataDic["Nitrogen2APressure"].IsError ||
  524. systemFacilities.FacilitiesDataDic["Nitrogen2BPressure"].IsError)
  525. {
  526. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility N2 Data is in error range");
  527. return false;
  528. }
  529. if (systemFacilities.FacilitiesDataDic["DiWaterPressure"].IsError)
  530. {
  531. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility Diw Pressure value is in error range");
  532. return false;
  533. }
  534. return true;
  535. }
  536. }
  537. }