Add EocReached and Total Current and correct naming

This commit is contained in:
atef 2023-04-20 13:19:33 +02:00
parent bf1c869cba
commit 7635a8175e
4 changed files with 46 additions and 33 deletions

View File

@ -42,6 +42,9 @@ public static class AvgBatteriesStatus
? OperatingTemperature
: Cold,
TotalCurrent = stati.Average(b => b.TotalCurrent),
EocReached = stati.All(b => b.EocReached),
};
return new CombinedStatus<Battery48TLStatus>

View File

@ -5,7 +5,7 @@ public static class Control
public static Decimal ControlGridPower(this StatusRecord status, Decimal targetPower)
{
return ControlPower(status.GridMeterStatus!.ActivePowerL123, targetPower, status.SalimaxConfig!.PConstant);
return ControlPower(status.GridMeterStatus!.Ac.ActivePower, targetPower, status.SalimaxConfig!.PConstant);
}
public static Decimal ControlInverterPower(this StatusRecord status, Decimal targetInverterPower)
@ -18,7 +18,7 @@ public static class Control
public static Decimal ControlBatteryPower(this StatusRecord status, Decimal targetBatteryPower, UInt16 i = 0) //this will use the avg batteries
{
return ControlPower(status.BatteriesStatus![i].Dc.Power, targetBatteryPower, status.SalimaxConfig!.PConstant);
return ControlPower(status.BatteriesStatus!.Combined.Dc.Power, targetBatteryPower, status.SalimaxConfig!.PConstant);
}
public static Decimal ControlLowBatterySoc(this StatusRecord status)
@ -29,14 +29,14 @@ public static class Control
public static Decimal LowerLimit(params Decimal[] deltas) => deltas.Max();
public static Decimal UpperLimit(params Decimal[] deltas) => deltas.Min();
private static Decimal HoldMinSocCurve(StatusRecord s, UInt16 i = 0)
private static Decimal HoldMinSocCurve(StatusRecord s)
{
// TODO: explain LowSOC curve
var a = -2 * s.SalimaxConfig!.SelfDischargePower / s.SalimaxConfig.HoldSocZone;
var b = -a * (s.SalimaxConfig.MinSoc + s.SalimaxConfig.HoldSocZone);
return s.BatteriesStatus![i].Soc * a + b; //this will use the avg batteries
return s.BatteriesStatus!.Combined.Soc * a + b; //this will use the avg batteries
}
private static Decimal ControlPower(Decimal measurement, Decimal target, Decimal p)

View File

@ -5,6 +5,9 @@ using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc;
using InnovEnergy.Lib.Devices.Trumpf.TruConvertDc;
using InnovEnergy.Lib.Time.Unix;
using InnovEnergy.Lib.Utils;
using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc.Enums;
using static InnovEnergy.App.SaliMax.SaliMaxRelays.RelayState;
@ -68,69 +71,69 @@ public static class Controller
//Grid-Tied 400V/50 Hz
{
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Open,
InverterStatus.AcDcActiveGridType: AcDcGridType.GridTied400V50Hz
InverterStatus.GridType: AcDcGridType.GridTied400V50Hz
} => 9,
{
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Open,
InverterStatus.AcDcActiveGridType: AcDcGridType.GridTied400V50Hz
InverterStatus.GridType: AcDcGridType.GridTied400V50Hz
} => 10,
{
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Open,
InverterStatus.AcDcActiveGridType: AcDcGridType.GridTied400V50Hz
InverterStatus.GridType: AcDcGridType.GridTied400V50Hz
} => 11,
{
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Open,
InverterStatus.AcDcActiveGridType: AcDcGridType.GridTied400V50Hz
InverterStatus.GridType: AcDcGridType.GridTied400V50Hz
} => 12,
{
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Closed,
InverterStatus.AcDcActiveGridType: AcDcGridType.GridTied400V50Hz
InverterStatus.GridType: AcDcGridType.GridTied400V50Hz
} => 13,
{
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Closed,
InverterStatus.AcDcActiveGridType: AcDcGridType.GridTied400V50Hz
InverterStatus.GridType: AcDcGridType.GridTied400V50Hz
} => 14,
{
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Closed,
InverterStatus.AcDcActiveGridType: AcDcGridType.GridTied400V50Hz
InverterStatus.GridType: AcDcGridType.GridTied400V50Hz
} => 15,
{
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Closed,
InverterStatus.AcDcActiveGridType: AcDcGridType.GridTied400V50Hz
InverterStatus.GridType: AcDcGridType.GridTied400V50Hz
} => 16,
//Island 400V / 50Hz
{
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Open,
InverterStatus.AcDcActiveGridType: AcDcGridType.Island400V50Hz
InverterStatus.GridType: AcDcGridType.Island400V50Hz
} => 17,
{
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Open,
InverterStatus.AcDcActiveGridType: AcDcGridType.Island400V50Hz
InverterStatus.GridType: AcDcGridType.Island400V50Hz
} => 18,
{
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Open,
InverterStatus.AcDcActiveGridType: AcDcGridType.Island400V50Hz
InverterStatus.GridType: AcDcGridType.Island400V50Hz
} => 19,
{
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Open,
InverterStatus.AcDcActiveGridType: AcDcGridType.Island400V50Hz
InverterStatus.GridType: AcDcGridType.Island400V50Hz
} => 20,
{
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Closed, //this is wrong
InverterStatus.AcDcActiveGridType: AcDcGridType.Island400V50Hz
InverterStatus.GridType: AcDcGridType.Island400V50Hz
} => 21,
{
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Closed,
InverterStatus.AcDcActiveGridType: AcDcGridType.Island400V50Hz
InverterStatus.GridType: AcDcGridType.Island400V50Hz
} => 22,
{
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Closed,
InverterStatus.AcDcActiveGridType: AcDcGridType.Island400V50Hz
InverterStatus.GridType: AcDcGridType.Island400V50Hz
} => 23,
{
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Closed,
InverterStatus.AcDcActiveGridType: AcDcGridType.Island400V50Hz
InverterStatus.GridType: AcDcGridType.Island400V50Hz
} => 24,
@ -149,7 +152,7 @@ public static class Controller
var lastEocTime = GetLastEocTime(statusRecord);
var timeSinceLastEoc = UnixTime.Now - lastEocTime;
_numberOfInverters = statusRecord.InverterStatus!.NumberOfConnectedSlaves;
_numberOfInverters = (UInt16)statusRecord.InverterStatus!.NumberOfConnectedSlaves ;
_mustChargeFlag = timeSinceLastEoc > MaxTimeWithoutEoc;
var noGridMeter = statusRecord.GridMeterStatus == null;
@ -263,7 +266,7 @@ public static class Controller
goal = "Calibration Charge";
delta = statusRecord.ControlInverterPower(statusRecord.SalimaxConfig.MaxInverterPower);
}
else if (statusRecord.AvgBatteriesStatus!.Soc < statusRecord.SalimaxConfig.MinSoc) // TODO
else if (statusRecord.BatteriesStatus!.Combined.Soc < statusRecord.SalimaxConfig.MinSoc) // TODO
{
goal = $"reach min SOC (Min soc: {statusRecord.SalimaxConfig.MinSoc})";
delta = statusRecord.ControlInverterPower(statusRecord.SalimaxConfig
@ -285,7 +288,7 @@ public static class Controller
delta = inverterAc2DcLimitPower;
}
var batteryChargingLimitPower = statusRecord.ControlBatteryPower(statusRecord.BatteriesStatus[0]!.MaxChargingPower);
var batteryChargingLimitPower = statusRecord.ControlBatteryPower(statusRecord.BatteriesStatus!.Combined.MaxChargingPower);
if (delta > batteryChargingLimitPower)
{
@ -304,12 +307,12 @@ public static class Controller
}
var batteryDischargingLimitPower =
statusRecord.ControlBatteryPower(statusRecord.BatteriesStatus[0]!.MaxDischargingPower); // TODO change to avg battery
statusRecord.ControlBatteryPower(statusRecord.BatteriesStatus.Combined.MaxDischargingPower); // TODO change to avg battery
if (delta < batteryDischargingLimitPower)
{
limitReason =
$"limited by max battery discharging power: {statusRecord.BatteriesStatus[0]!.MaxDischargingPower}";// TODO change to avg battery
$"limited by max battery discharging power: {statusRecord.BatteriesStatus.Combined.MaxDischargingPower}";// TODO change to avg battery
delta = batteryDischargingLimitPower;
}
@ -448,14 +451,21 @@ public static class Controller
}
private static UnixTime GetLastEocTime(StatusRecord statusRecord)
{ if (statusRecord.BatteriesStatus != null)
{
if (statusRecord.BatteriesStatus[0]!.Soc >= 100 && statusRecord.BatteriesStatus[1]!.Soc >= 100 )
if (statusRecord.BatteriesStatus!.Combined.EocReached)
{
Console.WriteLine("battery has reached EOC");
File.AppendAllTextAsync(Config.LogSalimaxLog, String.Join(Environment.NewLine, UnixTime.Now + "battery has reached EOC"));
File.AppendAllTextAsync(Config.LogSalimaxLog,
String.Join(Environment.NewLine,
UnixTime.Now + "battery has reached EOC"));
return UnixTime.Now;
}
}
else
{
Console.WriteLine("No battery Detected");
}
return statusRecord.SalimaxConfig.LastEoc;
}

View File

@ -17,7 +17,7 @@ public record StatusRecord
public EmuMeterStatus? GridMeterStatus { get; init; }
public SaliMaxRelayStatus? SaliMaxRelayStatus { get; init; }
public AmptStatus? AmptStatus { get; init; }
public AmptCommunicationUnitStatus? AmptStatus { get; init; }
public EmuMeterStatus? AcInToAcOutMeterStatus { get; init; }
public SalimaxConfig SalimaxConfig { get; init; } = null!;
}