PlatingCellRunRecipeRoutine.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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,
  195. () => CommonFunction.CheckRoutineStopState(_entryRoutine))
  196. //Deposition
  197. .LoopRun(RunRecipeStep.Deposition, () => { return _depositionRoutine.Start(_recipe, _isZeroCurrent,_powerSupplierStepPeriodDatas) == RState.Running; })
  198. .LoopRunWithStopStatus(RunRecipeStep.CheckDeposition, CheckDepositionEndStatus,
  199. () => CommonFunction.CheckRoutineStopState(_depositionRoutine))
  200. //Reclaim
  201. .LoopRun(RunRecipeStep.Reclaim, () => { return _reclaimRoutine.Start(_recipe, _isZeroCurrent,_device.PowerSupplier) == RState.Running; })
  202. .LoopRunWithStopStatus(RunRecipeStep.CheckReclaim, CheckReclaimEndStatus,
  203. () => CommonFunction.CheckRoutineStopState(_reclaimRoutine))
  204. //Rinse
  205. .LoopRun(RunRecipeStep.Rinse, () => { return _rinseRoutine.Start(_recipe) == RState.Running; })
  206. .LoopRunWithStopStatus(RunRecipeStep.CheckRinse, CheckRinseEndStatus,
  207. () => CommonFunction.CheckRoutineStopState(_rinseRoutine))
  208. //Dry
  209. .LoopRun(RunRecipeStep.Dry, () => { return _dryRoutine.Start(_recipe) == RState.Running; })
  210. .LoopRunWithStopStatus(RunRecipeStep.CheckDry, CheckDryEndStatus,
  211. () => CommonFunction.CheckRoutineStopState(_dryRoutine))
  212. .LoopEnd(RunRecipeStep.LoopEnd, UpdateCycleCount, _delay_1ms)
  213. .End(RunRecipeStep.End, NullFun);
  214. return Runner.Status;
  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. /// 检查interval rinse是否完成
  234. /// </summary>
  235. /// <returns></returns>
  236. private bool CheckInterRinseEndStatus()
  237. {
  238. bool result = CommonFunction.CheckRoutineEndState(_interRinseRoutine);
  239. SubRoutineStep = _interRinseRoutine.CurrentStep;
  240. return result;
  241. }
  242. /// <summary>
  243. /// 检查entry是否完成
  244. /// </summary>
  245. /// <returns></returns>
  246. private bool CheckEntryEndStatus()
  247. {
  248. bool result = CommonFunction.CheckRoutineEndState(_entryRoutine);
  249. SubRoutineStep = _entryRoutine.CurrentStep;
  250. return result;
  251. }
  252. /// <summary>
  253. /// 检查Deposition是否完成
  254. /// </summary>
  255. /// <returns></returns>
  256. private bool CheckDepositionEndStatus()
  257. {
  258. bool result = CommonFunction.CheckRoutineEndState(_depositionRoutine);
  259. SubRoutineStep = _depositionRoutine.CurrentStep;
  260. return result;
  261. }
  262. /// <summary>
  263. /// 检查Reclaim是否完成
  264. /// </summary>
  265. /// <returns></returns>
  266. private bool CheckReclaimEndStatus()
  267. {
  268. bool result = CommonFunction.CheckRoutineEndState(_reclaimRoutine);
  269. SubRoutineStep = _reclaimRoutine.CurrentStep;
  270. return result;
  271. }
  272. /// <summary>
  273. /// 检查Rinse是否完成
  274. /// </summary>
  275. /// <returns></returns>
  276. private bool CheckRinseEndStatus()
  277. {
  278. bool result = CommonFunction.CheckRoutineEndState(_rinseRoutine);
  279. SubRoutineStep = _rinseRoutine.CurrentStep;
  280. return result;
  281. }
  282. /// <summary>
  283. /// 检查Dry是否完成
  284. /// </summary>
  285. /// <returns></returns>
  286. private bool CheckDryEndStatus()
  287. {
  288. bool result = CommonFunction.CheckRoutineEndState(_dryRoutine);
  289. SubRoutineStep = _dryRoutine.CurrentStep;
  290. return result;
  291. }
  292. /// <summary>
  293. /// 启动
  294. /// </summary>
  295. /// <param name="objs"></param>
  296. /// <returns></returns>
  297. public RState Start(params object[] objs)
  298. {
  299. _recipe = objs[0] as DepRecipe;
  300. if (_recipe == null)
  301. {
  302. LOG.WriteLog(eEvent.ERR_METAL, Module, "recipe is null");
  303. return RState.Failed;
  304. }
  305. if (objs.Length > 1)
  306. {
  307. _isDummyLoad = (bool)objs[1];
  308. }
  309. if (objs.Length > 2)
  310. {
  311. _cycle = (int)objs[2];
  312. }
  313. _device = DEVICE.GetDevice<PlatingCellDevice>(Module);
  314. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  315. _rotationProviderAxis = BeckhoffAxisProviderManager.Instance.GetAxisProvider($"{Module}.Rotation");
  316. if (_rotationProviderAxis == null)
  317. {
  318. NotifyError(eEvent.ERR_PLATINGCELL, $"{Module}.Rotation Provider is not exist", 0);
  319. return RState.Failed;
  320. }
  321. //获取vertical entity
  322. string vertical = ModuleMatcherManager.Instance.GetPlatingVerticalByCell(Module);
  323. _verticalEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellVerticalEntity>(vertical);
  324. //获取platingcell eneity
  325. _platingCellEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(Module);
  326. //获取对应reservoir eneity
  327. string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module);
  328. _reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(reservoir);
  329. //获取vertical station信息对象
  330. _verticalBeckhoffStation = BeckhoffStationLocationManager.Instance.GetStationAxis($"{_verticalEntity.Module}", "Vertical");
  331. if (!CheckPreCondition())
  332. {
  333. return RState.Failed;
  334. }
  335. CalculatVerticalPosition(_recipe);
  336. if (!UpdatePowerStepDatas())
  337. {
  338. NotifyError(eEvent.ERR_PLATINGCELL, $"Update Power StepDatas Failed!", 0);
  339. return RState.Failed;
  340. }
  341. _currentCycle = 0;
  342. return Runner.Start(Module, "PlatingCell Run Recipe");
  343. }
  344. /// <summary>
  345. /// 初始化Power step步骤
  346. /// </summary>
  347. private bool UpdatePowerStepDatas()
  348. {
  349. _isZeroCurrent = false;
  350. _isRecipeContainsRevserseRotation = false;
  351. double current = 0;
  352. _totalMicrosecond = 0;
  353. _powerSupplierStepPeriodDatas.Clear();
  354. if (!_recipe.IsEntryTypeCold)//如果entry带上电保护,那么把上电保护的部分加到步阶电流的第一步
  355. {
  356. PowerSupplierStepPeriodData step = new PowerSupplierStepPeriodData(); //上电保护时间(提前上电时间+延迟时间)
  357. step.Hour = 0;
  358. step.Minute = (ushort)((_recipe.PlatingDelay) / 60);
  359. step.Second = (ushort)(_recipe.PlatingDelay % 60);
  360. step.Microsecond = 110; //到达entry位置提前100ms上电,提前一丢丢
  361. step.Voltage = _recipe.DepMaxVoltageWarning;
  362. step.Current = _recipe.EntryCurrent * 0.001; //recipe的entry current单位是毫安
  363. _powerSupplierStepPeriodDatas.Add(step);
  364. }
  365. foreach (var item in _recipe.DepSteps)
  366. {
  367. PowerSupplierStepPeriodData step = new PowerSupplierStepPeriodData();
  368. step.Current = item.CurrentValue;
  369. if(item.CurrentValue > _maxCurrent)
  370. {
  371. _maxCurrent = item.CurrentValue;
  372. }
  373. step.Hour = (ushort)(item.DurartionSeconds / 3600);
  374. step.Minute = (ushort)((item.DurartionSeconds - step.Hour * 3600) / 60);
  375. step.Second = (ushort)(item.DurartionSeconds % 60);
  376. step.Microsecond = 0;
  377. step.Voltage = _recipe.DepMaxVoltageWarning;
  378. _powerSupplierStepPeriodDatas.Add(step);
  379. current += step.Current;
  380. _totalMicrosecond += item.DurartionSeconds * 1000;
  381. }
  382. if (current == 0)
  383. {
  384. _isZeroCurrent = true;
  385. }
  386. if(_maxCurrent < _recipe.EntryCurrent)//最大电流要考虑entry current
  387. {
  388. _maxCurrent = _recipe.EntryCurrent;
  389. }
  390. if(_maxCurrent > 0.6) //设置电源挡位,有超过0.6A的电流则用高档,否则用中挡
  391. {
  392. return _device.PowerSupplier.SetPowerGrade("set power grade high", new object[] { (byte)2 });
  393. }
  394. else
  395. {
  396. return _device.PowerSupplier.SetPowerGrade("set power grade middle", new object[] { (byte)1 });
  397. }
  398. }
  399. /// <summary>
  400. /// 根据dep recipe计算出整个电镀过程中Rotation profile position可能去到的位置
  401. /// </summary>
  402. private void CalculatVerticalPosition(DepRecipe recipe)
  403. {
  404. foreach(var item in recipe.DepSteps)
  405. {
  406. if (item.BiDireaction)
  407. {
  408. _isRecipeContainsRevserseRotation = true;
  409. }
  410. else
  411. {
  412. continue;
  413. }
  414. }
  415. }
  416. /// <summary>
  417. /// 检验前置条件
  418. /// </summary>
  419. /// <returns></returns>
  420. private bool CheckPreCondition()
  421. {
  422. if (_recipe == null)
  423. {
  424. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Recipe is null");
  425. return false;
  426. }
  427. //if (_recipe.DepSteps.Count == 0)
  428. //{
  429. // LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Recipe DepSteps count is 0");
  430. // return false;
  431. //}
  432. if (!CheckAxisHome())
  433. {
  434. NotifyError(eEvent.ERR_PLATINGCELL, "Check Axis home error",0);
  435. return false;
  436. }
  437. if (!CheckFacility())
  438. {
  439. NotifyError(eEvent.ERR_PLATINGCELL, "Check facility error", 0);
  440. return false;
  441. }
  442. if (!CheckModuleAndReservoir())
  443. {
  444. NotifyError(eEvent.ERR_PLATINGCELL, "Check ModuleAndReservoir error", 0);
  445. return false;
  446. }
  447. return true;
  448. }
  449. private bool CheckModuleAndReservoir()
  450. {
  451. if (!_platingCellEntity.IsIdle)
  452. {
  453. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"{Module} is not initialized");
  454. return false;
  455. }
  456. if (!_reservoirEntity.IsIdle)
  457. {
  458. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Releated reseroivr is not initialized");
  459. return false;
  460. }
  461. if (!_reservoirEntity.TemperatureReached)
  462. {
  463. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Releated reseroivr temperature is not reached");
  464. return false;
  465. }
  466. if ("Manual".Equals(_reservoirEntity.PersistentValue.OperatingMode) && !WaferManager.Instance.CheckHasWafer(Module, 0))
  467. {
  468. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Run recipe in manual must has wafer!");
  469. return false;
  470. }
  471. return true;
  472. }
  473. /// <summary>
  474. /// 检查马达是否上电且home
  475. /// </summary>
  476. /// <returns></returns>
  477. private bool CheckAxisHome()
  478. {
  479. if (!_rotationAxis.IsSwitchOn)
  480. {
  481. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Rotation Axis is off");
  482. return false;
  483. }
  484. if (!_rotationAxis.IsHomed)
  485. {
  486. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Rotation Axis is not home");
  487. return false;
  488. }
  489. if (!_verticalEntity.AxisIsHome)
  490. {
  491. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Vertical Axis is not home");
  492. return false;
  493. }
  494. return true;
  495. }
  496. /// <summary>
  497. /// 检查facility
  498. /// </summary>
  499. /// <returns></returns>
  500. private bool CheckFacility()
  501. {
  502. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  503. if (systemFacilities == null)
  504. {
  505. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility is null");
  506. return false;
  507. }
  508. if (!systemFacilities.CDAEnable)
  509. {
  510. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility CDA is off");
  511. return false;
  512. }
  513. if (!systemFacilities.N2Enable)
  514. {
  515. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility N2 is off");
  516. return false;
  517. }
  518. if (!systemFacilities.DIFillEnable)
  519. {
  520. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility DIW is off");
  521. return false;
  522. }
  523. if (systemFacilities.FacilitiesDataDic["CDA1Pressure"].IsError || systemFacilities.FacilitiesDataDic["CDA2Pressure"].IsError)
  524. {
  525. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility CDA Data is in error range");
  526. return false;
  527. }
  528. if (systemFacilities.FacilitiesDataDic["Nitrogen1APressure"].IsError ||
  529. systemFacilities.FacilitiesDataDic["Nitrogen1BPressure"].IsError ||
  530. systemFacilities.FacilitiesDataDic["Nitrogen2APressure"].IsError ||
  531. systemFacilities.FacilitiesDataDic["Nitrogen2BPressure"].IsError)
  532. {
  533. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility N2 Data is in error range");
  534. return false;
  535. }
  536. if (systemFacilities.FacilitiesDataDic["DiWaterPressure"].IsError)
  537. {
  538. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility Diw Pressure value is in error range");
  539. return false;
  540. }
  541. return true;
  542. }
  543. }
  544. }