diff --git a/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs b/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs index d1208a2748f229191f58e1358f16c488316e1d55..72d0a7fb4004753eb32a2433acacd65f4c82d1c1 100644 --- a/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs +++ b/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs @@ -52,11 +52,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl if (nextAction != null && currentDistance.IsEqual(nextAction.ActionDistance)) { CurrentDrivingMode = DrivingMode.DrivingModeBrake; DrivingModes[CurrentDrivingMode].ResetMode(); + Log.Debug("Switching to DrivingMode BRAKE"); + BrakeTrigger = nextAction; break; } if (nextAction != null && currentDistance + ds > nextAction.ActionDistance) { return new ResponseDrivingCycleDistanceExceeded() { + //Source = this, MaxDistance = nextAction.ActionDistance - currentDistance }; } @@ -65,6 +68,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl if (Driver.DataBus.Distance >= BrakeTrigger.TriggerDistance) { CurrentDrivingMode = DrivingMode.DrivingModeDrive; DrivingModes[CurrentDrivingMode].ResetMode(); + Log.Debug("Switching to DrivingMode DRIVE"); } break; } @@ -94,17 +98,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl for (var i = 0; i < lookaheadData.Count; i++) { var entry = lookaheadData[i]; if (entry.VehicleTargetSpeed < currentSpeed) { - //var breakingDistance = Driver.ComputeDecelerationDistance(entry.VehicleTargetSpeed); - //Log.Debug("distance to decelerate from {0} to {1}: {2}", currentSpeed, entry.VehicleTargetSpeed, - // breakingDistance); - //Log.Debug("adding 'Braking' starting at distance {0}", entry.Distance - breakingDistance); - //nextActions.Add( - // new DrivingBehaviorEntry { - // Action = DefaultDriverStrategy.DrivingBehavior.Braking, - // ActionDistance = entry.Distance - breakingDistance, - // TriggerDistance = entry.Distance, - // NextTargetSpeed = entry.VehicleTargetSpeed - // }); var coastingDistance = Formulas.DecelerationDistance(currentSpeed, entry.VehicleTargetSpeed, Driver.LookaheadDeceleration); Log.Debug("adding 'Coasting' starting at distance {0}", entry.Distance - coastingDistance); @@ -220,16 +213,19 @@ 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) { + var brakingDistance = DriverStrategy.Driver.ComputeDecelerationDistance(DriverStrategy.BrakeTrigger.NextTargetSpeed); + Log.Debug("breaking distance: {0}, start braking @ {1}", brakingDistance, + DriverStrategy.BrakeTrigger.TriggerDistance - brakingDistance); + if (currentDistance + ds > DriverStrategy.BrakeTrigger.TriggerDistance - brakingDistance) { return new ResponseDrivingCycleDistanceExceeded() { - MaxDistance = DriverStrategy.BrakeTrigger.TriggerDistance - breakingDistance - currentDistance + //Source = this, + MaxDistance = DriverStrategy.BrakeTrigger.TriggerDistance - brakingDistance - currentDistance }; } if (currentDistance + Constants.SimulationSettings.DriverActionDistanceTolerance > - DriverStrategy.BrakeTrigger.TriggerDistance - breakingDistance) { + DriverStrategy.BrakeTrigger.TriggerDistance - brakingDistance) { Phase = BrakingPhase.Brake; + Log.Debug("Switching to BRAKE Phase. currentDistance: {0}", currentDistance); } } switch (Phase) { @@ -247,6 +243,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl }); break; case BrakingPhase.Brake: + var brakingDistance = + DriverStrategy.Driver.ComputeDecelerationDistance(DriverStrategy.BrakeTrigger.NextTargetSpeed); + Log.Debug("Phase: BRAKE. breaking distance: {0} start braking @ {1}", brakingDistance, + DriverStrategy.BrakeTrigger.TriggerDistance - brakingDistance); + response = DriverStrategy.Driver.DrivingActionBrake(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, gradient); break; diff --git a/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs index 82a7e5350ec97e3f061857cdd5276fe85866067c..b52bab2cce4a583a5676a84aea77b454095c93b5 100644 --- a/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs @@ -105,6 +105,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl if ((PreviousState.Distance + ds).IsGreater(CycleIntervalIterator.RightSample.Distance)) { // only drive until next sample point in cycle return new ResponseDrivingCycleDistanceExceeded { + Source = this, MaxDistance = CycleIntervalIterator.RightSample.Distance - PreviousState.Distance }; } @@ -128,7 +129,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl (CycleIntervalIterator.RightSample.Distance - PreviousState.Distance) < Constants.SimulationSettings.DriveOffDistance) { CurrentState.RequestToNextSamplePointDone = true; - return new ResponseDrivingCycleDistanceExceeded { MaxDistance = Constants.SimulationSettings.DriveOffDistance }; + return new ResponseDrivingCycleDistanceExceeded { + Source = this, + MaxDistance = Constants.SimulationSettings.DriveOffDistance + }; } CurrentState.Distance = PreviousState.Distance + ds; CurrentState.VehicleTargetSpeed = CycleIntervalIterator.LeftSample.VehicleTargetSpeed; diff --git a/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/Models/SimulationComponent/Impl/Driver.cs index 2ab94ce23a9a7b668de87f570af02931e64a57e6..8221cd697da4a003d392b35969393dfda0190353 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Driver.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Driver.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Security.Cryptography.X509Certificates; +using NLog; using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.Models.Connector.Ports; @@ -76,8 +77,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public IResponse Request(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient) { Log.Debug("==== DRIVER Request ===="); - Log.Debug("Request: absTime: {0}, dt: {1}, targetVelocity: {2}, gradient: {3}", absTime, dt, targetVelocity, - gradient); + Log.Debug("Request: absTime: {0}, dt: {1}, targetVelocity: {2}, gradient: {3} | distance: {4}, velocity: {5}", + absTime, dt, targetVelocity, gradient, DataBus.Distance, DataBus.VehicleSpeed()); var retVal = DriverStrategy.Request(absTime, dt, targetVelocity, gradient); @@ -92,6 +93,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl get { return DataBus; } } + /// <summary> + /// see documentation of IDriverActions + /// </summary> + /// <param name="absTime"></param> + /// <param name="ds"></param> + /// <param name="targetVelocity"></param> + /// <param name="gradient"></param> + /// <param name="previousResponse"></param> + /// <returns></returns> public IResponse DrivingActionAccelerate(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient, IResponse previousResponse = null) { @@ -142,7 +152,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } /// <summary> - /// + /// see documentation of IDriverActions /// </summary> /// <param name="absTime"></param> /// <param name="ds"></param> @@ -156,7 +166,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return CoastOrRollAction(absTime, ds, maxVelocity, gradient); } - + /// <summary> + /// see documentation of IDriverActions + /// </summary> + /// <param name="absTime"></param> + /// <param name="ds"></param> + /// <param name="maxVelocity"></param> + /// <param name="gradient"></param> + /// <returns></returns> public IResponse DrivingActionRoll(Second absTime, Meter ds, MeterPerSecond maxVelocity, Radian gradient) { Log.Debug("DrivingAction Roll"); @@ -202,6 +219,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Log.Debug("SearchOperatingPoint reduced the max. distance: {0} -> {1}. Issue new request from driving cycle!", operatingPoint.SimulationDistance, ds); return new ResponseDrivingCycleDistanceExceeded { + Source = this, MaxDistance = operatingPoint.SimulationDistance, }; } @@ -277,7 +295,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Log.Info( "SearchOperatingPoint Breaking reduced the max. distance: {0} -> {1}. Issue new request from driving cycle!", operatingPoint.SimulationDistance, ds); - return new ResponseDrivingCycleDistanceExceeded { MaxDistance = operatingPoint.SimulationDistance }; + return new ResponseDrivingCycleDistanceExceeded { + Source = this, + MaxDistance = operatingPoint.SimulationDistance + }; } Log.Debug("Found operating point for breaking. dt: {0}, acceleration: {1}", operatingPoint.SimulationInterval, @@ -334,6 +355,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl private OperatingPoint SearchBrakingPower(Second absTime, Meter ds, Radian gradient, MeterPerSquareSecond acceleration, IResponse initialResponse) { + Log.Info("Disabling logging during search iterations"); + LogManager.DisableLogging(); + var debug = new List<dynamic>(); // only used while testing var searchInterval = Constants.SimulationSettings.BreakingPowerInitialSearchInterval; @@ -364,6 +388,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl delta = DataBus.ClutchClosed(absTime) ? response.DeltaDragLoad : response.GearboxPowerRequest; if (delta.IsEqual(0, Constants.SimulationSettings.EngineFLDPowerTolerance)) { + LogManager.EnableLogging(); Log.Debug("found operating point in {0} iterations, delta: {1}", debug.Count, delta); return operatingPoint; } @@ -380,6 +405,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl breakingPower += searchInterval * -delta.Sign(); } while (retryCount++ < Constants.SimulationSettings.DriverSearchLoopThreshold); + LogManager.EnableLogging(); Log.Warn("Exceeded max iterations when searching for operating point!"); Log.Warn("exceeded: {0} ... {1}", ", ".Join(debug.Take(5)), ", ".Join(debug.Slice(-6))); Log.Error("Failed to find operating point for breaking!"); @@ -406,6 +432,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl protected OperatingPoint SearchOperatingPoint(Second absTime, Meter ds, Radian gradient, MeterPerSquareSecond acceleration, IResponse initialResponse, bool coasting = false) { + Log.Info("Disabling logging during search iterations"); + LogManager.DisableLogging(); + var debug = new List<dynamic>(); var retVal = new OperatingPoint { Acceleration = acceleration, SimulationDistance = ds }; @@ -469,6 +498,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl delta = actionRoll ? response.GearboxPowerRequest : (coasting ? response.DeltaDragLoad : response.DeltaFullLoad); if (delta.IsEqual(0, Constants.SimulationSettings.EngineFLDPowerTolerance)) { + LogManager.EnableLogging(); Log.Debug( "found operating point in {0} iterations. Engine Power req: {2}, Gearbox Power req: {3} delta: {1}", debug.Count, delta, response.EnginePowerRequest, response.GearboxPowerRequest); @@ -476,6 +506,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } } while (retryCount++ < Constants.SimulationSettings.DriverSearchLoopThreshold); + LogManager.EnableLogging(); Log.Warn("Exceeded max iterations when searching for operating point!"); Log.Warn("acceleration: {0} ... {1}", ", ".Join(debug.Take(5).Select(x => x.acceleration)), ", ".Join(debug.Slice(-6).Select(x => x.acceleration))); diff --git a/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs b/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs index efa3288110adea756b82a8913f34194e0ba27fb5..0ab18dabfb0443cbcb4cffab276018db80edc52f 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs @@ -104,7 +104,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl // sanity check: is the vehicle in step with the cycle? var distance = (SI)writer[ModalResultField.dist]; - if (!distance.IsEqual(_currentState.Distance.Value(), 1e-15)) { + if (!distance.IsEqual(_currentState.Distance.Value(), 1e-12)) { Log.Warn("distance diverges: {0}, distance: {1}", (distance - _currentState.Distance).Value(), distance); } //writer[ModalResultField.dist] = _currentState.Distance; diff --git a/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTest.cs b/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTest.cs index b5db640c961bb86469b8d03b1369753d45fee0f7..d622cc608febfab32667164974ea08cb85fe8024 100644 --- a/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTest.cs +++ b/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTest.cs @@ -50,8 +50,9 @@ namespace TUGraz.VectoCore.Tests.Integration.DriverStrategy { var cycle = CreateCycleData(new[] { // <s>,<v>,<grad>,<stop> - " 0, 80, 0, 0", - "500, 0, 0, 0", + " 0, 80, 0, 0", + "600, 0, 0, 2", + "800, 10, 0, 0" }); var run = CreatePowerTrain(cycle, "DriverStrategy_Accelerate_80_0_level.vmod"); diff --git a/VectoCoreTest/app.config b/VectoCoreTest/app.config index 8d34600b34fc1c5fd1ffb93754778b76ca3a03b8..841b330eef6936b0fa20aab969a0440d67fac879 100644 --- a/VectoCoreTest/app.config +++ b/VectoCoreTest/app.config @@ -20,6 +20,7 @@ </targets> <rules> <logger name="*" minlevel="Info" writeTo="LogFile" /> + <logger name="TUGraz.VectoCore.Models.SimulationComponent.Impl.*" minlevel="Debug" writeTo="LogFile" /> </rules> </nlog> </configuration> \ No newline at end of file