"normalize" DcBus
This commit is contained in:
parent
6c2360f0ad
commit
be452d190c
|
@ -62,7 +62,11 @@ public class AmptDevices
|
|||
|
||||
var busVoltage = nStringOptimizers == 0 ? 0 : soStati.Average(r => r.Voltage);
|
||||
var busCurrent = nStringOptimizers == 0 ? 0 : soStati.Sum (r => r.Current);
|
||||
var dc = DcBus.FromVoltageCurrent(busVoltage, busCurrent);
|
||||
var dc = new DcBus
|
||||
{
|
||||
Voltage = busVoltage,
|
||||
Current = busCurrent,
|
||||
};
|
||||
|
||||
// flatten the 2 strings of each SO into one array
|
||||
var strings = soStati.SelectMany(GetStrings).ToArray(nStrings);
|
||||
|
@ -80,8 +84,16 @@ public class AmptDevices
|
|||
{
|
||||
// hardcoded: every SO has 2 strings (produced like this by AMPT)
|
||||
|
||||
yield return DcBus.FromVoltageCurrent(r.String1Voltage, r.String1Current);
|
||||
yield return DcBus.FromVoltageCurrent(r.String2Voltage, r.String2Current);
|
||||
yield return new()
|
||||
{
|
||||
Voltage = r.String1Voltage,
|
||||
Current = r.String1Current,
|
||||
};
|
||||
yield return new()
|
||||
{
|
||||
Voltage = r.String2Voltage,
|
||||
Current = r.String2Current,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -35,11 +35,11 @@ public class Battery48TlRecords
|
|||
HeatingPower = records.Sum(b => b.HeatingPower),
|
||||
TimeToToc = records.Min(r => r.TimeToTOC),
|
||||
|
||||
Dc = DcBus.FromVoltageCurrent
|
||||
(
|
||||
records.Average(r => r.Dc.Voltage),
|
||||
records.Sum(r => r.Dc.Current)
|
||||
)
|
||||
Dc = new()
|
||||
{
|
||||
Voltage = records.Average(r => r.Dc.Voltage),
|
||||
Current = records.Sum(r => r.Dc.Current),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -72,11 +72,11 @@ public class AcDcDevicesRecord
|
|||
var p = Ac.Power.Active.Value;
|
||||
var i = u == 0 ? 0 : p / u;
|
||||
|
||||
return DcBus.FromVoltageCurrent
|
||||
(
|
||||
voltage: u,
|
||||
current: i
|
||||
);
|
||||
return new()
|
||||
{
|
||||
Voltage = u,
|
||||
Current = i,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,11 @@ namespace InnovEnergy.Lib.Devices.Trumpf.TruConvertDc;
|
|||
|
||||
public class DcDcDevicesRecord
|
||||
{
|
||||
private static readonly DcBus NoDevice = DcBus.FromVoltageCurrent(0, 0);
|
||||
private static readonly DcBus NoDevice = new()
|
||||
{
|
||||
Voltage = 0,
|
||||
Current = 0,
|
||||
};
|
||||
|
||||
public DcDcDevicesRecord(SystemControlRegisters? systemControl, IReadOnlyList<DcDcRecord> devices)
|
||||
{
|
||||
|
@ -14,16 +18,16 @@ public class DcDcDevicesRecord
|
|||
Devices = devices;
|
||||
}
|
||||
|
||||
public DcStatus Dc => new DcStatus
|
||||
public DcStatus Dc => new()
|
||||
{
|
||||
Battery = Devices.Count == 0
|
||||
Battery = Devices.Count == 0
|
||||
? NoDevice
|
||||
: DcBus.FromVoltageCurrent
|
||||
(
|
||||
Devices.Average(r => r.Status.Dc.Battery.Voltage.Value),
|
||||
Devices.Sum(r => r.Status.Dc.Battery.Current.Value)
|
||||
),
|
||||
|
||||
: new()
|
||||
{
|
||||
Voltage = Devices.Average(r => r.Status.Dc.Battery.Voltage.Value),
|
||||
Current = Devices.Sum(r => r.Status.Dc.Battery.Current.Value),
|
||||
},
|
||||
|
||||
Link = Devices.Count == 0
|
||||
? NoDevice
|
||||
: DcBus.FromVoltageCurrent
|
||||
|
@ -32,7 +36,7 @@ public class DcDcDevicesRecord
|
|||
Devices.Sum(r => r.Status.Dc.Link.Current.Value)
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
public SystemControlRegisters? SystemControl { get; }
|
||||
public IReadOnlyList<DcDcRecord> Devices { get; }
|
||||
|
||||
|
|
|
@ -21,19 +21,19 @@ public class DcDcStatus
|
|||
var linkCurrent = batteryCurrent == 0
|
||||
? 0
|
||||
: _Self.BatteryVoltage * _Self.BatteryCurrent / _Self.DcLinkVoltage;
|
||||
|
||||
|
||||
return new()
|
||||
{
|
||||
Link = DcBus.FromVoltageCurrent
|
||||
(
|
||||
voltage: _Self.DcLinkVoltage,
|
||||
current: -linkCurrent // TODO: review sign is reversed
|
||||
),
|
||||
Battery = DcBus.FromVoltageCurrent
|
||||
(
|
||||
voltage: _Self.BatteryVoltage,
|
||||
current: -batteryCurrent // TODO: review sign is reversed
|
||||
)
|
||||
Link = new()
|
||||
{
|
||||
Voltage = _Self.DcLinkVoltage,
|
||||
Current = -linkCurrent,
|
||||
},
|
||||
Battery = new()
|
||||
{
|
||||
Voltage = _Self.BatteryVoltage,
|
||||
Current = -batteryCurrent,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using InnovEnergy.Lib.StatusApi.Connections;
|
||||
using InnovEnergy.Lib.Units.Composite;
|
||||
|
||||
namespace InnovEnergy.Lib.StatusApi.DeviceTypes;
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using InnovEnergy.Lib.StatusApi.Connections;
|
||||
using InnovEnergy.Lib.Units;
|
||||
using InnovEnergy.Lib.Units.Composite;
|
||||
|
||||
namespace InnovEnergy.Lib.StatusApi.DeviceTypes;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace InnovEnergy.Lib.StatusApi.DeviceTypes;
|
|||
|
||||
public interface IDcDc
|
||||
{
|
||||
DcBus DcLeft { get; }
|
||||
DcBus DcLeft { get; }
|
||||
DcBus DcRight { get; }
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
using InnovEnergy.Lib.StatusApi.Connections;
|
||||
|
||||
namespace InnovEnergy.Lib.StatusApi.DeviceTypes;
|
||||
|
||||
public interface IDcMeter : IDcConnection
|
||||
{
|
||||
}
|
|
@ -2,9 +2,6 @@ namespace InnovEnergy.Lib.Units.Composite;
|
|||
|
||||
public sealed class Ac1Bus
|
||||
{
|
||||
private Ac1Bus()
|
||||
{}
|
||||
|
||||
public required Voltage Voltage { get; init; }
|
||||
public required Current Current { get; init; }
|
||||
public required AcPower Power { get; init; }
|
||||
|
|
|
@ -6,6 +6,8 @@ namespace InnovEnergy.Lib.Units.Composite;
|
|||
|
||||
public sealed class AcPower
|
||||
{
|
||||
private AcPower(){}
|
||||
|
||||
public required ApparentPower Apparent { get; init; }
|
||||
public required ActivePower Active { get; init; }
|
||||
public required ReactivePower Reactive { get; init; }
|
||||
|
@ -81,29 +83,24 @@ public sealed class AcPower
|
|||
CosPhi = Cos(phi.Value)
|
||||
};
|
||||
}
|
||||
|
||||
public static AcPower operator +(AcPower left, AcPower right)
|
||||
{
|
||||
return FromActiveReactive
|
||||
(
|
||||
left.Active + right.Active,
|
||||
left.Reactive + right.Reactive
|
||||
);
|
||||
}
|
||||
|
||||
public static AcPower operator -(AcPower left, AcPower right)
|
||||
{
|
||||
return left + -right;
|
||||
}
|
||||
public static AcPower operator +(AcPower left, AcPower right) => FromActiveReactive
|
||||
(
|
||||
left.Active + right.Active,
|
||||
left.Reactive + right.Reactive
|
||||
);
|
||||
|
||||
public static AcPower operator -(AcPower p)
|
||||
{
|
||||
return FromActiveReactive
|
||||
(
|
||||
-p.Active,
|
||||
-p.Reactive
|
||||
);
|
||||
}
|
||||
public static AcPower operator -(AcPower left, AcPower right) => FromActiveReactive
|
||||
(
|
||||
left.Active - right.Active,
|
||||
left.Reactive - right.Reactive
|
||||
);
|
||||
|
||||
public static AcPower operator -(AcPower p) => FromActiveReactive
|
||||
(
|
||||
-p.Active,
|
||||
-p.Reactive
|
||||
);
|
||||
|
||||
|
||||
public static implicit operator AcPower(Double p) => FromActiveReactive(p, 0);
|
||||
|
|
|
@ -4,18 +4,20 @@ namespace InnovEnergy.Lib.Units.Composite;
|
|||
|
||||
public sealed class DcBus
|
||||
{
|
||||
private DcBus() {}
|
||||
|
||||
public required Voltage Voltage { get; init; }
|
||||
public required Current Current { get; init; }
|
||||
public required DcPower Power { get; init; }
|
||||
public required Voltage Voltage { get; init; }
|
||||
public required Current Current { get; init; }
|
||||
|
||||
public DcPower Power => Voltage * Current;
|
||||
|
||||
public static DcBus FromVoltageCurrent(Voltage voltage, Current current) => new()
|
||||
{
|
||||
Voltage = voltage,
|
||||
Current = current,
|
||||
Power = current.Value * voltage.Value,
|
||||
};
|
||||
|
||||
public static DcBus Null => FromVoltageCurrent(0, 0);
|
||||
public static DcBus Null => new()
|
||||
{
|
||||
Voltage = 0,
|
||||
Current = 0,
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue