Introduce ClampMin and ClampMax
This commit is contained in:
parent
789780791f
commit
8feee5db43
|
@ -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
|
// 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
|
return s.AcDc.Dc.Voltage > s.Config.ReferenceDcBusVoltage
|
||||||
? control with { PowerCorrection = clampedPowerDelta.Clamp(-maxStep, -correction), LimitedBy = EssLimit.ChargeLimitedByMaxDcBusVoltage }
|
? control with { PowerCorrection = clampedPowerDelta.ClampMax(-correction), LimitedBy = EssLimit.ChargeLimitedByMaxDcBusVoltage }
|
||||||
: control with { PowerCorrection = clampedPowerDelta.Clamp(correction, maxStep), LimitedBy = EssLimit.DischargeLimitedByMinDcBusVoltage };
|
: control with { PowerCorrection = clampedPowerDelta.ClampMin(correction), LimitedBy = EssLimit.DischargeLimitedByMinDcBusVoltage };
|
||||||
}
|
}
|
||||||
|
|
||||||
// private static Double AdjustMaxChargePower(StatusRecord s, Double powerDelta)
|
// private static Double AdjustMaxChargePower(StatusRecord s, Double powerDelta)
|
||||||
|
|
|
@ -124,7 +124,16 @@ public static class Utils
|
||||||
return clamped;
|
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)
|
public static Decimal Clamp(this Decimal value, Decimal minValue, Decimal maxValue)
|
||||||
{
|
{
|
||||||
var clamped = Math.Min(maxValue, value);
|
var clamped = Math.Min(maxValue, value);
|
||||||
|
|
Loading…
Reference in New Issue