PlatingCellRunRecipeRoutine.cs 17 KB

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