using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc.DataTypes; using InnovEnergy.Lib.Units.Composite; using InnovEnergy.Lib.Utils; using static System.Math; 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; var phi = Acos(cosPhi) * (rpk == ReactivePowerKind.Inductive ? 1 : -1); var sinPhi = Sin(phi); return new AcPower { Active = s * cosPhi, Reactive = s * sinPhi }; } set { 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; _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; var phi = Acos(cosPhi) * (rpk == ReactivePowerKind.Inductive ? 1 : -1); var sinPhi = Sin(phi); return new AcPower { Active = s * cosPhi, Reactive = s * sinPhi }; } set { 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; _Self.ReactivePowerKindL2 = value.Reactive >= 0 ? ReactivePowerKind.Inductive : ReactivePowerKind.Capacitive; } } public AcPower L3 { get { var s = _Self.PowerSetpointL3; var cosPhi = _Self.CosPhiSetpointL3.Clamp(-1, 1); var rpk = _Self.ReactivePowerKindL3; var phi = Acos(cosPhi) * (rpk == ReactivePowerKind.Inductive ? 1 : -1); var sinPhi = Sin(phi); return new AcPower { Active = s * cosPhi, Reactive = s * sinPhi }; } set { 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; _Self.ReactivePowerKindL3 = value.Reactive >= 0 ? ReactivePowerKind.Inductive : ReactivePowerKind.Capacitive; } } internal AcPowerControl(AcDcRecord self) => _Self = self; private readonly AcDcRecord _Self; // public IEnumerator GetEnumerator() // { // yield return L1; // yield return L2; // yield return L3; // } // // IEnumerator IEnumerable.GetEnumerator() // { // return GetEnumerator(); // } }