Add EocReached and Total Current and correct naming
This commit is contained in:
parent
bf1c869cba
commit
7635a8175e
|
@ -41,7 +41,10 @@ public static class AvgBatteriesStatus
|
||||||
TemperatureState = stati.Any(b => b.TemperatureState == OperatingTemperature) // TODO: revisit when we have the overheated state
|
TemperatureState = stati.Any(b => b.TemperatureState == OperatingTemperature) // TODO: revisit when we have the overheated state
|
||||||
? OperatingTemperature
|
? OperatingTemperature
|
||||||
: Cold,
|
: Cold,
|
||||||
|
|
||||||
|
TotalCurrent = stati.Average(b => b.TotalCurrent),
|
||||||
|
|
||||||
|
EocReached = stati.All(b => b.EocReached),
|
||||||
};
|
};
|
||||||
|
|
||||||
return new CombinedStatus<Battery48TLStatus>
|
return new CombinedStatus<Battery48TLStatus>
|
||||||
|
|
|
@ -5,7 +5,7 @@ public static class Control
|
||||||
|
|
||||||
public static Decimal ControlGridPower(this StatusRecord status, Decimal targetPower)
|
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)
|
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
|
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)
|
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 LowerLimit(params Decimal[] deltas) => deltas.Max();
|
||||||
public static Decimal UpperLimit(params Decimal[] deltas) => deltas.Min();
|
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
|
// TODO: explain LowSOC curve
|
||||||
|
|
||||||
var a = -2 * s.SalimaxConfig!.SelfDischargePower / s.SalimaxConfig.HoldSocZone;
|
var a = -2 * s.SalimaxConfig!.SelfDischargePower / s.SalimaxConfig.HoldSocZone;
|
||||||
var b = -a * (s.SalimaxConfig.MinSoc + 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)
|
private static Decimal ControlPower(Decimal measurement, Decimal target, Decimal p)
|
||||||
|
|
|
@ -5,6 +5,9 @@ using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc;
|
||||||
using InnovEnergy.Lib.Devices.Trumpf.TruConvertDc;
|
using InnovEnergy.Lib.Devices.Trumpf.TruConvertDc;
|
||||||
using InnovEnergy.Lib.Time.Unix;
|
using InnovEnergy.Lib.Time.Unix;
|
||||||
using InnovEnergy.Lib.Utils;
|
using InnovEnergy.Lib.Utils;
|
||||||
|
|
||||||
|
using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc.Enums;
|
||||||
|
|
||||||
using static InnovEnergy.App.SaliMax.SaliMaxRelays.RelayState;
|
using static InnovEnergy.App.SaliMax.SaliMaxRelays.RelayState;
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,69 +71,69 @@ public static class Controller
|
||||||
//Grid-Tied 400V/50 Hz
|
//Grid-Tied 400V/50 Hz
|
||||||
{
|
{
|
||||||
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Open,
|
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Open,
|
||||||
InverterStatus.AcDcActiveGridType: AcDcGridType.GridTied400V50Hz
|
InverterStatus.GridType: AcDcGridType.GridTied400V50Hz
|
||||||
} => 9,
|
} => 9,
|
||||||
{
|
{
|
||||||
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Open,
|
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Open,
|
||||||
InverterStatus.AcDcActiveGridType: AcDcGridType.GridTied400V50Hz
|
InverterStatus.GridType: AcDcGridType.GridTied400V50Hz
|
||||||
} => 10,
|
} => 10,
|
||||||
{
|
{
|
||||||
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Open,
|
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Open,
|
||||||
InverterStatus.AcDcActiveGridType: AcDcGridType.GridTied400V50Hz
|
InverterStatus.GridType: AcDcGridType.GridTied400V50Hz
|
||||||
} => 11,
|
} => 11,
|
||||||
{
|
{
|
||||||
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Open,
|
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Open,
|
||||||
InverterStatus.AcDcActiveGridType: AcDcGridType.GridTied400V50Hz
|
InverterStatus.GridType: AcDcGridType.GridTied400V50Hz
|
||||||
} => 12,
|
} => 12,
|
||||||
{
|
{
|
||||||
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Closed,
|
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Closed,
|
||||||
InverterStatus.AcDcActiveGridType: AcDcGridType.GridTied400V50Hz
|
InverterStatus.GridType: AcDcGridType.GridTied400V50Hz
|
||||||
} => 13,
|
} => 13,
|
||||||
{
|
{
|
||||||
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Closed,
|
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Closed,
|
||||||
InverterStatus.AcDcActiveGridType: AcDcGridType.GridTied400V50Hz
|
InverterStatus.GridType: AcDcGridType.GridTied400V50Hz
|
||||||
} => 14,
|
} => 14,
|
||||||
{
|
{
|
||||||
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Closed,
|
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Closed,
|
||||||
InverterStatus.AcDcActiveGridType: AcDcGridType.GridTied400V50Hz
|
InverterStatus.GridType: AcDcGridType.GridTied400V50Hz
|
||||||
} => 15,
|
} => 15,
|
||||||
{
|
{
|
||||||
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Closed,
|
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Closed,
|
||||||
InverterStatus.AcDcActiveGridType: AcDcGridType.GridTied400V50Hz
|
InverterStatus.GridType: AcDcGridType.GridTied400V50Hz
|
||||||
} => 16,
|
} => 16,
|
||||||
|
|
||||||
//Island 400V / 50Hz
|
//Island 400V / 50Hz
|
||||||
{
|
{
|
||||||
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Open,
|
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Open,
|
||||||
InverterStatus.AcDcActiveGridType: AcDcGridType.Island400V50Hz
|
InverterStatus.GridType: AcDcGridType.Island400V50Hz
|
||||||
} => 17,
|
} => 17,
|
||||||
{
|
{
|
||||||
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Open,
|
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Open,
|
||||||
InverterStatus.AcDcActiveGridType: AcDcGridType.Island400V50Hz
|
InverterStatus.GridType: AcDcGridType.Island400V50Hz
|
||||||
} => 18,
|
} => 18,
|
||||||
{
|
{
|
||||||
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Open,
|
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Open,
|
||||||
InverterStatus.AcDcActiveGridType: AcDcGridType.Island400V50Hz
|
InverterStatus.GridType: AcDcGridType.Island400V50Hz
|
||||||
} => 19,
|
} => 19,
|
||||||
{
|
{
|
||||||
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Open,
|
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Open,
|
||||||
InverterStatus.AcDcActiveGridType: AcDcGridType.Island400V50Hz
|
InverterStatus.GridType: AcDcGridType.Island400V50Hz
|
||||||
} => 20,
|
} => 20,
|
||||||
{
|
{
|
||||||
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Closed, //this is wrong
|
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Closed, //this is wrong
|
||||||
InverterStatus.AcDcActiveGridType: AcDcGridType.Island400V50Hz
|
InverterStatus.GridType: AcDcGridType.Island400V50Hz
|
||||||
} => 21,
|
} => 21,
|
||||||
{
|
{
|
||||||
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Closed,
|
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Open, SaliMaxRelayStatus.K3: Closed,
|
||||||
InverterStatus.AcDcActiveGridType: AcDcGridType.Island400V50Hz
|
InverterStatus.GridType: AcDcGridType.Island400V50Hz
|
||||||
} => 22,
|
} => 22,
|
||||||
{
|
{
|
||||||
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Closed,
|
SaliMaxRelayStatus.K1: Open, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Closed,
|
||||||
InverterStatus.AcDcActiveGridType: AcDcGridType.Island400V50Hz
|
InverterStatus.GridType: AcDcGridType.Island400V50Hz
|
||||||
} => 23,
|
} => 23,
|
||||||
{
|
{
|
||||||
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Closed,
|
SaliMaxRelayStatus.K1: Closed, SaliMaxRelayStatus.K2: Closed, SaliMaxRelayStatus.K3: Closed,
|
||||||
InverterStatus.AcDcActiveGridType: AcDcGridType.Island400V50Hz
|
InverterStatus.GridType: AcDcGridType.Island400V50Hz
|
||||||
} => 24,
|
} => 24,
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,7 +152,7 @@ public static class Controller
|
||||||
var lastEocTime = GetLastEocTime(statusRecord);
|
var lastEocTime = GetLastEocTime(statusRecord);
|
||||||
var timeSinceLastEoc = UnixTime.Now - lastEocTime;
|
var timeSinceLastEoc = UnixTime.Now - lastEocTime;
|
||||||
|
|
||||||
_numberOfInverters = statusRecord.InverterStatus!.NumberOfConnectedSlaves;
|
_numberOfInverters = (UInt16)statusRecord.InverterStatus!.NumberOfConnectedSlaves ;
|
||||||
_mustChargeFlag = timeSinceLastEoc > MaxTimeWithoutEoc;
|
_mustChargeFlag = timeSinceLastEoc > MaxTimeWithoutEoc;
|
||||||
|
|
||||||
var noGridMeter = statusRecord.GridMeterStatus == null;
|
var noGridMeter = statusRecord.GridMeterStatus == null;
|
||||||
|
@ -263,7 +266,7 @@ public static class Controller
|
||||||
goal = "Calibration Charge";
|
goal = "Calibration Charge";
|
||||||
delta = statusRecord.ControlInverterPower(statusRecord.SalimaxConfig.MaxInverterPower);
|
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})";
|
goal = $"reach min SOC (Min soc: {statusRecord.SalimaxConfig.MinSoc})";
|
||||||
delta = statusRecord.ControlInverterPower(statusRecord.SalimaxConfig
|
delta = statusRecord.ControlInverterPower(statusRecord.SalimaxConfig
|
||||||
|
@ -285,7 +288,7 @@ public static class Controller
|
||||||
delta = inverterAc2DcLimitPower;
|
delta = inverterAc2DcLimitPower;
|
||||||
}
|
}
|
||||||
|
|
||||||
var batteryChargingLimitPower = statusRecord.ControlBatteryPower(statusRecord.BatteriesStatus[0]!.MaxChargingPower);
|
var batteryChargingLimitPower = statusRecord.ControlBatteryPower(statusRecord.BatteriesStatus!.Combined.MaxChargingPower);
|
||||||
|
|
||||||
if (delta > batteryChargingLimitPower)
|
if (delta > batteryChargingLimitPower)
|
||||||
{
|
{
|
||||||
|
@ -304,12 +307,12 @@ public static class Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
var batteryDischargingLimitPower =
|
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)
|
if (delta < batteryDischargingLimitPower)
|
||||||
{
|
{
|
||||||
limitReason =
|
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;
|
delta = batteryDischargingLimitPower;
|
||||||
}
|
}
|
||||||
|
@ -448,14 +451,21 @@ public static class Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UnixTime GetLastEocTime(StatusRecord statusRecord)
|
private static UnixTime GetLastEocTime(StatusRecord statusRecord)
|
||||||
{
|
{ if (statusRecord.BatteriesStatus != null)
|
||||||
if (statusRecord.BatteriesStatus[0]!.Soc >= 100 && statusRecord.BatteriesStatus[1]!.Soc >= 100 )
|
|
||||||
{
|
{
|
||||||
Console.WriteLine("battery has reached EOC");
|
if (statusRecord.BatteriesStatus!.Combined.EocReached)
|
||||||
File.AppendAllTextAsync(Config.LogSalimaxLog, String.Join(Environment.NewLine, UnixTime.Now + "battery has reached EOC"));
|
{
|
||||||
return UnixTime.Now;
|
Console.WriteLine("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;
|
return statusRecord.SalimaxConfig.LastEoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ public record StatusRecord
|
||||||
|
|
||||||
public EmuMeterStatus? GridMeterStatus { get; init; }
|
public EmuMeterStatus? GridMeterStatus { get; init; }
|
||||||
public SaliMaxRelayStatus? SaliMaxRelayStatus { get; init; }
|
public SaliMaxRelayStatus? SaliMaxRelayStatus { get; init; }
|
||||||
public AmptStatus? AmptStatus { get; init; }
|
public AmptCommunicationUnitStatus? AmptStatus { get; init; }
|
||||||
public EmuMeterStatus? AcInToAcOutMeterStatus { get; init; }
|
public EmuMeterStatus? AcInToAcOutMeterStatus { get; init; }
|
||||||
public SalimaxConfig SalimaxConfig { get; init; } = null!;
|
public SalimaxConfig SalimaxConfig { get; init; } = null!;
|
||||||
}
|
}
|
Loading…
Reference in New Issue