PlatingCellRunRecipeRoutine.cs 18 KB

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