From b133466576e63ceb60c72ddaaeefeb1e67cee646 Mon Sep 17 00:00:00 2001 From: Markus Quaritsch <Markus.Quaritsch@tugraz.at> Date: Wed, 18 Mar 2020 13:22:19 +0100 Subject: [PATCH] reading electric components of hybrid vehicle works in testcase --- .gitignore | 1 + .../VectoCommon/Models/PowertrainPosition.cs | 14 +++- .../VectoCore/Configuration/Constants.cs | 4 ++ .../FileIO/JSON/JSONComponentInputData.cs | 6 ++ .../FileIO/JSON/JSONInputDataFactory.cs | 2 + .../InputData/FileIO/JSON/JSONVehicleData.cs | 65 +++++++++++++++++-- VectoCore/VectoCore/Utils/VectoVersionCore.cs | 2 +- .../FileIO/JsonReadHybridTest.cs | 34 +++++++++- .../Class2_RigidTruck.vveh | 13 ++-- .../GenericBattery.vbat | 2 +- 10 files changed, 127 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 9020d964ab..b28bbafcb4 100644 --- a/.gitignore +++ b/.gitignore @@ -208,3 +208,4 @@ DISTR/ EPTP/ 201*-VECTO-*.zip Documentation/VehiclesReleaseComparisonDeclarationMode/tmp/ +.vs/ diff --git a/VectoCommon/VectoCommon/Models/PowertrainPosition.cs b/VectoCommon/VectoCommon/Models/PowertrainPosition.cs index ce5aeb6d81..de65b8ae9c 100644 --- a/VectoCommon/VectoCommon/Models/PowertrainPosition.cs +++ b/VectoCommon/VectoCommon/Models/PowertrainPosition.cs @@ -1,4 +1,6 @@ -namespace TUGraz.VectoCommon.InputData { +using TUGraz.VectoCommon.Utils; + +namespace TUGraz.VectoCommon.InputData { public enum PowertrainPosition { HybridP0, @@ -7,4 +9,14 @@ HybridP3, HybridP4 } + + public static class PowertrainPositionHelper + { + public const string Prefix = "Hybrid"; + + public static PowertrainPosition Parse(string pos) + { + return (Prefix + pos).ParseEnum<PowertrainPosition>(); + } + } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Configuration/Constants.cs b/VectoCore/VectoCore/Configuration/Constants.cs index e557706113..de6a563b80 100644 --- a/VectoCore/VectoCore/Configuration/Constants.cs +++ b/VectoCore/VectoCore/Configuration/Constants.cs @@ -237,6 +237,10 @@ namespace TUGraz.VectoCore.Configuration public const string GearshiftDataFile = ".vtcu"; + public const string BatteryFile = ".vbat"; + + public const string ElectricMotorFile = ".vem"; + public const string CycleFile = ".vdri"; public const string DriverAccelerationCurve = ".vacc"; diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONComponentInputData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONComponentInputData.cs index fcf915d548..d1d81a5a9f 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONComponentInputData.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONComponentInputData.cs @@ -81,6 +81,12 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON case Constants.FileExtensions.GearshiftDataFile: tmp = JSONInputDataFactory.ReadShiftParameters(filename, tolerateMissing); break; + case Constants.FileExtensions.BatteryFile: + tmp = JSONInputDataFactory.ReadBatteryData(filename, tolerateMissing); + break; + case Constants.FileExtensions.ElectricMotorFile: + tmp = JSONInputDataFactory.ReadElectricMotorData(filename, tolerateMissing); + break; } tmp.Switch() diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs index 7e6fdce660..43fc1239df 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs @@ -111,6 +111,8 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON return new JSONVehicleDataV8(json, filename, job, tolerateMissing); case 9: return new JSONVehicleDataV9(json, filename, job, tolerateMissing); + case 10: + return new JSONVehicleDataV10(json, filename, job, tolerateMissing); default: throw new VectoException("Vehicle-File: Unsupported FileVersion. Got {0}", version); } diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONVehicleData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONVehicleData.cs index a9c22669f9..03226f48b9 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONVehicleData.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONVehicleData.cs @@ -48,6 +48,9 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON { public class JSONVehicleDataV10 : JSONVehicleDataV9 { + private JSONElectricStorageEngineeringInputData _batteries; + private JSONElectricMotors _electricMotors; + public JSONVehicleDataV10(JObject data, string fileName, IJSONVehicleComponents job, bool tolerateMissing = false) : base(data, fileName, job, tolerateMissing) { } @@ -55,19 +58,73 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON protected override IElectricMachinesEngineeringInputData GetElectricMachines() { - // TODO! - throw new NotImplementedException(); + return _electricMotors ?? (_electricMotors = ReadMotors()); } protected override IElectricStorageEngineeringInputData GetElectricStorage() { - // TODO! - throw new NotImplementedException(); + return _batteries ?? (_batteries = ReadBatteries()); + } + + protected virtual JSONElectricMotors ReadMotors() + { + var retVal = new List<ElectricMachineEntry<IElectricMotorEngineeringInputData>>(); + foreach (var entry in Body["ElectricMotors"]) + { + var tmp = new ElectricMachineEntry<IElectricMotorEngineeringInputData>() + { + Position = PowertrainPositionHelper.Parse(entry.GetEx<string>("Position")), + Count = entry.GetEx<int>("Count"), + ElectricMachine = JSONInputDataFactory.ReadElectricMotorData(Path.Combine(BasePath, entry.GetEx<string>("MotorFile")), false) + }; + retVal.Add(tmp); + } + + return new JSONElectricMotors(retVal); + } + + + protected virtual JSONElectricStorageEngineeringInputData ReadBatteries() + { + return new JSONElectricStorageEngineeringInputData() { + Count = Body["Battery"].GetEx<int>("NumPacks"), + BatteryPack = JSONInputDataFactory.ReadBatteryData(Path.Combine(BasePath, Body["Battery"].GetEx<string>("BatteryFile")), false) + }; } #endregion } + public class JSONElectricMotors : IElectricMachinesEngineeringInputData { + private readonly IList<ElectricMachineEntry<IElectricMotorEngineeringInputData>> _entries; + + public JSONElectricMotors(List<ElectricMachineEntry<IElectricMotorEngineeringInputData>> entries) + { + _entries = entries; + } + + IList<ElectricMachineEntry<IElectricMotorDeclarationInputData>> IElectricMachinesDeclarationInputData.Entries + { + get { return _entries.Cast<ElectricMachineEntry<IElectricMotorDeclarationInputData>>().ToList(); } + //get { return null; } + } + + public virtual IList<ElectricMachineEntry<IElectricMotorEngineeringInputData>> Entries + { + get { return _entries; } + } + } + + public class JSONElectricStorageEngineeringInputData : IElectricStorageEngineeringInputData { + IBatteryPackDeclarationInputData IElectricStorageDeclarationInputData.BatteryPack + { + get { return BatteryPack; } + } + + public IBatteryPackEngineeringInputData BatteryPack { get; internal set; } + public int Count { get; internal set; } + } + // ################################################################### // ################################################################### diff --git a/VectoCore/VectoCore/Utils/VectoVersionCore.cs b/VectoCore/VectoCore/Utils/VectoVersionCore.cs index 3798ec4c6e..17f1333633 100644 --- a/VectoCore/VectoCore/Utils/VectoVersionCore.cs +++ b/VectoCore/VectoCore/Utils/VectoVersionCore.cs @@ -47,7 +47,7 @@ namespace TUGraz.VectoCore.Utils public static string VersionNumber { get { - return "0.6.0.1884" + SUFFIX; + return "0.6.0.1901" + SUFFIX; } } diff --git a/VectoCore/VectoCoreTest/FileIO/JsonReadHybridTest.cs b/VectoCore/VectoCoreTest/FileIO/JsonReadHybridTest.cs index 9baa043994..ef6341f1ac 100644 --- a/VectoCore/VectoCoreTest/FileIO/JsonReadHybridTest.cs +++ b/VectoCore/VectoCoreTest/FileIO/JsonReadHybridTest.cs @@ -1,5 +1,6 @@ using System.IO; using NUnit.Framework; +using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.InputData.FileIO.JSON; using TUGraz.VectoCore.InputData.Reader.ComponentData; @@ -54,8 +55,8 @@ namespace TUGraz.VectoCore.Tests.FileIO Assert.AreEqual("-401.07", fld.Rows[0][ElectricFullLoadCurveReader.Fields.GenerationTorque]); var fldMap = ElectricFullLoadCurveReader.Create(fld); - Assert.AreEqual(401.07, fldMap.FullLoadDriveTorque(0.RPMtoRad()).Value()); - Assert.AreEqual(-407.07, fldMap.FullGenerationTorque(0.RPMtoRad()).Value()); + Assert.AreEqual(-401.07, fldMap.FullLoadDriveTorque(0.RPMtoRad()).Value()); + Assert.AreEqual(401.07, fldMap.FullGenerationTorque(0.RPMtoRad()).Value()); var pwr = inputProvider.EfficiencyMap; Assert.AreEqual("0", pwr.Rows[0][ElectricMotorMapReader.Fields.MotorSpeed]); @@ -63,8 +64,35 @@ namespace TUGraz.VectoCore.Tests.FileIO Assert.AreEqual("9.8449", pwr.Rows[0][ElectricMotorMapReader.Fields.PowerElectrical]); var pwrMap = ElectricMotorMapReader.Create(pwr); - Assert.AreEqual(9844.9, pwrMap.LookupElectricPower(-0.RPMtoRad(), -800.SI<NewtonMeter>()).ElectricalPower.Value()); + Assert.AreEqual(-10171.0, pwrMap.LookupElectricPower(-0.RPMtoRad(), -800.SI<NewtonMeter>()).ElectricalPower.Value()); } + + [TestCase()] + public void TestReadHybridVehicle() + { + var inputProvider = JSONInputDataFactory.ReadJsonJob(@"TestData\Hybrids\GenericVehicle_Group2_P2\Class2_RigidTruck_ParHyb_ENG.vecto"); + + var engineering = inputProvider as IEngineeringInputDataProvider; + + Assert.NotNull(engineering); + + var bat = engineering.JobInputData.Vehicle.Components.ElectricStorage; + + Assert.NotNull(bat); + Assert.AreEqual(2, bat.Count); + Assert.AreEqual(5, bat.BatteryPack.MaxCurrentFactor); + Assert.AreEqual(0.12, bat.BatteryPack.InternalResistance.Value()); + + var em = engineering.JobInputData.Vehicle.Components.ElectricMachines; + + Assert.NotNull(em); + Assert.AreEqual(1, em.Entries.Count); + + Assert.AreEqual(PowertrainPosition.HybridP2, em.Entries[0].Position); + + Assert.AreEqual(0.15, em.Entries[0].ElectricMachine.Inertia.Value()); + + } } } \ No newline at end of file diff --git a/VectoCore/VectoCoreTest/TestData/Hybrids/GenericVehicle_Group2_P2/Class2_RigidTruck.vveh b/VectoCore/VectoCoreTest/TestData/Hybrids/GenericVehicle_Group2_P2/Class2_RigidTruck.vveh index 4ad2695224..b2cb739b7a 100644 --- a/VectoCore/VectoCoreTest/TestData/Hybrids/GenericVehicle_Group2_P2/Class2_RigidTruck.vveh +++ b/VectoCore/VectoCoreTest/TestData/Hybrids/GenericVehicle_Group2_P2/Class2_RigidTruck.vveh @@ -3,7 +3,7 @@ "CreatedBy": "", "Date": "2017-07-13T14:14:29.3226830Z", "AppVersion": "3", - "FileVersion": 7 + "FileVersion": 10 }, "Body": { "SavedInDeclMode": false, @@ -32,16 +32,17 @@ "LossMap": "", "Cycle": "" }, - "ElectricMotors": { - [ + "ElectricMotors": [ + { + "Count": 1, "Position": "P2", "MotorFile": "GenericEMotor240kW.vem" + } ], - }, - "Battery": { + "Battery": { "NumPacks": 2, "BatteryFile": "GenericBattery.vbat", - } + }, "TorqueLimits": {}, "IdlingSpeed": 0.0, "AxleConfig": { diff --git a/VectoCore/VectoCoreTest/TestData/Hybrids/GenericVehicle_Group2_P2/GenericBattery.vbat b/VectoCore/VectoCoreTest/TestData/Hybrids/GenericVehicle_Group2_P2/GenericBattery.vbat index 245d582805..1aa2c2ac95 100644 --- a/VectoCore/VectoCoreTest/TestData/Hybrids/GenericVehicle_Group2_P2/GenericBattery.vbat +++ b/VectoCore/VectoCoreTest/TestData/Hybrids/GenericVehicle_Group2_P2/GenericBattery.vbat @@ -8,7 +8,7 @@ "Body": { "SavedInDeclMode": false, "Model": "Generic Battery", - "InternalResistance": 1.1, + "InternalResistance": 0.12, "SOC_min": 20, "SOC_max": 80, "MaxCurrentFactor": 5, -- GitLab