throw exception if min is bigger than max in Clamp
This commit is contained in:
parent
3e2e3e7190
commit
789780791f
|
@ -63,7 +63,7 @@ public static class Controller
|
|||
return control; // current loop cannot happen
|
||||
|
||||
var nominalPower = acDcs.Average(d => d.Status.Nominal.Power);
|
||||
var maxStep = nominalPower / 25;
|
||||
var maxStep = nominalPower / 25; //TODO magic number to config
|
||||
|
||||
var clampedPowerDelta = powerDelta.Clamp(-maxStep, maxStep);
|
||||
|
||||
|
@ -80,8 +80,10 @@ public static class Controller
|
|||
if (powerDifference < maxStep)
|
||||
return control with { PowerCorrection = clampedPowerDelta };
|
||||
|
||||
var correction = powerDifference / 4;
|
||||
var correction = powerDifference / 4; //TODO magic number to config
|
||||
|
||||
|
||||
// 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 };
|
||||
|
|
|
@ -104,6 +104,9 @@ public static class Utils
|
|||
|
||||
public static Int32 Clamp(this Int32 value, Int32 minValue, Int32 maxValue)
|
||||
{
|
||||
if (minValue > maxValue)
|
||||
throw new ArgumentException();
|
||||
|
||||
var clamped = Math.Min(maxValue, value);
|
||||
clamped = Math.Max(minValue, clamped);
|
||||
|
||||
|
@ -112,6 +115,9 @@ public static class Utils
|
|||
|
||||
public static Double Clamp(this Double value, Double minValue, Double maxValue)
|
||||
{
|
||||
if (minValue > maxValue)
|
||||
throw new ArgumentException();
|
||||
|
||||
var clamped = Math.Min(maxValue, value);
|
||||
clamped = Math.Max(minValue, clamped);
|
||||
|
||||
|
|
Loading…
Reference in New Issue