diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs index 64e98f3945a2dfdddaba984e9cc60680d19d4523..fc9023c56f85bcadb529dbc2723a0c2b3a6ac4f6 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs @@ -181,8 +181,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var avgEngineSpeed = (PreviousState.EngineSpeed + angularVelocity) / 2.0; - var engineSpeedLimit = VectoMath.Min(DataBus.GetGearData(DataBus.Gear).MaxSpeed, - ModelData.FullLoadCurves[0].N95hSpeed); + var engineSpeedLimit = GetEngineSpeedLimit(); if (!dryRun && avgEngineSpeed.IsGreater(engineSpeedLimit, Constants.SimulationSettings.LineSearchTolerance)) { return new ResponseEngineSpeedTooHigh() { DeltaEngineSpeed = avgEngineSpeed - engineSpeedLimit }; } @@ -294,6 +293,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl }; } + protected virtual PerSecond GetEngineSpeedLimit() + { + return DataBus.Gear == 0 + ? ModelData.FullLoadCurves[0].N95hSpeed + : VectoMath.Min(DataBus.GetGearData(DataBus.Gear).MaxSpeed, + ModelData.FullLoadCurves[0].N95hSpeed); + } + private NewtonMeter ComputeDelta(NewtonMeter torqueOut, NewtonMeter totalTorqueDemand, NewtonMeter maxEngineTorque) { var deltaEngine = totalTorqueDemand - maxEngineTorque; @@ -577,7 +584,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl nextAngularSpeed = velocitySlope < 0 ? VectoMath.LimitTo(VectoMath.Max(_engineTargetSpeed, nextAngularSpeed), _engine.EngineIdleSpeed, engineMaxSpeed) : VectoMath.LimitTo(VectoMath.Min(_engineTargetSpeed, nextAngularSpeed), _engine.EngineIdleSpeed, engineMaxSpeed); - + var retVal = RequestPort.Request(absTime, dt, 0.SI<NewtonMeter>(), nextAngularSpeed); retVal.Switch(). diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/EngineOnlyCombustionEngine.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/EngineOnlyCombustionEngine.cs index dd481bd07eecc0a64e8a5c7eb35d8235d1dec592..9837ac690fae6f9fe70274b97260d0db795003ba 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/EngineOnlyCombustionEngine.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/EngineOnlyCombustionEngine.cs @@ -109,5 +109,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } return requestedEngineTorque; } + + protected override PerSecond GetEngineSpeedLimit() + { + return ModelData.FullLoadCurves[0].N95hSpeed; + } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/MeasuredSpeedDrivingCycle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/MeasuredSpeedDrivingCycle.cs index 948ab95cd8ec8ae326092065f59e54ceeaa9235a..d10714a91db57a2f0b5dba905a63cfd83620cfea 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/MeasuredSpeedDrivingCycle.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/MeasuredSpeedDrivingCycle.cs @@ -211,8 +211,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl y => ((ResponseDryRun)y).DeltaFullLoad.Value()); Log.Info( "Found operating point for driver acceleration. absTime: {0}, dt: {1}, acceleration: {2}, gradient: {3}", - absTime, - dt, acceleration, gradient); + absTime, dt, acceleration, gradient); } else { DataBus.BrakePower = SearchAlgorithm.Search(DataBus.BrakePower, r.Delta, -r.Delta, getYValue: result => DataBus.ClutchClosed(absTime) @@ -243,6 +242,17 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } response = NextComponent.Request(absTime, dt, acceleration, gradient); }) + .Case<ResponseEngineSpeedTooHigh>(r => { + acceleration = SearchAlgorithm.Search(acceleration, r.DeltaEngineSpeed, + Constants.SimulationSettings.OperatingPointInitialSearchIntervalAccelerating, + getYValue: result => ((ResponseDryRun)result).DeltaEngineSpeed, + evaluateFunction: x => NextComponent.Request(absTime, dt, x, gradient, true), + criterion: + y => ((ResponseDryRun)y).DeltaEngineSpeed.Value()); + Log.Info( + "Found operating point for driver acceleration. absTime: {0}, dt: {1}, acceleration: {2}, gradient: {3}", + absTime, dt, acceleration, gradient); + }) .Case<ResponseFailTimeInterval>(r => { dt = r.DeltaT; }) .Case<ResponseSuccess>() .Default( diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs index 4832ec5296cf0bcc37b5aa98131841b10a4e4ab0..65ce76834398b6ba575563cedabd0c337d5ae69e 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs @@ -35,6 +35,7 @@ using System.Linq; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Connector.Ports.Impl; using TUGraz.VectoCore.Models.Simulation; @@ -117,7 +118,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl debug.Add(response); response.Switch() .Case<ResponseGearShift>( - () => response = NextComponent.Request(absTime, dt, CycleIterator.LeftSample.Torque, angularVelocity)) + () => response = NextComponent.Request(absTime, dt, CurrentState.InTorque, angularVelocity)) .Case<ResponseUnderload>(r => { var torqueInterval = -r.Delta / (angularVelocity.IsEqual(0) ? 10.RPMtoRad() : angularVelocity); var torque = SearchAlgorithm.Search(CycleIterator.LeftSample.Torque, r.Delta, torqueInterval, @@ -135,6 +136,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl response = NextComponent.Request(absTime, dt, torque, angularVelocity); CurrentState.InAngularVelocity = angularVelocity; }) + .Case<ResponseEngineSpeedTooHigh>(r => { + angularVelocity = SearchAlgorithm.Search(angularVelocity, r.DeltaEngineSpeed, + 1.RPMtoRad(), + getYValue: result => ((ResponseDryRun)result).DeltaEngineSpeed, + evaluateFunction: x => NextComponent.Request(absTime, dt, CurrentState.InTorque, x, true), + criterion: y => ((ResponseDryRun)y).DeltaEngineSpeed.Value()); + }) .Case<ResponseFailTimeInterval>(r => { dt = r.DeltaT; }) .Case<ResponseSuccess>(() => { }) .Default( diff --git a/VectoCore/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs b/VectoCore/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs index 526abde344b684bb0779dacf8f023fb3c42b64ca..d42b318eaa33afb36e2f5748be2ec101ca80fdc9 100644 --- a/VectoCore/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs +++ b/VectoCore/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs @@ -115,6 +115,7 @@ namespace TUGraz.VectoCore.Tests.Integration.EngineOnlyCycle var vehicleContainer = new VehicleContainer(ExecutionMode.Engineering); var engine = new CombustionEngine(vehicleContainer, MockSimulationDataFactory.CreateEngineDataFromFile(EngineFile, 0)); + var gbx = new MockGearbox(vehicleContainer) { Gear = 0 }; var absTime = 0.SI<Second>(); var dt = 1.SI<Second>(); diff --git a/VectoCore/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs b/VectoCore/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs index 2a146114e36ab6db148716dc47b2df1df6c413ab..78407f374984ceec6544456c5e62770527eda0b9 100644 --- a/VectoCore/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs +++ b/VectoCore/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs @@ -78,6 +78,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var vehicle = new VehicleContainer(ExecutionMode.Engineering); var engineData = MockSimulationDataFactory.CreateEngineDataFromFile(CoachEngine, 0); var engine = new CombustionEngine(vehicle, engineData); + var gearbox = new MockGearbox(vehicle) { Gear = 0 }; var port = engine.OutPort(); @@ -94,8 +95,9 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent public void TestSimpleModalData() { var vehicle = new VehicleContainer(ExecutionMode.Engineering); - var engineData = MockSimulationDataFactory.CreateEngineDataFromFile(CoachEngine,0); + var engineData = MockSimulationDataFactory.CreateEngineDataFromFile(CoachEngine, 0); var engine = new CombustionEngine(vehicle, engineData); + var gearbox = new MockGearbox(vehicle) { Gear = 0 }; var port = engine.OutPort(); var absTime = 0.SI<Second>(); @@ -220,6 +222,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var vehicleContainer = new VehicleContainer(ExecutionMode.Engineering); var engineData = MockSimulationDataFactory.CreateEngineDataFromFile(engineFile, 0); var engine = new CombustionEngine(vehicleContainer, engineData); + var gearbox = new MockGearbox(vehicleContainer) { Gear = 0 }; var expectedResults = VectoCSVFile.Read(resultFile); diff --git a/VectoCore/VectoCoreTest/Utils/MockGearbox.cs b/VectoCore/VectoCoreTest/Utils/MockGearbox.cs index 00395fdcde6fcb062581214181760b162a610dec..b3ca3392532ec7fe1a8ff07bf402b673762d2464 100644 --- a/VectoCore/VectoCoreTest/Utils/MockGearbox.cs +++ b/VectoCore/VectoCoreTest/Utils/MockGearbox.cs @@ -70,7 +70,7 @@ namespace TUGraz.VectoCore.Tests.Utils get { return 1.SI<Second>(); } } - public uint NumGears { get; set; } + public uint NumGears { get; set; } public MeterPerSecond StartSpeed { @@ -96,7 +96,7 @@ namespace TUGraz.VectoCore.Tests.Utils public GearData GetGearData(uint gear) { - throw new NotImplementedException(); + return new GearData(); } public void Connect(ITnOutPort other)