From a4139d7a73c131d4632d49efe5ed134689892cf9 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Mon, 6 Feb 2023 11:01:36 +0100 Subject: [PATCH] Uni.RegValve clean-up. --- .../Uni/RegValve/ChangeRegValvePositionOp.cs | 2 +- TBF/Rig/Uni/RegValve/Factory.cs | 2 +- TBF/Rig/Uni/RegValve/Handlers.cs | 2 +- TBF/Rig/Uni/RegValve/SetFlowOp.cs | 58 ++++++++----------- TBF/Rig/Uni/RegValve/SetRegValvePositionOp.cs | 13 ++--- 5 files changed, 34 insertions(+), 43 deletions(-) diff --git a/TBF/Rig/Uni/RegValve/ChangeRegValvePositionOp.cs b/TBF/Rig/Uni/RegValve/ChangeRegValvePositionOp.cs index e4ff3520d..3eb94a3c1 100644 --- a/TBF/Rig/Uni/RegValve/ChangeRegValvePositionOp.cs +++ b/TBF/Rig/Uni/RegValve/ChangeRegValvePositionOp.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2021 Sensus Metering Systems +/// Copyright (c) 2021 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; diff --git a/TBF/Rig/Uni/RegValve/Factory.cs b/TBF/Rig/Uni/RegValve/Factory.cs index 0c0dafb98..4c0c96e9c 100644 --- a/TBF/Rig/Uni/RegValve/Factory.cs +++ b/TBF/Rig/Uni/RegValve/Factory.cs @@ -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; diff --git a/TBF/Rig/Uni/RegValve/Handlers.cs b/TBF/Rig/Uni/RegValve/Handlers.cs index 2ba144a37..b16a486f6 100644 --- a/TBF/Rig/Uni/RegValve/Handlers.cs +++ b/TBF/Rig/Uni/RegValve/Handlers.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2021 Sensus Metering Systems +/// Copyright (c) 2021 Sensus Slovensko a.s. /// using System; using log4net; diff --git a/TBF/Rig/Uni/RegValve/SetFlowOp.cs b/TBF/Rig/Uni/RegValve/SetFlowOp.cs index 217acf5df..da241045b 100644 --- a/TBF/Rig/Uni/RegValve/SetFlowOp.cs +++ b/TBF/Rig/Uni/RegValve/SetFlowOp.cs @@ -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 /// /// Control board device - /// Regulation valve component + /// Regulation valve component /// Flowmeter component /// Lower limit of the flow to be achieved in [m3/h] /// Upper limit of the flow to be achieved in [m3/h] - /// PID coefficient (float) + /// DoubleBox for measured flow /// Timeout for the flow setting in [s] - /// Flow setting starts after this delay [s] + /// Flow setting starts after this delay in [s] /// true = Leave the measurement running after op. stop /// Only Elde.Valve flow are used, other flow on the lists are ignored - 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; } - /// - /// Start this operation - /// + /// Start this operation 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 } } - /// Start this operation + /// Stop this operation 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; diff --git a/TBF/Rig/Uni/RegValve/SetRegValvePositionOp.cs b/TBF/Rig/Uni/RegValve/SetRegValvePositionOp.cs index fbc94082e..4d3665dc0 100644 --- a/TBF/Rig/Uni/RegValve/SetRegValvePositionOp.cs +++ b/TBF/Rig/Uni/RegValve/SetRegValvePositionOp.cs @@ -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 /// - /// Control board device + /// Control board device /// Regulation valve component /// Lower limit of the position to be achieved /// Upper limit of the position to be achieved /// Timeout in sec. for setting the flow /// Only Elde.Valve flow are used, other flow on the lists are ignored - 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());