PlatingCellInitializeRoutine.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using MECF.Framework.Common.Persistent.Reservoirs;
  6. using MECF.Framework.Common.RecipeCenter;
  7. using MECF.Framework.Common.Routine;
  8. using MECF.Framework.Common.ToolLayout;
  9. using PunkHPX8_Core;
  10. using PunkHPX8_RT.Devices.AXIS;
  11. using PunkHPX8_RT.Devices.PlatingCell;
  12. using PunkHPX8_RT.Devices.Reservoir;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Diagnostics.Eventing.Reader;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using System.Windows.Media.Imaging;
  20. namespace PunkHPX8_RT.Modules.PlatingCell
  21. {
  22. public class PlatingCellInitializeRoutine : RoutineBase, IRoutine
  23. {
  24. private enum InitializeStep
  25. {
  26. CheckPowerSupplierConnected,
  27. CheckClamShellClosed,
  28. VerticalGotoLoad,
  29. VerticalGotoLoadCheck,
  30. RotationHome,
  31. RotationHomeCheck,
  32. AngleEntryTilt,
  33. AngleEntryVertical,
  34. CheckClamShellOpen,
  35. OpenCAAndANIsoltaionValve,
  36. CheckCellFlowWait,
  37. CheckCellFlow,
  38. OpenCCRAndRinseValve,
  39. RinseDripIdleDelay,
  40. CloseCCRAndRinseValve,
  41. End
  42. }
  43. #region 内部变量
  44. /// <summary>
  45. /// 持久化对象
  46. /// </summary>
  47. private PlatingCellPersistentValue _persistentValue;
  48. /// <summary>
  49. /// 设备对象
  50. /// </summary>
  51. private PlatingCellDevice _platingCellDevice;
  52. /// <summary>
  53. /// 槽体对象
  54. /// </summary>
  55. private ReservoirDevice _reservoirDevice;
  56. /// <summary>
  57. /// Reservoir Recipe
  58. /// </summary>
  59. private ResRecipe _resRecipe;
  60. /// <summary>
  61. /// vertical axis
  62. /// </summary>
  63. private JetAxisBase _verticalAxis;
  64. /// <summary>
  65. /// Rotation axis
  66. /// </summary>
  67. private JetAxisBase _rotationAxis;
  68. /// <summary>
  69. /// _flowFaultHoldOffTime 单位ms
  70. /// </summary>
  71. private int _flowFaultHoldOffTime = 1000;
  72. /// <summary>
  73. /// Cell Flow Start Low Limit
  74. /// </summary>
  75. private double _cellFlowStartLowLimit = 3.0;
  76. /// <summary>
  77. /// Anode flow start low limit
  78. /// </summary>
  79. private double _anFlowStartLowLimit = 0.5;
  80. /// <summary>
  81. /// Rinse Drip Idle Period
  82. /// </summary>
  83. private int _rinseDripIdlePeriod = 1000;
  84. #endregion
  85. /// <summary>
  86. /// 构造函数
  87. /// </summary>
  88. /// <param name="module"></param>
  89. public PlatingCellInitializeRoutine(string module) : base(module)
  90. {
  91. }
  92. /// <summary>
  93. /// 中止
  94. /// </summary>
  95. public void Abort()
  96. {
  97. Runner.Stop("Manual Abort");
  98. }
  99. /// <summary>
  100. /// 监控
  101. /// </summary>
  102. /// <returns></returns>
  103. public RState Monitor()
  104. {
  105. Runner.Run(InitializeStep.CheckPowerSupplierConnected, CheckPowerSupplierStatus, _delay_1ms)
  106. .Run(InitializeStep.CheckClamShellClosed, () => _platingCellDevice.ClamShellClose(), CheckClamShellClosed, _delay_1ms)
  107. .Run(InitializeStep.VerticalGotoLoad, VerticalGotoLoad, NullFun, 100)
  108. .WaitWithStopCondition(InitializeStep.VerticalGotoLoadCheck, CheckVerticalPositionStatus, CheckVerticalPositionRunStop)
  109. .Run(InitializeStep.RotationHome, RotationGotoHome, NullFun, 100)
  110. .WaitWithStopCondition(InitializeStep.RotationHomeCheck, CheckRotationPositionStatus, CheckRotationPositionRunStop)
  111. .Run(InitializeStep.AngleEntryTilt, () => _platingCellDevice.HeadtTiltAction(), CheckAngleTilt, _delay_1ms)
  112. .Run(InitializeStep.AngleEntryVertical, () => _platingCellDevice.HeadtVerticalAction(), CheckAngleVertical, _delay_1ms)
  113. .Run(InitializeStep.CheckClamShellClosed, () => _platingCellDevice.ClamShellOpen(), CheckClamShellOpen, _delay_1ms)
  114. .Run(InitializeStep.OpenCAAndANIsoltaionValve, OpenReservoirIsolationValve,_delay_1ms)
  115. .Delay(InitializeStep.CheckCellFlowWait, _flowFaultHoldOffTime)
  116. .Run(InitializeStep.CheckCellFlow, CheckCellFlow, _delay_1ms)
  117. .Run(InitializeStep.OpenCCRAndRinseValve, OpenCCRAndRinseValve, _delay_1ms)
  118. .Delay(InitializeStep.RinseDripIdleDelay, _rinseDripIdlePeriod)
  119. .Run(InitializeStep.CloseCCRAndRinseValve, CloseCCRAndRinseValve, _delay_1ms)
  120. .End(InitializeStep.End, NullFun, _delay_1ms);
  121. return Runner.Status;
  122. }
  123. /// <summary>
  124. /// 检查cell flow
  125. /// </summary>
  126. /// <returns></returns>
  127. private bool CheckCellFlow()
  128. {
  129. if ("Manual".Equals(_persistentValue.OperatingMode))
  130. {
  131. if(_reservoirDevice.ReservoirData.CaFlow < _cellFlowStartLowLimit)
  132. {
  133. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"CA flow{_reservoirDevice.ReservoirData.CaFlow} is lower than cellFlowStartLowLimit{_cellFlowStartLowLimit}");
  134. _reservoirDevice.CAIsolationOff();
  135. return false;
  136. }
  137. if (_reservoirDevice.ReservoirData.AnFlow < _anFlowStartLowLimit)
  138. {
  139. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"AN flow{_reservoirDevice.ReservoirData.AnFlow} is lower than cellFlowStartLowLimit{_anFlowStartLowLimit}");
  140. _reservoirDevice.ANIsolationOff();
  141. return false;
  142. }
  143. }
  144. else
  145. {
  146. if (_reservoirDevice.ReservoirData.CaFlow < _resRecipe.CAFlowRateErrorLow)
  147. {
  148. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"CA flow{_reservoirDevice.ReservoirData.CaFlow} is lower than resRecipe CAFlowRateErrorLow{_resRecipe.CAFlowRateErrorLow}");
  149. return false;
  150. }
  151. if (_reservoirDevice.ReservoirData.AnFlow < _resRecipe.ANFlowRateErrorLow)
  152. {
  153. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"AN flow{_reservoirDevice.ReservoirData.AnFlow} is lower than resRecipe ANFlowRateErrorLow{_resRecipe.ANFlowRateErrorLow}");
  154. return false;
  155. }
  156. }
  157. return true;
  158. }
  159. /// <summary>
  160. /// 打开reservoir Isolation valve
  161. /// </summary>
  162. /// <returns></returns>
  163. private bool OpenReservoirIsolationValve()
  164. {
  165. return _reservoirDevice.ANIsolationOn() && _reservoirDevice.ANIsolationOn();
  166. }
  167. /// <summary>
  168. /// 打开CCR/Rinse valve
  169. /// </summary>
  170. /// <returns></returns>
  171. private bool OpenCCRAndRinseValve()
  172. {
  173. return _platingCellDevice.CCREnableAction() && _platingCellDevice.RinseEnableAction();
  174. }
  175. /// <summary>
  176. /// 关闭CCR/Rinse valve
  177. /// </summary>
  178. /// <returns></returns>
  179. private bool CloseCCRAndRinseValve()
  180. {
  181. return _platingCellDevice.CCRDisableAction() && _platingCellDevice.RinseDisableAction();
  182. }
  183. /// <summary>
  184. /// vertical 运动到Load位置
  185. /// </summary>
  186. /// <returns></returns>
  187. private bool VerticalGotoLoad()
  188. {
  189. if(_verticalAxis != null )
  190. {
  191. if (!_verticalAxis.IsSwitchOn)
  192. {
  193. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Vertical is not Power On");
  194. return false;
  195. }
  196. else if (!_verticalAxis.IsHomed)
  197. {
  198. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Vertical is not Home,Home vertical first");
  199. return false;
  200. }
  201. return _verticalAxis.PositionStation("Load", true);
  202. }
  203. else
  204. {
  205. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "vertical axis is null");
  206. return false;
  207. }
  208. }
  209. /// <summary>
  210. /// vertical 运动到Load位置
  211. /// </summary>
  212. /// <returns></returns>
  213. private bool RotationGotoHome()
  214. {
  215. if (_rotationAxis != null)
  216. {
  217. if (!_rotationAxis.IsSwitchOn)
  218. {
  219. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Roation is not Power On");
  220. return false;
  221. }
  222. else if (!_rotationAxis.IsHomed)
  223. {
  224. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Rotation is not Home,Home Rotation first");
  225. return false;
  226. }
  227. return _rotationAxis.PositionStation("Home", true);
  228. }
  229. else
  230. {
  231. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Rotation axis is null");
  232. return false;
  233. }
  234. }
  235. /// <summary>
  236. /// 检查ClamShell是否closed
  237. /// </summary>
  238. /// <returns></returns>
  239. private bool CheckClamShellClosed()
  240. {
  241. return _platingCellDevice.PlatingCellDeviceData.ClamShellClose;
  242. }
  243. /// <summary>
  244. /// 检查ClamShell是否Open
  245. /// </summary>
  246. /// <returns></returns>
  247. private bool CheckClamShellOpen()
  248. {
  249. return !_platingCellDevice.PlatingCellDeviceData.ClamShellClose;
  250. }
  251. /// <summary>
  252. /// 检查Angle是否Tilt
  253. /// </summary>
  254. /// <returns></returns>
  255. private bool CheckAngleTilt()
  256. {
  257. return _platingCellDevice.PlatingCellDeviceData.HeadTilt;
  258. }
  259. /// <summary>
  260. /// 检查Angle是否Vertical
  261. /// </summary>
  262. /// <returns></returns>
  263. private bool CheckAngleVertical()
  264. {
  265. return !_platingCellDevice.PlatingCellDeviceData.HeadTilt;
  266. }
  267. /// <summary>
  268. /// 检验Metal A/B 面PowerSupplier通讯状况
  269. /// </summary>
  270. /// <returns></returns>
  271. private bool CheckPowerSupplierStatus()
  272. {
  273. if (!_platingCellDevice.PowerSupplier.IsConnected)
  274. {
  275. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "power is not connected");
  276. return false;
  277. }
  278. return true;
  279. }
  280. /// <summary>
  281. /// 检验Vertical移动状态
  282. /// </summary>
  283. /// <returns></returns>
  284. private bool CheckVerticalPositionStatus()
  285. {
  286. return _verticalAxis.Status == RState.End;
  287. }
  288. /// <summary>
  289. /// 检验Vertical是否还在运动
  290. /// </summary>
  291. /// <returns></returns>
  292. private bool CheckVerticalPositionRunStop()
  293. {
  294. return _verticalAxis.Status == RState.Failed;
  295. }
  296. /// <summary>
  297. /// 检验Rotation移动状态
  298. /// </summary>
  299. /// <returns></returns>
  300. private bool CheckRotationPositionStatus()
  301. {
  302. return _rotationAxis.Status == RState.End;
  303. }
  304. /// <summary>
  305. /// 检验Rotaion是否还在运动
  306. /// </summary>
  307. /// <returns></returns>
  308. private bool CheckRotationPositionRunStop()
  309. {
  310. return _rotationAxis.Status == RState.Failed;
  311. }
  312. /// <summary>
  313. /// 获取Reservoir设备
  314. /// </summary>
  315. /// <returns></returns>
  316. private ReservoirDevice GetReservoirDevice()
  317. {
  318. string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module.ToString());
  319. return DEVICE.GetDevice<ReservoirDevice>(reservoir);
  320. }
  321. /// <summary>
  322. /// 启动
  323. /// </summary>
  324. /// <param name="objs"></param>
  325. /// <returns></returns>
  326. public RState Start(params object[] objs)
  327. {
  328. _persistentValue = (PlatingCellPersistentValue)objs[0];
  329. _platingCellDevice = DEVICE.GetDevice<PlatingCellDevice>(Module);
  330. _reservoirDevice = GetReservoirDevice();
  331. _flowFaultHoldOffTime = SC.GetValue<int>("PlatingCell.FlowFaultHoldOffTime");
  332. _rinseDripIdlePeriod = SC.GetValue<int>("PlatingCell.RinseDripIdlePeriod");
  333. _cellFlowStartLowLimit = SC.GetValue<double>("PlatingCell.CellFlowStartLowLimit");
  334. _anFlowStartLowLimit = SC.GetValue<double>("PlatingCell.ANFlowStartLowLimit");
  335. if("PlatingCell1".Equals(Module) || "PlatingCell2".Equals(Module))
  336. {
  337. _verticalAxis = DEVICE.GetDevice<JetAxisBase>("PlatingCell1_2.Vertical");
  338. }
  339. else
  340. {
  341. _verticalAxis = DEVICE.GetDevice<JetAxisBase>("PlatingCell3_4.Vertical");
  342. }
  343. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  344. string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module.ToString());
  345. ReservoirDevice reservoirDevice = DEVICE.GetDevice<ReservoirDevice>(reservoir);
  346. if (reservoirDevice == null)
  347. {
  348. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"{reservoir} device is null");
  349. return RState.Failed;
  350. }
  351. if (reservoirDevice.Recipe == null)
  352. {
  353. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"{reservoir} current recipe is null");
  354. return RState.Failed;
  355. }
  356. _resRecipe = reservoirDevice.Recipe;
  357. return Runner.Start(Module, "Start Reservoir Initialize");
  358. }
  359. }
  360. }