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