diff --git a/csharp/App/SaliMax/src/Ess/Controller.cs b/csharp/App/SaliMax/src/Ess/Controller.cs index 1e7599f88..55007e035 100644 --- a/csharp/App/SaliMax/src/Ess/Controller.cs +++ b/csharp/App/SaliMax/src/Ess/Controller.cs @@ -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) diff --git a/csharp/Lib/Utils/Utils.cs b/csharp/Lib/Utils/Utils.cs index 50dddeab3..5fa0c4a12 100644 --- a/csharp/Lib/Utils/Utils.cs +++ b/csharp/Lib/Utils/Utils.cs @@ -124,7 +124,16 @@ 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) { var clamped = Math.Min(maxValue, value);