VpwPurgeRoutine.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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 Aitex.Core.Util;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.Routine;
  8. using PunkHPX8_Core;
  9. using PunkHPX8_RT.Devices.VpwCell;
  10. using PunkHPX8_RT.Devices.VpwMain;
  11. using PunkHPX8_RT.Modules.VpwCell;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. namespace PunkHPX8_RT.Modules.VpwMain
  18. {
  19. public class VpwPurgeRoutine : RoutineBase, IRoutine
  20. {
  21. private enum PurgeStep
  22. {
  23. ChameberUp,
  24. SetRotationSpeed,
  25. StartRotation,
  26. CheckRotationRunning,
  27. CloseDiwDegas,
  28. N2PurgeDelay,
  29. CloseN2Purge,
  30. OpenDiwDegas,
  31. FlowDelay,
  32. CheckFlow,
  33. CheckCellFlow,
  34. StopRotation,
  35. CheckStopStatus,
  36. LastHomeRotation,
  37. CheckLastHomeRotation,
  38. CheckFlowOk,
  39. ChamberDown,
  40. LastCheckStatus,
  41. End
  42. }
  43. #region 常量
  44. /// <summary>
  45. /// 增加额外一分钟
  46. /// </summary>
  47. private const int PLUS_TIME = 60000;
  48. #endregion
  49. #region 内部变量
  50. /// <summary>
  51. /// Cell device集合
  52. /// </summary>
  53. private List<VpwCellDevice> _vpwCellDevices = new List<VpwCellDevice>();
  54. /// <summary>
  55. /// Main Device
  56. /// </summary>
  57. private VpwMainDevice _mainDevice;
  58. /// <summary>
  59. /// cell集合
  60. /// </summary>
  61. private List<VpwCellDevice> _cellLst = new List<VpwCellDevice>();
  62. /// <summary>
  63. /// N2 Purge时长
  64. /// </summary>
  65. private int _n2PurgeTime = 15000;
  66. /// <summary>
  67. /// Flow holder off time
  68. /// </summary>
  69. private int _flowFaultHolderoffTime = 15000;
  70. /// <summary>
  71. /// Degas delay时间
  72. /// </summary>
  73. private int _degasEnableDelayTime = 2000;
  74. /// <summary>
  75. /// 旋转速度
  76. /// </summary>
  77. private int _rotationSpeed = 0;
  78. /// <summary>
  79. /// 总流量起始流量数值
  80. /// </summary>
  81. private double _totalFlowStartLimit = 2.0;
  82. /// <summary>
  83. /// Cell起始流量数值
  84. /// </summary>
  85. private double _cellFlowStartLimit = 2.0;
  86. /// <summary>
  87. /// total flow合格
  88. /// </summary>
  89. private bool _totalFlowOk = false;
  90. /// <summary>
  91. /// cell flow合格集合
  92. /// </summary>
  93. private Dictionary<string, bool> _cellFlowOk = new Dictionary<string, bool>();
  94. /// <summary>
  95. /// 检验流量是否ok
  96. /// </summary>
  97. private bool _checkFlowOk = false;
  98. /// <summary>
  99. /// 总流量
  100. /// </summary>
  101. private double _totalFlow = 0;
  102. /// <summary>
  103. /// Cell注意集合
  104. /// </summary>
  105. private Dictionary<string, double> _cellFlows = new Dictionary<string, double>();
  106. /// <summary>
  107. /// 检验chamber是否上升/下降到位
  108. /// </summary>
  109. private int _checkChamberUpDownTimes = 3;
  110. #endregion
  111. /// <summary>
  112. /// 构造函数
  113. /// </summary>
  114. /// <param name="module"></param>
  115. /// <param name="device"></param>
  116. public VpwPurgeRoutine(string module) : base(module)
  117. {
  118. }
  119. /// <summary>
  120. /// 中止
  121. /// </summary>
  122. public void Abort()
  123. {
  124. Runner.Stop("Purge abort");
  125. }
  126. /// <summary>
  127. /// 监控
  128. /// </summary>
  129. /// <returns></returns>
  130. public RState Monitor()
  131. {
  132. Runner.Run(PurgeStep.ChameberUp, _mainDevice.ChamberUp, CheckChamberClosed, _checkChamberUpDownTimes*1000)
  133. .Run(PurgeStep.SetRotationSpeed, SetRotationSpeed, _delay_1s)
  134. .Run(PurgeStep.StartRotation, StartRotation, _delay_1ms)
  135. .Wait(PurgeStep.CheckRotationRunning, CheckRotationRunningStatus, 500)
  136. .Run(PurgeStep.CloseDiwDegas, CloseDiwDegas)
  137. .Delay(PurgeStep.N2PurgeDelay, _n2PurgeTime)
  138. .Run(PurgeStep.CloseN2Purge, _mainDevice.N2PurgeValveOff, _delay_1ms)
  139. .Run(PurgeStep.OpenDiwDegas, OpenDiwDegas, _delay_1ms)
  140. .Delay(PurgeStep.FlowDelay, _flowFaultHolderoffTime)
  141. .Run(PurgeStep.CheckFlow, CheckTotalFlow, _delay_1ms)
  142. .Run(PurgeStep.CheckCellFlow, CheckCellFlow, _delay_1ms)
  143. .Run(PurgeStep.StopRotation, StopRotationAxis, _delay_1ms)
  144. .WaitWithStopCondition(PurgeStep.CheckStopStatus, CheckStopPostionEndStatus, CheckStopPostionStopStatus)
  145. .Run(PurgeStep.LastHomeRotation, HomeAllRotation, _delay_1ms)
  146. .WaitWithStopCondition(PurgeStep.CheckLastHomeRotation, CheckAllRotationHomeStatus, CheckAllRotationHomeStopStatus)
  147. .Run(PurgeStep.CheckFlowOk, CheckFlowOk, _delay_1ms)
  148. .RunIf(PurgeStep.ChamberDown, _checkFlowOk, () => { return _mainDevice.ChamberDown(); },
  149. () => { return _mainDevice.CommonData.ChamberClosed && !_mainDevice.CommonData.ChamberOpened; })
  150. .Run(PurgeStep.LastCheckStatus, LastCheckResult, _delay_1ms)
  151. .End(PurgeStep.End, NullFun, _delay_1ms);
  152. return Runner.Status;
  153. }
  154. /// <summary>
  155. /// 检验Chamber关闭
  156. /// </summary>
  157. /// <returns></returns>
  158. private bool CheckChamberClosed()
  159. {
  160. return !_mainDevice.CommonData.ChamberClosed && _mainDevice.CommonData.ChamberOpened;
  161. }
  162. private bool SetRotationSpeed()
  163. {
  164. bool result = true;
  165. foreach (var item in _cellLst)
  166. {
  167. result &= item.SetRotationSpeed(_rotationSpeed);
  168. }
  169. return result;
  170. }
  171. /// <summary>
  172. /// 打开所有cell valve
  173. /// </summary>
  174. /// <returns></returns>
  175. private bool OpenCellDrainValve()
  176. {
  177. foreach (var device in _cellLst)
  178. {
  179. bool result = device.DrainValveOn();
  180. if (!result)
  181. {
  182. LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"{device.Module} open drain valve failed");
  183. CloseCellDrainValve();
  184. return false;
  185. }
  186. }
  187. return true;
  188. }
  189. /// <summary>
  190. /// 检验Cell Drain状态
  191. /// </summary>
  192. /// <returns></returns>
  193. private bool CheckCellDrainValveStatus()
  194. {
  195. foreach (var item in _cellLst)
  196. {
  197. bool result = item.CommonData.DrainValve;
  198. if (!result)
  199. {
  200. LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"{item.Module} drain valve is not opened");
  201. CloseCellDrainValve();
  202. return false;
  203. }
  204. }
  205. return true;
  206. }
  207. /// <summary>
  208. /// 关闭所有cell的Drain valve
  209. /// </summary>
  210. private void CloseCellDrainValve()
  211. {
  212. foreach (var item in _cellLst)
  213. {
  214. item.DrainValveOff();
  215. }
  216. }
  217. /// <summary>
  218. /// Home All Rotation
  219. /// </summary>
  220. /// <returns></returns>
  221. private bool HomeAllRotation()
  222. {
  223. foreach (var item in _cellLst)
  224. {
  225. bool result = item.HomeRotation();
  226. if (!result)
  227. {
  228. CloseCellDrainValve();
  229. return false;
  230. }
  231. }
  232. return true;
  233. }
  234. /// <summary>
  235. /// 检验所有Rotation Home成功
  236. /// </summary>
  237. /// <returns></returns>
  238. private bool CheckAllRotationHomeStatus()
  239. {
  240. int count = 0;
  241. foreach (var item in _cellLst)
  242. {
  243. bool result = item.CheckHomeEndStatus();
  244. if (result)
  245. {
  246. count++;
  247. }
  248. }
  249. bool success = count == _cellLst.Count;
  250. if (success)
  251. {
  252. foreach (var item in _cellLst)
  253. {
  254. item.SetRotationSpeed(_rotationSpeed);
  255. }
  256. }
  257. return success;
  258. }
  259. /// <summary>
  260. /// rotation电机 home是否停止
  261. /// </summary>
  262. /// <returns></returns>
  263. private bool CheckAllRotationHomeStopStatus()
  264. {
  265. foreach (var item in _cellLst)
  266. {
  267. bool result = item.CheckRotationStopStatus();
  268. if (result)
  269. {
  270. return true;
  271. }
  272. }
  273. return false;
  274. }
  275. /// <summary>
  276. /// 启动rotation
  277. /// </summary>
  278. /// <returns></returns>
  279. private bool StartRotation()
  280. {
  281. int totalTime = (_n2PurgeTime + _flowFaultHolderoffTime+ PLUS_TIME) / 1000;
  282. int targetPsition = _rotationSpeed * totalTime;
  283. foreach (var item in _cellLst)
  284. {
  285. bool result = item.RotationProfilePosition(targetPsition);
  286. if (!result)
  287. {
  288. StopAllRotation();
  289. return false;
  290. }
  291. }
  292. return true;
  293. }
  294. /// <summary>
  295. /// 检验Rotation是否运动
  296. /// </summary>
  297. /// <returns></returns>
  298. private bool CheckRotationRunningStatus()
  299. {
  300. foreach (var item in _cellLst)
  301. {
  302. bool result = item.CheckRotationRunning();
  303. if (!result)
  304. {
  305. StopAllRotation();
  306. return false;
  307. }
  308. }
  309. return true;
  310. }
  311. /// <summary>
  312. /// 停止所有rotation电机
  313. /// </summary>
  314. private void StopAllRotation()
  315. {
  316. foreach (var item in _cellLst)
  317. {
  318. item.StopProfilePosition();
  319. }
  320. }
  321. /// <summary>
  322. /// 关闭DiwDegas等
  323. /// </summary>
  324. /// <returns></returns>
  325. private bool CloseDiwDegas()
  326. {
  327. int count = 0;
  328. count += _mainDevice.DiwDegasValveOff() ? 1 : 0;
  329. count += _mainDevice.N2PurgeValveOn() ? 1 : 0;
  330. foreach (var item in _cellLst)
  331. {
  332. count += item.FlowDripOn() ? 1 : 0;
  333. count += item.FlowSmallOn() ? 1 : 0;
  334. count += item.FlowLargeOn() ? 1 : 0;
  335. }
  336. return count == _cellLst.Count * 3 + 2;
  337. }
  338. /// <summary>
  339. /// 打开DiwDegas
  340. /// </summary>
  341. /// <returns></returns>
  342. private bool OpenDiwDegas()
  343. {
  344. return _mainDevice.DiwDegasValveOn();
  345. }
  346. /// <summary>
  347. /// 检验流量
  348. /// </summary>
  349. /// <returns></returns>
  350. private bool CheckTotalFlow()
  351. {
  352. double totalFlow = _mainDevice.CommonData.DiwTotalFlow;
  353. if (totalFlow < _totalFlowStartLimit)
  354. {
  355. _totalFlowOk = false;
  356. }
  357. else
  358. {
  359. _totalFlowOk = true;
  360. }
  361. _totalFlow = totalFlow;
  362. return true;
  363. }
  364. /// <summary>
  365. /// 检验CellFlow
  366. /// </summary>
  367. /// <returns></returns>
  368. private bool CheckCellFlow()
  369. {
  370. foreach (var item in _cellLst)
  371. {
  372. double cellFlow = item.CommonData.DiwFlow;
  373. if (cellFlow < _cellFlowStartLimit)
  374. {
  375. _cellFlowOk[item.Module] = false;
  376. }
  377. else
  378. {
  379. _cellFlowOk[item.Module] = true;
  380. item.FlowSmallOff();
  381. item.FlowLargeOff();
  382. }
  383. _cellFlows[item.Module] = cellFlow;
  384. }
  385. return true;
  386. }
  387. /// <summary>
  388. /// 停止rotation
  389. /// </summary>
  390. /// <returns></returns>
  391. public bool StopRotationAxis()
  392. {
  393. foreach (var item in _cellLst)
  394. {
  395. bool result = item.StopProfilePosition();
  396. if (!result)
  397. {
  398. return false;
  399. }
  400. }
  401. return true;
  402. }
  403. /// <summary>
  404. /// 检验停止是否完成
  405. /// </summary>
  406. /// <returns></returns>
  407. public bool CheckStopPostionEndStatus()
  408. {
  409. foreach (var item in _cellLst)
  410. {
  411. bool result = item.CheckRotationEndStatus();
  412. if (!result)
  413. {
  414. return false;
  415. }
  416. }
  417. return true;
  418. }
  419. /// <summary>
  420. /// 检验停止失败状态
  421. /// </summary>
  422. /// <returns></returns>
  423. public bool CheckStopPostionStopStatus()
  424. {
  425. foreach (var item in _cellLst)
  426. {
  427. bool result = item.CheckRotationStopStatus();
  428. if (result)
  429. {
  430. return true;
  431. }
  432. }
  433. return false;
  434. }
  435. /// <summary>
  436. /// 检验流量是否ok
  437. /// </summary>
  438. /// <returns></returns>
  439. private bool CheckFlowOk()
  440. {
  441. if (!_totalFlowOk)
  442. {
  443. _checkFlowOk = false;
  444. return true;
  445. }
  446. foreach (var item in _cellLst)
  447. {
  448. if (!_cellFlowOk[item.Module])
  449. {
  450. _checkFlowOk = false;
  451. return true;
  452. }
  453. }
  454. _checkFlowOk = true;
  455. return true;
  456. }
  457. /// <summary>
  458. /// 最后确认结果
  459. /// </summary>
  460. /// <returns></returns>
  461. private bool LastCheckResult()
  462. {
  463. AllCellPostMsg();
  464. if (_totalFlowOk)
  465. {
  466. return true;
  467. }
  468. else
  469. {
  470. LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"total flow {_totalFlow} is less than {_totalFlowStartLimit}");
  471. return false;
  472. }
  473. }
  474. /// <summary>
  475. /// 所有cell推送消息
  476. /// </summary>
  477. private void AllCellPostMsg()
  478. {
  479. foreach (var item in _cellLst)
  480. {
  481. VpwCellEntity vpwCellEntity = Singleton<RouteManager>.Instance.GetModule<VpwCellEntity>(item.Module);
  482. if (!_cellFlowOk[item.Module])
  483. {
  484. vpwCellEntity.PostMsg((int)VPWCellMsg.Error);
  485. LOG.WriteLog(eEvent.ERR_VPW, item.Module, $"cell flow {_cellFlows[item.Module]} is less than {_cellFlowStartLimit}");
  486. }
  487. }
  488. }
  489. /// <summary>
  490. /// 检验Rotation电机是否上电
  491. /// </summary>
  492. /// <param name="device"></param>
  493. /// <returns></returns>
  494. private bool CheckRotationSwitchOn(VpwCellDevice device)
  495. {
  496. if (!device.CheckRotationSwitchOn())
  497. {
  498. LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"{device.Module} rotation is not switch on");
  499. return false;
  500. }
  501. return true;
  502. }
  503. /// <summary>
  504. /// 启动
  505. /// </summary>
  506. /// <param name="objs"></param>
  507. /// <returns></returns>
  508. public RState Start(params object[] objs)
  509. {
  510. List<VpwCellDevice> lstDevice = (List<VpwCellDevice>)objs[0];
  511. _vpwCellDevices.Clear();
  512. _cellFlows.Clear();
  513. _cellLst.Clear();
  514. _cellFlowOk.Clear();
  515. _totalFlowOk = false;
  516. _checkFlowOk = false;
  517. _totalFlow = 0;
  518. for (int i = 0; i < lstDevice.Count; i++)
  519. {
  520. _vpwCellDevices.Add(lstDevice[i]);
  521. VpwCellEntity vpwCellEntity = Singleton<RouteManager>.Instance.GetModule<VpwCellEntity>(lstDevice[i].Module);
  522. if (vpwCellEntity.IsAuto || vpwCellEntity.IsManual)
  523. {
  524. _cellLst.Add(lstDevice[i]);
  525. if (!CheckRotationSwitchOn(lstDevice[i]))
  526. {
  527. return RState.Failed;
  528. }
  529. _cellFlowOk[lstDevice[i].Module] = false;
  530. }
  531. }
  532. _mainDevice = DEVICE.GetDevice<VpwMainDevice>(Module.ToString());
  533. _n2PurgeTime = SC.GetValue<int>("VPWMain.Plumbing.N2PurgeTime");
  534. _flowFaultHolderoffTime = SC.GetValue<int>("VPWMain.Plumbing.FlowFaultHoldoffTime");
  535. double purgeMotorSpeed = SC.GetValue<double>("VPWMain.Plumbing.PurgeMotorSpeed");
  536. _rotationSpeed = (int)(Math.Round(purgeMotorSpeed * 360 / 60, 0));
  537. _totalFlowStartLimit = SC.GetValue<double>("VPWMain.Plumbing.TotalFlowStartLowLimit");
  538. _cellFlowStartLimit = SC.GetValue<double>("VPWMain.Plumbing.CellFlowStartLowLimit");
  539. _degasEnableDelayTime = SC.GetValue<int>("VPWMain.Plumbing.DegasEnableDelayTime");
  540. _checkChamberUpDownTimes = SC.GetValue<int>("VPWMain.ChamberUpDownCheckTime");
  541. return Runner.Start(Module, "VPW Purge");
  542. }
  543. }
  544. }