Changes in TBF.Rig.Uni.RegValve(s), TBF.Rig.CB.Uni.Action.RegVlvMoveToPos, etc.

This commit is contained in:
Milan Hanajik
2022-10-28 15:04:07 +02:00
parent ac5684a2b5
commit ae8a0ca4c1
10 changed files with 88 additions and 58 deletions
+11 -11
View File
@@ -262,7 +262,7 @@ namespace TBF.Rig.ControlBoard.Uni
///---------------------------------------------------------------------------------------------- ///----------------------------------------------------------------------------------------------
public static Action RegVlvIncrMove(bool isFromUI, int regValveId, double timeSec) public static Action RegVlvIncrMove(bool isFromUI, int regValveId, double timeSec)
{ {
int rvMovePar = Math.Abs(Convert.ToInt32(Math.Round(timeSec / 0.050))); /// Step is 50 ms int rvMovePar = Math.Abs(Convert.ToInt32(Math.Round(timeSec / 0.050))); /// Step is 50 ms
return new Action return new Action
{ {
@@ -290,21 +290,21 @@ namespace TBF.Rig.ControlBoard.Uni
} }
///---------------------------------------------------------------------------------------------- ///----------------------------------------------------------------------------------------------
public static Action RegVlvMoveToPos(bool isFromUI, int regValveId, double positionLo, double positionHi = -1) public static Action RegVlvMoveToPos(bool isFromUI, int regValveId, int adcValLo, int adcValHi = -1)
{ {
int rvMovePar1, rvMovePar2; /// TODO int rvMovePar1, rvMovePar2;
///
if (positionHi < 0) if (adcValHi >= 0)
{ {
/// Center position specified, calculate a range /// Lower and upper range of position specified
rvMovePar1 = 0; // TODO rvMovePar1 = adcValLo;
rvMovePar2 = 0; // TODO rvMovePar2 = adcValHi;
} }
else else
{ {
/// Lower and upper range of position specified /// Center position specified, calculate a range
rvMovePar1 = 0; // TODO rvMovePar1 = Math.Max(adcValLo - 5, 0);
rvMovePar2 = 0; // TODO rvMovePar2 = Math.Min(adcValLo + 5, 1023);
} }
return new Action return new Action
+3 -3
View File
@@ -859,12 +859,12 @@ namespace TBF.Rig.ControlBoard.Uni
/// </summary> /// </summary>
/// <param name="rvId">Reg. valve ID</param> /// <param name="rvId">Reg. valve ID</param>
/// <param name="position">Reg. valve position (0 .. 1.0)</param> /// <param name="position">Reg. valve position (0 .. 1.0)</param>
public void RegVlvMoveToPos(bool isFromUI, int regVId, double positionLo, double positionHi = -1) public void RegVlvMoveToPos(bool isFromUI, int regVId, int adcValLo, int adcValHi = -1)
{ {
if (IsUIBlocked && isFromUI) return; if (IsUIBlocked && isFromUI) return;
actionQueue.Enqueue(Action.RegVlvMoveToPos(isFromUI, regVId, positionLo, positionHi)); actionQueue.Enqueue(Action.RegVlvMoveToPos(isFromUI, regVId, adcValLo, adcValHi));
log.InfoFormat("Enqueue( RegVlvMoveToPos(rv={0}, positionLo={1}, positionHi={2}) )", regVId, positionLo, positionHi); log.InfoFormat("Enqueue( RegVlvMoveToPos(rv={0}, positionLo={1}, positionHi={2}) )", regVId, adcValLo, adcValHi);
foreach (var a in actionQueue) log.DebugFormat(" {0}", a); foreach (var a in actionQueue) log.DebugFormat(" {0}", a);
} }
+2 -2
View File
@@ -30,8 +30,8 @@ namespace TBF.Rig.Operations
setRVPosOps = new IOperation[rvCount]; setRVPosOps = new IOperation[rvCount];
for (int i = 0; i < rvCount; i++) for (int i = 0; i < rvCount; i++)
{ {
float posLo = Math.Max(positions[i] - 3.0f, 0); float posLo = positions[i] - 3.0f;
float posHi = Math.Min(positions[i] + 3.0f, 100.0f); float posHi = positions[i] + 3.0f;
setRVPosOps[i] = regulValves[i].SetRegValvePositionOp(posLo, posHi, timeout); setRVPosOps[i] = regulValves[i].SetRegValvePositionOp(posLo, posHi, timeout);
} }
} }
+28 -8
View File
@@ -32,15 +32,30 @@ namespace TBF.Rig.Uni.RegValve
public bool StoredPositionReuse { get { return regValveCfg.StoredPositionReuse; } } public bool StoredPositionReuse { get { return regValveCfg.StoredPositionReuse; } }
/// ///
public bool IsCoax { get { return false; } } public bool IsCoax { get { return false; } }
/// 0.0 .. 100.0 public RegValveState RegValveState
{
get
{
switch (UniCB.Data.RegVStatus[Idx1 - 1])
{
default:
case 0: return ControlBoard.Uni.RegValveState.Idle;
case 2: return ControlBoard.Uni.RegValveState.PwOrFreqRegul;
case 3: return ControlBoard.Uni.RegValveState.DacValueRegul;
}
}
}
/// Position 0.0 .. 100.0 in %
public double Position public double Position
{ {
get get
{ {
int denominator = DacValueOpen - DacValueClosed; int denominator = DacValueOpen - DacValueClosed;
if (denominator == 0) denominator = 1; if (denominator == 0) denominator = 1;
return 100.0 * Convert.ToDouble(UniCB.AnalogInput(adcChannel) - DacValueClosed) / Convert.ToDouble(denominator); return 100.0 * Convert.ToDouble(Math.Max(0, Math.Min(denominator, (int)UniCB.AnalogInput(adcChannel) - DacValueClosed)))
/ Convert.ToDouble(denominator);
} }
} }
/// ///
@@ -61,7 +76,6 @@ namespace TBF.Rig.Uni.RegValve
} }
int adcChannel; int adcChannel;
public RegValveState RegValveState;
public double TargetRegValvePosition; public double TargetRegValvePosition;
@@ -79,9 +93,15 @@ namespace TBF.Rig.Uni.RegValve
/// </summary> /// </summary>
/// <param name="rvId">Reg. valve ID</param> /// <param name="rvId">Reg. valve ID</param>
/// <param name="position">Reg. valve position (0 .. 1.0)</param> /// <param name="position">Reg. valve position (0 .. 1.0)</param>
public void MoveToPosition(bool isFromUI, double positionLo, double positionHi = -1) public void MoveToPosition(bool isFromUI, double posPctLo, double posPctHi = -1)
{ {
UniCB.RegVlvMoveToPos(isFromUI, Idx1, positionLo, positionHi); int adcDiff = Math.Abs(regValveCfg.AdcValueOpen - regValveCfg.AdcValueClosed);
int adcLower = Math.Min(regValveCfg.AdcValueOpen, regValveCfg.AdcValueClosed);
int targetAdcValLo = Math.Max(0, Convert.ToInt32(Math.Round((posPctLo * adcDiff / 100.0) + adcLower)));
int targetAdcValHi = (posPctHi < 0) ? -1 : Math.Min(1023, Convert.ToInt32(Math.Round((posPctHi * adcDiff / 100.0) + adcLower)));
UniCB.RegVlvMoveToPos(isFromUI, Idx1, targetAdcValLo, targetAdcValHi);
} }
@@ -137,8 +157,6 @@ namespace TBF.Rig.Uni.RegValve
this.UniCB = TbfComponents.FindComponent(cfg.ParentName, components) as UniCB; this.UniCB = TbfComponents.FindComponent(cfg.ParentName, components) as UniCB;
if (this.UniCB == null) throw new Exception(string.Format("Cannot find {0} (a parent of {1})", cfg.ParentName, Name)); if (this.UniCB == null) throw new Exception(string.Format("Cannot find {0} (a parent of {1})", cfg.ParentName, Name));
log.Warn(this.ToString());
} }
public override void Initialize() public override void Initialize()
@@ -153,6 +171,8 @@ namespace TBF.Rig.Uni.RegValve
if (args.Increase) IncreaseSetpoint(); else DecreaseSetpoint(); if (args.Increase) IncreaseSetpoint(); else DecreaseSetpoint();
} }
}; };
log.FatalFormat("{0} initialized: {1}", Name, this);
} }
/// ///
+12 -14
View File
@@ -1,5 +1,5 @@
/// ///
/// Copyright (c) 2021 Sensus Slovensko a.s. /// Copyright (c) 2021-2022 Sensus Slovensko a.s.
/// ///
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -17,8 +17,6 @@ namespace TBF.Rig.Uni.RegValve
return string.Format("SetRegValvePositionOp({0},{1},{2})", regV.Name, posLoPct, posHiPct); return string.Format("SetRegValvePositionOp({0},{1},{2})", regV.Name, posLoPct, posHiPct);
} }
const int CoaxValveNr = 7; /// Coax. valve has number 7
/// ///
/// Internal states of this operation /// Internal states of this operation
/// ///
@@ -88,7 +86,9 @@ namespace TBF.Rig.Uni.RegValve
opState = OpState.MoveToPosition; opState = OpState.MoveToPosition;
} }
/// <summary>Run this operation</summary> /// <summary>
/// Run this operation
/// </summary>
/// <returns> /// <returns>
/// Event.None . . . . . . . busy adjusting position /// Event.None . . . . . . . busy adjusting position
/// Event.PositionReached . . position reached /// Event.PositionReached . . position reached
@@ -98,29 +98,25 @@ namespace TBF.Rig.Uni.RegValve
{ {
if (opState == OpState.MoveToPosition) if (opState == OpState.MoveToPosition)
{ {
if (posLoPct >= posHiPct || posLoPct > 100.0f || posHiPct < 0) if (posLoPct >= posHiPct || posLoPct > 100.0 || posHiPct < 0)
{ {
return Event.OpArgumentError; return Event.OpArgumentError;
} }
regV.MoveToPosition(false, posLoPct, posHiPct); regV.MoveToPosition(false, posLoPct, posHiPct);
opState = OpState.CheckState; opState = OpState.CheckState;
log.WarnFormat("Run(): RV#={0}, state={1}, MoveToPosition(false, {2:D1}, {3:D1}) issued", regValveNr, opState, posLoPct, posHiPct);
return Event.None; return Event.None;
} }
if (positionReached) return Event.PositionReached; if (positionReached) return Event.PositionReached;
double positionPct = regV.Position; double positionPct = regV.Position;
log.WarnFormat("Run(): RV#={0}, actPos={1}%", regValveNr, positionPct.ToString("F1")); log.WarnFormat("Run(): RV#={0}, state={1}, pos={2}%", regValveNr, opState, positionPct.ToString("F1"));
if (opState == OpState.CheckState) if (opState == OpState.CheckState)
{ {
if (regValveNr == CoaxValveNr && (cBoard.State & (ulong)StatusP.CoaxRegValveBusy) == 0) if (posLoPct <= positionPct && positionPct <= posHiPct)
{
opState = OpState.MoveToPosition;
return Event.None;
}
else if (posLoPct <= positionPct && positionPct <= posHiPct)
{ {
positionReached = true; positionReached = true;
return Event.PositionReached; return Event.PositionReached;
@@ -153,6 +149,8 @@ namespace TBF.Rig.Uni.RegValve
} }
/// <summary>Stop this operation</summary> /// <summary>Stop this operation</summary>
public void Stop() { } public void Stop()
{
}
} }
} }
+15 -5
View File
@@ -55,10 +55,20 @@ namespace TBF.Rig.Uni.RegValveAnalog
/// TODO /// TODO
} }
/// <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 MoveToPosition(bool isFromUI, double posPct)
{
/// Converison assuming: 0..100 % ~ 4..20 mA , 0..20 mA ~ 0..1023
int targetAdcVal = Math.Max(0, Math.Min(1023, Convert.ToInt32(Math.Round(8.19 * posPct + 204.0))));
uniCB.RegVlvMoveToPos(isFromUI, Idx1, targetAdcVal);
}
public RegValve()
{ public RegValve() { }
}
public RegValve(Generic.IComponentCfg cfg, IList<Generic.IComponent> components) public RegValve(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
: base(cfg) : base(cfg)
@@ -67,13 +77,13 @@ namespace TBF.Rig.Uni.RegValveAnalog
uniCB = TbfComponents.FindComponent(cfg.ParentName, components) as UniCB; uniCB = TbfComponents.FindComponent(cfg.ParentName, components) as UniCB;
if (uniCB == null) throw new Exception("Cannot find " + Name + " parent"); if (uniCB == null) throw new Exception("Cannot find " + Name + " parent");
log.Warn(this.ToString());
} }
public override void Initialize() public override void Initialize()
{ {
this.dict = new Dictionary<double, double>(); this.dict = new Dictionary<double, double>();
log.FatalFormat("{0} initialized: {1}", Name, this);
} }
/// <summary> /// <summary>
@@ -14,7 +14,7 @@ namespace TBF.Rig.Uni.RegValveAnalog
private static readonly ILog log = LogManager.GetLogger(typeof(SetRegValvePositionOp)); private static readonly ILog log = LogManager.GetLogger(typeof(SetRegValvePositionOp));
public override string ToString() public override string ToString()
{ {
return string.Format("SetRegValvePositionOp({0},{1},{2})", regValve.Name, posLoPct, posHiPct); return string.Format("SetRegValvePositionOp({0},{1},{2})", regV.Name, posLoPct, posHiPct);
} }
/// ///
@@ -31,7 +31,7 @@ namespace TBF.Rig.Uni.RegValveAnalog
/// Set by the constructor /// Set by the constructor
readonly UniCB uniCB; readonly UniCB uniCB;
readonly RegValve regValve; readonly RegValve regV;
readonly double posLoPct; readonly double posLoPct;
readonly double posHiPct; readonly double posHiPct;
readonly int timeout; readonly int timeout;
@@ -52,11 +52,11 @@ namespace TBF.Rig.Uni.RegValveAnalog
/// <remarks>Only Elde.Valve flow are used, other flow on the lists are ignored</remarks> /// <remarks>Only Elde.Valve flow are used, other flow on the lists are ignored</remarks>
public SetRegValvePositionOp(UniCB uniCB, RegValve regV, double posLoPct, double posHiPct, int timeout) public SetRegValvePositionOp(UniCB uniCB, RegValve regV, double posLoPct, double posHiPct, int timeout)
{ {
if (uniCB == null) throw new ArgumentNullException("ctrlBoard");
this.uniCB = uniCB; this.uniCB = uniCB;
if (this.uniCB == null) throw new ArgumentNullException("ctrlBoard");
this.regValve = regV as RegValve; this.regV = regV;
if (regV == null) throw new ArgumentNullException("regValve is null or not Elde"); if (this.regV == null) throw new ArgumentNullException("regValve is null or not Elde");
this.posLoPct = posLoPct; this.posLoPct = posLoPct;
this.posHiPct = posHiPct; this.posHiPct = posHiPct;
@@ -79,7 +79,7 @@ namespace TBF.Rig.Uni.RegValveAnalog
{ {
positionReached = false; positionReached = false;
expireTime = StateMachine.Time + timeout; expireTime = StateMachine.Time + timeout;
log.InfoFormat("Start(): RV#={0}, reqPosLo={1}%, reqPosHi={2}%", regValve.Idx1, posLoPct.ToString("F1"), posHiPct.ToString("F1")); log.InfoFormat("Start(): RV#={0}, reqPosLo={1}%, reqPosHi={2}%", regV.Idx1, posLoPct.ToString("F1"), posHiPct.ToString("F1"));
opState = OpState.MoveToPosition; opState = OpState.MoveToPosition;
} }
@@ -98,15 +98,15 @@ namespace TBF.Rig.Uni.RegValveAnalog
return Event.OpArgumentError; return Event.OpArgumentError;
} }
uniCB.RegVlvMoveToPos(false, regValve.Idx1, posLoPct, posHiPct); regV.MoveToPosition(false, posLoPct);
opState = OpState.CheckState; opState = OpState.CheckState;
return Event.None; return Event.None;
} }
if (positionReached) return Event.PositionReached; if (positionReached) return Event.PositionReached;
double positionPct = regValve.Position; double positionPct = regV.Position;
log.WarnFormat("Run(): RV#={0}, actPos={1}%", regValve.Idx1, positionPct.ToString("F1")); log.WarnFormat("Run(): RV#={0}, actPos={1}%", regV.Idx1, positionPct.ToString("F1"));
if (opState == OpState.CheckState) if (opState == OpState.CheckState)
{ {
@@ -120,7 +120,7 @@ namespace TBF.Rig.Uni.RegValveAnalog
positionReached = true; positionReached = true;
return Event.PositionReached; return Event.PositionReached;
} }
else if (regValve.Idx1 < 6 else if (regV.Idx1 < 6
/// && uniCB.RegulValveState(regValve.Idx1) != RegulValveState.DacValueRegul // TODO: Reimplement /// && uniCB.RegulValveState(regValve.Idx1) != RegulValveState.DacValueRegul // TODO: Reimplement
) )
{ {
+2 -2
View File
@@ -51,8 +51,6 @@ namespace TBF.Rig.Uni.RegValveTandem
fixedRV = TbfComponents.FindComponent(RegulValveTandemCfg.FixedRVName, components) as TBF.Rig.Uni.RegValve.RegValve; fixedRV = TbfComponents.FindComponent(RegulValveTandemCfg.FixedRVName, components) as TBF.Rig.Uni.RegValve.RegValve;
if (fixedRV == null) throw new Exception("Cannot find fixed RV"); if (fixedRV == null) throw new Exception("Cannot find fixed RV");
log.Warn(this.ToString());
} }
public override void Initialize() public override void Initialize()
@@ -60,6 +58,8 @@ namespace TBF.Rig.Uni.RegValveTandem
fixedPctLo = Math.Max(0.0f, RegulValveTandemCfg.FixedRVPosition - 3.0f); fixedPctLo = Math.Max(0.0f, RegulValveTandemCfg.FixedRVPosition - 3.0f);
fixedPctHi = Math.Min(100.0f, RegulValveTandemCfg.FixedRVPosition + 3.0f); fixedPctHi = Math.Min(100.0f, RegulValveTandemCfg.FixedRVPosition + 3.0f);
this.dict = new Dictionary<double, double>(); this.dict = new Dictionary<double, double>();
log.FatalFormat("{0} initialized: {1}", Name, this);
} }
/// <summary> /// <summary>
+2 -2
View File
@@ -234,7 +234,7 @@ namespace TBF.Rig.Uni.RegValveTandem
/// ///
/// Done once, issues an appropriate ValveMove(...) command /// Done once, issues an appropriate ValveMove(...) command
/// ///
uniCB.RegVlvMoveToPos(false, regValve.Idx1, targetPositionLo, targetPositionHi); regValve.MoveToPosition(false, targetPositionLo, targetPositionHi);
opState = OpState.SettingPosition; opState = OpState.SettingPosition;
return Event.None; return Event.None;
@@ -255,7 +255,7 @@ namespace TBF.Rig.Uni.RegValveTandem
/// ///
/// Done once, issues an appropriate ValveMove(...) command /// Done once, issues an appropriate ValveMove(...) command
/// ///
uniCB.RegVlvMoveToPos(false, fixedRV.Idx1, fixedPctLo, fixedPctHi); fixedRV.MoveToPosition(false, fixedPctLo, fixedPctHi);
opState = OpState.SettingPosition_FixedRV; opState = OpState.SettingPosition_FixedRV;
return Event.None; return Event.None;
@@ -89,7 +89,9 @@ namespace TBF.Rig.Uni.RegValveTandem
firstRun = false; firstRun = false;
uniCB.RegVlvMoveToPos(false, regValve.Idx1, posLoPct, posHiPct); int adcPosLo = 0;
int adcPosHi = 0;
uniCB.RegVlvMoveToPos(false, regValve.Idx1, (short)adcPosLo, (short)adcPosHi);
return Event.None; return Event.None;
} }