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

This commit is contained in:
Milan Hanajik 2022-10-28 14:58:29 +02:00
parent ac5684a2b5
commit ae8a0ca4c1
10 changed files with 88 additions and 58 deletions

View File

@ -262,7 +262,7 @@ namespace TBF.Rig.ControlBoard.Uni
///----------------------------------------------------------------------------------------------
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
{
@ -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
///
if (positionHi < 0)
int rvMovePar1, rvMovePar2;
if (adcValHi >= 0)
{
/// Center position specified, calculate a range
rvMovePar1 = 0; // TODO
rvMovePar2 = 0; // TODO
/// Lower and upper range of position specified
rvMovePar1 = adcValLo;
rvMovePar2 = adcValHi;
}
else
{
/// Lower and upper range of position specified
rvMovePar1 = 0; // TODO
rvMovePar2 = 0; // TODO
/// Center position specified, calculate a range
rvMovePar1 = Math.Max(adcValLo - 5, 0);
rvMovePar2 = Math.Min(adcValLo + 5, 1023);
}
return new Action

View File

@ -859,12 +859,12 @@ namespace TBF.Rig.ControlBoard.Uni
/// </summary>
/// <param name="rvId">Reg. valve ID</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;
actionQueue.Enqueue(Action.RegVlvMoveToPos(isFromUI, regVId, positionLo, positionHi));
log.InfoFormat("Enqueue( RegVlvMoveToPos(rv={0}, positionLo={1}, positionHi={2}) )", regVId, positionLo, positionHi);
actionQueue.Enqueue(Action.RegVlvMoveToPos(isFromUI, regVId, adcValLo, adcValHi));
log.InfoFormat("Enqueue( RegVlvMoveToPos(rv={0}, positionLo={1}, positionHi={2}) )", regVId, adcValLo, adcValHi);
foreach (var a in actionQueue) log.DebugFormat(" {0}", a);
}

View File

@ -30,8 +30,8 @@ namespace TBF.Rig.Operations
setRVPosOps = new IOperation[rvCount];
for (int i = 0; i < rvCount; i++)
{
float posLo = Math.Max(positions[i] - 3.0f, 0);
float posHi = Math.Min(positions[i] + 3.0f, 100.0f);
float posLo = positions[i] - 3.0f;
float posHi = positions[i] + 3.0f;
setRVPosOps[i] = regulValves[i].SetRegValvePositionOp(posLo, posHi, timeout);
}
}

View File

@ -32,15 +32,30 @@ namespace TBF.Rig.Uni.RegValve
public bool StoredPositionReuse { get { return regValveCfg.StoredPositionReuse; } }
///
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
{
get
{
int denominator = DacValueOpen - DacValueClosed;
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;
public RegValveState RegValveState;
public double TargetRegValvePosition;
@ -79,9 +93,15 @@ namespace TBF.Rig.Uni.RegValve
/// </summary>
/// <param name="rvId">Reg. valve ID</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;
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()
@ -153,6 +171,8 @@ namespace TBF.Rig.Uni.RegValve
if (args.Increase) IncreaseSetpoint(); else DecreaseSetpoint();
}
};
log.FatalFormat("{0} initialized: {1}", Name, this);
}
///

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.Collections.Generic;
@ -17,8 +17,6 @@ namespace TBF.Rig.Uni.RegValve
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
///
@ -88,7 +86,9 @@ namespace TBF.Rig.Uni.RegValve
opState = OpState.MoveToPosition;
}
/// <summary>Run this operation</summary>
/// <summary>
/// Run this operation
/// </summary>
/// <returns>
/// Event.None . . . . . . . busy adjusting position
/// Event.PositionReached . . position reached
@ -98,29 +98,25 @@ namespace TBF.Rig.Uni.RegValve
{
if (opState == OpState.MoveToPosition)
{
if (posLoPct >= posHiPct || posLoPct > 100.0f || posHiPct < 0)
if (posLoPct >= posHiPct || posLoPct > 100.0 || posHiPct < 0)
{
return Event.OpArgumentError;
}
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;
}
if (positionReached) return Event.PositionReached;
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 (regValveNr == CoaxValveNr && (cBoard.State & (ulong)StatusP.CoaxRegValveBusy) == 0)
{
opState = OpState.MoveToPosition;
return Event.None;
}
else if (posLoPct <= positionPct && positionPct <= posHiPct)
if (posLoPct <= positionPct && positionPct <= posHiPct)
{
positionReached = true;
return Event.PositionReached;
@ -153,6 +149,8 @@ namespace TBF.Rig.Uni.RegValve
}
/// <summary>Stop this operation</summary>
public void Stop() { }
public void Stop()
{
}
}
}

