VPWHomeRoutine.cs 20 KB

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