Uni.RegValve function simplified, IFlowMeter includes functions from IIDrawingItCmpntWithMeasuredVal, ver. 3.1.1627
This commit is contained in:
@@ -20,6 +20,11 @@ namespace TBF.Rig.Uni.FlowMeter
|
||||
public int Idx1 { get { return (flowMeterCfg != null) ? flowMeterCfg.Idx1 : 0; } }
|
||||
public double NominalFlow { get { return (flowMeterCfg != null) ? flowMeterCfg.NominalFlow : 0; } }
|
||||
public double LtrPerPulse { get { return (flowMeterCfg != null) ? flowMeterCfg.NominalFlow / 7200.0 : 0; } } /// Nominal frequency is 2000 Hz
|
||||
public bool RangeEnabled(int ix) { return flowMeterCfg.RangeEnabled(ix); }
|
||||
public double GetTempLo(int ix) { return flowMeterCfg.GetTempLo(ix); }
|
||||
public double GetTempHi(int ix) { return flowMeterCfg.GetTempHi(ix); }
|
||||
public double GetPressLo(int ix) { return flowMeterCfg.GetPressLo(ix); }
|
||||
public double GetPressHi(int ix) { return flowMeterCfg.GetPressHi(ix); }
|
||||
|
||||
public SchematicDrawing.IDrawingItem DrawingItem { get { return flowMeterCfg as SchematicDrawing.IDrawingItem; } }
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ namespace TBF.Rig.Uni.RegValve
|
||||
/// <returns>SetFlowOp instance</returns>
|
||||
public IOperation SetFlowOp(GenericDevices.IFlowMeter flowMeter, double requiredFlowLo, double requiredFlowHi, DoubleBox measuredFlow, int timeout)
|
||||
{
|
||||
return new SetFlowOp(uniCB, this, flowMeter, requiredFlowLo, requiredFlowHi, measuredFlow, regValveCfg.ReTryCommands, timeout);
|
||||
return new SetFlowOp(uniCB, this, flowMeter, requiredFlowLo, requiredFlowHi, measuredFlow, timeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -191,7 +191,7 @@ namespace TBF.Rig.Uni.RegValve
|
||||
public IOperation SetFlowAndMeasureOp(GenericDevices.IFlowMeter flowMeter, double requiredFlowLo, double requiredFlowHi,
|
||||
DoubleBox measuredFlow, int timeout, float filterConstant)
|
||||
{
|
||||
return new SetFlowOp(uniCB, this, flowMeter, requiredFlowLo, requiredFlowHi, measuredFlow, regValveCfg.ReTryCommands, timeout, true);
|
||||
return new SetFlowOp(uniCB, this, flowMeter, requiredFlowLo, requiredFlowHi, measuredFlow, timeout, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -31,7 +31,6 @@ namespace TBF.Rig.Uni.RegValve
|
||||
public int StableTimeMs; /// 200..1500 ms, step is 50 ms
|
||||
public int FlowStableSec; /// 0..60 sec
|
||||
public bool StoredPositionReuse; /// true = store and re-use previous regulation valve positions
|
||||
public bool ReTryCommands;
|
||||
public string SetpFormat { get; set; }
|
||||
public Config.Unit SetpUnit { get; set; }
|
||||
|
||||
@@ -81,7 +80,6 @@ namespace TBF.Rig.Uni.RegValve
|
||||
StableTimeMs = 500;
|
||||
FlowStableSec = 5;
|
||||
StoredPositionReuse = false;
|
||||
ReTryCommands = false;
|
||||
|
||||
LblX = 38;
|
||||
SetpX = 38;
|
||||
@@ -92,7 +90,7 @@ namespace TBF.Rig.Uni.RegValve
|
||||
|
||||
public string ToString(int i)
|
||||
{
|
||||
return string.Format("Name={0} ({1}), Idx1={2}, Cat.={3}, ADC-Closed={4}, ADC-Open={5}, StabTm={6}ms, FlowStable={7}s, PosReuse={8}, ReTryCmds={9}",
|
||||
return string.Format("Name={0} ({1}), Idx1={2}, Cat.={3}, ADC-Closed={4}, ADC-Open={5}, StabTm={6}ms, FlowStable={7}s, PosReuse={8}",
|
||||
Name,
|
||||
(string.IsNullOrEmpty(ParentName) ? "-" : ParentName),
|
||||
Idx1,
|
||||
@@ -101,8 +99,7 @@ namespace TBF.Rig.Uni.RegValve
|
||||
AdcValueOpen,
|
||||
StableTimeMs,
|
||||
FlowStableSec,
|
||||
StoredPositionReuse,
|
||||
ReTryCommands);
|
||||
StoredPositionReuse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,6 @@ namespace TBF.Rig.Uni.RegValve
|
||||
stableTimeTextBox.Text = config.StableTimeMs.ToString();
|
||||
flowStableSecTextBox.Text = config.FlowStableSec.ToString();
|
||||
storedPosReuseCheckBox.Checked = config.StoredPositionReuse;
|
||||
reTryCommandsCheckBox.Checked = config.ReTryCommands;
|
||||
formatTextBox.Text = config.SetpFormat;
|
||||
unitsComboBox.Text = config.SetpUnit.ToString();
|
||||
|
||||
@@ -111,7 +110,6 @@ namespace TBF.Rig.Uni.RegValve
|
||||
stableTimeTextBox.Enabled = true;
|
||||
flowStableSecTextBox.Enabled = true;
|
||||
storedPosReuseCheckBox.Enabled = true;
|
||||
reTryCommandsCheckBox.Enabled = true;
|
||||
formatTextBox.Enabled = true;
|
||||
unitsComboBox.Enabled = true;
|
||||
}
|
||||
@@ -244,13 +242,6 @@ namespace TBF.Rig.Uni.RegValve
|
||||
flags |= CfgUpdateFlags.RestartRqrd;
|
||||
}
|
||||
|
||||
btmp = reTryCommandsCheckBox.Checked;
|
||||
if (config.ReTryCommands != btmp)
|
||||
{
|
||||
config.ReTryCommands = btmp;
|
||||
flags |= CfgUpdateFlags.RestartRqrd;
|
||||
}
|
||||
|
||||
if ((flags & CfgUpdateFlags.AnyChange) != 0)
|
||||
{
|
||||
RegValve.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.CfgChange, config));
|
||||
|
||||
-14
@@ -69,7 +69,6 @@ namespace TBF.Rig.Uni.RegValve
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.categoryComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.categoryLabel = new System.Windows.Forms.Label();
|
||||
this.reTryCommandsCheckBox = new System.Windows.Forms.CheckBox();
|
||||
this.unitsComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.unitsLabel = new System.Windows.Forms.Label();
|
||||
this.formatTextBox = new System.Windows.Forms.TextBox();
|
||||
@@ -429,17 +428,6 @@ namespace TBF.Rig.Uni.RegValve
|
||||
this.categoryLabel.TabIndex = 5;
|
||||
this.categoryLabel.Text = "Category";
|
||||
//
|
||||
// reTryCommandsCheckBox
|
||||
//
|
||||
this.reTryCommandsCheckBox.AutoSize = true;
|
||||
this.reTryCommandsCheckBox.Enabled = false;
|
||||
this.reTryCommandsCheckBox.Location = new System.Drawing.Point(31, 262);
|
||||
this.reTryCommandsCheckBox.Name = "reTryCommandsCheckBox";
|
||||
this.reTryCommandsCheckBox.Size = new System.Drawing.Size(108, 17);
|
||||
this.reTryCommandsCheckBox.TabIndex = 18;
|
||||
this.reTryCommandsCheckBox.Text = "Re-try commands";
|
||||
this.reTryCommandsCheckBox.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// unitsComboBox
|
||||
//
|
||||
this.unitsComboBox.Enabled = false;
|
||||
@@ -483,7 +471,6 @@ namespace TBF.Rig.Uni.RegValve
|
||||
this.Controls.Add(this.unitsLabel);
|
||||
this.Controls.Add(this.formatTextBox);
|
||||
this.Controls.Add(this.formatLabel);
|
||||
this.Controls.Add(this.reTryCommandsCheckBox);
|
||||
this.Controls.Add(this.categoryComboBox);
|
||||
this.Controls.Add(this.categoryLabel);
|
||||
this.Controls.Add(this.groupBox4);
|
||||
@@ -561,7 +548,6 @@ namespace TBF.Rig.Uni.RegValve
|
||||
private System.Windows.Forms.Label label4;
|
||||
private System.Windows.Forms.ComboBox categoryComboBox;
|
||||
private System.Windows.Forms.Label categoryLabel;
|
||||
private System.Windows.Forms.CheckBox reTryCommandsCheckBox;
|
||||
private System.Windows.Forms.ComboBox unitsComboBox;
|
||||
private System.Windows.Forms.Label unitsLabel;
|
||||
private System.Windows.Forms.TextBox formatTextBox;
|
||||
|
||||
@@ -21,14 +21,12 @@ namespace TBF.Rig.Uni.RegValve
|
||||
/// Set by the constructor
|
||||
readonly UniCB uniCB;
|
||||
readonly RegValve regV;
|
||||
readonly int regValveId;
|
||||
readonly IFlowMeter flowMeter;
|
||||
readonly double shrinkedTgtFlowLo;
|
||||
readonly double shrinkedTgtFlowHi;
|
||||
readonly double targetFlowAve;
|
||||
readonly int timeout;
|
||||
readonly bool leaveMeasurementRunning;
|
||||
readonly bool reTryCommands;
|
||||
|
||||
readonly double nominalFlow;
|
||||
readonly double maximalFlow;
|
||||
@@ -42,13 +40,9 @@ namespace TBF.Rig.Uni.RegValve
|
||||
ValveMoveToPosition1, /// Wait 1 takt
|
||||
ValveMoveToPosition2, /// This is actual move to position
|
||||
ValveMoveToPosition3, /// Wait 1 takt
|
||||
CheckStatePosition, /// Verify
|
||||
SettingPosition,
|
||||
ValveMoveToFlow1, /// Wait 1 takt
|
||||
ValveMoveToFlow2, /// This is actual move to flow
|
||||
ValveMoveToFlow3, /// Wait 1 takt
|
||||
CheckStateFlow, /// Verify
|
||||
SettingFlow,
|
||||
Wait4FlowMsrmntAndSendRVMove, /// Wait until the flow measurement starts, then issue reg. valve move command
|
||||
SettingFlow, /// Measure the flow and verify whether it is within limits sufficiently long time
|
||||
FlowReached,
|
||||
SendCommandAgain,
|
||||
}
|
||||
@@ -62,14 +56,14 @@ namespace TBF.Rig.Uni.RegValve
|
||||
int startTime;
|
||||
int expireTime;
|
||||
DoubleBox flowBox;
|
||||
int flowWithinBoundsTime;
|
||||
int isFlowOkDuration;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Set required water flow. Conditionally leave the measurement running.
|
||||
/// 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="flowMeter">Flowmeter component</param>
|
||||
/// <param name="targetFlowLo">Lower limit of the flow to be achieved in [m3/h]</param>
|
||||
@@ -78,10 +72,10 @@ namespace TBF.Rig.Uni.RegValve
|
||||
/// <param name="timeout">Timeout for the flow setting in [s]</param>
|
||||
/// <param name="leaveMeasurementRunning">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 cBoard, IRegValve regValve, IFlowMeter flowMeter, double targetFlowLo, double targetFlowHi,
|
||||
DoubleBox flowBox, bool reTryCmds, int timeout, bool leaveMeasurementRunning)
|
||||
public SetFlowOp(UniCB uniCB, IRegValve regValve, IFlowMeter flowMeter, double targetFlowLo, double targetFlowHi,
|
||||
DoubleBox flowBox, int timeout, bool leaveMeasurementRunning)
|
||||
{
|
||||
this.uniCB = cBoard;
|
||||
this.uniCB = uniCB;
|
||||
if (this.uniCB == null) throw new ArgumentNullException("cBoard is null or not Uni");
|
||||
|
||||
this.regV = regValve as RegValve;
|
||||
@@ -100,8 +94,6 @@ namespace TBF.Rig.Uni.RegValve
|
||||
this.flowBox = flowBox;
|
||||
if (this.flowBox == null) throw new ArgumentNullException("flowBox");
|
||||
|
||||
this.reTryCommands = reTryCmds;
|
||||
|
||||
this.timeout = timeout;
|
||||
|
||||
this.leaveMeasurementRunning = leaveMeasurementRunning;
|
||||
@@ -113,9 +105,9 @@ namespace TBF.Rig.Uni.RegValve
|
||||
/// Set required water flow - Do not leave the measurement running.
|
||||
/// Events: FlowSet
|
||||
/// </summary>
|
||||
public SetFlowOp(UniCB cBoard, IRegValve regValve, IFlowMeter flowMeter, double targetFlowLo, double targetFlowHi,
|
||||
DoubleBox flowbox, bool reTryCmds, int timeout)
|
||||
: this(cBoard, regValve, flowMeter, targetFlowLo, targetFlowHi, flowbox, reTryCmds, timeout, false)
|
||||
public SetFlowOp(UniCB uniCB, IRegValve regValve, IFlowMeter flowMeter, double targetFlowLo, double targetFlowHi,
|
||||
DoubleBox flowbox, int timeout)
|
||||
: this(uniCB, regValve, flowMeter, targetFlowLo, targetFlowHi, flowbox, timeout, false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -123,9 +115,9 @@ namespace TBF.Rig.Uni.RegValve
|
||||
/// Set required water flow - No timeout.
|
||||
/// Events: FlowSet
|
||||
/// </summary>
|
||||
public SetFlowOp(UniCB cBoard, IRegValve regValve, IFlowMeter flowMeter, double targetFlowLo, double targetFlowHi,
|
||||
DoubleBox flowbox, bool reTryCmds)
|
||||
: this(cBoard, regValve, flowMeter, targetFlowLo, targetFlowHi, flowbox, reTryCmds, int.MaxValue, false)
|
||||
public SetFlowOp(UniCB uniCB, IRegValve regValve, IFlowMeter flowMeter, double targetFlowLo, double targetFlowHi,
|
||||
DoubleBox flowbox)
|
||||
: this(uniCB, regValve, flowMeter, targetFlowLo, targetFlowHi, flowbox, int.MaxValue, false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -165,41 +157,20 @@ namespace TBF.Rig.Uni.RegValve
|
||||
/// <summary>Start this operation</summary>
|
||||
public void Start()
|
||||
{
|
||||
/// Store the current time, etc.
|
||||
startTime = StateMachine.Time;
|
||||
expireTime = StateMachine.Time + timeout;
|
||||
if (expireTime < 0) expireTime = int.MaxValue;
|
||||
|
||||
double flowMtrFreq = flowMeter.ReadFrequency();
|
||||
double flow = flowMeter.ReadFlow();
|
||||
isFlowOkDuration = 0;
|
||||
|
||||
currentReqFlowLo = shrinkedTgtFlowLo; /// Default lower limit
|
||||
currentReqFlowHi = shrinkedTgtFlowHi; /// Default upper limit
|
||||
if (flow != 0)
|
||||
{
|
||||
flowBox.Val = flow;
|
||||
if (flow >= targetFlowAve) currentReqFlowHi = targetFlowAve; /// Decrease upper limit
|
||||
if (flow <= targetFlowAve) currentReqFlowLo = targetFlowAve; /// Increase lower limit
|
||||
}
|
||||
|
||||
flowWithinBoundsTime = 0;
|
||||
|
||||
if (regV.regValveCfg.StoredPositionReuse && FetchTargetPosition(targetFlowAve, out targetPositionLo, out targetPositionHi))
|
||||
{
|
||||
log.InfoFormat("SetFlowOp:Start() rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3} FETCHED: posLo={4} posHi={5}",
|
||||
regValveId, flowMeter.Idx1, currentReqFlowLo, currentReqFlowHi, targetPositionLo, targetPositionHi);
|
||||
|
||||
opState = OpState.ValveMoveToPosition1;
|
||||
}
|
||||
else
|
||||
{
|
||||
log.InfoFormat("SetFlowOp:Start() rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3}",
|
||||
regValveId, flowMeter.Idx1, currentReqFlowLo, currentReqFlowHi);
|
||||
|
||||
opState = OpState.ValveMoveToFlow1;
|
||||
}
|
||||
|
||||
/// Start flow measurement
|
||||
/// Start the flow measurement
|
||||
uniCB.MeasureFlow(false, flowMeter.Idx1);
|
||||
|
||||
log.InfoFormat("SetFlowOp:Start() rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3}",
|
||||
regV.Idx1, flowMeter.Idx1, currentReqFlowLo, currentReqFlowHi);
|
||||
|
||||
opState = OpState.Wait4FlowMsrmntAndSendRVMove;
|
||||
}
|
||||
|
||||
/// <summary>Run this operation</summary>
|
||||
@@ -212,46 +183,35 @@ namespace TBF.Rig.Uni.RegValve
|
||||
/// </returns>
|
||||
public Event Run()
|
||||
{
|
||||
double rvPosition = regV.Position;
|
||||
double flowMtrFreq = flowMeter.ReadFrequency();
|
||||
double flow = flowMeter.ReadFlow();
|
||||
if (StateMachine.Time > expireTime) return Event.RegulValveTimeOut;
|
||||
|
||||
if (flow != 0)
|
||||
if (opState == OpState.Wait4FlowMsrmntAndSendRVMove)
|
||||
{
|
||||
flowBox.Val = flow;
|
||||
}
|
||||
if (!flowMeter.MsrmntAvailable) return Event.Starting;
|
||||
|
||||
log.InfoFormat("SetFlowOp:Run(T={0}) rv#={1} pos={2}% freq={3} flow={4} opState={5}",
|
||||
StateMachine.Time - startTime, regValveId, rvPosition.ToString("F1"), flowMtrFreq, flow, opState);
|
||||
double flow1 = flowMeter.ReadFlow();
|
||||
if (flow1 == 0) return Event.Starting;
|
||||
|
||||
if (StateMachine.Time > expireTime)
|
||||
{
|
||||
return Event.RegulValveTimeOut;
|
||||
}
|
||||
else if (opState == OpState.SendCommandAgain)
|
||||
{
|
||||
flowWithinBoundsTime = 0;
|
||||
/// Set the targer flow/frequency range
|
||||
currentReqFlowLo = shrinkedTgtFlowLo; /// Default lower limit
|
||||
currentReqFlowHi = shrinkedTgtFlowHi; /// Default upper limit
|
||||
if (flow1 >= targetFlowAve) currentReqFlowHi = targetFlowAve; /// Decrease upper limit
|
||||
if (flow1 <= targetFlowAve) currentReqFlowLo = targetFlowAve; /// Increase lower limit
|
||||
|
||||
if (regV.regValveCfg.StoredPositionReuse && FetchTargetPosition(targetFlowAve, out targetPositionLo, out targetPositionHi))
|
||||
{
|
||||
log.InfoFormat("Run(): rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3} FETCHED: posLo={4} posHi={5}",
|
||||
regValveId, flowMeter.Idx1, currentReqFlowLo, currentReqFlowHi, targetPositionLo, targetPositionHi);
|
||||
if ((currentReqFlowLo >= currentReqFlowHi) || (currentReqFlowLo > maximalFlow) || (currentReqFlowHi <= 0))
|
||||
{
|
||||
return Event.OpArgumentError;
|
||||
}
|
||||
|
||||
opState = OpState.ValveMoveToPosition1;
|
||||
}
|
||||
else
|
||||
{
|
||||
log.InfoFormat("Run(): rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3}",
|
||||
regValveId, flowMeter.Idx1, currentReqFlowLo, currentReqFlowHi);
|
||||
uniCB.SetFlow(false, regV.Idx1, 2000 * currentReqFlowLo / nominalFlow, 2000 * currentReqFlowHi / nominalFlow);
|
||||
|
||||
opState = OpState.ValveMoveToFlow1;
|
||||
}
|
||||
log.InfoFormat("Run(): rv#={0} TARGET: flowLo={1} flowHi={2}", regV.Idx1, currentReqFlowLo, currentReqFlowHi);
|
||||
|
||||
/// Start flow measurement
|
||||
uniCB.MeasureFlow(false, flowMeter.Idx1);
|
||||
opState = OpState.SettingFlow;
|
||||
return Event.Starting;
|
||||
}
|
||||
else if (opState == OpState.ValveMoveToPosition1)
|
||||
}
|
||||
|
||||
if (opState == OpState.ValveMoveToPosition1)
|
||||
{
|
||||
opState = OpState.ValveMoveToPosition2;
|
||||
return Event.Starting;
|
||||
@@ -266,142 +226,52 @@ namespace TBF.Rig.Uni.RegValve
|
||||
}
|
||||
else if (opState == OpState.ValveMoveToPosition3)
|
||||
{
|
||||
if (reTryCommands)
|
||||
{
|
||||
opState = OpState.CheckStatePosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
opState = OpState.SettingPosition;
|
||||
}
|
||||
opState = OpState.SettingPosition;
|
||||
return Event.Starting;
|
||||
}
|
||||
else if (opState == OpState.CheckStatePosition) /// Verify
|
||||
{
|
||||
if ((uniCB.State & (ulong)StatusP.TestWithRefFlowmtr) == 0)
|
||||
{
|
||||
opState = OpState.SendCommandAgain;
|
||||
return Event.Starting;
|
||||
}
|
||||
else if (regV.RegValveState != RegValveState.DacValueRegul)
|
||||
{
|
||||
/// Repeat appropriate ValveMove(...) command
|
||||
regV.MoveToPosition(false, targetPositionLo, targetPositionHi);
|
||||
|
||||
log.InfoFormat("SetFlowOp: ValveMove({0}, Position, {1}, {2}, {3})",
|
||||
regValveId, targetPositionLo, targetPositionHi, regV.StableTime);
|
||||
|
||||
opState = OpState.ValveMoveToPosition3;
|
||||
return Event.Starting;
|
||||
}
|
||||
else
|
||||
{
|
||||
opState = OpState.SettingPosition;
|
||||
return Event.Starting;
|
||||
}
|
||||
}
|
||||
else if (opState == OpState.SettingPosition)
|
||||
{
|
||||
/// Repeated untill position is reached
|
||||
if ((targetPositionLo <= rvPosition) && (rvPosition <= targetPositionHi))
|
||||
double rvPosition = regV.Position;
|
||||
if ((targetPositionLo <= rvPosition) && (rvPosition <= targetPositionHi))
|
||||
{
|
||||
opState = OpState.ValveMoveToFlow1;
|
||||
opState = OpState.Wait4FlowMsrmntAndSendRVMove;
|
||||
}
|
||||
return Event.Starting;
|
||||
}
|
||||
else if (opState == OpState.ValveMoveToFlow1)
|
||||
{
|
||||
opState = OpState.ValveMoveToFlow2;
|
||||
return Event.Starting;
|
||||
}
|
||||
else if (opState == OpState.ValveMoveToFlow2) /// Move to flow
|
||||
{
|
||||
///
|
||||
/// Done once, issues an appropriate ValveMove(...) command
|
||||
///
|
||||
if ((currentReqFlowLo >= currentReqFlowHi) || (currentReqFlowLo > maximalFlow) || (currentReqFlowHi <= 0))
|
||||
{
|
||||
return Event.OpArgumentError;
|
||||
}
|
||||
|
||||
log.InfoFormat("Run(): rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3}",
|
||||
regValveId, flowMeter.Idx1, currentReqFlowLo, currentReqFlowHi);
|
||||
|
||||
double freqLo = 2000.0 * currentReqFlowLo / nominalFlow;
|
||||
double freqHi = 2000.0 * currentReqFlowHi / nominalFlow;
|
||||
uniCB.SetFlow(false, regV.Idx1, freqLo, freqHi);
|
||||
|
||||
opState = OpState.ValveMoveToFlow3;
|
||||
return Event.Starting;
|
||||
}
|
||||
else if (opState == OpState.ValveMoveToFlow3)
|
||||
{
|
||||
if (reTryCommands)
|
||||
{
|
||||
opState = OpState.CheckStateFlow;
|
||||
}
|
||||
else
|
||||
{
|
||||
opState = OpState.SettingFlow;
|
||||
}
|
||||
return Event.Starting;
|
||||
}
|
||||
else if (opState == OpState.CheckStateFlow) /// Verify the flow setting
|
||||
{
|
||||
if ( (uniCB.State & (ulong)StatusP.TestWithRefFlowmtr) == 0 ||
|
||||
(regV.RegValveState & RegValveState.PwOrFreqRegul) != RegValveState.PwOrFreqRegul)
|
||||
{
|
||||
opState = OpState.SendCommandAgain;
|
||||
return Event.Starting;
|
||||
}
|
||||
else if (regV.RegValveState != RegValveState.PwOrFreqRegul)
|
||||
{
|
||||
/// Done once, issues an appropriate ValveMove(...) command
|
||||
double freqLo = 2000.0 * currentReqFlowLo / nominalFlow;
|
||||
double freqHi = 2000.0 * currentReqFlowHi / nominalFlow;
|
||||
uniCB.SetFlow(false, regV.Idx1, freqLo, freqHi);
|
||||
|
||||
log.InfoFormat("SetFlowOp: ValveMove({0}, Frequency, {1}, {2}, {3})",
|
||||
regValveId, freqLo, freqHi, regV.StableTime);
|
||||
|
||||
opState = OpState.ValveMoveToFlow3;
|
||||
return Event.Starting;
|
||||
}
|
||||
else
|
||||
{
|
||||
opState = OpState.SettingFlow;
|
||||
return Event.Busy;
|
||||
}
|
||||
}
|
||||
else if (opState == OpState.SettingFlow)
|
||||
{
|
||||
/// Regulation valve is setting flow to the required value
|
||||
///
|
||||
double frequency = flowMeter.ReadFrequency();
|
||||
double flow = flowMeter.ReadFlow();
|
||||
if (flow != 0) flowBox.Val = flow;
|
||||
|
||||
if ((currentReqFlowLo <= flow) && (flow <= currentReqFlowHi))
|
||||
{
|
||||
/// Flow is within range
|
||||
isFlowOkDuration++;
|
||||
|
||||
if (flowWithinBoundsTime++ >= regV.FlowStableSec)
|
||||
if (isFlowOkDuration >= regV.FlowStableSec)
|
||||
{
|
||||
/// Flow is within range for sufficiently long time
|
||||
|
||||
if (regV.regValveCfg.StoredPositionReuse)
|
||||
{
|
||||
double rvPosition = regV.Position; /// Read the current position
|
||||
double storedPosition;
|
||||
if (regV.Dict.TryGetValue(targetFlowAve, out storedPosition))
|
||||
{
|
||||
/// update the stored valve position
|
||||
|
||||
StoreTargetPosition(targetFlowAve, (rvPosition + storedPosition) / 2.0);
|
||||
log.InfoFormat("Run(): rv#={0} reqFlow={1} pos={2}% stored={3} <--- Updating a stored position",
|
||||
regValveId, targetFlowAve, rvPosition.ToString("F1"), storedPosition);
|
||||
regV.Idx1, targetFlowAve, rvPosition.ToString("F1"), storedPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
/// store the valve position
|
||||
StoreTargetPosition(targetFlowAve, rvPosition);
|
||||
log.InfoFormat("Run(): rv#={0} reqFlow={1} pos={2}% <--- Storing a new position",
|
||||
regValveId, targetFlowAve, rvPosition.ToString("F1"));
|
||||
regV.Idx1, targetFlowAve, rvPosition.ToString("F1"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -412,24 +282,22 @@ namespace TBF.Rig.Uni.RegValve
|
||||
}
|
||||
else
|
||||
{
|
||||
log.InfoFormat("flow = {0} m3/h (lo={1}, hi={2}, FLOW_OK_TIMER={3}s)", flow, currentReqFlowLo, currentReqFlowHi, flowWithinBoundsTime);
|
||||
log.InfoFormat("flow = {0} m3/h (lo={1}, hi={2}, FLOW_OK_TIMER={3}s)", flow, currentReqFlowLo, currentReqFlowHi, isFlowOkDuration);
|
||||
return Event.Busy;
|
||||
}
|
||||
}
|
||||
else if (StateMachine.Time > expireTime)
|
||||
{
|
||||
return Event.RegulValveTimeOut;
|
||||
}
|
||||
else
|
||||
{
|
||||
log.InfoFormat("flow = {0} m3/h (lo={1}, hi={2})", flow, currentReqFlowLo, currentReqFlowHi);
|
||||
flowWithinBoundsTime = 0;
|
||||
/// Flow is out of range
|
||||
isFlowOkDuration = 0;
|
||||
|
||||
log.InfoFormat("flow = {0} m3/h (lo={1}, hi={2})", flow, currentReqFlowLo, currentReqFlowHi);
|
||||
return Event.Busy;
|
||||
}
|
||||
}
|
||||
else /// opState == OpState.FlowReached
|
||||
{
|
||||
log.InfoFormat("flow = {0} m3/h (lo={1}, hi={2}, REACHED)", flow, currentReqFlowLo, currentReqFlowHi);
|
||||
log.InfoFormat("flow = {0} m3/h (lo={1}, hi={2}, REACHED)", flowMeter.ReadFlow(), currentReqFlowLo, currentReqFlowHi);
|
||||
return Event.FlowReached;
|
||||
}
|
||||
}
|
||||
@@ -439,7 +307,7 @@ namespace TBF.Rig.Uni.RegValve
|
||||
{
|
||||
if (!leaveMeasurementRunning)
|
||||
{
|
||||
/// Stop measurement
|
||||
/// Stop flow measurement
|
||||
uniCB.Stop(false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user