View File

@ -55,10 +55,20 @@ namespace TBF.Rig.Uni.RegValveAnalog
/// 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)
: base(cfg)
@ -67,13 +77,13 @@ namespace TBF.Rig.Uni.RegValveAnalog
uniCB = TbfComponents.FindComponent(cfg.ParentName, components) as UniCB;
if (uniCB == null) throw new Exception("Cannot find " + Name + " parent");
log.Warn(this.ToString());
}
public override void Initialize()
{
this.dict = new Dictionary<double, double>();
log.FatalFormat("{0} initialized: {1}", Name, this);
}
/// <summary>

View File

@ -14,7 +14,7 @@ namespace TBF.Rig.Uni.RegValveAnalog
private static readonly ILog log = LogManager.GetLogger(typeof(SetRegValvePositionOp));
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
readonly UniCB uniCB;
readonly RegValve regValve;
readonly RegValve regV;
readonly double posLoPct;
readonly double posHiPct;
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>
public SetRegValvePositionOp(UniCB uniCB, RegValve regV, double posLoPct, double posHiPct, int timeout)
{
if (uniCB == null) throw new ArgumentNullException("ctrlBoard");
this.uniCB = uniCB;
if (this.uniCB == null) throw new ArgumentNullException("ctrlBoard");
this.regValve = regV as RegValve;
if (regV == null) throw new ArgumentNullException("regValve is null or not Elde");
this.regV = regV;
if (this.regV == null) throw new ArgumentNullException("regValve is null or not Elde");
this.posLoPct = posLoPct;
this.posHiPct = posHiPct;
@ -79,7 +79,7 @@ namespace TBF.Rig.Uni.RegValveAnalog
{
positionReached = false;
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;
}
@ -98,15 +98,15 @@ namespace TBF.Rig.Uni.RegValveAnalog
return Event.OpArgumentError;
}
uniCB.RegVlvMoveToPos(false, regValve.Idx1, posLoPct, posHiPct);
regV.MoveToPosition(false, posLoPct);
opState = OpState.CheckState;
return Event.None;
}
if (positionReached) return Event.PositionReached;
double positionPct = regValve.Position;
log.WarnFormat("Run(): RV#={0}, actPos={1}%", regValve.Idx1, positionPct.ToString("F1"));
double positionPct = regV.Position;
log.WarnFormat("Run(): RV#={0}, actPos={1}%", regV.Idx1, positionPct.ToString("F1"));
if (opState == OpState.CheckState)
{
@ -120,7 +120,7 @@ namespace TBF.Rig.Uni.RegValveAnalog
positionReached = true;
return Event.PositionReached;
}
else if (regValve.Idx1 < 6
else if (regV.Idx1 < 6
/// && uniCB.RegulValveState(regValve.Idx1) != RegulValveState.DacValueRegul // TODO: Reimplement
)
{

View File

@ -51,8 +51,6 @@ namespace TBF.Rig.Uni.RegValveTandem
fixedRV = TbfComponents.FindComponent(RegulValveTandemCfg.FixedRVName, components) as TBF.Rig.Uni.RegValve.RegValve;
if (fixedRV == null) throw new Exception("Cannot find fixed RV");
log.Warn(this.ToString());
}
public override void Initialize()
@ -60,6 +58,8 @@ namespace TBF.Rig.Uni.RegValveTandem
fixedPctLo = Math.Max(0.0f, RegulValveTandemCfg.FixedRVPosition - 3.0f);
fixedPctHi = Math.Min(100.0f, RegulValveTandemCfg.FixedRVPosition + 3.0f);
this.dict = new Dictionary<double, double>();
log.FatalFormat("{0} initialized: {1}", Name, this);
}
/// <summary>

View File

@ -234,7 +234,7 @@ namespace TBF.Rig.Uni.RegValveTandem
///
/// Done once, issues an appropriate ValveMove(...) command
///
uniCB.RegVlvMoveToPos(false, regValve.Idx1, targetPositionLo, targetPositionHi);
regValve.MoveToPosition(false, targetPositionLo, targetPositionHi);
opState = OpState.SettingPosition;
return Event.None;
@ -255,7 +255,7 @@ namespace TBF.Rig.Uni.RegValveTandem
///
/// Done once, issues an appropriate ValveMove(...) command
///
uniCB.RegVlvMoveToPos(false, fixedRV.Idx1, fixedPctLo, fixedPctHi);
fixedRV.MoveToPosition(false, fixedPctLo, fixedPctHi);
opState = OpState.SettingPosition_FixedRV;
return Event.None;

View File

@ -89,7 +89,9 @@ namespace TBF.Rig.Uni.RegValveTandem
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;
}