ReservoirPumpSpeedHelper.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.Metal;
  6. using MECF.Framework.Common.CommonData.Reservoir;
  7. using MECF.Framework.Common.RecipeCenter;
  8. using MECF.Framework.Common.ToolLayout;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Reflection;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace CyberX8_RT.Devices.Reservoir
  16. {
  17. public class ReservoirPumpSpeedHelper
  18. {
  19. #region 内部变量
  20. /// <summary>
  21. /// 时间
  22. /// </summary>
  23. private DateTime _updateTime=DateTime.Now;
  24. /// <summary>
  25. /// 模块名称
  26. /// </summary>
  27. private string _moduleName;
  28. /// <summary>
  29. /// AN流量总和
  30. /// </summary>
  31. private double _anTotalFlow = 0;
  32. /// <summary>
  33. /// CA流量总和
  34. /// </summary>
  35. private double _caTotalFlow = 0;
  36. /// <summary>
  37. /// 设备对象
  38. /// </summary>
  39. StandardHotReservoirDevice _device;
  40. #endregion
  41. /// <summary>
  42. /// 构造函数
  43. /// </summary>
  44. /// <param name="moduleName"></param>
  45. public ReservoirPumpSpeedHelper(string moduleName, StandardHotReservoirDevice reservoirDevice)
  46. {
  47. _moduleName = moduleName;
  48. _device = reservoirDevice;
  49. }
  50. /// <summary>
  51. /// 监控
  52. /// </summary>
  53. public void Monitor(ResRecipe resRecipe)
  54. {
  55. int cellFlowUpdatePeriod = SC.GetValue<int>("Reservoir.CellFlowUpdatePeriod");
  56. if(DateTime.Now.Subtract(_updateTime).TotalSeconds > cellFlowUpdatePeriod)
  57. {
  58. _updateTime = DateTime.Now;
  59. AdjustCAPumpSpeed(resRecipe);
  60. }
  61. }
  62. /// <summary>
  63. /// 调节阴极泵速
  64. /// </summary>
  65. private void AdjustCAPumpSpeed(ResRecipe resRecipe)
  66. {
  67. if (_device.ReservoirData.RegulatePumpSignalIn)
  68. {
  69. double caPumpSpeed = _device.ReservoirData.RegulatePumpSpeed;
  70. double averageCAFlow = GetAverageCAFlow();
  71. if (averageCAFlow == 0)
  72. {
  73. return;
  74. }
  75. double caPumpMaxSpeed = SC.GetValue<double>("Reservoir.MaxPumpSpeed");
  76. double caFlowDelta = resRecipe.CAFlowSetPoint - averageCAFlow;
  77. double newCAPumpSpeed = 330 * caFlowDelta + caPumpSpeed;
  78. if (newCAPumpSpeed <= 0 || newCAPumpSpeed > caPumpMaxSpeed)
  79. {
  80. return;
  81. }
  82. if (Math.Abs(newCAPumpSpeed - caPumpSpeed) >= 10)
  83. {
  84. _device.RegulatePumpSpeed(newCAPumpSpeed);
  85. }
  86. }
  87. }
  88. /// <summary>
  89. /// 获取平均阳极流量
  90. /// </summary>
  91. /// <returns></returns>
  92. private double GetAverageCAFlow()
  93. {
  94. int count = 0;
  95. _caTotalFlow = 0;
  96. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(_moduleName);
  97. if (reservoirItem != null)
  98. {
  99. List<MetalItem> metalItems = reservoirItem.MetalCells;
  100. if (metalItems != null && metalItems.Count > 0)
  101. {
  102. foreach (MetalItem metalItem in metalItems)
  103. {
  104. StandardHotMetalDevice metalDevice = DEVICE.GetDevice<StandardHotMetalDevice>(metalItem.ModuleName);
  105. if (metalDevice != null&&metalDevice.IsAuto)
  106. {
  107. count++;
  108. _caTotalFlow += metalDevice.MetalDeviceData.CellFlow;
  109. }
  110. }
  111. }
  112. if (count != 0)
  113. {
  114. return _caTotalFlow / count;
  115. }
  116. }
  117. return 0;
  118. }
  119. }
  120. }