123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using MECF.Framework.Common.Beckhoff.ModuleIO;
- using MECF.Framework.Common.Routine;
- using MECF.Framework.Common.ToolLayout;
- using MECF.Framework.Common.TwinCat;
- using CyberX8_Core;
- using CyberX8_RT.Devices.Metal;
- using CyberX8_RT.Devices.Reservoir;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using CyberX8_RT.Devices.Safety;
- using MECF.Framework.Common.IOCore;
- namespace CyberX8_RT.Modules.Reservoir
- {
- public class ANPumpOnRoutine : RoutineBase, IRoutine
- {
- private enum ANPumpStep
- {
- PumpSpeed,
- Delay,
- ANByPass,
- CellsFillValve,
- FlowDelay,
- CheckFlow,
- CheckByPass,
- End
- }
- #region 常量
- private const string AN_A_PINENABLE = "ANAPinEnable";
- private const string AN_B_PINENABLE = "ANBPinEnable";
- private const string AN_PUMP = "ANPump";
- private const string AN_BY_PASS = "ANByPass";
- #endregion
- #region 内部变量
- /// <summary>
- /// 默认泵速
- /// </summary>
- private double _anPumpSpeed = 5000;
- /// <summary>
- /// flow fault hold off时长
- /// </summary>
- private int _flowFaultHoldOffTime = 10000;
- /// <summary>
- /// 阳极最小流量
- /// </summary>
- private double _anMinFlow = 0.2;
- /// <summary>
- /// 最小Bypass数值
- /// </summary>
- private int _anBypassMinCellCount;
- /// <summary>
- /// AN流量总和
- /// </summary>
- private double _anTotalFlow = 0;
- /// <summary>
- /// Reservoir设备
- /// </summary>
- private CompactMembranReservoirDevice _device;
- /// <summary>
- /// 阳极打开阀Cell总数
- /// </summary>
- private int _anOpenValveCount;
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public ANPumpOnRoutine(string module) : base(module)
- {
- }
- /// <summary>
- /// 中止
- /// </summary>
- public void Abort()
- {
- Runner.Stop("Manual abort");
- }
- /// <summary>
- /// 监控
- /// </summary>
- /// <returns></returns>
- public RState Monitor()
- {
- Runner.Run(ANPumpStep.PumpSpeed, () => { return ANPumpSpeed(_anPumpSpeed); }, _delay_1ms)
- .Run(ANPumpStep.ANByPass,ANByPassOn,_delay_1ms)
- .Run(ANPumpStep.CellsFillValve, OpenAllCellsFillValve,_delay_1ms)
- .Delay(ANPumpStep.Delay, _flowFaultHoldOffTime)
- .Run(ANPumpStep.CheckFlow,CheckAllFlow,_delay_1ms)
- .RunIf(ANPumpStep.CheckByPass, CheckTotalFlowBypass(),ANByPassOff,NullFun,_delay_1ms)
- .End(ANPumpStep.End, NullFun, _delay_1ms);
- return Runner.Status;
- }
- /// <summary>
- /// Pump Speed
- /// </summary>
- /// <param name="speed"></param>
- /// <returns></returns>
- private bool ANPumpSpeed(double speed)
- {
- SafetyDevice safetyDevice = DEVICE.GetDevice<SafetyDevice>("Safety");
- if (safetyDevice != null && !safetyDevice.SafetyData.PumpEdm)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"Safety PumpEdm is Activate");
- return false;
- }
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{AN_PUMP}");
- return IOModuleManager.Instance.WriteIoValue(ioName, speed);
- }
- /// <summary>
- /// Pump Bypass
- /// </summary>
- /// <param name="speed"></param>
- /// <returns></returns>
- private bool ANByPassOn()
- {
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{AN_BY_PASS}");
- return IOModuleManager.Instance.WriteIoValue(ioName, true);
- }
- /// <summary>
- /// Pump Bypass
- /// </summary>
- /// <param name="speed"></param>
- /// <returns></returns>
- private bool ANByPassOff()
- {
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{AN_BY_PASS}");
- return IOModuleManager.Instance.WriteIoValue(ioName, false);
- }
- /// <summary>
- /// 检验所有流量
- /// </summary>
- /// <returns></returns>
- private bool OpenAllCellsFillValve()
- {
- bool result = false;
- ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module.ToString());
- if (reservoirItem != null)
- {
- List<MetalItem> metalItems = reservoirItem.MetalCells;
- if (metalItems != null && metalItems.Count > 0)
- {
- foreach (MetalItem metalItem in metalItems)
- {
- if (metalItem.Installed)
- {
- CompactMembranMetalDevice metalDevice = DEVICE.GetDevice<CompactMembranMetalDevice>(metalItem.ModuleName);
- if (metalDevice != null && metalDevice.IsAuto)
- {
- _anOpenValveCount++;
- result = metalDevice.AnSideAFillOn("", null);
- if(!result)
- {
- return false;
- }
- result = metalDevice.AnSideBFillOn("", null);
- if (!result)
- {
- return false;
- }
- }
- }
- }
- }
- }
- return true;
- }
- /// <summary>
- /// 关闭所有Cell的Flow Valve
- /// </summary>
- /// <returns></returns>
- private bool CloseAllCellsFlowValve()
- {
- ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module.ToString());
- if (reservoirItem != null)
- {
- List<MetalItem> metalItems = reservoirItem.MetalCells;
- if (metalItems != null && metalItems.Count > 0)
- {
- foreach (MetalItem metalItem in metalItems)
- {
- if (metalItem.Installed)
- {
- CompactMembranMetalDevice metalDevice = DEVICE.GetDevice<CompactMembranMetalDevice>(metalItem.ModuleName);
- if (metalDevice != null && metalDevice.IsAuto)
- {
- metalDevice.AnSideAFillOff("", null);
- metalDevice.AnSideBFillOff("", null);
- }
- }
- }
- }
- }
- return true;
- }
- /// <summary>
- /// 检验所有流量
- /// </summary>
- /// <returns></returns>
- private bool CheckAllFlow()
- {
- if (_anOpenValveCount == 0)
- {
- return true;
- }
- _anTotalFlow = 0.0;
- ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module.ToString());
- if (reservoirItem != null)
- {
- List<MetalItem> metalItems = reservoirItem.MetalCells;
- if (metalItems != null && metalItems.Count > 0)
- {
- foreach (MetalItem metalItem in metalItems)
- {
- if (metalItem.Installed)
- {
- CompactMembranMetalDevice metalDevice = DEVICE.GetDevice<CompactMembranMetalDevice>(metalItem.ModuleName);
- if (metalDevice != null&&metalDevice.IsAuto)
- {
- _anTotalFlow += metalDevice.ANACellFlow.CounterValue;
- _anTotalFlow += metalDevice.ANBCellFlow.CounterValue;
- }
- }
- }
- }
- }
- if(_anTotalFlow<=_anMinFlow)
- {
- CloseAllCellsFlowValve();
- ANPumpSpeed(0);
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"total flow {_anTotalFlow} is not over {_anMinFlow}");
- return false;
- }
- else
- {
- LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"total flow {_anTotalFlow} is over {_anMinFlow}");
- return true;
- }
- }
- /// <summary>
- /// 检验总流量Bypass情况
- /// </summary>
- /// <returns></returns>
- private bool CheckTotalFlowBypass()
- {
- return _anTotalFlow > _anBypassMinCellCount;
- }
- /// <summary>
- /// 启动
- /// </summary>
- /// <param name="objs"></param>
- /// <returns></returns>
- public RState Start(params object[] objs)
- {
- _device = DEVICE.GetDevice<CompactMembranReservoirDevice>(Module);
- _anPumpSpeed = SC.GetValue<double>("Reservoir.ANDefaultPumpSpeed");
- _flowFaultHoldOffTime = SC.GetValue<int>($"Reservoir.{Module}.FlowFaultHoldOffTime");
- _anBypassMinCellCount = SC.GetValue<int>($"Reservoir.{Module}.ANBypassMinCellCount");
- _anTotalFlow = 0;
- return Runner.Start(Module, "AN Pump On");
- }
- }
- }
|