Uni.RegValve clean-up.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
///
|
||||
/// Copyright (c) 2021 Sensus Metering Systems
|
||||
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
///
|
||||
/// Copyright (c) 2021 Sensus Metering Systems
|
||||
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
||||
///
|
||||
using System.Collections.Generic;
|
||||
using TBF.Rig.Generic;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
///
|
||||
/// Copyright (c) 2021 Sensus Metering Systems
|
||||
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using log4net;
|
||||
|
||||
@@ -19,11 +19,10 @@ namespace TBF.Rig.Uni.RegValve
|
||||
return string.Format("SetFlowOp({0}, Qfrom={1}, Qto={2})", regV.Name, shrinkedTgtFlowLo, shrinkedTgtFlowHi);
|
||||
}
|
||||
|
||||
|
||||
public const double RqrdFlowRangeRatio = 0.5;
|
||||
|
||||
///
|
||||
/// Set by the constructor
|
||||
/// Set by the constructor
|
||||
///
|
||||
readonly UniCB uniCB;
|
||||
readonly RegValve regV;
|
||||
@@ -36,8 +35,8 @@ namespace TBF.Rig.Uni.RegValve
|
||||
readonly bool leaveFlowControlRunning;
|
||||
|
||||
readonly double maximalFlow;
|
||||
|
||||
///
|
||||
|
||||
///
|
||||
/// Internal state of this operation
|
||||
///
|
||||
enum OpState
|
||||
@@ -56,13 +55,12 @@ namespace TBF.Rig.Uni.RegValve
|
||||
|
||||
double currentReqFlowLo;
|
||||
double currentReqFlowHi;
|
||||
double targetPositionLo;
|
||||
double targetPositionHi;
|
||||
double targetPositionLo;
|
||||
double targetPositionHi;
|
||||
|
||||
int startTime;
|
||||
int setFlowTime;
|
||||
int expireTime;
|
||||
DoubleBox flowBox;
|
||||
DoubleBox msrdFlow;
|
||||
int isFlowOkDuration;
|
||||
|
||||
|
||||
@@ -71,23 +69,23 @@ namespace TBF.Rig.Uni.RegValve
|
||||
/// Events: FlowSet, FlowTimeOut
|
||||
/// </summary>
|
||||
/// <param name="uniCB">Control board device</param>
|
||||
/// <param name="regulValve">Regulation valve component</param>
|
||||
/// <param name="regValve">Regulation valve component</param>
|
||||
/// <param name="flowMeter">Flowmeter component</param>
|
||||
/// <param name="qFrom">Lower limit of the flow to be achieved in [m3/h]</param>
|
||||
/// <param name="qTo">Upper limit of the flow to be achieved in [m3/h]</param>
|
||||
/// <param name="pidCoef">PID coefficient (float)</param>
|
||||
/// <param name="msrdFlow">DoubleBox for measured flow</param>
|
||||
/// <param name="timeout">Timeout for the flow setting in [s]</param>
|
||||
/// <param name="delay">Flow setting starts after this delay [s]</param>
|
||||
/// <param name="delay">Flow setting starts after this delay in [s]</param>
|
||||
/// <param name="leaveFlowControlRunning">true = Leave the measurement running after op. stop</param>
|
||||
/// <remarks>Only Elde.Valve flow are used, other flow on the lists are ignored</remarks>
|
||||
public SetFlowOp(UniCB uniCB, IRegValve regValve, IFlowMeter flowMeter, double qFrom, double qTo, DoubleBox flowBox,
|
||||
public SetFlowOp(UniCB uniCB, IRegValve regValve, IFlowMeter flowMeter, double qFrom, double qTo, DoubleBox msrdFlow,
|
||||
int timeout, int delay, bool leaveFlowControlRunning)
|
||||
{
|
||||
this.uniCB = uniCB;
|
||||
if (this.uniCB == null) throw new ArgumentNullException("cBoard is null or not Uni");
|
||||
this.uniCB = uniCB;
|
||||
if (this.uniCB == null) throw new ArgumentNullException("Control board is null or not Uni");
|
||||
|
||||
this.regV = regValve as RegValve;
|
||||
if (this.regV == null) throw new ArgumentNullException("regValve is null or not Uni");
|
||||
if (this.regV == null) throw new ArgumentNullException(string.Format("{0} is not Uni.RegValve", regValve.Name));
|
||||
|
||||
this.flowMeter = flowMeter;
|
||||
if (this.flowMeter == null) throw new ArgumentNullException("flowMeter");
|
||||
@@ -97,15 +95,14 @@ namespace TBF.Rig.Uni.RegValve
|
||||
double rqrdFlowLoBeforeCorr = qFrom - MeasurementCorrection.GetCorrection(qFrom, flowMeter.Corrections);
|
||||
double rqrdFlowHiBeforeCorr = qTo - MeasurementCorrection.GetCorrection(qTo, flowMeter.Corrections);
|
||||
targetFlowAve = (rqrdFlowLoBeforeCorr + rqrdFlowHiBeforeCorr) / 2;
|
||||
shrinkedTgtFlowLo = (RqrdFlowRangeRatio * rqrdFlowLoBeforeCorr) + ((1 - RqrdFlowRangeRatio) * targetFlowAve); /// Move the lower limit 15% of the range up
|
||||
shrinkedTgtFlowHi = (RqrdFlowRangeRatio * rqrdFlowHiBeforeCorr) + ((1 - RqrdFlowRangeRatio) * targetFlowAve); /// Move the upper limit 15% of the range down
|
||||
|
||||
this.flowBox = flowBox;
|
||||
if (this.flowBox == null) throw new ArgumentNullException("flowBox");
|
||||
shrinkedTgtFlowLo = (RqrdFlowRangeRatio * rqrdFlowLoBeforeCorr)
|
||||
+ ((1 - RqrdFlowRangeRatio) * targetFlowAve); /// Move the lower limit 15% of the range up
|
||||
shrinkedTgtFlowHi = (RqrdFlowRangeRatio * rqrdFlowHiBeforeCorr)
|
||||
+ ((1 - RqrdFlowRangeRatio) * targetFlowAve); /// Move the upper limit 15% of the range down
|
||||
|
||||
this.msrdFlow = msrdFlow;
|
||||
this.timeout = timeout;
|
||||
this.delay = delay;
|
||||
|
||||
this.leaveFlowControlRunning = leaveFlowControlRunning;
|
||||
|
||||
log.Debug(this.ToString());
|
||||
@@ -171,16 +168,13 @@ namespace TBF.Rig.Uni.RegValve
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start this operation
|
||||
/// </summary>
|
||||
/// <summary>Start this operation</summary>
|
||||
public void Start()
|
||||
{
|
||||
log.InfoFormat("SetFlowOp:Start() rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3}",
|
||||
regV.Idx1, flowMeter.Idx1, currentReqFlowLo, currentReqFlowHi);
|
||||
|
||||
/// Store the current time, etc.
|
||||
startTime = StateMachine.Time;
|
||||
setFlowTime = StateMachine.Time + delay;
|
||||
expireTime = StateMachine.Time + timeout;
|
||||
if (expireTime < 0) expireTime = int.MaxValue;
|
||||
@@ -273,17 +267,16 @@ namespace TBF.Rig.Uni.RegValve
|
||||
///
|
||||
double frequency = flowMeter.ReadFrequency();
|
||||
double flow = flowMeter.ReadFlow();
|
||||
if (flow != 0) flowBox.Val = flow;
|
||||
if (msrdFlow != null && flow != 0) msrdFlow.Val = flow;
|
||||
|
||||
if ((currentReqFlowLo <= flow) && (flow <= currentReqFlowHi))
|
||||
if (currentReqFlowLo <= flow && flow <= currentReqFlowHi)
|
||||
{
|
||||
/// Flow is within range
|
||||
isFlowOkDuration++;
|
||||
isFlowOkDuration++; /// Increment the flow within range duration
|
||||
|
||||
if (isFlowOkDuration >= regV.FlowStableSec)
|
||||
{
|
||||
/// Flow is within range for sufficiently long time
|
||||
if (regV.regValveCfg.StoredPositionReuse)
|
||||
if (regV.StoredPositionReuse)
|
||||
{
|
||||
double rvPosition = regV.Position; /// Read the current position
|
||||
double storedPosition;
|
||||
@@ -330,13 +323,12 @@ namespace TBF.Rig.Uni.RegValve
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Start this operation</summary>
|
||||
/// <summary>Stop this operation</summary>
|
||||
public void Stop()
|
||||
{
|
||||
if (!leaveFlowControlRunning)
|
||||
{
|
||||
/// Stop flow measurement
|
||||
uniCB.StopFlowControl(false, regV.Idx1);
|
||||
uniCB.StopFlowControl(false, regV.Idx1); /// Stop the flow measurement
|
||||
}
|
||||
|
||||
opState = OpState.Idle;
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace TBF.Rig.Uni.RegValve
|
||||
OpState opState;
|
||||
|
||||
/// Set by the constructor
|
||||
readonly UniCB cBoard;
|
||||
readonly UniCB uniCB;
|
||||
readonly RegValve regV;
|
||||
readonly int regValveNr;
|
||||
readonly double posLoPct;
|
||||
@@ -45,24 +45,23 @@ namespace TBF.Rig.Uni.RegValve
|
||||
/// Set required water flow.
|
||||
/// Events: FlowSet, FlowTimeOut
|
||||
/// </summary>
|
||||
/// <param name="cBoard">Control board device</param>
|
||||
/// <param name="uniCB">Control board device</param>
|
||||
/// <param name="_regulValve">Regulation valve component</param>
|
||||
/// <param name="posLoPct">Lower limit of the position to be achieved</param>
|
||||
/// <param name="posHiPct">Upper limit of the position to be achieved</param>
|
||||
/// <param name="timeout">Timeout in sec. for setting the flow</param>
|
||||
/// <remarks>Only Elde.Valve flow are used, other flow on the lists are ignored</remarks>
|
||||
public SetRegValvePositionOp(UniCB cBoard, RegValve regValve, double posLoPct, double posHiPct, int timeout)
|
||||
public SetRegValvePositionOp(UniCB uniCB, RegValve regV, double posLoPct, double posHiPct, int timeout)
|
||||
{
|
||||
this.cBoard = cBoard;
|
||||
if (this.cBoard == null) throw new ArgumentNullException("ctrlBoard");
|
||||
this.uniCB = uniCB;
|
||||
if (this.uniCB == null) throw new ArgumentNullException("ctrlBoard");
|
||||
|
||||
this.regV = regValve as RegValve;
|
||||
this.regV = regV as RegValve;
|
||||
if (this.regV == null) throw new ArgumentNullException("regValve is null or not Elde");
|
||||
this.regValveNr = this.regV.Idx1;
|
||||
|
||||
this.posLoPct = posLoPct;
|
||||
this.posHiPct = posHiPct;
|
||||
|
||||
this.timeout = timeout;
|
||||
|
||||
log.Debug(this.ToString());
|
||||
|
||||
Reference in New Issue
Block a user