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
|
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> 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 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 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 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> switchPointsRaw;
|
||||||
IList<SwitchPoint> switchPoints;
|
IList<SwitchPoint> switchPoints;
|
||||||
int nextIx;
|
int nextIx;
|
||||||
int swStartTime;
|
int swStartTime;
|
||||||
|
int maxDelayTime; /// Max. delay from all valve/pump switches.
|
||||||
|
/// Relative time in [s] from the start of the operation
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Processes coupled valves and creates switch points.
|
/// 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> CollectSwitchPoints(IList<IValve> valvesOpen, IList<IValve> valvesClose)
|
||||||
{
|
{
|
||||||
IList<SwitchPoint> result = new List<SwitchPoint>();
|
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)
|
foreach (var valve in StateMachine.CoupledValves)
|
||||||
{
|
{
|
||||||
@@ -51,9 +71,7 @@ namespace TBF.BenchControl.Elde.Valve
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.Add(new SwitchPoint { TimeSec = time,
|
result.Add(new SwitchPoint(time, ValveBase.MakeList(valve), null));
|
||||||
VOpen = ValveBase.MakeList(valve),
|
|
||||||
VClose = new List<IValve>() });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((!valve.InvertCouple && valvesClose.Contains(valve.CoupledTo)) ||
|
else if ((!valve.InvertCouple && valvesClose.Contains(valve.CoupledTo)) ||
|
||||||
@@ -67,9 +85,7 @@ namespace TBF.BenchControl.Elde.Valve
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.Add(new SwitchPoint { TimeSec = time,
|
result.Add(new SwitchPoint(time, null, ValveBase.MakeList(valve)));
|
||||||
VOpen = new List<IValve>(),
|
|
||||||
VClose = ValveBase.MakeList(valve) });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,7 +185,8 @@ namespace TBF.BenchControl.Elde.Valve
|
|||||||
{
|
{
|
||||||
controlBoard.SetValves(switchPoints[0].MasksOpen, switchPoints[0].MasksClose);
|
controlBoard.SetValves(switchPoints[0].MasksOpen, switchPoints[0].MasksClose);
|
||||||
swStartTime = StateMachine.Time;
|
swStartTime = StateMachine.Time;
|
||||||
nextIx = 1;
|
maxDelayTime = switchPoints[0].MaxDelay;
|
||||||
|
nextIx = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Run this operation</summary>
|
/// <summary>Run this operation</summary>
|
||||||
@@ -178,13 +195,22 @@ namespace TBF.BenchControl.Elde.Valve
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public Event Run()
|
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 (StateMachine.Time >= swStartTime + switchPoints[nextIx].TimeSec)
|
||||||
{
|
{
|
||||||
controlBoard.SetValves(switchPoints[nextIx].MasksOpen, switchPoints[nextIx].MasksClose);
|
if (switchPoints[nextIx].TimeSec + switchPoints[nextIx].MaxDelay > maxDelayTime)
|
||||||
nextIx++;
|
{
|
||||||
|
maxDelayTime = switchPoints[nextIx].TimeSec + switchPoints[nextIx].MaxDelay;
|
||||||
|
}
|
||||||
|
controlBoard.SetValves(switchPoints[nextIx].MasksOpen, switchPoints[nextIx].MasksClose);
|
||||||
|
nextIx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Event.None;
|
return Event.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user