From d2dddc4d7037fa7cdecb7061a35902cdcceff464 Mon Sep 17 00:00:00 2001 From: Markus Quaritsch <markus.quaritsch@tugraz.at> Date: Tue, 8 Sep 2015 16:03:13 +0200 Subject: [PATCH] more work on braking testcase --- .../Models/SimulationComponent/Impl/Clutch.cs | 2 +- .../Impl/DefaultDriverStrategy.cs | 7 ++++--- .../Impl/DistanceBasedDrivingCycle.cs | 4 ++-- .../Models/SimulationComponent/Impl/Driver.cs | 14 ++++++-------- .../Models/SimulationComponent/Impl/Gearbox.cs | 7 +++++++ .../DriverStrategy/DriverStrategyTest.cs | 10 +++++----- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/VectoCore/Models/SimulationComponent/Impl/Clutch.cs b/VectoCore/Models/SimulationComponent/Impl/Clutch.cs index c507bede2f..e977fe1c6f 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Clutch.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Clutch.cs @@ -101,7 +101,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl //} else { var engineSpeedNorm = (angularVelocity - _idleSpeed) / (_ratedSpeed - _idleSpeed); - if (engineSpeedNorm < Constants.SimulationSettings.CluchNormSpeed) { + if (DataBus.Gear == 1 && engineSpeedNorm < Constants.SimulationSettings.CluchNormSpeed) { _clutchState = SimulationComponent.ClutchState.ClutchSlipping; var engineSpeed0 = VectoMath.Max(_idleSpeed, angularVelocity); diff --git a/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs b/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs index c2bd91d43a..d1208a2748 100644 --- a/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs +++ b/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs @@ -147,7 +147,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl //===================================== - public class DriverModeDrive : IDriverMode + public class DriverModeDrive : LoggingObject, IDriverMode { public DefaultDriverStrategy DriverStrategy { get; set; } @@ -184,7 +184,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl //===================================== - public class DriverModeBrake : IDriverMode + public class DriverModeBrake : LoggingObject, IDriverMode { protected enum BrakingPhase { @@ -221,6 +221,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var currentDistance = DriverStrategy.Driver.DataBus.Distance; if (Phase == BrakingPhase.Coast) { var breakingDistance = DriverStrategy.Driver.ComputeDecelerationDistance(DriverStrategy.BrakeTrigger.NextTargetSpeed); + Log.Info("breaking distance: {0}", breakingDistance); if (currentDistance + ds > DriverStrategy.BrakeTrigger.TriggerDistance - breakingDistance) { return new ResponseDrivingCycleDistanceExceeded() { MaxDistance = DriverStrategy.BrakeTrigger.TriggerDistance - breakingDistance - currentDistance @@ -250,7 +251,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl gradient); break; } - // todo: @@@quam: add resonse.switch to indicate expected responses? + return response; } diff --git a/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs index 114986066c..9743d5a03c 100644 --- a/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs @@ -206,8 +206,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } // separately test for equality and greater than to have tolerance for equality comparison - if (CurrentState.Distance.IsEqual(CycleIntervalIterator.RightSample.Distance) || - CurrentState.Distance > CycleIntervalIterator.RightSample.Distance) { + if (CurrentState.Distance.IsGreaterOrEqual(CycleIntervalIterator.RightSample.Distance)) { // we have reached the end of the current interval in the cycle, move on... CycleIntervalIterator.MoveNext(); } @@ -295,6 +294,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { // cycleIndex has to be max. next to last (so that rightSample is still valid. if (CurrentCycleIndex >= Data.Entries.Count - 2) { + LastEntry = true; return false; } CurrentCycleIndex++; diff --git a/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/Models/SimulationComponent/Impl/Driver.cs index 6657405b07..abff49fabb 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Driver.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Driver.cs @@ -163,12 +163,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var retVal = CoastOrRollAction(absTime, ds, maxVelocity, gradient); retVal.Switch(). - //Case<ResponseFailTimeInterval>(r => { - // retVal = new ResponseDrivingCycleDistanceExceeded() { - // Source = r.Source, - // MaxDistance = - // }; - //}). Case<ResponseGearShift>(() => { throw new UnexpectedResponseException("DrivingAction Roll: Gearshift during Roll action", retVal); }); @@ -267,6 +261,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Case<ResponseOverload>(r => retVal = r). Case<ResponseUnderload>(). // will be handled in SearchBrakingPower Case<ResponseGearShift>(). // will be handled in SearchBrakingPower + Case<ResponseFailTimeInterval>(r => retVal = new ResponseDrivingCycleDistanceExceeded() { + Source = this, + MaxDistance = DataBus.VehicleSpeed() * r.DeltaT + operatingPoint.Acceleration / 2 * r.DeltaT * r.DeltaT + }). Default(r => { throw new UnexpectedResponseException("DrivingAction Brake: first request", r); }); @@ -453,8 +451,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl searchInterval *= intervalFactor; retVal.Acceleration += searchInterval * -delta.Sign(); - if (retVal.Acceleration < (curve.Deceleration - Constants.SimulationSettings.MinimumAcceleration) - || retVal.Acceleration > (curve.Acceleration + Constants.SimulationSettings.MinimumAcceleration)) { + if (retVal.Acceleration < (DriverData.AccelerationCurve.MaxDeceleration() - searchInterval) + || retVal.Acceleration > (DriverData.AccelerationCurve.MaxAcceleration() + searchInterval)) { throw new VectoSimulationException( "Could not find an operating point: operating point outside of driver acceleration limits."); } diff --git a/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs index 0287197891..972893a7ba 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs @@ -117,12 +117,19 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } if (!outTorque.IsEqual(0, Constants.SimulationSettings.EngineFLDPowerTolerance)) { + if (outTorque > 0) { return new ResponseOverload { Delta = outTorque * outEngineSpeed, Source = this, GearboxPowerRequest = outTorque * outEngineSpeed }; } + return new ResponseUnderload { + Delta = outTorque * outEngineSpeed, + Source = this, + GearboxPowerRequest = outTorque * outEngineSpeed + }; + } var neutralResponse = Next.Request(absTime, dt, 0.SI<NewtonMeter>(), null); neutralResponse.GearboxPowerRequest = outTorque * outEngineSpeed; diff --git a/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTest.cs b/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTest.cs index 8ae5fd713d..a51beb17cb 100644 --- a/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTest.cs +++ b/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTest.cs @@ -20,7 +20,7 @@ namespace TUGraz.VectoCore.Tests.Integration.DriverStrategy [TestClass] public class DriverStrategyTest { - public const string AccelerationFile = @"TestData\Components\Coach.vacc"; + public const string AccelerationFile = @"TestData\Components\Truck.vacc"; public const string EngineFile = @"TestData\Components\24t Coach.veng"; @@ -39,7 +39,7 @@ namespace TUGraz.VectoCore.Tests.Integration.DriverStrategy "900, 85, 0, 0", }); - var run = CreatePowerTrain(cycle, "DriverStrategy_Accelerate_0_80_level.vmod"); + var run = CreatePowerTrain(cycle, "DriverStrategy_Accelerate_0_85_level.vmod"); run.Run(); } @@ -50,11 +50,11 @@ namespace TUGraz.VectoCore.Tests.Integration.DriverStrategy { var cycle = CreateCycleData(new[] { // <s>,<v>,<grad>,<stop> - " 0, 80, 0, 0", - "900, 0, 0, 0", + " 0, 10, 0, 0", + "500, 0, 0, 0", }); - var run = CreatePowerTrain(cycle, "DriverStrategy_Accelerate_0_80_level.vmod"); + var run = CreatePowerTrain(cycle, "DriverStrategy_Accelerate_80_0_level.vmod"); run.Run(); } -- GitLab