VPWHomeRoutine.cs 22 KB

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