Add calculated powers (loads etc.), Dc Load is still broken

This commit is contained in:
ig 2023-06-22 10:17:06 +02:00
parent d1d9575052
commit f7ee9276a3
4 changed files with 50 additions and 38 deletions

View File

@ -17,10 +17,11 @@ public record StatusRecord
public Battery48TlRecords Battery { get; init; } = null!;
public EmuMeterRegisters? GridMeter { get; init; }
public EmuMeterRegisters? LoadOnAcIsland { get; init; }
public AcDevicePower? LoadOnAcGrid { get; init; } = null!;
public AcDevicePower? PvOnAcGrid { get; init; } = null!;
public AcDevicePower? PvOnAcIsland { get; init; } = null!;
public DcDevicePower? LoadOnDc { get; init; } = null!;
public AcPowerDevice? LoadOnAcGrid { get; init; } = null!;
public AcPowerDevice? PvOnAcGrid { get; init; } = null!;
public AcPowerDevice? PvOnAcIsland { get; init; } = null!;
public AcPowerDevice? AcGridToAcIsland { get; init; } = null!;
public DcPowerDevice? LoadOnDc { get; init; } = null!;
public RelaysRecord? Relays { get; init; }
public AmptStatus PvOnDc { get; init; } = null!;
public Config Config { get; init; } = null!;

View File

@ -43,7 +43,6 @@ internal static class Program
// private const String InternalMeter = "10.0.4.2"; // "192.168.1.241";
// private const String AmptIp = "10.0.5.1"; // "192.168.1.249";
private static readonly TcpChannel TruConvertAcChannel = new TcpChannel("localhost", 5001);
private static readonly TcpChannel TruConvertDcChannel = new TcpChannel("localhost", 5002);
private static readonly TcpChannel GridMeterChannel = new TcpChannel("localhost", 5003);
@ -107,31 +106,35 @@ internal static class Program
var gridMeter = gridMeterDevice.Read();
var pvOnDc = amptDevice.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 pvOnAcGrid = AcDevicePower.Null;
var pvOnAcIsland = AcDevicePower.Null;
var loadOnAcGrid = pvOnAcGrid.Power +
pvOnAcIsland.Power +
(gridMeter is null ? AcPower.Null : gridMeter.Ac.Power) +
(loadOnAcIsland is null ? AcPower.Null : loadOnAcIsland.Ac.Power);
var loadOnAcGrid = gridPower
+ pvOnAcGrid.Power
+ pvOnAcIsland.Power
- islandLoadPower
- inverterAcPower;
var gridBusToIslandBusPower = gridPower
+ pvOnAcGrid.Power
- loadOnAcGrid;
var dcPowers = new[]
{
acDc?.Dc.Power.Value,
pvOnDc?.Dc?.Power.Value,
dcDc?.Dc.Link.Power.Value
};
// var dcPower = acDc.Dc.Power.Value
// + pvOnDc.Dc?.Power.Value ?? 0
// - dcDc.Dc.Link.Power.Value;
var loadOnDc = dcPowers.Any(p => p is null)
? null
: new DcDevicePower { Power = dcPowers.Sum(p => p)!} ;
var dcPower = 0;
var loadOnDc = new DcPowerDevice { Power = dcPower} ;
return new StatusRecord
{
AcDc = acDc ?? AcDcDevicesRecord.Null,
DcDc = dcDc ?? DcDcDevicesRecord.Null,
AcDc = acDc ?? AcDcDevicesRecord.Null,
DcDc = dcDc ?? DcDcDevicesRecord.Null,
Battery = battery ?? Battery48TlRecords.Null,
Relays = relays,
GridMeter = gridMeter,
@ -140,9 +143,10 @@ internal static class Program
PvOnAcIsland = pvOnAcIsland,
PvOnDc = pvOnDc ?? AmptStatus.Null,
LoadOnAcGrid = new AcDevicePower { Power = -loadOnAcGrid },
LoadOnAcIsland = loadOnAcIsland,
LoadOnDc = loadOnDc,
AcGridToAcIsland = new AcPowerDevice { Power = gridBusToIslandBusPower },
LoadOnAcGrid = new AcPowerDevice { Power = loadOnAcGrid },
LoadOnAcIsland = loadOnAcIsland,
LoadOnDc = loadOnDc,
Config = Config.Load() // load from disk every iteration, so config can be changed while running
};
@ -176,6 +180,14 @@ internal static class Program
record.Relays.ToCsv().WriteLine();
var emuMeterRegisters = record.GridMeter;
if (emuMeterRegisters is not null)
{
emuMeterRegisters.Ac.Power.Active.WriteLine("Grid Active");
//emuMeterRegisters.Ac.Power.Reactive.WriteLine("Grid Reactive");
}
record.ControlConstants();
record.ControlSystemState();
@ -186,8 +198,8 @@ internal static class Program
record.EssControl = essControl;
record.AcDc.SystemControl.ApplyDefaultSettingsAc();
record.DcDc.SystemControl.ApplyDefaultSettingsDc();
record.AcDc.SystemControl.ApplyAcDcDefaultSettings();
record.DcDc.SystemControl.ApplyDcDcDefaultSettings();
DistributePower(record, essControl);
@ -322,7 +334,7 @@ internal static class Program
});
}
private static void ApplyDefaultSettingsAc(this SystemControlRegisters? sc)
private static void ApplyAcDcDefaultSettings(this SystemControlRegisters? sc)
{
if (sc is null)
return;
@ -343,18 +355,17 @@ internal static class Program
sc.ResetAlarmsAndWarnings = true;
}
private static void ApplyDefaultSettingsDc(this SystemControlRegisters? sc)
private static void ApplyDcDcDefaultSettings(this SystemControlRegisters? sc)
{
if (sc is null)
return;
sc.SystemConfig = DcDcOnly;
#if DEBUG
#if DEBUG
sc.CommunicationTimeout = TimeSpan.FromMinutes(2);
#else
#else
sc.CommunicationTimeout = TimeSpan.FromSeconds(20);
#endif
#endif
sc.PowerSetPointActivation = PowerSetPointActivation.Immediate;
sc.UseSlaveIdForAddressing = true;
@ -367,7 +378,7 @@ internal static class Program
{
timeStamp.WriteLine();
var csv = status.ToCsv();//.WriteLine();
var csv = status.ToCsv();
var s3Path = timeStamp + ".csv";
var request = S3Config.CreatePutRequest(s3Path);
var response = await request.PutAsync(new StringContent(csv));

View File

@ -2,9 +2,9 @@ using InnovEnergy.Lib.Units.Composite;
namespace InnovEnergy.App.SaliMax.VirtualDevices;
public class AcDevicePower
public class AcPowerDevice
{
public AcPower Power { get; init; } = AcPower.Null;
public static AcDevicePower Null { get; } = new AcDevicePower();
public static AcPowerDevice Null => new AcPowerDevice();
}

View File

@ -2,7 +2,7 @@ using InnovEnergy.Lib.Units.Power;
namespace InnovEnergy.App.SaliMax.VirtualDevices;
public class DcDevicePower
public class DcPowerDevice
{
public DcPower Power { get; init; } = DcPower.Null;
}