Flow control during a test, version 1.5.121.
This commit is contained in:
@@ -464,9 +464,12 @@ namespace TBF.BenchControl.Elde
|
||||
/// <param name="readers">An array of register readers</param>
|
||||
/// <param name="refPulses">Number of reference pulses to complete the test</param>
|
||||
/// <returns>Created operation</returns>
|
||||
public IOperation StartMeasurementOp(OutputPath outputPath, TestMethods method, int refPulses, float filterConstant)
|
||||
public IOperation StartMeasurementOp(OutputPath outputPath, TestMethods method,
|
||||
float requiredFlowLo, float requiredFlowHi,
|
||||
int refPulses, float filterConstant)
|
||||
{
|
||||
return new StartMeasurementOp(this, outputPath, method, refPulses, filterConstant);
|
||||
return new StartMeasurementOp(this, outputPath, method,
|
||||
requiredFlowLo, requiredFlowHi, refPulses, filterConstant);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -31,7 +31,9 @@ namespace TBF.BenchControl.Elde.RegulValve
|
||||
|
||||
readonly float nominalFlow;
|
||||
|
||||
/// Process values
|
||||
///
|
||||
/// Internal states of this operation
|
||||
///
|
||||
enum OpState
|
||||
{
|
||||
Idle = 0,
|
||||
|
||||
@@ -9,18 +9,38 @@ namespace TBF.BenchControl.Elde
|
||||
public class StartMeasurementOp : IOperation
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(StartMeasurementOp));
|
||||
public override string ToString() { return string.Format("StartMeasurementOp(ref={0},pulses={1})", flowMeterIdx, refPulses); }
|
||||
public override string ToString() { return string.Format("StartMeasurementOp(ref={0},pulses={1})", flowMeterNr, refPulses); }
|
||||
|
||||
/// Set by the constructor
|
||||
readonly ControlBoardDev controlBoard;
|
||||
readonly int flowMeterIdx;
|
||||
readonly int refPulses; /// Number of reference pulses for a complete test
|
||||
readonly Elde.RegulValve.RegulValve regulValve;
|
||||
readonly int regulValveNr;
|
||||
readonly int flowMeterNr;
|
||||
readonly float nominalFlow;
|
||||
readonly float reqFlowLo;
|
||||
readonly float reqFlowHi;
|
||||
readonly float reqFlowAve;
|
||||
readonly float pidCoef;
|
||||
readonly int refPulses; /// Number of reference pulses for a complete test
|
||||
readonly TestMethods testMethod;
|
||||
readonly float filterConstant;
|
||||
readonly int diverterIdx;
|
||||
readonly int diverterNr;
|
||||
|
||||
bool started = false;
|
||||
|
||||
///
|
||||
/// Internal states of this operation
|
||||
///
|
||||
enum OpState
|
||||
{
|
||||
StartingTest,
|
||||
TestStarted,
|
||||
ValveMoveToFlow,
|
||||
OpCompleted,
|
||||
}
|
||||
OpState opState;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Starts the measurement.
|
||||
/// Events: MeasurementStarted
|
||||
@@ -30,30 +50,42 @@ namespace TBF.BenchControl.Elde
|
||||
/// <param name="method">Test method</param>
|
||||
/// <param name="refPulses">Test duration in number of reference flowmeter pulses</param>
|
||||
/// <param name="filterConstant">Specifies filter for watermeter pulses</param>
|
||||
public StartMeasurementOp(ControlBoardDev controlBoard, OutputPath outputPath,
|
||||
TestMethods method, int refPulses, float filterConstant)
|
||||
public StartMeasurementOp(ControlBoardDev controlBoard, OutputPath outputPath, TestMethods method,
|
||||
float requiredFlowLo, float requiredFlowHi,
|
||||
int refPulses, float filterConstant)
|
||||
{
|
||||
if (controlBoard == null) throw new ArgumentNullException("controlBoardDev");
|
||||
this.controlBoard = controlBoard;
|
||||
|
||||
if (outputPath.FlowMeter is Elde.FlowMeter.FlowMeter)
|
||||
{
|
||||
flowMeterIdx = (outputPath.FlowMeter as Elde.FlowMeter.FlowMeter).Idx1;
|
||||
flowMeterNr = (outputPath.FlowMeter as Elde.FlowMeter.FlowMeter).Idx1;
|
||||
}
|
||||
else if (outputPath.FlowMeter is Elde.FlowMeterTwins.FlowMeter)
|
||||
{
|
||||
flowMeterIdx = 0;
|
||||
flowMeterNr = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("flowMeter is null or is not Elde");
|
||||
}
|
||||
|
||||
regulValve = outputPath.RegulValve as Elde.RegulValve.RegulValve;
|
||||
if (regulValve == null) throw new ArgumentNullException("regValve is null or not Elde");
|
||||
regulValveNr = this.regulValve.Idx1;
|
||||
|
||||
if (outputPath.Diverter is Elde.Diverter.Diverter)
|
||||
{
|
||||
diverterIdx = (outputPath.Diverter as Elde.Diverter.Diverter).AdcNr - 4;
|
||||
diverterNr = (outputPath.Diverter as Elde.Diverter.Diverter).AdcNr - 4;
|
||||
}
|
||||
|
||||
nominalFlow = outputPath.FlowMeter.NominalFlow;
|
||||
|
||||
this.reqFlowLo = requiredFlowLo;
|
||||
this.reqFlowHi = requiredFlowHi;
|
||||
this.reqFlowAve = (reqFlowLo + reqFlowHi) / 2.0f;
|
||||
this.pidCoef = outputPath.PidCoef;
|
||||
|
||||
this.refPulses = refPulses;
|
||||
this.testMethod = method;
|
||||
this.filterConstant = filterConstant;
|
||||
@@ -66,13 +98,15 @@ namespace TBF.BenchControl.Elde
|
||||
{
|
||||
controlBoard.SyncRoute();
|
||||
#if IPERLST
|
||||
int flowMeterIdxAndDiv = flowMeterIdx + 16 * diverterIdx;
|
||||
int flowMeterIdxAndDiv = flowMeterNr + 16 * diverterNr;
|
||||
#else
|
||||
int flowMeterIdxAndDiv = flowMeterIdx;
|
||||
int flowMeterIdxAndDiv = flowMeterNr;
|
||||
#endif
|
||||
|
||||
controlBoard.SendCommand(Command.Start, flowMeterIdxAndDiv, controlBoard.Route, refPulses, testMethod,
|
||||
filterConstant, 20, 0, StopDevs.None);
|
||||
|
||||
opState = OpState.StartingTest;
|
||||
}
|
||||
|
||||
/// <summary>Run this operation</summary>
|
||||
@@ -81,19 +115,50 @@ namespace TBF.BenchControl.Elde
|
||||
/// </returns>
|
||||
public Event Run()
|
||||
{
|
||||
if (started) return Event.MeasurementStarted;
|
||||
StatusP statusP = controlBoard.StatusP;
|
||||
log.DebugFormat("statusP = {0} {1} {2} {3}",
|
||||
(((ulong)statusP >> 48) & 0xFFFF).ToString("X4"),
|
||||
(((ulong)statusP >> 32) & 0xFFFF).ToString("X4"),
|
||||
(((ulong)statusP >> 16) & 0xFFFF).ToString("X4"),
|
||||
((ulong)statusP & 0xFFFF).ToString("X4"));
|
||||
if (0 != (statusP & StatusP.TestInProgress))
|
||||
{
|
||||
log.Info("Test started");
|
||||
started = true;
|
||||
return Event.MeasurementStarted;
|
||||
}
|
||||
if (opState == OpState.StartingTest)
|
||||
{
|
||||
StatusP statusP = controlBoard.StatusP;
|
||||
log.DebugFormat("statusP = {0} {1} {2} {3}",
|
||||
(((ulong)statusP >> 48) & 0xFFFF).ToString("X4"),
|
||||
(((ulong)statusP >> 32) & 0xFFFF).ToString("X4"),
|
||||
(((ulong)statusP >> 16) & 0xFFFF).ToString("X4"),
|
||||
((ulong)statusP & 0xFFFF).ToString("X4"));
|
||||
|
||||
if (0 != (statusP & StatusP.TestInProgress))
|
||||
{
|
||||
log.Info("Test started");
|
||||
opState = OpState.TestStarted;
|
||||
}
|
||||
|
||||
return Event.None;
|
||||
}
|
||||
else if (opState == OpState.TestStarted)
|
||||
{
|
||||
///
|
||||
/// 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);
|
||||
|
||||
opState = OpState.OpCompleted;
|
||||
return Event.None;
|
||||
}
|
||||
else if (opState == OpState.OpCompleted)
|
||||
{
|
||||
return Event.MeasurementStarted;
|
||||
}
|
||||
|
||||
return Event.None;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user