SetFlowOp with verification and re-sending the command.
This commit is contained in:
parent
9dc3759f99
commit
2cd877fb17
@ -37,15 +37,18 @@ namespace TBF.BenchControl.Elde.RegulValve
|
||||
enum OpState
|
||||
{
|
||||
Idle = 0,
|
||||
ValveMoveToPosition,
|
||||
Wait1, /// This is actual move to position
|
||||
ValveMoveToPosition1, /// Wait 1 takt
|
||||
ValveMoveToPosition2, /// This is actual move to position
|
||||
ValveMoveToPosition3, /// Wait 1 takt
|
||||
ValveMoveToPosition4, /// Verify
|
||||
SettingPosition,
|
||||
ValveMoveToFlow,
|
||||
Wait2, /// This is actual move to flow
|
||||
Wait3,
|
||||
ValveMoveToFlow2, /// This is move to flow 2
|
||||
ValveMoveToFlow1, /// Wait 1 takt
|
||||
ValveMoveToFlow2, /// This is actual move to flow
|
||||
ValveMoveToFlow3, /// Wait 1 takt
|
||||
ValveMoveToFlow4, /// Verify
|
||||
SettingFlow,
|
||||
FlowReached,
|
||||
SendCommandAgain,
|
||||
}
|
||||
OpState opState;
|
||||
|
||||
@ -172,14 +175,14 @@ namespace TBF.BenchControl.Elde.RegulValve
|
||||
log.InfoFormat("Start(): rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3} FETCHED: posLo={4} posHi={5}",
|
||||
regulValveNr, flowMeterNr, reqFlowLo, reqFlowHi, targetPositionLo, targetPositionHi);
|
||||
|
||||
opState = OpState.ValveMoveToPosition;
|
||||
opState = OpState.ValveMoveToPosition1;
|
||||
}
|
||||
else
|
||||
{
|
||||
log.InfoFormat("Start(): rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3}",
|
||||
regulValveNr, flowMeterNr, reqFlowLo, reqFlowHi);
|
||||
|
||||
opState = OpState.ValveMoveToFlow;
|
||||
opState = OpState.ValveMoveToFlow1;
|
||||
}
|
||||
|
||||
expireTime = StateMachine.Time + timeout;
|
||||
@ -207,67 +210,94 @@ namespace TBF.BenchControl.Elde.RegulValve
|
||||
log.InfoFormat("Run(): rv#={0} pos={1}% freq={2} flow={3} opState={4}",
|
||||
regulValveNr, rvPosition.ToString("F1"), flowMtrFreq, flow, opState);
|
||||
|
||||
if (opState == OpState.ValveMoveToPosition)
|
||||
|
||||
if (opState == OpState.SendCommandAgain)
|
||||
{
|
||||
opState = OpState.Wait1;
|
||||
flowWithinBoundsTime = 0;
|
||||
|
||||
if (regulValve.RegulValveCfg.StoredPositionReuse && FetchTargetPosition(reqFlowAve, out targetPositionLo, out targetPositionHi))
|
||||
{
|
||||
log.InfoFormat("Start(): rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3} FETCHED: posLo={4} posHi={5}",
|
||||
regulValveNr, flowMeterNr, reqFlowLo, reqFlowHi, targetPositionLo, targetPositionHi);
|
||||
|
||||
opState = OpState.ValveMoveToPosition1;
|
||||
}
|
||||
else
|
||||
{
|
||||
log.InfoFormat("Start(): rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3}",
|
||||
regulValveNr, flowMeterNr, reqFlowLo, reqFlowHi);
|
||||
|
||||
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'
|
||||
controlBoard.SendCommand(Command.Start, flowMeterNr, controlBoard.Route, int.MaxValue, tm,
|
||||
0.0f, (int)pidCoef, 0, sd);
|
||||
return Event.None;
|
||||
}
|
||||
else if (opState == OpState.Wait1) /// Move to position
|
||||
else if (opState == OpState.ValveMoveToPosition1)
|
||||
{
|
||||
///
|
||||
/// Done once, issues an appropriate ValveMove(...) command
|
||||
///
|
||||
opState = OpState.ValveMoveToPosition2;
|
||||
return Event.None;
|
||||
}
|
||||
else if (opState == OpState.ValveMoveToPosition2) /// Move to position
|
||||
{
|
||||
/// Issues the appropriate ValveMove(...) command
|
||||
controlBoard.ValveMove(regulValveNr, RegulValveMode.TargetPosition,
|
||||
new float[2] { targetPositionLo, targetPositionHi },
|
||||
regulValve.StableTime);
|
||||
regulValve.StableTime);
|
||||
|
||||
opState = OpState.SettingPosition;
|
||||
return Event.None;
|
||||
}
|
||||
else if (opState == OpState.ValveMoveToPosition3)
|
||||
{
|
||||
opState = OpState.ValveMoveToPosition4;
|
||||
return Event.None;
|
||||
}
|
||||
else if (opState == OpState.ValveMoveToPosition4) /// Verify
|
||||
{
|
||||
if (((ulong)controlBoard.StatusP & (ulong)StatusP.TestInProgress) == 0)
|
||||
{
|
||||
opState = OpState.SendCommandAgain;
|
||||
return Event.None;
|
||||
}
|
||||
else if (controlBoard.RegulValveState(regulValveNr) != RegulValveState.DacValueRegul)
|
||||
{
|
||||
/// Repeat appropriate ValveMove(...) command
|
||||
controlBoard.ValveMove(regulValveNr, RegulValveMode.TargetPosition,
|
||||
new float[2] { targetPositionLo, targetPositionHi },
|
||||
regulValve.StableTime);
|
||||
|
||||
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.ValveMoveToFlow;
|
||||
}
|
||||
return Event.None;
|
||||
}
|
||||
else if (opState == OpState.ValveMoveToFlow)
|
||||
{
|
||||
opState = OpState.Wait2;
|
||||
if ((targetPositionLo <= rvPosition) && (rvPosition <= targetPositionHi))
|
||||
{
|
||||
opState = OpState.ValveMoveToFlow1;
|
||||
}
|
||||
return Event.None;
|
||||
}
|
||||
else if (opState == OpState.Wait2) /// Move to flow
|
||||
{
|
||||
///
|
||||
/// 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.Wait3;
|
||||
return Event.None;
|
||||
}
|
||||
else if (opState == OpState.Wait3)
|
||||
else if (opState == OpState.ValveMoveToFlow1)
|
||||
{
|
||||
opState = OpState.ValveMoveToFlow2;
|
||||
return Event.None;
|
||||
}
|
||||
else if (opState == OpState.ValveMoveToFlow2)
|
||||
else if (opState == OpState.ValveMoveToFlow2) /// Move to flow
|
||||
{
|
||||
///
|
||||
/// Done once, issues an appropriate ValveMove(...) command
|
||||
@ -286,9 +316,39 @@ namespace TBF.BenchControl.Elde.RegulValve
|
||||
new float[2] { freqLo, freqHi },
|
||||
regulValve.StableTime);
|
||||
|
||||
opState = OpState.SettingFlow;
|
||||
opState = OpState.ValveMoveToFlow3;
|
||||
return Event.None;
|
||||
}
|
||||
else if (opState == OpState.ValveMoveToFlow3)
|
||||
{
|
||||
opState = OpState.ValveMoveToFlow4;
|
||||
return Event.None;
|
||||
}
|
||||
else if (opState == OpState.ValveMoveToFlow4)
|
||||
{
|
||||
if (((ulong)controlBoard.StatusP & (ulong)StatusP.TestInProgress) == 0)
|
||||
{
|
||||
opState = OpState.SendCommandAgain;
|
||||
return Event.None;
|
||||
}
|
||||
else if (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);
|
||||
|
||||
opState = OpState.ValveMoveToFlow3;
|
||||
return Event.None;
|
||||
}
|
||||
else
|
||||
{
|
||||
opState = OpState.SettingFlow;
|
||||
return Event.None;
|
||||
}
|
||||
}
|
||||
else if (opState == OpState.SettingFlow)
|
||||
{
|
||||
///
|
||||
@ -296,33 +356,33 @@ namespace TBF.BenchControl.Elde.RegulValve
|
||||
///
|
||||
if ((reqFlowLo <= flow) && (flow <= reqFlowHi))
|
||||
{
|
||||
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"));
|
||||
}
|
||||
}
|
||||
opState = OpState.FlowReached;
|
||||
return Event.FlowReached;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Event.None;
|
||||
}
|
||||
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"));
|
||||
}
|
||||
}
|
||||
opState = OpState.FlowReached;
|
||||
return Event.FlowReached;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Event.None;
|
||||
}
|
||||
}
|
||||
else if (StateMachine.Time > expireTime)
|
||||
{
|
||||
@ -330,7 +390,7 @@ namespace TBF.BenchControl.Elde.RegulValve
|
||||
}
|
||||
else
|
||||
{
|
||||
flowWithinBoundsTime = 0;
|
||||
flowWithinBoundsTime = 0;
|
||||
return Event.None;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user