2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using log4net;
|
|
|
|
|
|
using TBF.BenchControl.GenericDevices;
|
2014-07-31 15:04:09 +00:00
|
|
|
|
using TBF.Boxes;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
namespace TBF.BenchControl.Elde.RegulValve
|
|
|
|
|
|
{
|
|
|
|
|
|
public class SetFlowOp : IOperation
|
|
|
|
|
|
{
|
|
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(SetFlowOp));
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
|
{
|
2015-01-03 20:17:06 +00:00
|
|
|
|
return string.Format("SetFlowOp({0}, Qfrom={1}, Qto={2}, PID={3})", regulValve.Name, reqFlowLo, reqFlowHi, pidCoef);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-02-07 21:27:32 +00:00
|
|
|
|
const int CoaxValveNr = 7; /// Coax. valve has number 7
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// Set by the constructor
|
|
|
|
|
|
readonly ControlBoardDev controlBoard;
|
|
|
|
|
|
readonly Elde.RegulValve.RegulValve regulValve;
|
|
|
|
|
|
readonly int regulValveNr;
|
|
|
|
|
|
readonly int flowMeterNr;
|
|
|
|
|
|
readonly float reqFlowLo;
|
|
|
|
|
|
readonly float reqFlowHi;
|
|
|
|
|
|
readonly float reqFlowAve;
|
2015-01-03 20:17:06 +00:00
|
|
|
|
readonly float pidCoef;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
readonly int timeout;
|
|
|
|
|
|
readonly bool leaveMeasurementRunning;
|
|
|
|
|
|
|
2014-09-10 11:43:33 +00:00
|
|
|
|
readonly float nominalFlow;
|
|
|
|
|
|
|
2015-09-22 16:39:00 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Internal states of this operation
|
|
|
|
|
|
///
|
2014-07-28 07:54:35 +00:00
|
|
|
|
enum OpState
|
|
|
|
|
|
{
|
|
|
|
|
|
Idle = 0,
|
2015-10-15 17:49:42 +00:00
|
|
|
|
ValveMoveToPosition1, /// Wait 1 takt
|
|
|
|
|
|
ValveMoveToPosition2, /// This is actual move to position
|
|
|
|
|
|
ValveMoveToPosition3, /// Wait 1 takt
|
|
|
|
|
|
ValveMoveToPosition4, /// Verify
|
2014-07-28 07:54:35 +00:00
|
|
|
|
SettingPosition,
|
2015-10-15 17:49:42 +00:00
|
|
|
|
ValveMoveToFlow1, /// Wait 1 takt
|
|
|
|
|
|
ValveMoveToFlow2, /// This is actual move to flow
|
|
|
|
|
|
ValveMoveToFlow3, /// Wait 1 takt
|
|
|
|
|
|
ValveMoveToFlow4, /// Verify
|
2014-07-28 07:54:35 +00:00
|
|
|
|
SettingFlow,
|
|
|
|
|
|
FlowReached,
|
2015-10-15 17:49:42 +00:00
|
|
|
|
SendCommandAgain,
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
OpState opState;
|
|
|
|
|
|
|
|
|
|
|
|
float targetPositionLo;
|
|
|
|
|
|
float targetPositionHi;
|
|
|
|
|
|
|
|
|
|
|
|
int expireTime;
|
|
|
|
|
|
FloatBox measuredFlow;
|
2014-09-08 18:24:46 +00:00
|
|
|
|
int flowWithinBoundsTime;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Set required water flow. Conditionally leave the measurement running.
|
|
|
|
|
|
/// Events: FlowSet, FlowTimeOut
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="controlBoard">Control board device</param>
|
2015-02-03 09:30:24 +00:00
|
|
|
|
/// <param name="_regulValve">Regulation valve component</param>
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// <param name="flowMeter">Flowmeter component</param>
|
|
|
|
|
|
/// <param name="requiredFlowLo">Lower limit of the flow to be achieved in [m3/h]</param>
|
|
|
|
|
|
/// <param name="requiredFlowHi">Upper limit of the flow to be achieved in [m3/h]</param>
|
2015-01-03 20:17:06 +00:00
|
|
|
|
/// <param name="pidCoef">PID coefficient (float)</param>
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// <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>
|
2015-02-03 09:30:24 +00:00
|
|
|
|
public SetFlowOp(ControlBoardDev controlBoard, IRegulValve _regulValve, IFlowMeter flowMeter,
|
2015-01-03 20:17:06 +00:00
|
|
|
|
float requiredFlowLo, float requiredFlowHi, float pidCoef, FloatBox measuredFlow,
|
|
|
|
|
|
int timeout, bool leaveMeasurementRunning)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (controlBoard == null) throw new ArgumentNullException("ctrlBoard");
|
|
|
|
|
|
this.controlBoard = controlBoard;
|
|
|
|
|
|
|
2015-02-03 09:30:24 +00:00
|
|
|
|
regulValve = _regulValve as Elde.RegulValve.RegulValve;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
if (regulValve == null) throw new ArgumentNullException("regValve is null or not Elde");
|
2015-02-03 09:30:24 +00:00
|
|
|
|
regulValveNr = this.regulValve.Idx1;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2014-09-10 11:43:33 +00:00
|
|
|
|
if (flowMeter is Elde.FlowMeter.FlowMeter)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.flowMeterNr = (flowMeter as Elde.FlowMeter.FlowMeter).Idx1;
|
|
|
|
|
|
}
|
2014-09-15 20:00:30 +00:00
|
|
|
|
else if (flowMeter is Elde.FlowMeterTwins.FlowMeter)
|
2014-09-10 11:43:33 +00:00
|
|
|
|
{
|
|
|
|
|
|
this.flowMeterNr = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new ArgumentNullException("flowMeter is null or not Elde");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nominalFlow = flowMeter.NominalFlow;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
this.reqFlowLo = requiredFlowLo;
|
|
|
|
|
|
this.reqFlowHi = requiredFlowHi;
|
|
|
|
|
|
this.reqFlowAve = (reqFlowLo + reqFlowHi) / 2.0f;
|
2015-01-03 20:17:06 +00:00
|
|
|
|
this.pidCoef = pidCoef;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
this.measuredFlow = measuredFlow;
|
|
|
|
|
|
|
|
|
|
|
|
this.timeout = timeout;
|
|
|
|
|
|
|
|
|
|
|
|
this.leaveMeasurementRunning = leaveMeasurementRunning;
|
|
|
|
|
|
|
|
|
|
|
|
log.Debug(this.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Set required water flow - Do not leave the measurement running.
|
|
|
|
|
|
/// Events: FlowSet
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public SetFlowOp(ControlBoardDev controlBoard, IRegulValve regValve, IFlowMeter flowMeter,
|
2015-01-03 20:17:06 +00:00
|
|
|
|
float requiredFlowLo, float requiredFlowHi, float pidCoef, FloatBox measuredFlow, int timeout)
|
|
|
|
|
|
: this(controlBoard, regValve, flowMeter, requiredFlowLo, requiredFlowHi, pidCoef, measuredFlow, timeout, false)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Set required water flow - No timeout.
|
|
|
|
|
|
/// Events: FlowSet
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public SetFlowOp(ControlBoardDev controlBoard, IRegulValve regValve, IFlowMeter flowMeter,
|
2015-01-03 20:17:06 +00:00
|
|
|
|
float requiredFlowLo, float requiredFlowHi, float pidCoef, FloatBox measuredFlow)
|
|
|
|
|
|
: this(controlBoard, regValve, flowMeter, requiredFlowLo, pidCoef, requiredFlowHi, measuredFlow, int.MaxValue, false)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Fetch target position limits from the dictionary or return false
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="avgReqFlow">Average of the flow targer range (input)</param>
|
|
|
|
|
|
/// <param name="positionLo">Target valve position low limit (output)</param>
|
|
|
|
|
|
/// <param name="positionHi">Target valve position high limit (output)</param>
|
|
|
|
|
|
/// <returns>true when positions for the target flow are stored in the memory, otherwise return false</returns>
|
|
|
|
|
|
bool FetchTargetPosition(float avgReqFlow, out float positionLo, out float positionHi)
|
|
|
|
|
|
{
|
|
|
|
|
|
float targetPosition;
|
|
|
|
|
|
if (regulValve.Dict.TryGetValue(avgReqFlow, out targetPosition))
|
|
|
|
|
|
{
|
|
|
|
|
|
positionLo = Math.Max(targetPosition * 0.95f, 0.0f);
|
|
|
|
|
|
positionHi = Math.Min(targetPosition * 1.05f, 100.0f);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
positionLo = 0.0f;
|
|
|
|
|
|
positionHi = 0.0f;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StoreTargetPosition(float avgReqFlow, float actPosition)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!regulValve.Dict.ContainsKey(reqFlowAve))
|
|
|
|
|
|
{
|
|
|
|
|
|
regulValve.Dict.Add(new KeyValuePair<float, float>(avgReqFlow, actPosition));
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Start this operation</summary>
|
|
|
|
|
|
public void Start()
|
|
|
|
|
|
{
|
2014-09-08 18:24:46 +00:00
|
|
|
|
flowWithinBoundsTime = 0;
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
if (regulValve.RegulValveCfg.StoredPositionReuse && FetchTargetPosition(reqFlowAve, out targetPositionLo, out targetPositionHi))
|
|
|
|
|
|
{
|
2016-04-20 10:43:59 +00:00
|
|
|
|
log.InfoFormat("SetFlowOp:Start() rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3} FETCHED: posLo={4} posHi={5}",
|
2014-07-28 07:54:35 +00:00
|
|
|
|
regulValveNr, flowMeterNr, reqFlowLo, reqFlowHi, targetPositionLo, targetPositionHi);
|
|
|
|
|
|
|
2015-10-15 17:49:42 +00:00
|
|
|
|
opState = OpState.ValveMoveToPosition1;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-04-20 10:43:59 +00:00
|
|
|
|
log.InfoFormat("SetFlowOp:Start() rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3}",
|
2014-07-28 07:54:35 +00:00
|
|
|
|
regulValveNr, flowMeterNr, reqFlowLo, reqFlowHi);
|
|
|
|
|
|
|
2015-10-15 17:49:42 +00:00
|
|
|
|
opState = OpState.ValveMoveToFlow1;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-08-01 06:36:17 +00:00
|
|
|
|
expireTime = StateMachine.Time + timeout;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
if (expireTime < 0) expireTime = int.MaxValue;
|
|
|
|
|
|
|
|
|
|
|
|
TestMethods tm = 0;
|
|
|
|
|
|
StopDevs sd = 0;
|
2015-02-03 09:30:24 +00:00
|
|
|
|
// '_regulValve.RegulValveCfg.PidCoef' replaced by a casted operation parameter 'pidCoef'
|
2016-04-04 07:23:07 +00:00
|
|
|
|
controlBoard.SendCommand(Command.Start, flowMeterNr, controlBoard.Route,
|
|
|
|
|
|
int.MaxValue, int.MaxValue, tm,
|
2015-01-04 22:21:12 +00:00
|
|
|
|
0.0f, (int)pidCoef, 0, sd);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Run this operation</summary>
|
|
|
|
|
|
/// <returns>
|
2014-08-08 14:25:51 +00:00
|
|
|
|
/// Event.None, Event.FlowReached, Event.RegulValveTimeOut, Event.OpArgumentError
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// </returns>
|
|
|
|
|
|
public Event Run()
|
|
|
|
|
|
{
|
|
|
|
|
|
float rvPosition = controlBoard.RValvePosition(regulValveNr);
|
|
|
|
|
|
float flowMtrFreq = controlBoard.ReferenceFreq;
|
2014-09-10 11:43:33 +00:00
|
|
|
|
float flow = flowMtrFreq * nominalFlow / 2000.0f;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2014-07-31 15:04:09 +00:00
|
|
|
|
if (measuredFlow != null) measuredFlow.Val = flow;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2016-04-20 10:43:59 +00:00
|
|
|
|
log.InfoFormat("SetFlowOp:Run() rv#={0} pos={1}% freq={2} flow={3} opState={4}",
|
2014-07-28 07:54:35 +00:00
|
|
|
|
regulValveNr, rvPosition.ToString("F1"), flowMtrFreq, flow, opState);
|
|
|
|
|
|
|
2015-10-15 17:49:42 +00:00
|
|
|
|
|
|
|
|
|
|
if (opState == OpState.SendCommandAgain)
|
2015-09-18 05:46:57 +00:00
|
|
|
|
{
|
2015-10-15 17:49:42 +00:00
|
|
|
|
flowWithinBoundsTime = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (regulValve.RegulValveCfg.StoredPositionReuse && FetchTargetPosition(reqFlowAve, out targetPositionLo, out targetPositionHi))
|
|
|
|
|
|
{
|
2016-05-31 09:07:11 +00:00
|
|
|
|
log.InfoFormat("Run(): rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3} FETCHED: posLo={4} posHi={5}",
|
|
|
|
|
|
regulValveNr, flowMeterNr, reqFlowLo, reqFlowHi, targetPositionLo, targetPositionHi);
|
2015-10-15 17:49:42 +00:00
|
|
|
|
|
|
|
|
|
|
opState = OpState.ValveMoveToPosition1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-05-31 09:07:11 +00:00
|
|
|
|
log.InfoFormat("Run(): rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3}",
|
|
|
|
|
|
regulValveNr, flowMeterNr, reqFlowLo, reqFlowHi);
|
2015-10-15 17:49:42 +00:00
|
|
|
|
|
|
|
|
|
|
opState = OpState.ValveMoveToFlow1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
expireTime = StateMachine.Time + timeout;
|
|
|
|
|
|
if (expireTime < 0) expireTime = int.MaxValue;
|
|
|
|
|
|
|
|
|
|
|
|
TestMethods tm = 0;
|
|
|
|
|
|
StopDevs sd = 0;
|
|
|
|
|
|
// '_regulValve.RegulValveCfg.PidCoef' replaced by a casted operation parameter 'pidCoef'
|
2016-04-04 07:23:07 +00:00
|
|
|
|
controlBoard.SendCommand(Command.Start, flowMeterNr, controlBoard.Route,
|
|
|
|
|
|
int.MaxValue, int.MaxValue, tm,
|
2015-10-15 17:49:42 +00:00
|
|
|
|
0.0f, (int)pidCoef, 0, sd);
|
2015-09-18 05:46:57 +00:00
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
2015-10-15 17:49:42 +00:00
|
|
|
|
else if (opState == OpState.ValveMoveToPosition1)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2015-10-15 17:49:42 +00:00
|
|
|
|
opState = OpState.ValveMoveToPosition2;
|
|
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (opState == OpState.ValveMoveToPosition2) /// Move to position
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Issues the appropriate ValveMove(...) command
|
2014-07-28 07:54:35 +00:00
|
|
|
|
controlBoard.ValveMove(regulValveNr, RegulValveMode.TargetPosition,
|
2014-09-05 12:17:12 +00:00
|
|
|
|
new float[2] { targetPositionLo, targetPositionHi },
|
2015-10-15 17:49:42 +00:00
|
|
|
|
regulValve.StableTime);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
opState = OpState.SettingPosition;
|
|
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
2015-10-15 17:49:42 +00:00
|
|
|
|
else if (opState == OpState.ValveMoveToPosition3)
|
2015-09-18 05:46:57 +00:00
|
|
|
|
{
|
2015-10-15 17:49:42 +00:00
|
|
|
|
opState = OpState.ValveMoveToPosition4;
|
2015-09-18 05:46:57 +00:00
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
2015-10-15 17:49:42 +00:00
|
|
|
|
else if (opState == OpState.ValveMoveToPosition4) /// Verify
|
|
|
|
|
|
{
|
2015-10-21 06:00:44 +00:00
|
|
|
|
if (((ulong)controlBoard.StatusP & (ulong)StatusP.RefPulsesMsrmnt) == 0)
|
2015-10-15 17:49:42 +00:00
|
|
|
|
{
|
|
|
|
|
|
opState = OpState.SendCommandAgain;
|
|
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
2016-02-07 21:27:32 +00:00
|
|
|
|
else if (regulValveNr == CoaxValveNr && ((ulong)controlBoard.StatusP & (ulong)StatusP.CoaxRegValveBusy) == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Repeat appropriate ValveMove(...) command
|
|
|
|
|
|
controlBoard.ValveMove(regulValveNr, RegulValveMode.TargetPosition,
|
|
|
|
|
|
new float[2] { (targetPositionLo + targetPositionHi) / 2, (targetPositionLo + targetPositionHi) / 2 },
|
|
|
|
|
|
regulValve.StableTime);
|
|
|
|
|
|
|
2016-04-20 10:43:59 +00:00
|
|
|
|
log.InfoFormat("SetFlowOp: ValveMove({0}, Position, {1}, {2}, {3})",
|
|
|
|
|
|
regulValveNr, (targetPositionLo + targetPositionHi) / 2, (targetPositionLo + targetPositionHi) / 2, regulValve.StableTime);
|
|
|
|
|
|
|
|
|
|
|
|
opState = OpState.ValveMoveToPosition3;
|
2016-02-07 21:27:32 +00:00
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (regulValveNr < 6 && controlBoard.RegulValveState(regulValveNr) != RegulValveState.DacValueRegul)
|
2015-10-15 17:49:42 +00:00
|
|
|
|
{
|
|
|
|
|
|
/// Repeat appropriate ValveMove(...) command
|
|
|
|
|
|
controlBoard.ValveMove(regulValveNr, RegulValveMode.TargetPosition,
|
|
|
|
|
|
new float[2] { targetPositionLo, targetPositionHi },
|
|
|
|
|
|
regulValve.StableTime);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2016-04-20 10:43:59 +00:00
|
|
|
|
log.InfoFormat("SetFlowOp: ValveMove({0}, Position, {1}, {2}, {3})",
|
|
|
|
|
|
regulValveNr, targetPositionLo, targetPositionHi, regulValve.StableTime);
|
|
|
|
|
|
|
2015-10-15 17:49:42 +00:00
|
|
|
|
opState = OpState.ValveMoveToPosition3;
|
|
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
opState = OpState.SettingPosition;
|
|
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (opState == OpState.SettingPosition)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Repeated untill position is reached
|
|
|
|
|
|
if ((targetPositionLo <= rvPosition) && (rvPosition <= targetPositionHi))
|
|
|
|
|
|
{
|
|
|
|
|
|
opState = OpState.ValveMoveToFlow1;
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
return Event.None;
|
2015-10-15 17:49:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (opState == OpState.ValveMoveToFlow1)
|
2015-09-18 05:46:57 +00:00
|
|
|
|
{
|
|
|
|
|
|
opState = OpState.ValveMoveToFlow2;
|
|
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
2015-10-15 17:49:42 +00:00
|
|
|
|
else if (opState == OpState.ValveMoveToFlow2) /// Move to flow
|
2015-05-21 14:38:27 +00:00
|
|
|
|
{
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Done once, issues an appropriate ValveMove(...) command
|
|
|
|
|
|
///
|
|
|
|
|
|
if (reqFlowLo >= reqFlowHi || reqFlowLo > nominalFlow || reqFlowHi <= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Event.OpArgumentError;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.InfoFormat("Run(): rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3}",
|
|
|
|
|
|
regulValveNr, flowMeterNr, reqFlowLo, reqFlowHi);
|
|
|
|
|
|
|
|
|
|
|
|
float freqLo = 2000.0f * reqFlowLo / nominalFlow;
|
|
|
|
|
|
float freqHi = 2000.0f * reqFlowHi / nominalFlow;
|
|
|
|
|
|
controlBoard.ValveMove(regulValveNr, RegulValveMode.TargetFrequency,
|
|
|
|
|
|
new float[2] { freqLo, freqHi },
|
|
|
|
|
|
regulValve.StableTime);
|
|
|
|
|
|
|
2015-10-15 17:49:42 +00:00
|
|
|
|
opState = OpState.ValveMoveToFlow3;
|
|
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (opState == OpState.ValveMoveToFlow3)
|
|
|
|
|
|
{
|
|
|
|
|
|
opState = OpState.ValveMoveToFlow4;
|
2015-05-21 14:38:27 +00:00
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
2016-05-25 12:13:18 +00:00
|
|
|
|
else if (opState == OpState.ValveMoveToFlow4) /// Verify the flow setting
|
2015-10-15 17:49:42 +00:00
|
|
|
|
{
|
2016-05-31 09:32:02 +00:00
|
|
|
|
if (regulValveNr != CoaxValveNr && (((ulong)controlBoard.StatusP & (ulong)StatusP.RefPulsesMsrmnt) == 0 ||
|
|
|
|
|
|
(controlBoard.RegulValveState(regulValveNr) & RegulValveState.PwOrFreqRegul) != RegulValveState.PwOrFreqRegul))
|
2015-10-15 17:49:42 +00:00
|
|
|
|
{
|
|
|
|
|
|
opState = OpState.SendCommandAgain;
|
|
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
2016-02-07 21:27:32 +00:00
|
|
|
|
else if (regulValveNr == CoaxValveNr && ((ulong)controlBoard.StatusP & (ulong)StatusP.CoaxRegValveBusy) == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Done once, issues an appropriate ValveMove(...) command
|
|
|
|
|
|
float freqLo = 2000.0f * reqFlowLo / nominalFlow;
|
|
|
|
|
|
float freqHi = 2000.0f * reqFlowHi / nominalFlow;
|
|
|
|
|
|
controlBoard.ValveMove(regulValveNr, RegulValveMode.TargetFrequency,
|
|
|
|
|
|
new float[2] { (freqLo + freqHi) / 2.0f, (freqLo + freqHi) / 2.0f },
|
|
|
|
|
|
regulValve.StableTime);
|
|
|
|
|
|
|
2016-04-20 10:43:59 +00:00
|
|
|
|
log.InfoFormat("SetFlowOp: ValveMove({0}, Frequency, {1}, {2}, {3})",
|
|
|
|
|
|
regulValveNr, (freqLo + freqHi) / 2.0f, (freqLo + freqHi) / 2.0f, regulValve.StableTime);
|
|
|
|
|
|
|
2016-02-07 21:27:32 +00:00
|
|
|
|
opState = OpState.ValveMoveToFlow3;
|
|
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
2016-04-10 19:30:24 +00:00
|
|
|
|
else if (regulValveNr < 6 && controlBoard.RegulValveState(regulValveNr) != RegulValveState.PwOrFreqRegul)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Done once, issues an appropriate ValveMove(...) command
|
|
|
|
|
|
float freqLo = 2000.0f * reqFlowLo / nominalFlow;
|
|
|
|
|
|
float freqHi = 2000.0f * reqFlowHi / nominalFlow;
|
|
|
|
|
|
controlBoard.ValveMove(regulValveNr, RegulValveMode.TargetFrequency,
|
|
|
|
|
|
new float[2] { freqLo, freqHi },
|
|
|
|
|
|
regulValve.StableTime);
|
|
|
|
|
|
|
2016-04-20 10:43:59 +00:00
|
|
|
|
log.InfoFormat("SetFlowOp: ValveMove({0}, Frequency, {1}, {2}, {3})",
|
|
|
|
|
|
regulValveNr, freqLo, freqHi, regulValve.StableTime);
|
|
|
|
|
|
|
|
|
|
|
|
opState = OpState.ValveMoveToFlow3;
|
2016-04-10 19:30:24 +00:00
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
2015-10-15 17:49:42 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
opState = OpState.SettingFlow;
|
|
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
else if (opState == OpState.SettingFlow)
|
|
|
|
|
|
{
|
2015-02-01 14:07:15 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Repeated untill the required flow is reached
|
|
|
|
|
|
///
|
2014-07-28 07:54:35 +00:00
|
|
|
|
if ((reqFlowLo <= flow) && (flow <= reqFlowHi))
|
|
|
|
|
|
{
|
2015-10-15 17:49:42 +00:00
|
|
|
|
if (flowWithinBoundsTime++ >= regulValve.FlowStableSec)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (regulValve.RegulValveCfg.StoredPositionReuse)
|
|
|
|
|
|
{
|
|
|
|
|
|
float storedPosition;
|
|
|
|
|
|
if (regulValve.Dict.TryGetValue(reqFlowAve, out storedPosition))
|
|
|
|
|
|
{
|
|
|
|
|
|
/// update the stored valve position
|
|
|
|
|
|
StoreTargetPosition(reqFlowAve, (rvPosition + storedPosition) / 2.0f);
|
|
|
|
|
|
log.InfoFormat("Run(): rv#={0} reqFlow={1} pos={2}% stored={3} <--- Updating a stored position",
|
|
|
|
|
|
regulValveNr, reqFlowAve, rvPosition.ToString("F1"), storedPosition);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
/// store the valve position
|
|
|
|
|
|
StoreTargetPosition(reqFlowAve, rvPosition);
|
|
|
|
|
|
log.InfoFormat("Run(): rv#={0} reqFlow={1} pos={2}% <--- Storing a new position",
|
|
|
|
|
|
regulValveNr, reqFlowAve, rvPosition.ToString("F1"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-02-07 21:27:32 +00:00
|
|
|
|
|
|
|
|
|
|
log.InfoFormat("flow = {0} m3/h (lo={1}, hi={2}, REACHED)", flow, reqFlowLo, reqFlowHi);
|
|
|
|
|
|
|
2015-10-15 17:49:42 +00:00
|
|
|
|
opState = OpState.FlowReached;
|
|
|
|
|
|
return Event.FlowReached;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-02-07 21:27:32 +00:00
|
|
|
|
log.InfoFormat("flow = {0} m3/h (lo={1}, hi={2}, FLOW_OK_TIMER={3}s)", flow, reqFlowLo, reqFlowHi, flowWithinBoundsTime);
|
2015-10-15 17:49:42 +00:00
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
2014-08-01 06:36:17 +00:00
|
|
|
|
else if (StateMachine.Time > expireTime)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
return Event.RegulValveTimeOut;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-02-07 21:27:32 +00:00
|
|
|
|
log.InfoFormat("flow = {0} m3/h (lo={1}, hi={2})", flow, reqFlowLo, reqFlowHi);
|
2015-10-15 17:49:42 +00:00
|
|
|
|
flowWithinBoundsTime = 0;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else /// opState == OpState.FlowReached
|
|
|
|
|
|
{
|
2016-02-07 21:27:32 +00:00
|
|
|
|
log.InfoFormat("flow = {0} m3/h (lo={1}, hi={2}, REACHED)", flow, reqFlowLo, reqFlowHi);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
return Event.FlowReached;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Start this operation</summary>
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
|
{
|
|
|
|
|
|
opState = OpState.Idle;
|
|
|
|
|
|
|
|
|
|
|
|
if (leaveMeasurementRunning) return;
|
|
|
|
|
|
|
|
|
|
|
|
/// Stop measurement
|
|
|
|
|
|
TestMethods tm = 0;
|
|
|
|
|
|
StopDevs sd = StopDevs.RegValveRegulation;
|
2016-04-04 07:23:07 +00:00
|
|
|
|
controlBoard.SendCommand(Command.Stop, flowMeterNr, controlBoard.Route,
|
|
|
|
|
|
50000, 50000, tm,
|
2014-07-28 07:54:35 +00:00
|
|
|
|
0.0f, 20, 0, sd);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|