Update the energy flow calculation and add the ascii topology as a comment

This commit is contained in:
atef 2023-08-30 13:44:58 +02:00
parent 9edd875066
commit 9e31046f43
1 changed files with 84 additions and 27 deletions

View File

@ -18,6 +18,7 @@ using InnovEnergy.Lib.Devices.Trumpf.TruConvertDc.Control;
using InnovEnergy.Lib.Protocols.Modbus.Channels;
using InnovEnergy.Lib.Time.Unix;
using InnovEnergy.Lib.Units;
using InnovEnergy.Lib.Units.Power;
using InnovEnergy.Lib.Utils;
using static InnovEnergy.Lib.Devices.Trumpf.SystemControl.DataTypes.SystemConfig;
using AcPower = InnovEnergy.Lib.Units.Composite.AcPower;
@ -96,37 +97,77 @@ internal static class Program
StatusRecord ReadStatus()
{
var battery = batteryDevices.Read();
// ┌────┐ ┌────┐
// │ Pv │ │ Pv │ ┌────┐
// └────┘ └────┘ │ Pv │
// V V └────┘
// V V V
// (b) 0 W (e) 0 W V
// V V (i) 13.2 kW ┌────────────┐
// V V V │ Battery │
// ┌─────────┐ ┌──────────┐ ┌────────────┐ ┌─────────┐ V ├────────────┤
// │ Grid │ │ Grid Bus │ │ Island Bus │ │ AC/DC │ ┌────────┐ ┌───────┐ │ 52.3 V │
// ├─────────┤ -10.3 kW ├──────────┤ -11.7 kW ├────────────┤ -11.7 kW ├─────────┤ -11.7 kW │ Dc Bus │ 1008 W │ DC/DC │ 1008 W │ 99.1 % │
// │ -3205 W │<<<<<<<<<<│ 244 V │<<<<<<<<<<│ 244 V │<<<<<<<<<<│ -6646 W │<<<<<<<<<<├────────┤>>>>>>>>>>├───────┤>>>>>>>>>>│ 490 mA │
// │ -3507 W │ (a) │ 244 V │ (d) │ 244 V │ (g) │ -5071 W │ (h) │ 776 V │ (k) │ 56 V │ (l) │ 250 °C │
// │ -3605 W │ K1 │ 246 V │ K2 │ 246 V │ K3 └─────────┘ └────────┘ └───────┘ │ 445 A │
// └─────────┘ └──────────┘ └────────────┘ V │ 0 Warnings │
// V V V │ 0 Alarms │
// V V (j) 0 W └────────────┘
// (c) 1400 W (f) 0 W V
// V V V
// V V ┌──────┐
// ┌──────┐ ┌──────┐ │ Load │
// │ Load │ │ Load │ └──────┘
// └──────┘ └──────┘
// AC side
// a + b - c - d = 0 [eq1]
// d + e - f - g = 0 [eq2]
//
// c & d are not measured!
//
// d = f + g - e [eq2]
// c = a + b - d [eq1]
//
// DC side
// h + i - j - k = 0 [eq3]
//
// g = h assuming no losses in ACDC
// k = l assuming no losses in DCDC
// j = h + i - k [eq3]
var acDc = acDcDevices.Read();
var dcDc = dcDcDevices.Read();
var relays = saliMaxRelaysDevice.Read();
var loadOnAcIsland = acIslandLoadMeter.Read();
var gridMeter = gridMeterDevice.Read();
var pvOnDc = amptDevice.Read();
var battery = batteryDevices.Read();
var pvOnAcGrid = AcPowerDevice.Null;
var pvOnAcIsland = AcPowerDevice.Null;
var gridPower = gridMeter is null ? AcPower.Null : gridMeter.Ac.Power;
var islandLoadPower = loadOnAcIsland is null ? AcPower.Null : loadOnAcIsland.Ac.Power;
var inverterAcPower = acDc.Ac.Power;
var inverterDcPower = acDc.Dc.Power;
var loadOnAcGrid = gridPower
+ pvOnAcGrid.Power
+ pvOnAcIsland.Power
- islandLoadPower
- inverterAcPower;
var gridBusToIslandBusPower = gridPower
+ pvOnAcGrid.Power
- loadOnAcGrid;
// var dcPower = acDc.Dc.Power.Value
// + pvOnDc.Dc?.Power.Value ?? 0
// - dcDc.Dc.Link.Power.Value;
var dcPower = 0;
var loadOnDc = new DcPowerDevice { Power = dcPower} ;
var a = gridPower;
var b = pvOnAcGrid.Power;
var e = pvOnAcIsland.Power;
var f = islandLoadPower;
var g = inverterAcPower;
var h = inverterDcPower;
var i = pvOnDc?.Dc.Power;
var k = dcDc.Dc.Link.Power;
var l = k;
var j = Sum(h, i, -k);
var d = Sum(f, g, -e);
var c = Sum(a, b, -d);
return new StatusRecord
{
@ -140,10 +181,10 @@ internal static class Program
PvOnAcIsland = pvOnAcIsland,
PvOnDc = pvOnDc,
AcGridToAcIsland = new AcPowerDevice { Power = gridBusToIslandBusPower },
LoadOnAcGrid = new AcPowerDevice { Power = loadOnAcGrid },
AcGridToAcIsland = new AcPowerDevice { Power = d },
LoadOnAcGrid = new AcPowerDevice { Power = c },
LoadOnAcIsland = loadOnAcIsland,
LoadOnDc = loadOnDc,
LoadOnDc = new DcPowerDevice { Power = j.Value},
StateMachine = StateMachine.Default,
EssControl = EssControl.Default,
@ -332,10 +373,26 @@ internal static class Program
if (response.StatusCode != 200)
{
Console.WriteLine("ERROR: PUT");
var error = response.GetStringAsync();
var error = await response.GetStringAsync();
Console.WriteLine(error);
}
return true;
}
private static ActivePower? Sum(ActivePower? e, ActivePower? f, ActivePower? g)
{
if (e is null || f is null || g is null)
return null;
return f + g + e;
}
private static AcPower? Sum(AcPower? e, AcPower? f, AcPower? g)
{
if (e is null || f is null || g is null)
return null;
return f + g + e;
}
}