PlatingCellRunRecipeRoutine.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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.RecipeCenter;
  8. using MECF.Framework.Common.Routine;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using MECF.Framework.Common.ToolLayout;
  11. using MECF.Framework.Common.Utilities;
  12. using PunkHPX8_Core;
  13. using PunkHPX8_RT.Devices.AXIS;
  14. using PunkHPX8_RT.Devices.Facilities;
  15. using PunkHPX8_RT.Devices.PlatingCell;
  16. using PunkHPX8_RT.Modules.Reservoir;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. using static Mono.Security.X509.X520;
  23. namespace PunkHPX8_RT.Modules.PlatingCell
  24. {
  25. public class PlatingCellRunRecipeRoutine : RoutineBase, IRoutine
  26. {
  27. private enum RunRecipeStep
  28. {
  29. Delay,
  30. VerticalGotoRinse,
  31. CheckVerticalGotoRinse,
  32. InterRinse,
  33. CheckInterRinse,
  34. RotationStartEntry,
  35. RotationChangeToEntrySpeed,
  36. AngleTilt,
  37. VerticalGotoPlate,
  38. WaitEntryCurrentProtectedFromRinse,
  39. WaitEntryCurrentProtectedFromHome,
  40. EntryCurrentProtected,
  41. CheckVertical,
  42. End
  43. }
  44. #region 常量
  45. private const int ALL_DAY_MILLOSECONDS = 24 * 60 * 60 * 1000;
  46. /// <summary>
  47. /// ROTATION电机转速比例
  48. /// </summary>
  49. private const int SPEED_RATIO = 1;
  50. #endregion
  51. #region 内部变量
  52. /// <summary>
  53. /// recipe
  54. /// </summary>
  55. private DepRecipe _recipe;
  56. /// <summary>
  57. /// Platingcell device
  58. /// </summary>
  59. private PlatingCellDevice _device;
  60. /// <summary>
  61. /// Rotation axis
  62. /// </summary>
  63. private JetAxisBase _rotationAxis;
  64. /// <summary>
  65. ///rotation Provider对象
  66. /// </summary>
  67. private BeckhoffProviderAxis _rotationProviderAxis;
  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. /// interbal rinse routien
  85. /// </summary>
  86. private PlatingCellInterRinseRoutine _interRinseRoutine;
  87. /// <summary>
  88. /// vertical axis entity
  89. /// </summary>
  90. private PlatingCellVerticalEntity _verticalEntity;
  91. /// <summary>
  92. /// vertical 轴的位置数据
  93. /// </summary>
  94. private BeckhoffStationAxis _verticalBeckhoffStation;
  95. /// <summary>
  96. /// recipe中是否存在电机反转
  97. /// </summary>
  98. private bool _isRecipeContainsRevserseRotation = false;
  99. /// <summary>
  100. /// run recipe 过程中电机会停的位置(需要根据recipe计算出来)
  101. /// </summary>
  102. private List<int> _targetPositionList = new List<int>();
  103. #endregion
  104. /// <summary>
  105. /// 构造函数
  106. /// </summary>
  107. /// <param name="module"></param>
  108. public PlatingCellRunRecipeRoutine(string module) : base(module)
  109. {
  110. _interRinseRoutine = new PlatingCellInterRinseRoutine(module);
  111. }
  112. /// <summary>
  113. /// 中止
  114. /// </summary>
  115. public void Abort()
  116. {
  117. Runner.Stop("Manual Abort");
  118. }
  119. /// <summary>
  120. /// 监控
  121. /// </summary>
  122. /// <returns></returns>
  123. public RState Monitor()
  124. { //vertical去rinse位置
  125. Runner.RunIf(RunRecipeStep.VerticalGotoRinse, _recipe.RinseBeforeEntryEnable, () => { return StartVertical("Rinse",_recipe.IntervalRinseZoffset); }, _delay_1ms)
  126. .WaitWithStopConditionIf(RunRecipeStep.CheckVerticalGotoRinse, _recipe.RinseBeforeEntryEnable, CheckVerticalEnd, CheckVerticalError)
  127. //执行interval rinse
  128. .RunIf(RunRecipeStep.InterRinse, _recipe.RinseBeforeEntryEnable, () => { return _interRinseRoutine.Start(_recipe, _rotationAxis, _device, _rotationProviderAxis, _targetPositionList[0]) == RState.Running; })
  129. .WaitWithStopConditionIf(RunRecipeStep.CheckInterRinse, _recipe.RinseBeforeEntryEnable, CheckInterRinseEndStatus,
  130. () => CommonFunction.CheckRoutineStopState(_interRinseRoutine))
  131. //启动Rotation/Rotation 设置为entry 转速
  132. .RunIf(RunRecipeStep.RotationStartEntry, !_recipe.RinseBeforeEntryEnable, RotationStartEntry, _delay_1ms) //没有intercal rinse 在entry开始的时候启动rotation
  133. .RunIf(RunRecipeStep.RotationChangeToEntrySpeed, _recipe.RinseBeforeEntryEnable, () => { return ChangeSpeed(_recipe.EntrySpinSpeed); }, _delay_1ms) //有intercal rinse 直接变速
  134. //Angle tilt 操作
  135. .Run(RunRecipeStep.AngleTilt, _device.HeadtTiltAction, () => { return _device.PlatingCellDeviceData.HeadTilt; }, _delay_1s)
  136. .Run(RunRecipeStep.VerticalGotoPlate, () => { return StartVertical("Plate", _recipe.EntryZoffset); }, _delay_1ms)
  137. .DelayIf(RunRecipeStep.WaitEntryCurrentProtectedFromRinse, !_recipe.RinseBeforeEntryEnable,CalculateVerticaMoveTime("Rinse","Entry") - 110 > 0 ? CalculateVerticaMoveTime("Rinse", "Entry"):0) //提前110ms,多10ms
  138. .DelayIf(RunRecipeStep.WaitEntryCurrentProtectedFromHome, _recipe.RinseBeforeEntryEnable,CalculateVerticaMoveTime("Home","Entry") - 110 > 0 ? CalculateVerticaMoveTime("Home", "Entry") : 0)
  139. .End(RunRecipeStep.End, NullFun);
  140. return Runner.Status;
  141. }
  142. /// <summary>
  143. /// 计算vertical 从一个位置移动到另一个位置用时
  144. /// </summary>
  145. /// <param name="sourceLocation"></param>
  146. /// <param name="destinationLocation"></param>
  147. /// <returns>返回值单位毫秒</returns>
  148. private int CalculateVerticaMoveTime(string sourceLocation,string destinationLocation)
  149. {
  150. Station sourceStation = _verticalBeckhoffStation.Stations.FirstOrDefault(p => p.Name == $"{_verticalEntity.Module}.{sourceLocation}");
  151. Station destinationStation = _verticalBeckhoffStation.Stations.FirstOrDefault(p => p.Name == $"{_verticalEntity.Module}.{destinationLocation}");
  152. Double.TryParse(sourceStation.Position, out double sourcePosition);
  153. Double.TryParse(destinationStation.Position, out double destinationPosition);
  154. double time = Math.Abs(destinationPosition - sourcePosition) / _verticalEntity.MotionData.ProfileVelocity * 10;
  155. if (time <= 0)
  156. {
  157. NotifyError(eEvent.WARN_PLATINGCELL, "Calculate Vertica Move Time is 0", 0);
  158. return 0;
  159. }
  160. return (int)time;
  161. }
  162. /// <summary>
  163. /// change speed
  164. /// </summary>
  165. /// <returns></returns>
  166. private bool ChangeSpeed(int speed) //参数speed单位是rmp
  167. {
  168. double realSpeed = BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(speed);
  169. bool result = _rotationAxis.ChangeSpeed((int)realSpeed);
  170. if (!result)
  171. {
  172. NotifyError(eEvent.ERR_PLATINGCELL, "Change Speed failed", 0);
  173. return false;
  174. }
  175. return true;
  176. }
  177. private bool CheckInterRinseEndStatus()
  178. {
  179. bool result = CommonFunction.CheckRoutineEndState(_interRinseRoutine);
  180. SubRoutineStep = _interRinseRoutine.CurrentStep;
  181. return result;
  182. }
  183. /// <summary>
  184. /// rotation 从entry步骤开始旋转
  185. /// </summary>
  186. /// <returns></returns>
  187. private bool RotationStartEntry()
  188. {
  189. bool result = _rotationAxis.ProfilePosition(_targetPositionList[0], _recipe.IntervalRinseSpeed * SPEED_RATIO, 0, 0);
  190. if (!result)
  191. {
  192. NotifyError(eEvent.ERR_PLATINGCELL, "Start Rotation is failed", 0);
  193. return false;
  194. }
  195. return true;
  196. }
  197. /// <summary>
  198. /// vertical 运行
  199. /// </summary>
  200. /// <param name="positionName"></param> 目标位置名称
  201. /// <param name="offset"></param> 偏移量
  202. /// <returns></returns>
  203. private bool StartVertical(string positionName,double offset)
  204. {
  205. double position = 0;
  206. Station station = _verticalBeckhoffStation.Stations.FirstOrDefault(p => p.Name == $"{_verticalEntity.Module}.{positionName}");
  207. if (station != null)
  208. {
  209. if(!Double.TryParse(station.Position, out position))
  210. {
  211. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "vertical station position is error");
  212. return false;
  213. }
  214. }
  215. else
  216. {
  217. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"vertical station {_verticalEntity.Module}.{positionName} is null");
  218. return false;
  219. }
  220. return _verticalEntity.CheckToPostMessage<PlatingCellVerticalState, PlatingCellVerticalEntity.VerticalMsg>(Aitex.Core.RT.Log.eEvent.INFO_PLATINGCELL,
  221. Module, (int)PlatingCellVerticalEntity.VerticalMsg.Position, position + offset);
  222. }
  223. /// <summary>
  224. /// 检验垂直电机是否运动完成
  225. /// </summary>
  226. /// <returns></returns>
  227. private bool CheckVerticalEnd()
  228. {
  229. return _verticalEntity.IsIdle;
  230. }
  231. /// <summary>
  232. /// 检验垂直是否出现错误
  233. /// </summary>
  234. /// <returns></returns>
  235. private bool CheckVerticalError()
  236. {
  237. return _verticalEntity.IsError;
  238. }
  239. /// <summary>
  240. /// 启动
  241. /// </summary>
  242. /// <param name="objs"></param>
  243. /// <returns></returns>
  244. public RState Start(params object[] objs)
  245. {
  246. _recipe = objs[0] as DepRecipe;
  247. if (_recipe == null)
  248. {
  249. LOG.WriteLog(eEvent.ERR_METAL, Module, "recipe is null");
  250. return RState.Failed;
  251. }
  252. if (objs.Length > 1)
  253. {
  254. _cycle = (int)objs[1];
  255. }
  256. _device = DEVICE.GetDevice<PlatingCellDevice>(Module);
  257. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  258. _rotationProviderAxis = BeckhoffAxisProviderManager.Instance.GetAxisProvider($"{Module}.Rotation");
  259. if (_rotationProviderAxis == null)
  260. {
  261. NotifyError(eEvent.ERR_PLATINGCELL, $"{Module}.Rotation Provider is not exist", 0);
  262. return RState.Failed;
  263. }
  264. //获取vertical entity
  265. string vertical = ModuleMatcherManager.Instance.GetPlatingVerticalByCell(Module);
  266. _verticalEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellVerticalEntity>(vertical);
  267. //获取platingcell eneity
  268. _platingCellEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(Module);
  269. //获取对应reservoir eneity
  270. string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module);
  271. _reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(reservoir);
  272. //获取vertical station信息对象
  273. _verticalBeckhoffStation = BeckhoffStationLocationManager.Instance.GetStationAxis($"{_verticalEntity.Module}", "Vertical");
  274. if (!CheckPreCondition())
  275. {
  276. return RState.Failed;
  277. }
  278. CalculatVerticalPosition(_recipe);
  279. _currentCycle = 0;
  280. return Runner.Start(Module, "Run Recipe");
  281. }
  282. /// <summary>
  283. /// 根据dep recipe计算出整个电镀过程中Rotation profile position可能去到的位置
  284. /// </summary>
  285. private void CalculatVerticalPosition(DepRecipe recipe)
  286. {
  287. foreach(var item in recipe.DepSteps)
  288. {
  289. if (item.BiDireaction)
  290. {
  291. _isRecipeContainsRevserseRotation = true;
  292. }
  293. else
  294. {
  295. continue;
  296. }
  297. }
  298. //不存在双向旋转直接给roation一个很大的值,电镀完成后再停止
  299. if (!_isRecipeContainsRevserseRotation)
  300. {
  301. _targetPositionList.Add(12 * 60 * 60 * 500 * 6); //以500rmp 运行12个小时的位置
  302. }
  303. else
  304. {
  305. }
  306. }
  307. /// <summary>
  308. /// 检验前置条件
  309. /// </summary>
  310. /// <returns></returns>
  311. private bool CheckPreCondition()
  312. {
  313. if (_recipe == null)
  314. {
  315. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Recipe is null");
  316. return false;
  317. }
  318. //if (_recipe.DepSteps.Count == 0)
  319. //{
  320. // LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Recipe DepSteps count is 0");
  321. // return false;
  322. //}
  323. CheckAxisHome();
  324. CheckFacility();
  325. CheckModuleAndReservoir();
  326. return true;
  327. }
  328. private bool CheckModuleAndReservoir()
  329. {
  330. if (!_platingCellEntity.IsIdle)
  331. {
  332. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"{Module} is not initialized");
  333. return false;
  334. }
  335. if (!_reservoirEntity.IsIdle)
  336. {
  337. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Releated reseroivr is not initialized");
  338. return false;
  339. }
  340. if (!_reservoirEntity.TemperatureReached)
  341. {
  342. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Releated reseroivr temperature is not reached");
  343. return false;
  344. }
  345. if ("Manual".Equals(_reservoirEntity.PersistentValue.OperatingMode) && !WaferManager.Instance.CheckHasWafer(Module, 0))
  346. {
  347. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Run recipe in manual must has wafer!");
  348. return false;
  349. }
  350. return true;
  351. }
  352. /// <summary>
  353. /// 检查马达是否上电且home
  354. /// </summary>
  355. /// <returns></returns>
  356. private bool CheckAxisHome()
  357. {
  358. if (!_rotationAxis.IsSwitchOn)
  359. {
  360. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Rotation Axis is off");
  361. return false;
  362. }
  363. if (!_rotationAxis.IsHomed)
  364. {
  365. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Rotation Axis is not home");
  366. return false;
  367. }
  368. if (!_verticalEntity.IsIdle)
  369. {
  370. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Vertical Axis is not home");
  371. return false;
  372. }
  373. return true;
  374. }
  375. /// <summary>
  376. /// 检查facility
  377. /// </summary>
  378. /// <returns></returns>
  379. private bool CheckFacility()
  380. {
  381. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  382. if (systemFacilities == null)
  383. {
  384. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility is null");
  385. return false;
  386. }
  387. if (!systemFacilities.CDAEnable)
  388. {
  389. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility CDA is off");
  390. return false;
  391. }
  392. if (!systemFacilities.N2Enable)
  393. {
  394. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility N2 is off");
  395. return false;
  396. }
  397. if (!systemFacilities.DIFillEnable)
  398. {
  399. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility DIW is off");
  400. return false;
  401. }
  402. if (systemFacilities.FacilitiesDataDic["CDA1Pressure"].IsError || systemFacilities.FacilitiesDataDic["CDA2Pressure"].IsError)
  403. {
  404. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility CDA Data is in errro range");
  405. return false;
  406. }
  407. if (systemFacilities.FacilitiesDataDic["Nitrogen1APressure"].IsError ||
  408. systemFacilities.FacilitiesDataDic["Nitrogen1BPressure"].IsError ||
  409. systemFacilities.FacilitiesDataDic["Nitrogen2APressure"].IsError ||
  410. systemFacilities.FacilitiesDataDic["Nitrogen2BPressure"].IsError)
  411. {
  412. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility N2 Data is in errro range");
  413. return false;
  414. }
  415. if (systemFacilities.FacilitiesDataDic["DiWaterPressure"].IsError)
  416. {
  417. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility Diw Pressure value is in errro range");
  418. return false;
  419. }
  420. return true;
  421. }
  422. }
  423. }