diff --git a/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/Models/SimulationComponent/Impl/Driver.cs index 799d85981349b400c7187e4d7d2c88f32aedb18a..ece3dec1281e68111d2c40b4a935cfa244b0a3f8 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Driver.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Driver.cs @@ -96,7 +96,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var currentDistance = DataBus.Distance(); var nextDrivingActions = GetNextDrivingActions(currentDistance); - Log.DebugFormat(", ".Join(nextDrivingActions.Select(x => string.Format("[{0}]: {1}", x.ActionDistance, x.Action)))); + Log.DebugFormat(", ".Join(nextDrivingActions.Select(x => string.Format("({0}: {1})", x.ActionDistance, x.Action)))); if (CurrentState.DrivingAction.Action == DrivingBehavior.Stopped && targetVelocity >= DataBus.VehicleSpeed()) { @@ -196,6 +196,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var searchInterval = Constants.SimulationSettings.BreakingPowerInitialSearchInterval; var originalDs = ds; + Watt previousDelta = null; do { ds = originalDs; @@ -203,6 +204,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ? -response.DeltaDragLoad : -response.AxlegearPowerRequest; + if (previousDelta == null) { + previousDelta = 2 * delta; + } + exceeded.Add(delta); if (delta.IsEqual(0, Constants.SimulationSettings.EngineFLDPowerTolerance)) { Log.DebugFormat("found operating point in {0} iterations, delta: {1}", exceeded.Count, delta); @@ -210,7 +215,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } breakingPower += searchInterval * (delta > 0 ? -1 : 1); - searchInterval /= 2.0; + + searchInterval /= VectoMath.Limit((previousDelta / delta).Cast<Scalar>(), 1.1, 2.0); + previousDelta = delta; CurrentState.dt = ComputeTimeInterval(CurrentState.Acceleration, ref ds); DataBus.BreakPower = breakingPower; @@ -358,7 +365,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Log.DebugFormat("Limiting coasting deceleration from {0} to {1}", CurrentState.Acceleration, DeclarationData.Driver.LookAhead.Deceleration); CurrentState.Acceleration = DeclarationData.Driver.LookAhead.Deceleration; - CurrentState.dt = ComputeTimeInterval(CurrentState.Acceleration, ref ds); + //CurrentState.dt = ComputeTimeInterval(CurrentState.Acceleration, ref ds); Log.DebugFormat("Changed dt due to limited coasting deceleration. dt: {0}", CurrentState.dt); } @@ -430,6 +437,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl throw new VectoSimulationException("Could not achieve minimum acceleration"); } searchInterval /= 2.0; + CurrentState.dt = ComputeTimeInterval(CurrentState.Acceleration, ref ds); response = Next.Request(absTime, CurrentState.dt, CurrentState.Acceleration, gradient, true); } while (CurrentState.RetryCount++ < Constants.SimulationSettings.DriverSearchLoopThreshold); diff --git a/VectoCore/Utils/VectoMath.cs b/VectoCore/Utils/VectoMath.cs index a50139c75c6ff87829f52e3c8fab10cb20e4e663..39cde29bf4e557343e1900cbd4839321ac1c5ecf 100644 --- a/VectoCore/Utils/VectoMath.cs +++ b/VectoCore/Utils/VectoMath.cs @@ -73,16 +73,16 @@ namespace TUGraz.VectoCore.Utils return c1.CompareTo(c2) >= 0 ? c1 : c2; } - public static T Limit<T>(T value, T lowerBound, T upperBound) where T : SIBase<T> + public static T Limit<T>(T value, T lowerBound, T upperBound) where T : IComparable { - if (lowerBound > upperBound) { + if (lowerBound.CompareTo(upperBound) > 0) { throw new VectoException("VectoMath.Limit: lowerBound must not be greater than upperBound"); } - if (value > upperBound) { + if (value.CompareTo(upperBound) > 0) { return upperBound; } - if (value < lowerBound) { + if (value.CompareTo(lowerBound) < 0) { return lowerBound; } return value; diff --git a/VectoCoreTest/Integration/SimulationRuns/FullPowertrain.cs b/VectoCoreTest/Integration/SimulationRuns/FullPowertrain.cs index f1757f240301101658a59e1c719d0f91cd441f59..2f6c6d678fd7025d4ce3f2487ce3e6602a8226fc 100644 --- a/VectoCoreTest/Integration/SimulationRuns/FullPowertrain.cs +++ b/VectoCoreTest/Integration/SimulationRuns/FullPowertrain.cs @@ -89,10 +89,8 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns }). Default(r => Assert.Fail("Unexpected Response: {0}", r)); } - - Assert.IsInstanceOfType(response, typeof(ResponseCycleFinished)); - modalWriter.Finish(); + Assert.IsInstanceOfType(response, typeof(ResponseCycleFinished)); } [TestMethod] @@ -135,7 +133,12 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns var cnt = 0; while (!(response is ResponseCycleFinished) && container.Distance().Value() < 17000) { Log.InfoFormat("Test New Request absTime: {0}, ds: {1}", absTime, ds); - response = cyclePort.Request(absTime, ds); + try { + response = cyclePort.Request(absTime, ds); + } catch (Exception) { + modalWriter.Finish(); + throw; + } Log.InfoFormat("Test Got Response: {0},", response); response.Switch(). @@ -156,10 +159,8 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns }). Default(r => Assert.Fail("Unexpected Response: {0}", r)); } - - Assert.IsInstanceOfType(response, typeof(ResponseCycleFinished)); - modalWriter.Finish(); + Assert.IsInstanceOfType(response, typeof(ResponseCycleFinished)); }