Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit bd4cfa01 authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

adding debug statements

parent 3df2353a
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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;
......
......@@ -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)));
......
......@@ -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;
......
......@@ -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");
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment