ReservoirPumpSpeedHelper.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.SCCore;
  4. using CyberX8_RT.Devices.Metal;
  5. using MECF.Framework.Common.CommonData.Reservoir;
  6. using MECF.Framework.Common.RecipeCenter;
  7. using MECF.Framework.Common.ToolLayout;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Reflection;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace CyberX8_RT.Devices.Reservoir
  15. {
  16. public class ReservoirPumpSpeedHelper
  17. {
  18. #region 内部变量
  19. /// <summary>
  20. /// 时间
  21. /// </summary>
  22. private DateTime _updateTime=DateTime.Now;
  23. /// <summary>
  24. /// 模块名称
  25. /// </summary>
  26. private string _moduleName;
  27. /// <summary>
  28. /// AN流量总和
  29. /// </summary>
  30. private double _anTotalFlow = 0;
  31. /// <summary>
  32. /// CA流量总和
  33. /// </summary>
  34. private double _caTotalFlow = 0;
  35. /// <summary>
  36. /// 设备对象
  37. /// </summary>
  38. CompactMembranReservoirDevice _device;
  39. #endregion
  40. /// <summary>
  41. /// 构造函数
  42. /// </summary>
  43. /// <param name="moduleName"></param>
  44. public ReservoirPumpSpeedHelper(string moduleName,CompactMembranReservoirDevice reservoirDevice)
  45. {
  46. _moduleName = moduleName;
  47. _device = reservoirDevice;
  48. }
  49. /// <summary>
  50. /// 监控
  51. /// </summary>
  52. public void Monitor(ResRecipe resRecipe)
  53. {
  54. int cellFlowUpdatePeriod = SC.GetValue<int>("Reservoir.CellFlowUpdatePeriod");
  55. if(DateTime.Now.Subtract(_updateTime).TotalSeconds > cellFlowUpdatePeriod)
  56. {
  57. _updateTime = DateTime.Now;
  58. AdjustANPumpSpeed(resRecipe);
  59. AdjustCAPumpSpeed(resRecipe);
  60. }
  61. }
  62. /// <summary>
  63. /// 调节阳极泵速
  64. /// </summary>
  65. private void AdjustANPumpSpeed(ResRecipe resRecipe)
  66. {
  67. double anPumpSpeed = _device.ReservoirData.ANPump;
  68. if (anPumpSpeed != 0)
  69. {
  70. double averageANFlow = GetAverageANFlow();
  71. if (averageANFlow == 0)
  72. {
  73. return;
  74. }
  75. double anFlowDelta = resRecipe.ANFlowSetPoint - averageANFlow;
  76. double newANPumpSpeed = 1.8 * anFlowDelta + anPumpSpeed;
  77. if (newANPumpSpeed <= 0)
  78. {
  79. return;
  80. }
  81. if (Math.Abs(newANPumpSpeed - anPumpSpeed) >= 0.01)
  82. {
  83. _device.AnPump(newANPumpSpeed);
  84. }
  85. }
  86. }
  87. /// <summary>
  88. /// 调节阳极泵速
  89. /// </summary>
  90. private void AdjustCAPumpSpeed(ResRecipe resRecipe)
  91. {
  92. if (_device.ReservoirData.CAPumpEnable)
  93. {
  94. double caPumpSpeed = _device.ReservoirData.CAPumpSpeed;
  95. double averageCAFlow = GetAverageCAFlow();
  96. if (averageCAFlow == 0)
  97. {
  98. return;
  99. }
  100. double caPumpMaxSpeed = SC.GetValue<double>("Reservoir.CAMaxPumpSpeed");
  101. double caFlowDelta = resRecipe.CAFlowSetPoint - averageCAFlow;
  102. double newCAPumpSpeed = 330 * caFlowDelta + caPumpSpeed;
  103. if (newCAPumpSpeed <= 0 || newCAPumpSpeed > caPumpMaxSpeed)
  104. {
  105. return;
  106. }
  107. if (Math.Abs(newCAPumpSpeed - caPumpSpeed) >= 10)
  108. {
  109. _device.CAPumpSpeed(newCAPumpSpeed);
  110. }
  111. }
  112. }
  113. /// <summary>
  114. /// 获取平均阳极流量
  115. /// </summary>
  116. /// <returns></returns>
  117. private double GetAverageANFlow()
  118. {
  119. int count = 0;
  120. _anTotalFlow = 0;
  121. double ANOverFlow = SC.GetValue<double>("Reservoir.ANOverFlow");
  122. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(_moduleName);
  123. if (reservoirItem == null)
  124. {
  125. return 0;
  126. }
  127. List<MetalItem> metalItems = reservoirItem.MetalCells;
  128. if (metalItems == null || metalItems.Count == 0)
  129. {
  130. return 0;
  131. }
  132. foreach (MetalItem metalItem in metalItems)
  133. {
  134. CompactMembranMetalDevice metalDevice = DEVICE.GetDevice<CompactMembranMetalDevice>(metalItem.ModuleName);
  135. if (metalDevice == null || metalDevice.IsManual || metalDevice.IsDisable)
  136. {
  137. continue;
  138. }
  139. if (metalDevice.MetalDeviceData.ANAPinEnable&&metalDevice.ANACellFlow.CounterValue < ANOverFlow)
  140. {
  141. _anTotalFlow += metalDevice.ANACellFlow.CounterValue;
  142. count++;
  143. }
  144. if (metalDevice.MetalDeviceData.ANBPinEnable&&metalDevice.ANBCellFlow.CounterValue<ANOverFlow)
  145. {
  146. _anTotalFlow += metalDevice.ANBCellFlow.CounterValue;
  147. count++;
  148. }
  149. }
  150. if (count != 0)
  151. {
  152. return _anTotalFlow / count;
  153. }
  154. return 0;
  155. }
  156. /// <summary>
  157. /// 获取平均阳极流量
  158. /// </summary>
  159. /// <returns></returns>
  160. private double GetAverageCAFlow()
  161. {
  162. int count = 0;
  163. _caTotalFlow = 0;
  164. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(_moduleName);
  165. if (reservoirItem != null)
  166. {
  167. List<MetalItem> metalItems = reservoirItem.MetalCells;
  168. if (metalItems != null && metalItems.Count > 0)
  169. {
  170. foreach (MetalItem metalItem in metalItems)
  171. {
  172. CompactMembranMetalDevice metalDevice = DEVICE.GetDevice<CompactMembranMetalDevice>(metalItem.ModuleName);
  173. if (metalDevice != null&&metalDevice.IsAuto)
  174. {
  175. if (metalDevice.MetalDeviceData.CellFlowValve)
  176. {
  177. count++;
  178. _caTotalFlow += metalDevice.MetalDeviceData.CellFlow;
  179. }
  180. }
  181. }
  182. }
  183. if (count != 0)
  184. {
  185. return _caTotalFlow / count;
  186. }
  187. }
  188. return 0;
  189. }
  190. }
  191. }