Files
tbf/TBF/Rig/Uni/RegValveTandem/RegValveTandem.cs
T

118 lines
4.8 KiB
C#

///
/// Copyright (c) 2021 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using log4net;
using TBF.Rig.ControlBoard.Uni;
using TBF.Rig.Generic;
using TBF.Boxes;
namespace TBF.Rig.Uni.RegValveTandem
{
public class RegValveTandem : ComponentBase, GenericDevices.IRegValve
{
private static readonly ILog log = LogManager.GetLogger(typeof(RegValveTandem));
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
public readonly RegValveTandemCfg RegulValveTandemCfg;
IDictionary<double, double> dict;
public IDictionary<double, double> Dict { get { return dict; } }
UniCB uniCB { get { return regValve.UniCB; } }
public ValveCategory Category { get { return RegulValveTandemCfg.Category; } }
readonly TBF.Rig.Uni.RegValve.RegValve regValve;
readonly TBF.Rig.Uni.RegValve.RegValve fixedRV;
float fixedPctLo; /// [%]
float fixedPctHi; /// [%]
public int FlowStableSec { get { return RegulValveTandemCfg.FlowStableSec; } } /// 0..60 sec
///
public bool IsCoax { get { return false; } }
public double Position
{
get { return regValve.Position; }
}
public RegValveTandem() { }
public RegValveTandem(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
: base(cfg)
{
RegulValveTandemCfg = cfg as RegValveTandemCfg;
regValve = TbfComponents.FindComponent(RegulValveTandemCfg.RegulValveName, components) as TBF.Rig.Uni.RegValve.RegValve;
if (regValve == null) throw new Exception("Cannot find regulation valve");
fixedRV = TbfComponents.FindComponent(RegulValveTandemCfg.FixedRVName, components) as TBF.Rig.Uni.RegValve.RegValve;
if (fixedRV == null) throw new Exception("Cannot find fixed RV");
log.Warn(this.ToString());
}
public override void Initialize()
{
fixedPctLo = Math.Max(0.0f, RegulValveTandemCfg.FixedRVPosition - 3.0f);
fixedPctHi = Math.Min(100.0f, RegulValveTandemCfg.FixedRVPosition + 3.0f);
this.dict = new Dictionary<double, double>();
}
/// <summary>
/// Operation to set the water flow within tolerances
/// Events: Event.None, Event.FlowReached, Event.FlowTimeOut
/// </summary>
/// <param name="flowMeter">Flowmeter component</param>
/// <param name="requiredFlowLo">Lower limit of the required flow [m3/h]</param>
/// <param name="requiredFlowHi">Higher limit of the required flow [m3/h]</param>
/// <param name="pidCoef">PID coefficient (float)</param>
/// <param name="measuredFlow">Measured flow [m3/h]</param>
/// <param name="timeout">Timeout in [s]</param>
/// <returns>SetFlowOp instance</returns>
public IOperation SetFlowOp(GenericDevices.IFlowMeter flowMeter, double requiredFlowLo, double requiredFlowHi,
DoubleBox measuredFlow, int timeout, int delay)
{
return new SetFlowOp(uniCB, regValve, fixedRV, fixedPctLo, fixedPctHi, flowMeter, requiredFlowLo, requiredFlowHi,
measuredFlow, timeout, delay);
}
/// <summary>
/// Operation to set the water flow within tolerances. Leave the measurement running.
/// Events: Event.None, Event.FlowReached, Event.FlowTimeOut
/// </summary>
/// <param name="flowMeter">Flowmeter component</param>
/// <param name="requiredFlowLo">Lower limit of the required flow [m3/h]</param>
/// <param name="requiredFlowHi">Higher limit of the required flow [m3/h]</param>
/// <param name="measuredFlow">Measured flow [m3/h]</param>
/// <param name="timeout">Timeout in [s]</param>
/// <returns>SetFlowOp instance</returns>
public IOperation SetFlowAndMeasureOp(GenericDevices.IFlowMeter flowMeter, double requiredFlowLo, double requiredFlowHi,
DoubleBox measuredFlow, int timeout, float filterConstant)
{
return new SetFlowOp(uniCB, regValve, fixedRV, fixedPctLo, fixedPctHi,
flowMeter, requiredFlowLo, requiredFlowHi, measuredFlow, timeout, 0, true);
}
/// <summary>
/// Operation to set the regulation valve to a required position
/// Events: Event.None
/// </summary>
/// <param name="flowLo">Lower limit of the required valve position in [%]</param>
/// <param name="flowLo">Higher limit of the required valve position in [%]</param>
/// <returns>SetPositionOp instance</returns>
public IOperation SetRegValvePositionOp(double pctLo, double pctHi, int timeoutMs)
{
return null;
}
public IOperation ChangeRegValvePositionOp(double timePulseSec)
{
return null;
}
}
}