Calibration next day added.
This commit is contained in:
parent
1fb9be93e9
commit
e56cad22a9
|
@ -10,6 +10,8 @@ namespace InnovEnergy.App.SaliMax.Ess;
|
|||
public static class Controller
|
||||
{
|
||||
private static readonly Double BatteryHeatingPower = 200.0; // TODO: move to config
|
||||
private static Boolean _hasOriginalNextDayAt10AmBeenChecked = false;
|
||||
private static DateTime _nextDayAt10Am = DateTime.Now;
|
||||
|
||||
public static EssMode SelectControlMode(this StatusRecord s)
|
||||
{
|
||||
|
@ -190,7 +192,7 @@ public static class Controller
|
|||
private static Boolean MustDoCalibrationCharge(this StatusRecord statusRecord)
|
||||
{
|
||||
var calibrationChargeForced = statusRecord.Config.ForceCalibrationCharge;
|
||||
var batteryCalibrationChargeRequested = statusRecord.Battery?.CalibrationChargeRequested?? false ;
|
||||
var batteryCalibrationChargeRequested = BatteryCalibrationChargeRequested(statusRecord.Battery?.CalibrationChargeRequested?? false) ;
|
||||
|
||||
var mustDoCalibrationCharge = batteryCalibrationChargeRequested || calibrationChargeForced == CalibrationChargeType.Yes || calibrationChargeForced == CalibrationChargeType.UntilEoc ;
|
||||
|
||||
|
@ -204,6 +206,58 @@ public static class Controller
|
|||
return mustDoCalibrationCharge;
|
||||
}
|
||||
|
||||
private static Boolean BatteryCalibrationChargeRequested(Boolean calibrationChargeRequested)
|
||||
{
|
||||
if (calibrationChargeRequested)
|
||||
{
|
||||
if (!_hasOriginalNextDayAt10AmBeenChecked)
|
||||
{
|
||||
_nextDayAt10Am = CalculateNextCalibrationTime();
|
||||
_hasOriginalNextDayAt10AmBeenChecked = true;
|
||||
}
|
||||
|
||||
if (CheckNextCalibrationTime(_nextDayAt10Am))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_hasOriginalNextDayAt10AmBeenChecked = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Boolean CheckNextCalibrationTime(DateTime nextCalibrationTime)
|
||||
{
|
||||
var currentDateAndTime = DateTime.Now;
|
||||
Console.WriteLine(" next 10 am is: " + nextCalibrationTime);
|
||||
Console.WriteLine(" currentDateAndTime: " + currentDateAndTime);
|
||||
|
||||
// Check if the current time is greater than or equal to the original nextCalibrationTime
|
||||
var x = currentDateAndTime >= nextCalibrationTime;
|
||||
Console.WriteLine(" we are checking next 10 am : " + x);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
private static DateTime CalculateNextCalibrationTime()
|
||||
{
|
||||
var currentDateAndTime = DateTime.Now;
|
||||
|
||||
// Calculate the next 10 AM within the same day
|
||||
var nextCalibrationTime = new DateTime(currentDateAndTime.Year, currentDateAndTime.Month, currentDateAndTime.Day, 9, 0, 0); // next 9am
|
||||
|
||||
// If the current time is already past 10 AM, move to the next day
|
||||
if (currentDateAndTime.Hour >= 9)
|
||||
{
|
||||
nextCalibrationTime = nextCalibrationTime.AddDays(1);
|
||||
}
|
||||
|
||||
return nextCalibrationTime;
|
||||
}
|
||||
|
||||
private static Double ControlGridPower(this StatusRecord status, Double targetPower)
|
||||
{
|
||||
|
@ -215,7 +269,7 @@ public static class Controller
|
|||
);
|
||||
}
|
||||
|
||||
public static Double ControlInverterPower(this StatusRecord status, Double targetInverterPower)
|
||||
private static Double ControlInverterPower(this StatusRecord status, Double targetInverterPower)
|
||||
{
|
||||
return ControlPower
|
||||
(
|
||||
|
@ -225,7 +279,7 @@ public static class Controller
|
|||
);
|
||||
}
|
||||
|
||||
public static Double ControlBatteryPower(this StatusRecord status, Double targetBatteryPower)
|
||||
private static Double ControlBatteryPower(this StatusRecord status, Double targetBatteryPower)
|
||||
{
|
||||
return ControlPower
|
||||
(
|
||||
|
@ -265,5 +319,4 @@ public static class Controller
|
|||
var ki = i * errorSum;
|
||||
return ki + kp;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue