UniCB and Uni.RegValve functionality, ver. 3.1.1602
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
///
|
||||
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using log4net;
|
||||
using Dirichlet.Numerics;
|
||||
@@ -10,12 +11,15 @@ namespace TBF.BenchControl.ControlBoard.Uni
|
||||
public enum ActionID
|
||||
{
|
||||
/// Basic
|
||||
ChangeRoute = 1, /// Change digital outputs (route)
|
||||
SetFlow = 2, /// Set flow
|
||||
MeasureFlow = 4, /// Activate a flow meter to measure the flow
|
||||
StartTest = 8, /// Start a test
|
||||
Stop = 16, /// Stop a test or a flow regulation
|
||||
SwitchDiverter = 32, /// Switch diverter to tank/sink
|
||||
ChangeRoute = 1, /// Change digital outputs (route)
|
||||
MeasureFlow = 2, /// Activate a flow meter to measure the flow
|
||||
SetFlow = 4, /// Set flow
|
||||
StartTest = 8, /// Start a test
|
||||
StopTest = 0x10, /// Stop a test or a flow regulation
|
||||
RegVlvIncrMove = 0x20,
|
||||
RegVlvMoveToPos = 0x40,
|
||||
RegVlvStop = 0x80,
|
||||
SwitchDiverter = 0x100, /// Switch diverter to tank/sink
|
||||
|
||||
/// Advanced
|
||||
GetDiverterTransitionData,
|
||||
@@ -38,13 +42,14 @@ namespace TBF.BenchControl.ControlBoard.Uni
|
||||
public bool ToTank { get; set; } /// SwitchDiverter argument
|
||||
public int TotalPulsesCount { get; set; } /// StartTest argument
|
||||
public int MassPulsesCount { get; set; } /// StartTest argument
|
||||
public int FlowRegP1 { get; set; } /// SetFlow
|
||||
public int FlowRegP2 { get; set; } /// SetFlow
|
||||
public RegValveMode RegVMode { get; set; } /// SetFlow, RegVlvIncrMove, RegVlvMoveToPos, RegVlvStop
|
||||
public int RVMovePar1 { get; set; } /// SetFlow, RegVlvIncrMove, RegVlvMoveToPos
|
||||
public int RVMovePar2 { get; set; } /// SetFlow, RegVlvIncrMove, RegVlvMoveToPos
|
||||
public int PID { get; set; } /// SetFlow
|
||||
public int TolerRV { get; set; } /// SetFlow
|
||||
public int StabTime { get; set; } /// SetFlow
|
||||
public int DivThreshold { get; set; } /// StartTest argument
|
||||
int StartStop { get; set; } /// Implicitly used by SetFlow, StartTest and Stop: -1=not defined, 0=stop, 1=start
|
||||
int StartStop { get; set; } /// Implicitly used by StartTest and StopTest: -1=not defined, 0=stop, 1=start
|
||||
|
||||
|
||||
public Action()
|
||||
@@ -53,14 +58,15 @@ namespace TBF.BenchControl.ControlBoard.Uni
|
||||
FlowMId = -1;
|
||||
RegVId = -1;
|
||||
DivId = -1;
|
||||
RegVMode = RegValveMode.None;
|
||||
StartStop = -1;
|
||||
|
||||
/// These values are used by one action type only. No conflicts possible
|
||||
Route = 0;
|
||||
FlowRegP1 = 0;
|
||||
FlowRegP2 = 0;
|
||||
TotalPulsesCount = 0;
|
||||
MassPulsesCount = 0;
|
||||
RVMovePar1 = 0;
|
||||
RVMovePar2 = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +77,7 @@ namespace TBF.BenchControl.ControlBoard.Uni
|
||||
|
||||
public bool IsStop()
|
||||
{
|
||||
return (ActionId & ActionID.Stop) != 0;
|
||||
return (ActionId & ActionID.StopTest) != 0;
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
@@ -87,9 +93,10 @@ namespace TBF.BenchControl.ControlBoard.Uni
|
||||
{
|
||||
Route = action.Route;
|
||||
}
|
||||
bool CompareChangeRouteArgs(Action action)
|
||||
/// Check whether new action arguments are compatible with alredy collected arguments (true = yes)
|
||||
bool CheckSharedChangeRouteArgs(Action newAction)
|
||||
{
|
||||
return Route == action.Route;
|
||||
return Route == newAction.Route;
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
@@ -105,44 +112,51 @@ namespace TBF.BenchControl.ControlBoard.Uni
|
||||
{
|
||||
FlowMId = action.FlowMId;
|
||||
}
|
||||
bool CompareMeasureFlowArgs(Action action)
|
||||
/// Check whether new action arguments are compatible with alredy collected arguments (true = yes)
|
||||
bool CheckSharedMeasureFlowArgs(Action newAction)
|
||||
{
|
||||
return (FlowMId == -1 || FlowMId == action.FlowMId);
|
||||
return (FlowMId == -1 || FlowMId == newAction.FlowMId);
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
public static Action SetFlow(int flowMeterId, int regValveId, int flowRegPar1, int flowRegPar2,
|
||||
public static Action SetFlow(int flowMeterId, int regValveId, double freqLo, double freqHi,
|
||||
int pid, int tolerRV, int stabTime)
|
||||
{
|
||||
int rvMovePar1 = Convert.ToInt32(Math.Round(13.1072 * freqLo));
|
||||
int rvMovePar2 = Convert.ToInt32(Math.Round(13.1072 * freqHi));
|
||||
|
||||
return new Action
|
||||
{
|
||||
ActionId = ActionID.SetFlow,
|
||||
FlowMId = flowMeterId,
|
||||
RegVId = regValveId,
|
||||
FlowRegP1 = flowRegPar1,
|
||||
FlowRegP2 = flowRegPar2,
|
||||
RegVMode = RegValveMode.TargetFrequency,
|
||||
RVMovePar1 = rvMovePar1,
|
||||
RVMovePar2 = rvMovePar2,
|
||||
PID = pid,
|
||||
TolerRV = tolerRV,
|
||||
StabTime = stabTime,
|
||||
StartStop = 1,
|
||||
};
|
||||
}
|
||||
void SetSetFlowArgs(Action action)
|
||||
{
|
||||
FlowMId = action.FlowMId;
|
||||
RegVId = action.RegVId;
|
||||
FlowRegP1 = action.FlowRegP1;
|
||||
FlowRegP2 = action.FlowRegP2;
|
||||
RegVMode = action.RegVMode;
|
||||
RVMovePar1 = action.RVMovePar1;
|
||||
RVMovePar2 = action.RVMovePar2;
|
||||
PID = action.PID;
|
||||
TolerRV = action.TolerRV;
|
||||
StabTime = action.StabTime;
|
||||
StartStop = 1;
|
||||
}
|
||||
bool CompareSetFlowArgs(Action action)
|
||||
/// Check whether new action arguments are compatible with alredy collected arguments (true = yes)
|
||||
bool CheckSharedSetFlowArgs(Action newAction)
|
||||
{
|
||||
return (FlowMId == -1 || FlowMId == action.FlowMId) &&
|
||||
(RegVId == -1 || RegVId == action.RegVId) &&
|
||||
(StartStop == -1 || StartStop == 1);
|
||||
return (FlowMId == -1 || FlowMId == newAction.FlowMId) &&
|
||||
(RegVId == -1 || RegVId == newAction.RegVId) &&
|
||||
(RegVMode == RegValveMode.None || RegVMode == newAction.RegVMode) &&
|
||||
(RVMovePar1 == -1 || RVMovePar1 == newAction.RVMovePar1) &&
|
||||
(RVMovePar2 == -1 || RVMovePar2 == newAction.RVMovePar2);
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
@@ -173,31 +187,128 @@ namespace TBF.BenchControl.ControlBoard.Uni
|
||||
MassPulsesCount = action.MassPulsesCount;
|
||||
StartStop = 1;
|
||||
}
|
||||
bool CompareStartTestArgs(Action action)
|
||||
/// Check whether new action arguments are compatible with alredy collected arguments (true = yes)
|
||||
bool CheckSharedStartTestArgs(Action newAction)
|
||||
{
|
||||
return (FlowMId == -1 || FlowMId == action.FlowMId) &&
|
||||
(DivId == -1 || DivId == action.DivId) &&
|
||||
return (FlowMId == -1 || FlowMId == newAction.FlowMId) &&
|
||||
(DivId == -1 || DivId == newAction.DivId) &&
|
||||
(StartStop == -1 || StartStop == 1);
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
public static Action Stop()
|
||||
public static Action StopTest()
|
||||
{
|
||||
return new Action()
|
||||
{
|
||||
ActionId = ActionID.Stop,
|
||||
ActionId = ActionID.StopTest,
|
||||
StartStop = 0,
|
||||
};
|
||||
}
|
||||
void SetStopArgs(Action action)
|
||||
void SetStopTestArgs(Action action)
|
||||
{
|
||||
StartStop = 0;
|
||||
}
|
||||
bool CompareStopArgs(Action action)
|
||||
/// Check whether new action arguments are compatible with alredy collected arguments (true = yes)
|
||||
bool CheckSharedStopTestArgs(Action action)
|
||||
{
|
||||
return (StartStop == -1 || StartStop == 0);
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
public static Action RegVlvIncrMove(int regValveId, double timeSec)
|
||||
{
|
||||
int rvMovePar = Math.Abs(Convert.ToInt32(Math.Round(timeSec / 0.050))); /// Step is 50 ms
|
||||
|
||||
return new Action
|
||||
{
|
||||
ActionId = ActionID.RegVlvIncrMove,
|
||||
RegVId = regValveId,
|
||||
RegVMode = (timeSec >= 0) ? RegValveMode.PulseWidth : RegValveMode.PulseWidthNeg,
|
||||
RVMovePar1 = rvMovePar,
|
||||
RVMovePar2 = rvMovePar,
|
||||
};
|
||||
}
|
||||
void SetRegVlvIncrMoveArgs(Action action)
|
||||
{
|
||||
RegVId = action.RegVId;
|
||||
RegVMode = action.RegVMode;
|
||||
RVMovePar1 = action.RVMovePar1;
|
||||
RVMovePar2 = action.RVMovePar2;
|
||||
}
|
||||
/// Check whether new action arguments are compatible with alredy collected arguments (true = yes)
|
||||
bool CheckSharedRegVlvIncrMoveArgs(Action newAction)
|
||||
{
|
||||
return (RegVId == -1 || RegVId == newAction.RegVId) &&
|
||||
(RegVMode == RegValveMode.None || RegVMode == newAction.RegVMode);
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
public static Action RegVlvMoveToPos(int regValveId, double positionLo, double positionHi = -1)
|
||||
{
|
||||
int rvMovePar1, rvMovePar2; /// TODO
|
||||
///
|
||||
if (positionHi < 0)
|
||||
{
|
||||
/// Center position specified, calculate a range
|
||||
rvMovePar1 = 0; // TODO
|
||||
rvMovePar2 = 0; // TODO
|
||||
}
|
||||
else
|
||||
{
|
||||
/// Lower and upper range of position specified
|
||||
rvMovePar1 = 0; // TODO
|
||||
rvMovePar2 = 0; // TODO
|
||||
}
|
||||
|
||||
return new Action
|
||||
{
|
||||
ActionId = ActionID.RegVlvMoveToPos,
|
||||
RegVId = regValveId,
|
||||
RegVMode = RegValveMode.TargetPosition,
|
||||
RVMovePar1 = rvMovePar1,
|
||||
RVMovePar2 = rvMovePar2,
|
||||
};
|
||||
}
|
||||
void SetRegVlvMoveToPosArgs(Action action)
|
||||
{
|
||||
RegVId = action.RegVId;
|
||||
RegVMode = action.RegVMode;
|
||||
RVMovePar1 = action.RVMovePar1;
|
||||
RVMovePar2 = action.RVMovePar2;
|
||||
}
|
||||
/// Check whether new action arguments are compatible with alredy collected arguments (true = yes)
|
||||
bool CheckSharedRegVlvMoveToPosArgs(Action newAction)
|
||||
{
|
||||
return (RegVId == -1 || RegVId == newAction.RegVId) &&
|
||||
(RegVMode == RegValveMode.None || RegVMode == newAction.RegVMode);
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
public static Action RegVlvStop(int regValveId)
|
||||
{
|
||||
return new Action
|
||||
{
|
||||
ActionId = ActionID.RegVlvMoveToPos,
|
||||
RegVId = regValveId,
|
||||
RegVMode = RegValveMode.Stop,
|
||||
RVMovePar1 = 0,
|
||||
RVMovePar2 = 0,
|
||||
};
|
||||
}
|
||||
void SetRegVlvStopArgs(Action action)
|
||||
{
|
||||
RegVId = action.RegVId;
|
||||
RegVMode = action.RegVMode;
|
||||
RVMovePar1 = action.RVMovePar1;
|
||||
RVMovePar2 = action.RVMovePar2;
|
||||
}
|
||||
/// Check whether new action arguments are compatible with alredy collected arguments (true = yes)
|
||||
bool CheckSharedRegVlvStopArgs(Action newAction)
|
||||
{
|
||||
return (RegVId == -1 || RegVId == newAction.RegVId) &&
|
||||
(RegVMode == RegValveMode.None || RegVMode == newAction.RegVMode);
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
public static Action SwitchDiverter(int divId, bool toTank)
|
||||
{
|
||||
@@ -213,7 +324,8 @@ namespace TBF.BenchControl.ControlBoard.Uni
|
||||
DivId = action.DivId;
|
||||
ToTank = action.ToTank;
|
||||
}
|
||||
bool CompareSwitchDiverterArgs(Action action)
|
||||
/// Check whether new action arguments are compatible with alredy collected arguments (true = yes)
|
||||
bool CheckSharedSwitchDiverterArgs(Action action)
|
||||
{
|
||||
return (DivId == -1 || DivId == action.DivId);
|
||||
}
|
||||
@@ -229,27 +341,27 @@ namespace TBF.BenchControl.ControlBoard.Uni
|
||||
case ActionID.MeasureFlow: SetMeasureFlowArgs(action); return;
|
||||
case ActionID.SetFlow: SetSetFlowArgs(action); return;
|
||||
case ActionID.StartTest: SetStartTestArgs(action); return;
|
||||
case ActionID.Stop: SetStopArgs(action); return;
|
||||
case ActionID.StopTest: SetStopTestArgs(action); return;
|
||||
case ActionID.SwitchDiverter: SetSwitchDiverterArgs(action); return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether there is a conflict in usage of arguments.
|
||||
/// Check whether new action arguments are compatible with alredy collected arguments
|
||||
/// </summary>
|
||||
/// <param name="action">2nd action</param>
|
||||
/// <returns>true if there is no conflict</returns>
|
||||
bool CompareSharedArgs(Action action)
|
||||
/// <param name="action">Action to be executed together with already collected actions</param>
|
||||
/// <returns>true when compatible</returns>
|
||||
bool CheckSharedArgs(Action action)
|
||||
{
|
||||
switch (action.ActionId)
|
||||
{
|
||||
case ActionID.ChangeRoute: return CompareChangeRouteArgs(action);
|
||||
case ActionID.MeasureFlow: return CompareMeasureFlowArgs(action);
|
||||
case ActionID.SetFlow: return CompareSetFlowArgs(action);
|
||||
case ActionID.StartTest: return CompareStartTestArgs(action);
|
||||
case ActionID.Stop: return CompareStopArgs(action);
|
||||
case ActionID.SwitchDiverter: return CompareSwitchDiverterArgs(action);
|
||||
case ActionID.ChangeRoute: return CheckSharedChangeRouteArgs(action);
|
||||
case ActionID.MeasureFlow: return CheckSharedMeasureFlowArgs(action);
|
||||
case ActionID.SetFlow: return CheckSharedSetFlowArgs(action);
|
||||
case ActionID.StartTest: return CheckSharedStartTestArgs(action);
|
||||
case ActionID.StopTest: return CheckSharedStopTestArgs(action);
|
||||
case ActionID.SwitchDiverter: return CheckSharedSwitchDiverterArgs(action);
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
@@ -267,7 +379,7 @@ namespace TBF.BenchControl.ControlBoard.Uni
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
var peekA = queue.Peek();
|
||||
if ((resultA.ActionId & peekA.ActionId) == 0 && resultA.CompareSharedArgs(peekA) == true)
|
||||
if ((resultA.ActionId & peekA.ActionId) == 0 && resultA.CheckSharedArgs(peekA) == true)
|
||||
{
|
||||
/// ActionId would not be repeated and arguments are compatible => apply the new action
|
||||
resultA.SetArgs(peekA);
|
||||
@@ -293,7 +405,7 @@ namespace TBF.BenchControl.ControlBoard.Uni
|
||||
args = string.Format("Route={0}", Route.ToString("X16"));
|
||||
break;
|
||||
case ActionID.SetFlow:
|
||||
args = string.Format("Etalon={0} RV={1} Par1={2} Par2={3}", FlowMId, RegVId, FlowRegP1, FlowRegP2);
|
||||
args = string.Format("Etalon={0} RV={1} Par1={2} Par2={3}", FlowMId, RegVId, RVMovePar1, RVMovePar2);
|
||||
break;
|
||||
case ActionID.MeasureFlow:
|
||||
args = string.Format("Etalon={0}", FlowMId);
|
||||
|
||||
@@ -58,11 +58,11 @@ namespace TBF.BenchControl.ControlBoard.Uni
|
||||
message[26] = 0;
|
||||
|
||||
/// Regulation valve
|
||||
message[27] = (action.RegVId < 0) ? (byte)0 : (byte)action.RegVId;
|
||||
message[28] = (byte)(action.FlowRegP1 & 0xFF);
|
||||
message[29] = (byte)((action.FlowRegP1 >> 8) & 0xFF);
|
||||
message[30] = (byte)(action.FlowRegP2 & 0xFF);
|
||||
message[31] = (byte)((action.FlowRegP2 >> 8) & 0xFF);
|
||||
message[27] = (action.RegVId < 0) ? (byte)0 : (byte)(action.RegVId | (int)action.RegVMode);
|
||||
message[28] = (byte)(action.RVMovePar1 & 0xFF);
|
||||
message[29] = (byte)((action.RVMovePar1 >> 8) & 0xFF);
|
||||
message[30] = (byte)(action.RVMovePar2 & 0xFF);
|
||||
message[31] = (byte)((action.RVMovePar2 >> 8) & 0xFF);
|
||||
message[32] = action.IsStop() ? (byte)0x20 : action.IsStart() ? (byte)0x42 : (byte)0; /// ZStavReg
|
||||
|
||||
/// DA1
|
||||
@@ -154,10 +154,10 @@ namespace TBF.BenchControl.ControlBoard.Uni
|
||||
|
||||
public enum TestMethods
|
||||
{
|
||||
Diverter = 0x01, /// bit 0: 1=Mass method (diverters are used), 0=Volume method
|
||||
FixedStart = 0x02, /// bit 1: 1=fixed start method, 0=flying start method
|
||||
Synchro = 0x04, /// bit 2: 1=Synchro method, 0=Pulse counting
|
||||
MassAndContinue = 0x10, /// bit 4: 1=Method with mass measurement followed by a volume method
|
||||
Diverter = 0x01, /// bit 0: 1=Mass method (diverters are used), 0=Volume method
|
||||
FixedStart = 0x02, /// bit 1: 1=fixed start method, 0=flying start method
|
||||
Synchro = 0x04, /// bit 2: 1=Synchro method, 0=Pulse counting
|
||||
MassAndContinue = 0x10, /// bit 4: 1=Method with mass measurement followed by a volume method
|
||||
}
|
||||
|
||||
public enum ValveChgFlag : byte
|
||||
@@ -170,10 +170,11 @@ namespace TBF.BenchControl.ControlBoard.Uni
|
||||
public enum RegValveMode : byte
|
||||
{
|
||||
None = 0,
|
||||
PulseWidth = 1, /// Pulse width 0.05 .. 2 sec.
|
||||
TargetPosition = 2, /// Low and high position (=DAC value) limits (0..100%) are specified
|
||||
TargetFrequency = 3, /// Low and high frequency limits (0..2000Hz,0..2200Hz) are specified
|
||||
Stop = 4, /// Stop regulation
|
||||
TargetFrequency = 0x10, /// Low and high frequency limits (0..2000Hz,0..2200Hz) are specified
|
||||
TargetPosition = 0x20, /// Low and high position (=DAC value) limits (0..100%) are specified
|
||||
Stop = 0x30, /// Stop regulation
|
||||
PulseWidth = 0x40, /// Pulse width 0.05 .. 2 sec.
|
||||
PulseWidthNeg = 0xC0, /// Pulse width 0.05 .. 2 sec.
|
||||
}
|
||||
|
||||
public enum RegValveState : byte
|
||||
|
||||
@@ -440,9 +440,7 @@ namespace TBF.BenchControl.ControlBoard.Uni
|
||||
///
|
||||
public IOperation SetFlowOp(double flowLimLo, double flowLimHi, TBF.Boxes.DoubleBox measuredFlow, int timeout)
|
||||
{
|
||||
//var msg = new OutputMessage(Command.Start, );
|
||||
// scheduledActionQueue.Enqueue(Action.Stop());
|
||||
return null;
|
||||
return Devices.RegValve.SetFlowOp(Devices.FlowMeter,flowLimLo, flowLimHi, measuredFlow, timeout);
|
||||
}
|
||||
|
||||
public IOperation StopFlowRegulationOp()
|
||||
@@ -532,6 +530,31 @@ namespace TBF.BenchControl.ControlBoard.Uni
|
||||
|
||||
#endregion
|
||||
|
||||
public void SetFlow(int flowMeterId, int regVId, double freqLo, double freqHi)
|
||||
{
|
||||
scheduledActionQueue.Enqueue(Action.SetFlow(flowMeterId, regVId, freqLo, freqHi, Convert.ToInt32(Math.Round(Devices.PidCoef)), 0, 200));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform incremental movement of a regulation valve
|
||||
/// </summary>
|
||||
/// <param name="rvId">Reg. valve ID</param>
|
||||
/// <param name="time">Time in seconds, positive value opens the reg. valve</param>
|
||||
public void RegVlvIncrMove(int regVId, double time)
|
||||
{
|
||||
scheduledActionQueue.Enqueue(Action.RegVlvIncrMove(regVId, time));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move a regulation valve to specfied position
|
||||
/// </summary>
|
||||
/// <param name="rvId">Reg. valve ID</param>
|
||||
/// <param name="position">Reg. valve position (0 .. 1.0)</param>
|
||||
public void RegVlvMoveToPos(int regVId, double positionLo, double positionHi = -1)
|
||||
{
|
||||
scheduledActionQueue.Enqueue(Action.RegVlvMoveToPos(regVId, positionLo, positionHi));
|
||||
}
|
||||
|
||||
public void DiverterToTank(int divNr1)
|
||||
{
|
||||
scheduledActionQueue.Enqueue(Action.SwitchDiverter(divNr1, true));
|
||||
|
||||
Reference in New Issue
Block a user