SetValves operation uses Delay of 'Valve', 'Pump' and 'PumpWithFM'
This commit is contained in:
@@ -14,18 +14,38 @@ namespace TBF.BenchControl.Elde.Valve
|
||||
|
||||
class SwitchPoint
|
||||
{
|
||||
public int TimeSec; /// Time [s]
|
||||
public int TimeSec; /// Relative time in [s] from the start of the operation
|
||||
public IList<IValve> VOpen; /// List of valves to open in this point of time
|
||||
public IList<IValve> VClose; /// List of valves to close in this point of time
|
||||
public ulong MasksOpen; /// OR-ed bitmasks of valves to open in this point of time
|
||||
public ulong MasksClose; /// OR-ed bitmasks of valves to close in this point of time
|
||||
public int MaxDelay; /// Max. delay in [s] of all valves to be opened or closed
|
||||
|
||||
public SwitchPoint(int time, IList<IValve> vOpen, IList<IValve> vClose)
|
||||
{
|
||||
this.TimeSec = time;
|
||||
this.VOpen = (vOpen == null) ? new List<IValve>() : vOpen;
|
||||
this.VClose = (vClose == null) ? new List<IValve>() : vClose;
|
||||
}
|
||||
|
||||
/// Max. delay in [s] of all valves to be opened or closed
|
||||
public int MaxDelay
|
||||
{
|
||||
get
|
||||
{
|
||||
int max = 0;
|
||||
foreach (var vlv in VOpen) if (vlv.Delay > max) max = vlv.Delay;
|
||||
foreach (var vlv in VClose) if (vlv.Delay > max) max = vlv.Delay;
|
||||
return max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IList<SwitchPoint> switchPointsRaw;
|
||||
IList<SwitchPoint> switchPoints;
|
||||
int nextIx;
|
||||
int swStartTime;
|
||||
int maxDelayTime; /// Max. delay from all valve/pump switches.
|
||||
/// Relative time in [s] from the start of the operation
|
||||
|
||||
/// <summary>
|
||||
/// Processes coupled valves and creates switch points.
|
||||
@@ -36,7 +56,7 @@ namespace TBF.BenchControl.Elde.Valve
|
||||
IList<SwitchPoint> CollectSwitchPoints(IList<IValve> valvesOpen, IList<IValve> valvesClose)
|
||||
{
|
||||
IList<SwitchPoint> result = new List<SwitchPoint>();
|
||||
result.Add(new SwitchPoint { TimeSec = 0, VOpen = valvesOpen, VClose = valvesClose });
|
||||
result.Add(new SwitchPoint(0, valvesOpen, valvesClose));
|
||||
|
||||
foreach (var valve in StateMachine.CoupledValves)
|
||||
{
|
||||
@@ -51,9 +71,7 @@ namespace TBF.BenchControl.Elde.Valve
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(new SwitchPoint { TimeSec = time,
|
||||
VOpen = ValveBase.MakeList(valve),
|
||||
VClose = new List<IValve>() });
|
||||
result.Add(new SwitchPoint(time, ValveBase.MakeList(valve), null));
|
||||
}
|
||||
}
|
||||
else if ((!valve.InvertCouple && valvesClose.Contains(valve.CoupledTo)) ||
|
||||
@@ -67,9 +85,7 @@ namespace TBF.BenchControl.Elde.Valve
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(new SwitchPoint { TimeSec = time,
|
||||
VOpen = new List<IValve>(),
|
||||
VClose = ValveBase.MakeList(valve) });
|
||||
result.Add(new SwitchPoint(time, null, ValveBase.MakeList(valve)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -169,6 +185,7 @@ namespace TBF.BenchControl.Elde.Valve
|
||||
{
|
||||
controlBoard.SetValves(switchPoints[0].MasksOpen, switchPoints[0].MasksClose);
|
||||
swStartTime = StateMachine.Time;
|
||||
maxDelayTime = switchPoints[0].MaxDelay;
|
||||
nextIx = 1;
|
||||
}
|
||||
|
||||
@@ -178,13 +195,22 @@ namespace TBF.BenchControl.Elde.Valve
|
||||
/// </returns>
|
||||
public Event Run()
|
||||
{
|
||||
if (nextIx >= switchPoints.Count) return Event.ValvesSet;
|
||||
if (nextIx >= switchPoints.Count)
|
||||
{
|
||||
if (StateMachine.Time >= swStartTime + maxDelayTime) return Event.ValvesSet;
|
||||
else return Event.None;
|
||||
}
|
||||
|
||||
if (StateMachine.Time >= swStartTime + switchPoints[nextIx].TimeSec)
|
||||
{
|
||||
if (switchPoints[nextIx].TimeSec + switchPoints[nextIx].MaxDelay > maxDelayTime)
|
||||
{
|
||||
maxDelayTime = switchPoints[nextIx].TimeSec + switchPoints[nextIx].MaxDelay;
|
||||
}
|
||||
controlBoard.SetValves(switchPoints[nextIx].MasksOpen, switchPoints[nextIx].MasksClose);
|
||||
nextIx++;
|
||||
}
|
||||
|
||||
return Event.None;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user