Introduce ClampMin and ClampMax

This commit is contained in:
atef 2023-06-20 15:34:04 +02:00
parent 789780791f
commit 8feee5db43
2 changed files with 11 additions and 2 deletions

View File

@ -85,8 +85,8 @@ public static class Controller
// find out if we reach the lower or upper Dc limit by comparing the current Dc voltage to the reference voltage
return s.AcDc.Dc.Voltage > s.Config.ReferenceDcBusVoltage
? control with { PowerCorrection = clampedPowerDelta.Clamp(-maxStep, -correction), LimitedBy = EssLimit.ChargeLimitedByMaxDcBusVoltage }
: control with { PowerCorrection = clampedPowerDelta.Clamp(correction, maxStep), LimitedBy = EssLimit.DischargeLimitedByMinDcBusVoltage };
? control with { PowerCorrection = clampedPowerDelta.ClampMax(-correction), LimitedBy = EssLimit.ChargeLimitedByMaxDcBusVoltage }
: control with { PowerCorrection = clampedPowerDelta.ClampMin(correction), LimitedBy = EssLimit.DischargeLimitedByMinDcBusVoltage };
}
// private static Double AdjustMaxChargePower(StatusRecord s, Double powerDelta)

View File

@ -124,6 +124,15 @@ public static class Utils
return clamped;
}
public static Double ClampMax(this Double value, Double maxValue)
{
return Math.Min(maxValue, value);
}
public static Double ClampMin(this Double value, Double minValue)
{
return Math.Max(minValue, value);
}
public static Decimal Clamp(this Decimal value, Decimal minValue, Decimal maxValue)
{