VpwPurgeRoutine.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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. #endregion
  107. /// <summary>
  108. /// 构造函数
  109. /// </summary>
  110. /// <param name="module"></param>
  111. /// <param name="device"></param>
  112. public VpwPurgeRoutine(string module) : base(module)
  113. {
  114. }
  115. /// <summary>
  116. /// 中止
  117. /// </summary>
  118. public void Abort()
  119. {
  120. Runner.Stop("Purge abort");
  121. }
  122. /// <summary>
  123. /// 监控
  124. /// </summary>
  125. /// <returns></returns>
  126. public RState Monitor()
  127. {
  128. Runner.Run(PurgeStep.ChameberUp, _mainDevice.ChamberUp, CheckChamberClosed, _delay_1s)
  129. .Run(PurgeStep.SetRotationSpeed, SetRotationSpeed, _delay_1s)
  130. .Run(PurgeStep.StartRotation, StartRotation, _delay_1ms)
  131. .Wait(PurgeStep.CheckRotationRunning, CheckRotationRunningStatus, 500)
  132. .Run(PurgeStep.CloseDiwDegas, CloseDiwDegas)
  133. .Delay(PurgeStep.N2PurgeDelay, _n2PurgeTime)
  134. .Run(PurgeStep.CloseN2Purge, _mainDevice.N2PurgeValveOff, _delay_1ms)
  135. .Run(PurgeStep.OpenDiwDegas, OpenDiwDegas, _delay_1ms)
  136. .Delay(PurgeStep.FlowDelay, _flowFaultHolderoffTime)
  137. .Run(PurgeStep.CheckFlow, CheckTotalFlow, _delay_1ms)
  138. .Run(PurgeStep.CheckCellFlow, CheckCellFlow, _delay_1ms)
  139. .Run(PurgeStep.StopRotation, StopRotationAxis, _delay_1ms)
  140. .WaitWithStopCondition(PurgeStep.CheckStopStatus, CheckStopPostionEndStatus, CheckStopPostionStopStatus)
  141. .Run(PurgeStep.LastHomeRotation, HomeAllRotation, _delay_1ms)
  142. .WaitWithStopCondition(PurgeStep.CheckLastHomeRotation, CheckAllRotationHomeStatus, CheckAllRotationHomeStopStatus)
  143. .Run(PurgeStep.CheckFlowOk, CheckFlowOk, _delay_1ms)
  144. .RunIf(PurgeStep.ChamberDown, _checkFlowOk, () => { return _mainDevice.ChamberDown(); },
  145. () => { return !_mainDevice.CommonData.ChamberClosed && _mainDevice.CommonData.ChamberOpened; })
  146. .Run(PurgeStep.LastCheckStatus, LastCheckResult, _delay_1ms)
  147. .End(PurgeStep.End, NullFun, _delay_1ms);
  148. return Runner.Status;
  149. }
  150. /// <summary>
  151. /// 检验Chamber关闭
  152. /// </summary>
  153. /// <returns></returns>
  154. private bool CheckChamberClosed()
  155. {
  156. return _mainDevice.CommonData.ChamberClosed && !_mainDevice.CommonData.ChamberOpened;
  157. }
  158. private bool SetRotationSpeed()
  159. {
  160. bool result = true;
  161. foreach (var item in _cellLst)
  162. {
  163. result &= item.SetRotationSpeed(_rotationSpeed);
  164. }
  165. return result;
  166. }
  167. /// <summary>
  168. /// 打开所有cell valve
  169. /// </summary>
  170. /// <returns></returns>
  171. private bool OpenCellDrainValve()
  172. {
  173. foreach (var device in _cellLst)
  174. {
  175. bool result = device.DrainValveOn();
  176. if (!result)
  177. {
  178. LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"{device.Module} open drain valve failed");
  179. CloseCellDrainValve();
  180. return false;
  181. }
  182. }
  183. return true;
  184. }
  185. /// <summary>
  186. /// 检验Cell Drain状态
  187. /// </summary>
  188. /// <returns></returns>
  189. private bool CheckCellDrainValveStatus()
  190. {
  191. foreach (var item in _cellLst)
  192. {
  193. bool result = item.CommonData.DrainValve;
  194. if (!result)
  195. {
  196. LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"{item.Module} drain valve is not opened");
  197. CloseCellDrainValve();
  198. return false;
  199. }
  200. }
  201. return true;
  202. }
  203. /// <summary>
  204. /// 关闭所有cell的Drain valve
  205. /// </summary>
  206. private void CloseCellDrainValve()
  207. {
  208. foreach (var item in _cellLst)
  209. {
  210. item.DrainValveOff();
  211. }
  212. }
  213. /// <summary>
  214. /// Home All Rotation
  215. /// </summary>
  216. /// <returns></returns>
  217. private bool HomeAllRotation()
  218. {
  219. foreach (var item in _cellLst)
  220. {
  221. bool result = item.HomeRotation();
  222. if (!result)
  223. {
  224. CloseCellDrainValve();
  225. return false;
  226. }
  227. }
  228. return true;
  229. }
  230. /// <summary>
  231. /// 检验所有Rotation Home成功
  232. /// </summary>
  233. /// <returns></returns>
  234. private bool CheckAllRotationHomeStatus()
  235. {
  236. int count = 0;
  237. foreach (var item in _cellLst)
  238. {
  239. bool result = item.CheckHomeEndStatus();
  240. if (result)
  241. {
  242. count++;
  243. }
  244. }
  245. bool success = count == _cellLst.Count;
  246. if (success)
  247. {
  248. foreach (var item in _cellLst)
  249. {
  250. item.SetRotationSpeed(_rotationSpeed);
  251. }
  252. }
  253. return success;
  254. }
  255. /// <summary>
  256. /// rotation电机 home是否停止
  257. /// </summary>
  258. /// <returns></returns>
  259. private bool CheckAllRotationHomeStopStatus()
  260. {
  261. foreach (var item in _cellLst)
  262. {
  263. bool result = item.CheckRotationStopStatus();
  264. if (result)
  265. {
  266. return true;
  267. }
  268. }
  269. return false;
  270. }
  271. /// <summary>
  272. /// 启动rotation
  273. /// </summary>
  274. /// <returns></returns>
  275. private bool StartRotation()
  276. {
  277. int totalTime = (_n2PurgeTime + _flowFaultHolderoffTime+ PLUS_TIME) / 1000;
  278. int targetPsition = _rotationSpeed * totalTime;
  279. foreach (var item in _cellLst)
  280. {
  281. bool result = item.RotationProfilePosition(targetPsition);
  282. if (!result)
  283. {
  284. StopAllRotation();
  285. return false;
  286. }
  287. }
  288. return true;
  289. }
  290. /// <summary>
  291. /// 检验Rotation是否运动
  292. /// </summary>
  293. /// <returns></returns>
  294. private bool CheckRotationRunningStatus()
  295. {
  296. foreach (var item in _cellLst)
  297. {
  298. bool result = item.CheckRotationRunning();
  299. if (!result)
  300. {
  301. StopAllRotation();
  302. return false;
  303. }
  304. }
  305. return true;
  306. }
  307. /// <summary>
  308. /// 停止所有rotation电机
  309. /// </summary>
  310. private void StopAllRotation()
  311. {
  312. foreach (var item in _cellLst)
  313. {
  314. item.StopProfilePosition();
  315. }
  316. }
  317. /// <summary>
  318. /// 关闭DiwDegas等
  319. /// </summary>
  320. /// <returns></returns>
  321. private bool CloseDiwDegas()
  322. {
  323. int count = 0;
  324. count += _mainDevice.DiwDegasValveOff() ? 1 : 0;
  325. count += _mainDevice.N2PurgeValveOn() ? 1 : 0;
  326. foreach (var item in _cellLst)
  327. {
  328. count += item.FlowDripOn() ? 1 : 0;
  329. count += item.FlowSmallOn() ? 1 : 0;
  330. count += item.FlowLargeOn() ? 1 : 0;
  331. }
  332. return count == _cellLst.Count * 3 + 2;
  333. }
  334. /// <summary>
  335. /// 打开DiwDegas
  336. /// </summary>
  337. /// <returns></returns>
  338. private bool OpenDiwDegas()
  339. {
  340. return _mainDevice.DiwDegasValveOff();
  341. }
  342. /// <summary>
  343. /// 检验流量
  344. /// </summary>
  345. /// <returns></returns>
  346. private bool CheckTotalFlow()
  347. {
  348. double totalFlow = _mainDevice.CommonData.DiwTotalFlow;
  349. if (totalFlow < _totalFlowStartLimit)
  350. {
  351. _totalFlowOk = false;
  352. }
  353. else
  354. {
  355. _totalFlowOk = true;
  356. }
  357. _totalFlow = totalFlow;
  358. return true;
  359. }
  360. /// <summary>
  361. /// 检验CellFlow
  362. /// </summary>
  363. /// <returns></returns>
  364. private bool CheckCellFlow()
  365. {
  366. foreach (var item in _cellLst)
  367. {
  368. double cellFlow = item.CommonData.DiwFlow;
  369. if (cellFlow < _cellFlowStartLimit)
  370. {
  371. _cellFlowOk[item.Module] = false;
  372. }
  373. else
  374. {
  375. _cellFlowOk[item.Module] = true;
  376. item.FlowSmallOff();
  377. item.FlowLargeOff();
  378. }
  379. _cellFlows[item.Module] = cellFlow;
  380. }
  381. return true;
  382. }
  383. /// <summary>
  384. /// 停止rotation
  385. /// </summary>
  386. /// <returns></returns>
  387. public bool StopRotationAxis()
  388. {
  389. foreach (var item in _cellLst)
  390. {
  391. bool result = item.StopProfilePosition();
  392. if (!result)
  393. {
  394. return false;
  395. }
  396. }
  397. return true;
  398. }
  399. /// <summary>
  400. /// 检验停止是否完成
  401. /// </summary>
  402. /// <returns></returns>
  403. public bool CheckStopPostionEndStatus()
  404. {
  405. foreach (var item in _cellLst)
  406. {
  407. bool result = item.CheckRotationEndStatus();
  408. if (!result)
  409. {
  410. return false;
  411. }
  412. }
  413. return true;
  414. }
  415. /// <summary>
  416. /// 检验停止失败状态
  417. /// </summary>
  418. /// <returns></returns>
  419. public bool CheckStopPostionStopStatus()
  420. {
  421. foreach (var item in _cellLst)
  422. {
  423. bool result = item.CheckRotationStopStatus();
  424. if (result)
  425. {
  426. return true;
  427. }
  428. }
  429. return false;
  430. }
  431. /// <summary>
  432. /// 检验流量是否ok
  433. /// </summary>
  434. /// <returns></returns>
  435. private bool CheckFlowOk()
  436. {
  437. if (!_totalFlowOk)
  438. {
  439. _checkFlowOk = false;
  440. return true;
  441. }
  442. foreach (var item in _cellLst)
  443. {
  444. if (!_cellFlowOk[item.Module])
  445. {
  446. _checkFlowOk = false;
  447. return true;
  448. }
  449. }
  450. _checkFlowOk = true;
  451. return true;
  452. }
  453. /// <summary>
  454. /// 最后确认结果
  455. /// </summary>
  456. /// <returns></returns>
  457. private bool LastCheckResult()
  458. {
  459. AllCellPostMsg();
  460. if (_totalFlowOk)
  461. {
  462. return true;
  463. }
  464. else
  465. {
  466. LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"total flow {_totalFlow} is less than {_totalFlowStartLimit}");
  467. return false;
  468. }
  469. }
  470. /// <summary>
  471. /// 所有cell推送消息
  472. /// </summary>
  473. private void AllCellPostMsg()
  474. {
  475. foreach (var item in _cellLst)
  476. {
  477. VpwCellEntity vpwCellEntity = Singleton<RouteManager>.Instance.GetModule<VpwCellEntity>(item.Module);
  478. if (!_cellFlowOk[item.Module])
  479. {
  480. vpwCellEntity.PostMsg((int)VpwCellMsg.Error);
  481. LOG.WriteLog(eEvent.ERR_VPW, item.Module, $"cell flow {_cellFlows[item.Module]} is less than {_cellFlowStartLimit}");
  482. }
  483. }
  484. }
  485. /// <summary>
  486. /// 检验Rotation电机是否上电
  487. /// </summary>
  488. /// <param name="device"></param>
  489. /// <returns></returns>
  490. private bool CheckRotationSwitchOn(VpwCellDevice device)
  491. {
  492. if (!device.CheckRotationSwitchOn())
  493. {
  494. LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"{device.Module} rotation is not switch on");
  495. return false;
  496. }
  497. return true;
  498. }
  499. /// <summary>
  500. /// 启动
  501. /// </summary>
  502. /// <param name="objs"></param>
  503. /// <returns></returns>
  504. public RState Start(params object[] objs)
  505. {
  506. List<VpwCellDevice> lstDevice = (List<VpwCellDevice>)objs[0];
  507. _vpwCellDevices.Clear();
  508. _cellFlows.Clear();
  509. _cellLst.Clear();
  510. _cellFlowOk.Clear();
  511. _totalFlowOk = false;
  512. _checkFlowOk = false;
  513. _totalFlow = 0;
  514. for (int i = 0; i < lstDevice.Count; i++)
  515. {
  516. _vpwCellDevices.Add(lstDevice[i]);
  517. VpwCellEntity vpwCellEntity = Singleton<RouteManager>.Instance.GetModule<VpwCellEntity>(lstDevice[i].Module);
  518. if (vpwCellEntity.IsAuto || vpwCellEntity.IsManual)
  519. {
  520. _cellLst.Add(lstDevice[i]);
  521. if (!CheckRotationSwitchOn(lstDevice[i]))
  522. {
  523. return RState.Failed;
  524. }
  525. _cellFlowOk[lstDevice[i].Module] = false;
  526. }
  527. }
  528. _mainDevice = DEVICE.GetDevice<VpwMainDevice>(Module.ToString());
  529. _n2PurgeTime = SC.GetValue<int>("VPWMain.Plumbing.N2PurgeTime");
  530. _flowFaultHolderoffTime = SC.GetValue<int>("VPWMain.Plumbing.FlowFaultHoldoffTime");
  531. double purgeMotorSpeed = SC.GetValue<double>("VPWMain.Plumbing.PurgeMotorSpeed");
  532. _rotationSpeed = (int)(Math.Round(purgeMotorSpeed * 360 / 60, 0));
  533. _totalFlowStartLimit = SC.GetValue<double>("VPWMain.Plumbing.TotalFlowStartLowLimit");
  534. _cellFlowStartLimit = SC.GetValue<double>("VPWMain.Plumbing.CellFlowStartLowLimit");
  535. _degasEnableDelayTime = SC.GetValue<int>("VPWMain.Plumbing.DegasEnableDelayTime");
  536. return Runner.Start(Module, "VPW Purge");
  537. }
  538. }
  539. }