diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs b/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs index a6e16a6e0ad50d067472dea23de0e76c27f6328b..b06f9f3f5987c6dc8771cb9fe358693188d2f079 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs @@ -425,6 +425,11 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl get { return Driver != null ? Driver.DriverAcceleration : 0.SI<MeterPerSquareSecond>(); } } + public Radian RoadGradient + { + get { return DrivingCycle.RoadGradient; } + } + public Meter CycleStartDistance { get { return DrivingCycle == null ? 0.SI<Meter>() : DrivingCycle.CycleStartDistance; } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/IDriverActions.cs b/VectoCore/VectoCore/Models/SimulationComponent/IDriverActions.cs index d76fbcf6059e766e6eeede5268112a54309af9f9..aba54b2fcfe60dfebdd8b95a091c82ed7bf4f687 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/IDriverActions.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/IDriverActions.cs @@ -32,6 +32,7 @@ using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Models.Simulation.DataBus; +using TUGraz.VectoCore.Models.SimulationComponent.Impl; using DriverData = TUGraz.VectoCore.Models.SimulationComponent.Data.DriverData; namespace TUGraz.VectoCore.Models.SimulationComponent @@ -83,12 +84,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent /// <param name="gradient"></param> /// <param name="previousResponse"></param> /// <param name="targetDistance"></param> + /// <param name="overrideAction"></param> /// <returns> /// * ResponseSuccess /// * ResponseDrivingCycleDistanceExceeded: vehicle is at low speed, coasting would lead to stop before ds is reached. /// </returns> IResponse DrivingActionBrake(Second absTime, Meter ds, MeterPerSecond nextTargetSpeed, Radian gradient, - IResponse previousResponse = null, Meter targetDistance = null); + IResponse previousResponse = null, Meter targetDistance = null, DrivingAction? overrideAction = null); /// <summary> /// perform a 'roll driving action', i.e., the clutch is open and the vehicle rolls without motoring. adjust the acceleration diff --git a/VectoCore/VectoCore/Models/SimulationComponent/IDrivingCycleInfo.cs b/VectoCore/VectoCore/Models/SimulationComponent/IDrivingCycleInfo.cs index 71bde5add4566bebeb517e7a7ac5904b38983b4e..b1dbbb4f80c0174ba57eee7e5960fd88361cad69 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/IDrivingCycleInfo.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/IDrivingCycleInfo.cs @@ -58,6 +58,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent Meter Altitude { get; } + Radian RoadGradient { get; } + Meter CycleStartDistance { get; } IReadOnlyList<DrivingCycleData.DrivingCycleEntry> LookAhead(Meter lookaheadDistance); diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs index 054ad5684ae6f6cb12421b0b1af067c0a0dfde0f..fd02cf2bd42d33cd595ee6bdfc4da56284d6ab83 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs @@ -653,7 +653,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl response = Driver.DrivingActionAccelerate(absTime, ds, 1.KMPHtoMeterPerSecond(), gradient); if (response is ResponseUnderload) { - response = Driver.DrivingActionBrake(absTime, ds, 1.KMPHtoMeterPerSecond(), gradient, response); + response = Driver.DrivingActionBrake(absTime, ds, 1.KMPHtoMeterPerSecond(), gradient, response, overrideAction: DrivingAction.Accelerate); } } else { response = Driver.DrivingActionBrake( diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs index 41e0fb4be6976c8745d39aa031a137a0ed98bd66..880d2db7d8ac22de7b86a3b5016edb79606cbf36 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs @@ -496,6 +496,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl get { return PreviousState.Altitude; } } + public Radian RoadGradient { get { return CurrentState.Gradient; } } + + public sealed class DrivingCycleState { public DrivingCycleState Clone() diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs index 34bfd9b2a0b0fd7f05b59f4b23d6c63927da96b3..6427763daa34ba797f3aa2d1ebc0dcddc63e681e 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs @@ -478,10 +478,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return response; } - public IResponse DrivingActionBrake(Second absTime, Meter ds, MeterPerSecond nextTargetSpeed, Radian gradient, - IResponse previousResponse = null, Meter targetDistance = null) + public IResponse DrivingActionBrake(Second absTime, Meter ds, MeterPerSecond nextTargetSpeed, Radian gradient, IResponse previousResponse = null, Meter targetDistance = null, DrivingAction? overrideAction = null) { - DrivingAction = DrivingAction.Brake; + DrivingAction = overrideAction ?? DrivingAction.Brake; IterationStatistics.Increment(this, "Brake"); Log.Debug("DrivingAction Brake"); diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs index 94d3d8bab43761a9d847a0d2bfc625887494c983..be70c77dcf9df2ef01752b2b8dfef8623bea7ac3 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs @@ -209,6 +209,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var halted = DataBus.DrivingAction == DrivingAction.Halt; var driverDeceleratingNegTorque = DataBus.DriverBehavior == DrivingBehavior.Braking && DataBus.DrivingAction == DrivingAction.Brake && + (DataBus.RoadGradient.IsSmaller(0) || inAngularVelocity.IsSmaller(DataBus.EngineIdleSpeed)) && (DataBus.BrakePower.IsGreater(0) || inTorque.IsSmaller(0)); var vehiclespeedBelowThreshold = DataBus.VehicleSpeed.IsSmaller(Constants.SimulationSettings.ClutchDisengageWhenHaltingSpeed); diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/MeasuredSpeedDrivingCycle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/MeasuredSpeedDrivingCycle.cs index 488de7cd83ca88aacc05da9ab59ce649b8abcd62..0a034b7e93eaa53ebd17c094e564eb3c74483406 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/MeasuredSpeedDrivingCycle.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/MeasuredSpeedDrivingCycle.cs @@ -360,6 +360,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl get { return CycleIterator.LeftSample.Altitude; } } + public Radian RoadGradient { get { return CycleIterator.LeftSample.RoadGradient; } } + public Meter CycleStartDistance { get { return 0.SI<Meter>(); } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs index 8ab87a9c102d883a436ec4923fe447674cf7320a..ca9a5ad198b6e16e81e7c6636a81eb11455996df 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs @@ -203,6 +203,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl get { return 0.SI<Meter>(); } } + public Radian RoadGradient { get { return 0.SI<Radian>(); } } + public Meter CycleStartDistance { get { return 0.SI<Meter>(); } diff --git a/VectoCore/VectoCoreTest/Integration/FuelTypesTest.cs b/VectoCore/VectoCoreTest/Integration/FuelTypesTest.cs index 46175a7e039a206a00604509594548d8a58c53e5..d8c0b996ded59c547da700cbb9fe1a38fdb900e5 100644 --- a/VectoCore/VectoCoreTest/Integration/FuelTypesTest.cs +++ b/VectoCore/VectoCoreTest/Integration/FuelTypesTest.cs @@ -40,6 +40,7 @@ using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.Simulation.Impl; using TUGraz.VectoCore.OutputData; using TUGraz.VectoCore.OutputData.FileIO; +using TUGraz.VectoCore.Tests.Utils; namespace TUGraz.VectoCore.Tests.Integration { @@ -57,45 +58,45 @@ namespace TUGraz.VectoCore.Tests.Integration [Category("LongRunning")] [Category("Integration")] [TestCase(FuelType.DieselCI, null, - @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 0, - 0.0002199424, 0.0002199424, 26.3060719, 0.0006886, 9390.531125, + @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 0, + 0.000219919455699735, 0.000219919455699735, 26.3061549880066, 0.000688347896340172, 9390.5607583787, TestName = "Diesel LH Low"), TestCase(FuelType.EthanolCI, null, @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 0, - 0.0002199424, 0.0002225401, 27.136125, 0.000402797, 5651.912176, + 0.000219919455699735, 0.000222516929585952, 27.1362109251161, 0.000402755642550574, 5651.93001148319, TestName = "Ethanol/CI LH Low"), TestCase(FuelType.DieselCI, null, @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 1, - 0.0002547295, 0.0002547295, 30.4611849, 0.0007971, 10873.790098, + 0.000254656206506391, 0.000254656206506391, 30.4612687208601, 0.000797073926365003, 10873.8200178229, TestName = "Diesel LH Ref"), TestCase(FuelType.EthanolCI, null, @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 1, - 0.0002547295, 0.000257738, 31.4223473, 0.00046650, 6544.646499, + 0.000254656206506391, 0.000257663956976937, 31.4224337776753, 0.000466371762128257, 6544.66450721421, TestName = "Ethanol/CI LH Ref"), TestCase(FuelType.EthanolPI, null, @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 1, - 0.0002547295, 0.00025299078, 32.17776628, 0.0005312806, 7410.475219, + 0.000254656206506391, 0.000252917938885187, 32.1778548199983, 0.000531127671658892, 7410.49560933597, TestName = "Ethanol/PI LH Ref"), TestCase(FuelType.PetrolPI, null, @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 1, - 0.0002547295, 0.00025472954, 34.0448537, 0.0007743778, 10568.203491, + 0.000254656206506391, 0.000254656206506391, 34.0449473939025, 0.000774154867779428, 10568.2325700152, TestName = "Petrol/PI LH Ref"), TestCase(FuelType.LPGPI, null, @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 1, - 0.0002547295, 0.0002547295, double.NaN, 0.00076928, 11714.1532673, + 0.000254656206506391, 0.000254656206506391, null, 0.0007690617436493, 11714.185499294, TestName = "LPG/PI LH Ref"), TestCase(FuelType.NGPI, TankSystem.Liquefied, @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 1, - 0.0002547295, 0.00023397765, double.NaN, 0.00064811809, 11484.963312, + 0.000254656206506391, 0.000233910283369414, null, 0.000647931484933277, 11484.9949134382, TestName = "LNG/PI LH Ref"), TestCase(FuelType.NGPI, TankSystem.Compressed, @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 1, - 0.0002547295, 0.0002393396, double.NaN, 0.000643823, 11484.963312, + 0.000254656206506391, 0.000239270727363297, null, 0.00064363825660727, 11484.9949134383, TestName = "CNG/PI LH Ref"), ] public void TestFuelTypesCO2(FuelType fuelType, TankSystem? tankSystem, string jobName, int runIdx, - double expectedFCMap, double expectedFCFinal, double expectedFCperkm, double expectedCo2, double expectedMJ) + double expectedFCMap, double expectedFCFinal, double? expectedFCperkm, double expectedCo2, double expectedMJ) { // the same engine fc-map is used for different fuel types, thus the difference in expected results var fileWriter = new FileOutputWriter(jobName); @@ -125,19 +126,20 @@ namespace TUGraz.VectoCore.Tests.Integration // restore data table before assertions modContainer.Data = modData; - Console.WriteLine("FC-Map g/m: {0}, FC-Final g/m {1}, FC-Final l/100km: {2}, CO2 g/m: {3}, Energy J/m: {4}", +// Console.WriteLine("FC-Map g/m: {0}, FC-Final g/m {1}, FC-Final l/100km: {2}, CO2 g/m: {3}, Energy J/m: {4}", + Console.WriteLine("{0}, {1}, {2}, {3}, {4}", modContainer.FCMapPerMeter().Value(), modContainer.FuelConsumptionFinal().Value(), modContainer.FuelConsumptionFinalVolumePerMeter()?.ConvertToLiterPer100Kilometer().Value ?? double.NaN, modContainer.CO2PerMeter().Value(), modContainer.EnergyPerMeter().Value()); - Assert.AreEqual(expectedFCMap, modContainer.FCMapPerMeter().Value(), 1e-6); - Assert.AreEqual(expectedFCFinal, modContainer.FuelConsumptionFinal().Value(), 1e-3); - Assert.AreEqual(expectedFCperkm, modContainer.FuelConsumptionFinalVolumePerMeter()?.ConvertToLiterPer100Kilometer().Value ?? double.NaN, 1e-6); - - Assert.AreEqual(expectedCo2, modContainer.CO2PerMeter().Value(), 1e-6); - Assert.AreEqual(expectedMJ, modContainer.EnergyPerMeter().Value(), 1e-3); + AssertHelper.AreRelativeEqual(expectedFCMap, modContainer.FCMapPerMeter(), 1e-6); + AssertHelper.AreRelativeEqual(expectedFCFinal, modContainer.FuelConsumptionFinal(), 1e-3); + AssertHelper.AreRelativeEqual(expectedFCperkm, modContainer.FuelConsumptionFinalVolumePerMeter()?.ConvertToLiterPer100Kilometer().Value.SI() ?? null, 1e-6); + + AssertHelper.AreRelativeEqual(expectedCo2, modContainer.CO2PerMeter(), 1e-6); + AssertHelper.AreRelativeEqual(expectedMJ, modContainer.EnergyPerMeter(), 1e-3); } } } diff --git a/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs b/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs index 1aedb2dd045d98a72e5f17086cf40a0af250b962..dda8efaba41e5777d674b9f572e52defadc6d066 100644 --- a/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs +++ b/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs @@ -257,10 +257,10 @@ namespace TUGraz.VectoCore.Tests.Integration Console.WriteLine(string.Join("; ", view.AsEnumerable().Select(x => x[SummaryDataContainer.FCMAP_KM].ToString().ToDouble()))); Assert.AreEqual(201.39195, view.Rows[0][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); Assert.AreEqual(239.28546, view.Rows[1][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); - Assert.AreEqual(170.11718, view.Rows[2][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); - Assert.AreEqual(183.02680, view.Rows[3][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); - Assert.AreEqual(224.07271, view.Rows[4][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); - Assert.AreEqual(254.35646, view.Rows[5][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); + Assert.AreEqual(170.15249, view.Rows[2][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); + Assert.AreEqual(183.06219, view.Rows[3][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); + Assert.AreEqual(224.26907, view.Rows[4][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); + Assert.AreEqual(254.53269, view.Rows[5][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); } [TestCase(EngineSpeedLimitJobATDecl)] diff --git a/VectoCore/VectoCoreTest/Utils/MockAuxiliaryDemand.cs b/VectoCore/VectoCoreTest/Utils/MockAuxiliaryDemand.cs index 5727095d70e2a35e696b988d5f994f322a63b3c6..e7c52d8c318860e4c37b8e294608746647bbf0e0 100644 --- a/VectoCore/VectoCoreTest/Utils/MockAuxiliaryDemand.cs +++ b/VectoCore/VectoCoreTest/Utils/MockAuxiliaryDemand.cs @@ -88,6 +88,8 @@ namespace TUGraz.VectoCore.Tests.Utils get { return 0.SI<Meter>(); } } + public Radian RoadGradient { get { return 0.SI<Radian>(); } } + protected override void DoWriteModalResults(IModalDataContainer container) { container[ModalResultField.dist] = 0.SI<Meter>(); diff --git a/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs b/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs index 51429c000ea7a3c1b2157a1a7eeac4949e5e1808..297349fcf063bb586cc9dfbcc53c906c9c866af0 100644 --- a/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs +++ b/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs @@ -163,6 +163,7 @@ namespace TUGraz.VectoCore.Tests.Utils } public Watt BrakePower { get; set; } + public Radian RoadGradient { get; set; } public Meter CycleStartDistance { get; set; } public IReadOnlyList<DrivingCycleData.DrivingCycleEntry> LookAhead(Meter lookaheadDistance)