2023-06-13 11:01:01 +00:00
|
|
|
using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc.DataTypes;
|
|
|
|
using InnovEnergy.Lib.Units.Composite;
|
|
|
|
using InnovEnergy.Lib.Utils;
|
2023-09-01 06:54:46 +00:00
|
|
|
using static System.Math;
|
2023-06-13 11:01:01 +00:00
|
|
|
|
|
|
|
namespace InnovEnergy.Lib.Devices.Trumpf.TruConvertAc.Control;
|
|
|
|
|
|
|
|
public class AcPowerControl
|
|
|
|
{
|
|
|
|
public AcPower L1
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
var s = _Self.PowerSetpointL1;
|
|
|
|
var cosPhi = _Self.CosPhiSetpointL1.Clamp(-1, 1);
|
|
|
|
var rpk = _Self.ReactivePowerKindL1;
|
2023-09-01 06:54:46 +00:00
|
|
|
var phi = Acos(cosPhi) * (rpk == ReactivePowerKind.Inductive ? 1 : -1);
|
|
|
|
var sinPhi = Sin(phi);
|
2023-06-13 11:01:01 +00:00
|
|
|
|
2023-09-01 06:54:46 +00:00
|
|
|
return new AcPower { Active = s * cosPhi, Reactive = s * sinPhi };
|
2023-06-13 11:01:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2023-09-01 06:54:46 +00:00
|
|
|
var s = value.Apparent;
|
|
|
|
var p = value.Active;
|
|
|
|
var q = value.Reactive;
|
|
|
|
|
|
|
|
_Self.PowerSetpointL1 = s;
|
|
|
|
_Self.CosPhiSetpointL1 = s == 0 ? 1 : p / s;
|
|
|
|
_Self.SinPhiSetpointL1 = s == 0 ? 0 : q / s;
|
2023-06-13 11:01:01 +00:00
|
|
|
_Self.ReactivePowerKindL1 = value.Reactive >= 0
|
|
|
|
? ReactivePowerKind.Inductive
|
|
|
|
: ReactivePowerKind.Capacitive;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public AcPower L2
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
var s = _Self.PowerSetpointL2;
|
|
|
|
var cosPhi = _Self.CosPhiSetpointL2.Clamp(-1, 1);
|
|
|
|
var rpk = _Self.ReactivePowerKindL2;
|
2023-09-01 06:54:46 +00:00
|
|
|
var phi = Acos(cosPhi) * (rpk == ReactivePowerKind.Inductive ? 1 : -1);
|
|
|
|
var sinPhi = Sin(phi);
|
2023-06-13 11:01:01 +00:00
|
|
|
|
2023-09-01 06:54:46 +00:00
|
|
|
return new AcPower { Active = s * cosPhi, Reactive = s * sinPhi };
|
2023-06-13 11:01:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2023-09-01 06:54:46 +00:00
|
|
|
var s = value.Apparent;
|
|
|
|
var p = value.Active;
|
|
|
|
var q = value.Reactive;
|
|
|
|
|
|
|
|
_Self.PowerSetpointL2 = s;
|
|
|
|
_Self.CosPhiSetpointL2 = s == 0 ? 1 : p / s;
|
|
|
|
_Self.SinPhiSetpointL2 = s == 0 ? 0 : q / s;
|
2023-06-13 11:01:01 +00:00
|
|
|
_Self.ReactivePowerKindL2 = value.Reactive >= 0
|
|
|
|
? ReactivePowerKind.Inductive
|
|
|
|
: ReactivePowerKind.Capacitive;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-01 06:54:46 +00:00
|
|
|
|
2023-06-13 11:01:01 +00:00
|
|
|
public AcPower L3
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
var s = _Self.PowerSetpointL3;
|
|
|
|
var cosPhi = _Self.CosPhiSetpointL3.Clamp(-1, 1);
|
|
|
|
var rpk = _Self.ReactivePowerKindL3;
|
2023-09-01 06:54:46 +00:00
|
|
|
var phi = Acos(cosPhi) * (rpk == ReactivePowerKind.Inductive ? 1 : -1);
|
|
|
|
var sinPhi = Sin(phi);
|
2023-06-13 11:01:01 +00:00
|
|
|
|
2023-09-01 06:54:46 +00:00
|
|
|
return new AcPower { Active = s * cosPhi, Reactive = s * sinPhi };
|
2023-06-13 11:01:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2023-09-01 06:54:46 +00:00
|
|
|
var s = value.Apparent;
|
|
|
|
var p = value.Active;
|
|
|
|
var q = value.Reactive;
|
|
|
|
|
|
|
|
_Self.PowerSetpointL3 = s;
|
|
|
|
_Self.CosPhiSetpointL3 = s == 0 ? 1 : p / s;
|
|
|
|
_Self.SinPhiSetpointL3 = s == 0 ? 0 : q / s;
|
2023-06-13 11:01:01 +00:00
|
|
|
_Self.ReactivePowerKindL3 = value.Reactive >= 0
|
|
|
|
? ReactivePowerKind.Inductive
|
|
|
|
: ReactivePowerKind.Capacitive;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal AcPowerControl(AcDcRecord self) => _Self = self;
|
|
|
|
private readonly AcDcRecord _Self;
|
|
|
|
|
|
|
|
// public IEnumerator<AcPower> GetEnumerator()
|
|
|
|
// {
|
|
|
|
// yield return L1;
|
|
|
|
// yield return L2;
|
|
|
|
// yield return L3;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
// {
|
|
|
|
// return GetEnumerator();
|
|
|
|
// }
|
|
|
|
}
|