PlatingCellRunRecipeRoutine.cs 21 KB

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