VPWHomeRoutine.cs 21 KB

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