fix bugs introduced by 'required' changes

This commit is contained in:
ig 2023-06-27 17:01:40 +02:00
parent 7f97ab8e14
commit a761e46686
5 changed files with 40 additions and 24 deletions

View File

@ -30,11 +30,17 @@ public static class Controller
mode.WriteLine(); mode.WriteLine();
if (mode is EssMode.Off or EssMode.NoGridMeter) if (mode is EssMode.Off or EssMode.NoGridMeter)
return new EssControl(mode, EssLimit.NoLimit, PowerCorrection: 0, PowerSetpoint: 0); return EssControl.Default;
var essDelta = s.ComputePowerDelta(mode); var essDelta = s.ComputePowerDelta(mode);
var unlimitedControl = new EssControl(mode, EssLimit.NoLimit, essDelta, 0); var unlimitedControl = new EssControl
{
Mode = mode,
LimitedBy = EssLimit.NoLimit,
PowerCorrection = essDelta,
PowerSetpoint = 0
};
var limitedControl = unlimitedControl var limitedControl = unlimitedControl
.LimitChargePower(s) .LimitChargePower(s)

View File

@ -3,13 +3,21 @@ using InnovEnergy.Lib.Units.Power;
namespace InnovEnergy.App.SaliMax.Ess; namespace InnovEnergy.App.SaliMax.Ess;
public record EssControl public record EssControl
(
EssMode Mode,
EssLimit LimitedBy,
ActivePower PowerCorrection,
ActivePower PowerSetpoint
)
{ {
public required EssMode Mode { get; init; }
public required EssLimit LimitedBy { get; init; }
public required ActivePower PowerCorrection { get; init; }
public required ActivePower PowerSetpoint { get; init; }
public static EssControl Default { get; } = new()
{
Mode = EssMode.Off,
LimitedBy = EssLimit.NoLimit,
PowerCorrection = 0,
PowerSetpoint = 0
};
public EssControl LimitChargePower(Double controlDelta, EssLimit reason) public EssControl LimitChargePower(Double controlDelta, EssLimit reason)
{ {
var overload = PowerCorrection - controlDelta; var overload = PowerCorrection - controlDelta;

View File

@ -25,7 +25,7 @@ public record StatusRecord
public required RelaysRecord? Relays { get; init; } public required RelaysRecord? Relays { get; init; }
public required AmptStatus PvOnDc { get; init; } public required AmptStatus PvOnDc { get; init; }
public required Config Config { get; init; } public required Config Config { get; init; }
public required EssControl EssControl { get; init; } public required EssControl EssControl { get; set; } // TODO: init only
public required StateMachine StateMachine { get; init; } public required StateMachine StateMachine { get; init; }
} }

View File

@ -148,6 +148,8 @@ internal static class Program
LoadOnAcIsland = loadOnAcIsland, LoadOnAcIsland = loadOnAcIsland,
LoadOnDc = loadOnDc, LoadOnDc = loadOnDc,
StateMachine = StateMachine.Default,
EssControl = EssControl.Default,
Config = Config.Load() // load from disk every iteration, so config can be changed while running Config = Config.Load() // load from disk every iteration, so config can be changed while running
}; };
} }
@ -228,17 +230,17 @@ internal static class Program
var islandToGridBusPower = inverterPower + islandLoadPower; var islandToGridBusPower = inverterPower + islandLoadPower;
var gridLoadPower = s.LoadOnAcGrid is null ? 0: s.LoadOnAcGrid.Power.Active; var gridLoadPower = s.LoadOnAcGrid is null ? 0: s.LoadOnAcGrid.Power.Active;
var gridPowerByPhase = TextBlock.AlignLeft(s.GridMeter.Ac.L1.Power.Active.ToStringRounded(), var gridPowerByPhase = TextBlock.AlignLeft(s.GridMeter.Ac.L1.Power.Active.ToDisplayString(),
s.GridMeter.Ac.L2.Power.Active.ToStringRounded(), s.GridMeter.Ac.L2.Power.Active.ToDisplayString(),
s.GridMeter.Ac.L3.Power.Active.ToStringRounded()); s.GridMeter.Ac.L3.Power.Active.ToDisplayString());
var gridVoltageByPhase = TextBlock.AlignLeft(s.GridMeter.Ac.L1.Voltage.ToStringRounded(), var gridVoltageByPhase = TextBlock.AlignLeft(s.GridMeter.Ac.L1.Voltage.ToDisplayString(),
s.GridMeter.Ac.L2.Voltage.ToStringRounded(), s.GridMeter.Ac.L2.Voltage.ToDisplayString(),
s.GridMeter.Ac.L3.Voltage.ToStringRounded()); s.GridMeter.Ac.L3.Voltage.ToDisplayString());
var inverterPowerByPhase = TextBlock.AlignLeft(s.AcDc.Ac.L1.Power.Active.ToStringRounded(), var inverterPowerByPhase = TextBlock.AlignLeft(s.AcDc.Ac.L1.Power.Active.ToDisplayString(),
s.AcDc.Ac.L2.Power.Active.ToStringRounded(), s.AcDc.Ac.L2.Power.Active.ToDisplayString(),
s.AcDc.Ac.L3.Power.Active.ToStringRounded()); s.AcDc.Ac.L3.Power.Active.ToDisplayString());
// ReSharper disable once CoVariantArrayConversion // ReSharper disable once CoVariantArrayConversion
var inverterPowerByAcDc = TextBlock.AlignLeft(s.AcDc.Devices var inverterPowerByAcDc = TextBlock.AlignLeft(s.AcDc.Devices
@ -246,7 +248,7 @@ internal static class Program
.ToArray()); .ToArray());
var dcLinkVoltage = TextBlock.CenterHorizontal("", var dcLinkVoltage = TextBlock.CenterHorizontal("",
s.DcDc.Dc.Link.Voltage.ToStringRounded(), s.DcDc.Dc.Link.Voltage.ToDisplayString(),
""); "");
//var inverterPowerByPhase = new ActivePower[(Int32)s.AcDc.Ac.L1.Power.Active, (Int32)s.AcDc.Ac.L2.Power.Active, (Int32)s.AcDc.Ac.L3.Power.Active]; //var inverterPowerByPhase = new ActivePower[(Int32)s.AcDc.Ac.L1.Power.Active, (Int32)s.AcDc.Ac.L2.Power.Active, (Int32)s.AcDc.Ac.L3.Power.Active];
@ -273,7 +275,7 @@ internal static class Program
var gridBox = TextBlock.AlignLeft(gridPowerByPhase).TitleBox("Grid"); var gridBox = TextBlock.AlignLeft(gridPowerByPhase).TitleBox("Grid");
var inverterBox = TextBlock.AlignLeft(inverterPowerByAcDc).TitleBox("Inverter"); var inverterBox = TextBlock.AlignLeft(inverterPowerByAcDc).TitleBox("Inverter");
var dcDcBox = TextBlock.AlignLeft(dc48Voltage).TitleBox("DC/DC"); var dcDcBox = TextBlock.AlignLeft(dc48Voltage).TitleBox("DC/DC");
var batteryBox = TextBlock.AlignLeft(batteryVoltage.ToStringRounded(), batterySoc.ToStringRounded(), batteryCurrent.ToStringRounded(), batteryTemp.ToStringRounded()).TitleBox("Battery"); var batteryBox = TextBlock.AlignLeft(batteryVoltage.ToDisplayString(), batterySoc.ToDisplayString(), batteryCurrent.ToDisplayString(), batteryTemp.ToDisplayString()).TitleBox("Battery");