VPWHomeRoutine.cs 21 KB

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