Fixed a bug in transition sequences with more RV-s changed in one step

This commit is contained in:
Milan Hanajik
2014-12-12 13:57:24 +01:00
parent 6d6b322fb5
commit 4794000f75
@@ -439,7 +439,7 @@ namespace TBF.BenchControl.Sequences
Bridge.OnActivity(this, string.Format(message, transitionSequence.Name, step.ItemNr + 1, stepsCount));
//------------------------------------------------
/// Get new regulation valve positions and calculate the number of valves to change
/// FM controlled pumps are canged imediately without using any state operations
float[] allFMPumpPcts = Utils.GetPumpWithFMPcts(step);
for (int i = 0; i < allFMPumpPcts.Length; i++)
{
@@ -458,76 +458,68 @@ namespace TBF.BenchControl.Sequences
}
}
/// Get new regulation valve positions and calculate the number of valves to change
/// Get new regulation valve positions,
float[] allRegvPositions = Utils.GetRegulValvesPositions(step);
///
IList<IOperation> rvPosOperations = new List<IOperation>();
/// Prepare necessary SetRegValvePositionOp operations for RV-s with changed positions
IList<IOperation> rvPosOps = new List<IOperation>();
for (int i = 0; i < allRegvPositions.Length; i++)
{
if (allRegvPositions[i] >= 0) /// Negative value means no position change
{
rvPosOperations.Add(RegulValves[i].SetRegulValvePositionOp(
Math.Max(0, allRegvPositions[i] - 0.05f), Math.Min(100.0f, allRegvPositions[i] + 0.05f), 60));
rvPosOps.Add(RegulValves[i]
.SetRegulValvePositionOp(Math.Max(0, allRegvPositions[i] - 0.05f),
Math.Min(100.0f, allRegvPositions[i] + 0.05f), 60));
}
}
int changingRVsCount = rvPosOperations.Count; /// Number of RV-s with changing position in this step
/// Duration must be at least the number of regulation valves to change seconds
int duration = Math.Max(step.Duration, changingRVsCount);
/// Max. one SetRegulValvePositionOp can be started or stopped in one sub-step
/// Total step duration will be 'delay' + 2 * number of regulation valves to change in seconds
/// so that each regulation valve setting is greater then or equal to the step duration.
int delay = Math.Max(1, step.Duration - rvPosOps.Count);
bool stopFlag = false;
for (int i = 0; i < 2 * rvPosOps.Count + 1; i++)
{
State subStep = State.Create(string.Format("SequenceBase.Transition() : Step {0}.1/{1}",
step.ItemNr + 1, 2 * rvPosOps.Count + 1 - i))
.AddOperation(checkUiOp)
.AddOperation(StateMachine.ControlBoard.SetValvesOp(Utils.ValvesOpen(step), Utils.ValvesClose(step)))
.AddOperation(new TimerOp((i == rvPosOps.Count) ? delay : 1));
///
/// The first state updates all (regular) valves and the 1st regulation valve to be changed
/// Max. one regulation valve may be controlled in each sub-step (in each state)
///
State oneStep = State.Create(string.Format("SequenceBase.Transition() : Step {0}.1/{1}", step.ItemNr + 1, stepsCount))
.AddOperation(checkUiOp)
.AddOperation(StateMachine.ControlBoard.SetValvesOp(Utils.ValvesOpen(step), Utils.ValvesClose(step)))
.AddOperation(new TimerOp((changingRVsCount <= 1) ? step.Duration : 1));
for (int j = 0; j < rvPosOps.Count; j++)
{
if (i >= j && i <= rvPosOps.Count + 1 + j) subStep.AddOperation(rvPosOps[j]);
}
if (changingRVsCount > 0)
{
oneStep.AddOperation(rvPosOperations[0]);
}
oneStep.EnterState();
subStep.EnterState();
do
{
e = StateMachine.WaitRunDevsRunOps();
log.InfoFormat("RV1={0}% RV2={1}% RV3={2}% RV4={3}% RV5={4}%", StateMachine.ControlBoard.RValvePosition(1),
StateMachine.ControlBoard.RValvePosition(2), StateMachine.ControlBoard.RValvePosition(3),
StateMachine.ControlBoard.RValvePosition(4), StateMachine.ControlBoard.RValvePosition(5));
if (e.Contains(Event.Error)) return Event.Error;
if (e.Contains(Event.RegulValveTimeOut)) return Event.Error;
if (e.Contains(Event.UiCmdStop)) return Event.UiCmdStop;
}
while (!e.Contains(Event.TimerExpired));
do
{
e = StateMachine.WaitRunDevsRunOps();
log.InfoFormat("RV1={0}% RV2={1}% RV3={2}% RV4={3}% RV5={4}%", StateMachine.ControlBoard.RValvePosition(1),
StateMachine.ControlBoard.RValvePosition(2), StateMachine.ControlBoard.RValvePosition(3),
StateMachine.ControlBoard.RValvePosition(4), StateMachine.ControlBoard.RValvePosition(5));
if (e.Contains(Event.Error) || e.Contains(Event.RegulValveTimeOut))
{
return Event.Error;
}
if (e.Contains(Event.UiCmdStop))
{
stopFlag = true;
if (i <= rvPosOps.Count)
{
i--;
i = 2 * rvPosOps.Count - i;
break;
}
}
}
while (e.Contains(Event.TimerBusy));
///
/// Additional extra states the 2nd and all subsequent regulation valves to be changed
/// Max. one regulation valve may be controlled in each sub-step (in each state)
///
for (int j = 1; j < changingRVsCount; j++)
{
/// The first state updating all plain valves and the 1st regulation valve
/// Max. one regulation valve may change in each step
State oneStepContinued = State.Create(string.Format("SequenceBase.Transition() : Step {0}.{2}/{1}", step.ItemNr + 1, stepsCount, j + 1))
.AddOperation(checkUiOp)
.AddOperation(new TimerOp((j == changingRVsCount - 1) ? (step.Duration - changingRVsCount + 1) : 1));
for (int k = 0; k <= j; k++) { oneStepContinued.AddOperation(rvPosOperations[k]); }
oneStepContinued.EnterState();
}
if (stopFlag) return Event.UiCmdStop;
do
{
e = StateMachine.WaitRunDevsRunOps();
log.InfoFormat("RV1={0}% RV2={1}% RV3={2}% RV4={3}% RV5={4}%", StateMachine.ControlBoard.RValvePosition(1),
StateMachine.ControlBoard.RValvePosition(2), StateMachine.ControlBoard.RValvePosition(3),
StateMachine.ControlBoard.RValvePosition(4), StateMachine.ControlBoard.RValvePosition(5));
if (e.Contains(Event.Error)) return Event.Error;
if (e.Contains(Event.RegulValveTimeOut)) return Event.Error;
if (e.Contains(Event.UiCmdStop)) return Event.UiCmdStop;
}
while (!e.Contains(Event.TimerExpired));
}
}
}