VPWHomeRoutine.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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. CheckTotalFlowOk,
  40. CheckCellFlow,
  41. StopRotation,
  42. CheckStopStatus,
  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. .Run(HomeStep.LastHomeRotation,HomeAllRotation,_delay_1ms)
  158. .WaitWithStopCondition(HomeStep.CheckLastHomeRotation, CheckAllRotationHomeStatus, CheckAllRotationHomeStopStatus)
  159. .Run(HomeStep.CheckFlowOk,CheckFlowOk,_delay_1ms)
  160. .DelayIf(HomeStep.DegasDelay,_checkFlowOk,_degasEnableDelayTime)
  161. .RunIf(HomeStep.OpenDegas,_checkFlowOk,OpenDegasPump,_delay_1ms)
  162. .RunIf(HomeStep.ChamberDown,_checkFlowOk, () => { return _mainDevice.ChamberDown(); },
  163. () => { return _mainDevice.CommonData.ChamberClosed && !_mainDevice.CommonData.ChamberOpened; })
  164. .Run(HomeStep.LastCheckStatus,LastCheckResult,_delay_1ms)
  165. .End(HomeStep.End,NullFun, _delay_1ms);
  166. return Runner.Status;
  167. }
  168. /// <summary>
  169. /// 检验Chamber关闭
  170. /// </summary>
  171. /// <returns></returns>
  172. private bool CheckChamberClosed()
  173. {
  174. return !_mainDevice.CommonData.ChamberClosed && _mainDevice.CommonData.ChamberOpened;
  175. }
  176. /// <summary>
  177. /// 打开所有cell valve
  178. /// </summary>
  179. /// <returns></returns>
  180. private bool OpenCellDrainValve()
  181. {
  182. foreach(var device in _cellLst)
  183. {
  184. bool result= device.DrainValveOn();
  185. if (!result)
  186. {
  187. LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"{device.Module} open drain valve failed");
  188. return false;
  189. }
  190. }
  191. return true;
  192. }
  193. /// <summary>
  194. /// 检验Cell Drain状态
  195. /// </summary>
  196. /// <returns></returns>
  197. private bool CheckCellDrainValveStatus()
  198. {
  199. foreach (var item in _cellLst)
  200. {
  201. bool result = item.CommonData.DrainValve;
  202. if (!result)
  203. {
  204. LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"{item.Module} drain valve is not opened");
  205. return false;
  206. }
  207. }
  208. return true;
  209. }
  210. /// <summary>
  211. /// Home All Rotation
  212. /// </summary>
  213. /// <returns></returns>
  214. private bool HomeAllRotation()
  215. {
  216. foreach(var item in _cellLst)
  217. {
  218. bool result = item.HomeRotation();
  219. if (!result)
  220. {
  221. return false;
  222. }
  223. }
  224. return true;
  225. }
  226. /// <summary>
  227. /// 检验所有Rotation Home成功
  228. /// </summary>
  229. /// <returns></returns>
  230. private bool CheckAllRotationHomeStatus()
  231. {
  232. int count = 0;
  233. foreach (var item in _cellLst)
  234. {
  235. bool result = item.CheckHomeEndStatus();
  236. if (result)
  237. {
  238. count++;
  239. }
  240. }
  241. bool success= count == _cellLst.Count ;
  242. if (success)
  243. {
  244. foreach(var item in _cellLst)
  245. {
  246. item.SetRotationSpeed(_rotationSpeed);
  247. }
  248. }
  249. return success;
  250. }
  251. /// <summary>
  252. /// rotation电机 home是否停止
  253. /// </summary>
  254. /// <returns></returns>
  255. private bool CheckAllRotationHomeStopStatus()
  256. {
  257. foreach (var item in _cellLst)
  258. {
  259. bool result = item.CheckRotationStopStatus();
  260. if (result)
  261. {
  262. return true;
  263. }
  264. }
  265. return false;
  266. }
  267. /// <summary>
  268. /// 启动rotation
  269. /// </summary>
  270. /// <returns></returns>
  271. private bool StartRotation()
  272. {
  273. int totalTime =(_n2PurgeTime + _flowFaultHolderoffTime + PLUS_TIME)/1000;
  274. int targetPsition = _rotationSpeed * totalTime;
  275. foreach (var item in _cellLst)
  276. {
  277. bool result = item.RotationProfilePosition(targetPsition);
  278. if (!result)
  279. {
  280. StopAllRotation();
  281. return false;
  282. }
  283. }
  284. return true;
  285. }
  286. /// <summary>
  287. /// 检验Rotation是否运动
  288. /// </summary>
  289. /// <returns></returns>
  290. private bool CheckRotationRunningStatus()
  291. {
  292. foreach (var item in _cellLst)
  293. {
  294. bool result = item.CheckRotationRunning();
  295. if (!result)
  296. {
  297. StopAllRotation();
  298. return false;
  299. }
  300. }
  301. return true;
  302. }
  303. /// <summary>
  304. /// 停止所有rotation电机
  305. /// </summary>
  306. private void StopAllRotation()
  307. {
  308. foreach (var item in _cellLst)
  309. {
  310. item.StopProfilePosition();
  311. }
  312. }
  313. /// <summary>
  314. /// 关闭DiwDegas等
  315. /// </summary>
  316. /// <returns></returns>
  317. private bool CloseDiwDegas()
  318. {
  319. int count = 0;
  320. count+=_mainDevice.DiwDegasValveOff()?1:0;
  321. count+=_mainDevice.BoosterPumpDisable()?1:0;
  322. count+=_mainDevice.N2PurgeValveOn()?1:0;
  323. foreach(var item in _cellLst)
  324. {
  325. count += item.FlowDripOff()?1:0;
  326. count += item.FlowSmallOff() ? 1 : 0;
  327. count += item.FlowLargeOff() ? 1 : 0;
  328. }
  329. return count==_cellLst.Count*3+3;
  330. }
  331. /// <summary>
  332. /// 打开Boost Pump
  333. /// </summary>
  334. /// <returns></returns>
  335. private bool OpenBoostPump()
  336. {
  337. int count = 0;
  338. count += _mainDevice.BoosterPumpEnable()?1:0;
  339. count += _mainDevice.DiwEnable() ? 1 : 0;
  340. count += _mainDevice.DiwProcessOn() ? 1 : 0;
  341. count += _mainDevice.DiwDegasValveOn() ? 1 : 0;
  342. foreach (var item in _cellLst)
  343. {
  344. count += item.FlowDripOn() ? 1 : 0;
  345. count += item.FlowSmallOn() ? 1 : 0;
  346. count += item.FlowLargeOn() ? 1 : 0;
  347. }
  348. return count == _cellLst.Count*3+4;
  349. }
  350. /// <summary>
  351. /// 检验流量
  352. /// </summary>
  353. /// <returns></returns>
  354. private bool CheckTotalFlow()
  355. {
  356. double totalFlow = _mainDevice.CommonData.DiwTotalFlow;
  357. if (totalFlow < _totalFlowStartLimit)
  358. {
  359. _totalFlowOk = false;
  360. }
  361. else
  362. {
  363. _totalFlowOk = true;
  364. }
  365. _totalFlow = totalFlow;
  366. return true;
  367. }
  368. /// <summary>
  369. /// 检验CellFlow
  370. /// </summary>
  371. /// <returns></returns>
  372. private bool CheckCellFlow()
  373. {
  374. foreach (var item in _cellLst)
  375. {
  376. double cellFlow = item.CommonData.DiwFlow;
  377. if (cellFlow < _cellFlowStartLimit)
  378. {
  379. _cellFlowOk[item.Module] = false;
  380. item.FlowSmallOff();
  381. item.FlowLargeOff();
  382. }
  383. else
  384. {
  385. _cellFlowOk[item.Module] = true;
  386. }
  387. _cellFlows[item.Module] = cellFlow;
  388. }
  389. return true;
  390. }
  391. /// <summary>
  392. /// 停止rotation
  393. /// </summary>
  394. /// <returns></returns>
  395. public bool StopRotationAxis()
  396. {
  397. foreach(var item in _cellLst)
  398. {
  399. bool result = item.StopProfilePosition();
  400. if (!result)
  401. {
  402. return false;
  403. }
  404. }
  405. return true;
  406. }
  407. /// <summary>
  408. /// 检验停止是否完成
  409. /// </summary>
  410. /// <returns></returns>
  411. public bool CheckStopPostionEndStatus()
  412. {
  413. foreach (var item in _cellLst)
  414. {
  415. bool result = item.CheckRotationEndStatus();
  416. if (!result)
  417. {
  418. return false;
  419. }
  420. }
  421. return true;
  422. }
  423. /// <summary>
  424. /// 检验停止失败状态
  425. /// </summary>
  426. /// <returns></returns>
  427. public bool CheckStopPostionStopStatus()
  428. {
  429. foreach (var item in _cellLst)
  430. {
  431. bool result = item.CheckRotationStopStatus();
  432. if (result)
  433. {
  434. return true;
  435. }
  436. }
  437. return false;
  438. }
  439. /// <summary>
  440. /// 检验流量是否ok
  441. /// </summary>
  442. /// <returns></returns>
  443. private bool CheckFlowOk()
  444. {
  445. if (!_totalFlowOk)
  446. {
  447. _checkFlowOk = false;
  448. return true;
  449. }
  450. foreach(var item in _cellLst)
  451. {
  452. if (!_cellFlowOk[item.Module])
  453. {
  454. _checkFlowOk = false;
  455. return true;
  456. }
  457. }
  458. _checkFlowOk = true;
  459. return true;
  460. }
  461. /// <summary>
  462. /// 打开Degas Pump和Adjust
  463. /// </summary>
  464. /// <returns></returns>
  465. private bool OpenDegasPump()
  466. {
  467. int count = 0;
  468. count+=_mainDevice.DegasPumpEnable()?1:0;
  469. count+=_mainDevice.DegasAdjustOn()?1:0;
  470. return count == 2;
  471. }
  472. /// <summary>
  473. /// 最后确认结果
  474. /// </summary>
  475. /// <returns></returns>
  476. private bool LastCheckResult()
  477. {
  478. //当前是Main Home
  479. if (Module == ModuleName.VPWMain1.ToString())
  480. {
  481. AllCellPostMsg();
  482. if (_totalFlowOk)
  483. {
  484. return true;
  485. }
  486. else
  487. {
  488. LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"total flow {_totalFlow} is less than {_totalFlowStartLimit}");
  489. return false;
  490. }
  491. }
  492. else
  493. {
  494. AllCellPostMsg();
  495. VpwMainEntity vpwMainEntity = Singleton<RouteManager>.Instance.GetModule<VpwMainEntity>(ModuleName.VPWMain1.ToString());
  496. if (_totalFlowOk)
  497. {
  498. vpwMainEntity.CheckToPostMessage<VPWMainState, VPWMainMsg>(eEvent.INFO_VPWMAIN, ModuleName.VPWMain1.ToString(), (int)VPWCellMsg.EnterIdle);
  499. }
  500. else
  501. {
  502. vpwMainEntity.PostMsg((int)VPWMainMsg.Error);
  503. LOG.WriteLog(eEvent.ERR_VPWMAIN,ModuleName.VPWMain1.ToString(), $"total flow {_totalFlow} is less than {_totalFlowStartLimit}");
  504. }
  505. if (_cellFlowOk[Module])
  506. {
  507. return true;
  508. }
  509. else
  510. {
  511. LOG.WriteLog(eEvent.ERR_VPW, Module, $"cell flow {_cellFlows[Module]} is less than {_cellFlowStartLimit}");
  512. return false;
  513. }
  514. }
  515. }
  516. /// <summary>
  517. /// 所有cell推送消息
  518. /// </summary>
  519. private void AllCellPostMsg()
  520. {
  521. foreach (var item in _cellLst)
  522. {
  523. //过滤当前本身的cell
  524. if (item.Module == Module)
  525. {
  526. continue;
  527. }
  528. //若cell流量是ok,则post msg变成idle
  529. VpwCellEntity vpwCellEntity = Singleton<RouteManager>.Instance.GetModule<VpwCellEntity>(item.Module);
  530. if (_cellFlowOk[item.Module])
  531. {
  532. vpwCellEntity.CheckToPostMessage<VPWCellState, VPWCellMsg>(eEvent.INFO_VPW, item.Module, (int)VPWCellMsg.EnterIdle);
  533. }
  534. else//则cell流量是不ok,则post error msg
  535. {
  536. vpwCellEntity.PostMsg((int)VPWCellMsg.Error);
  537. LOG.WriteLog(eEvent.ERR_VPW, item.Module, $"cell flow {_cellFlows[item.Module]} is less than {_cellFlowStartLimit}");
  538. }
  539. }
  540. }
  541. /// <summary>
  542. /// 启动
  543. /// </summary>
  544. /// <param name="objs"></param>
  545. /// <returns></returns>
  546. public RState Start(params object[] objs)
  547. {
  548. List<VpwCellDevice> lstDevice = (List<VpwCellDevice>)objs[0];
  549. _vpwCellDevices.Clear();
  550. _cellFlows.Clear();
  551. _cellLst.Clear();
  552. _cellFlowOk.Clear();
  553. _totalFlowOk = false;
  554. _checkFlowOk = false;
  555. _totalFlow = 0;
  556. for (int i = 0; i < lstDevice.Count; i++)
  557. {
  558. _vpwCellDevices.Add(lstDevice[i]);
  559. VpwCellEntity vpwCellEntity = Singleton<RouteManager>.Instance.GetModule<VpwCellEntity>(lstDevice[i].Module);
  560. if (vpwCellEntity.IsAuto || vpwCellEntity.IsManual)
  561. {
  562. _cellLst.Add(lstDevice[i]);
  563. if (!CheckRotationSwitchOn(lstDevice[i])){
  564. return RState.Failed;
  565. }
  566. _cellFlowOk[lstDevice[i].Module]=false;
  567. }
  568. }
  569. _mainDevice = DEVICE.GetDevice<VpwMainDevice>(ModuleName.VPWMain1.ToString());
  570. _n2PurgeTime = SC.GetValue<int>("VPWMain.Plumbing.N2PurgeTime");
  571. _flowFaultHolderoffTime = SC.GetValue<int>("VPWMain.Plumbing.FlowFaultHoldoffTime");
  572. double purgeMotorSpeed = SC.GetValue<double>("VPWMain.Plumbing.PurgeMotorSpeed");
  573. _rotationSpeed = (int)(Math.Round(purgeMotorSpeed*6,0));
  574. _totalFlowStartLimit = SC.GetValue<double>("VPWMain.Plumbing.TotalFlowStartLowLimit");
  575. _cellFlowStartLimit = SC.GetValue<double>("VPWMain.Plumbing.CellFlowStartLowLimit");
  576. _degasEnableDelayTime = SC.GetValue<int>("VPWMain.Plumbing.DegasEnableDelayTime");
  577. _checkChamberUpDownTimes = SC.GetValue<int>("VPWMain.ChamberUpDownCheckTime");
  578. return Runner.Start(Module,"VPW Home");
  579. }
  580. /// <summary>
  581. /// 检验Rotation电机是否上电
  582. /// </summary>
  583. /// <param name="device"></param>
  584. /// <returns></returns>
  585. private bool CheckRotationSwitchOn(VpwCellDevice device)
  586. {
  587. if (!device.CheckRotationSwitchOn())
  588. {
  589. LOG.WriteLog(eEvent.ERR_VPWMAIN, Module, $"{device.Module} rotation is not switch on");
  590. return false;
  591. }
  592. return true;
  593. }
  594. }
  595. }