Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 6dcf35a7 authored by Michael KRISPER's avatar Michael KRISPER
Browse files

DefaultDriverStrategy: Added more info to debugData for easier debugging. Reformated code

parent 3c13edc4
No related branches found
No related tags found
No related merge requests found
......@@ -855,9 +855,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public class DriverModeDrive : AbstractDriverMode
{
protected override IResponse DoHandleRequest(
Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient,
bool prohibitOverspeed = false)
protected override IResponse DoHandleRequest(Second absTime, Meter ds, MeterPerSecond targetVelocity,
Radian gradient, bool prohibitOverspeed = false)
{
var debug = new DebugData();
......@@ -874,8 +873,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
}
for (var i = 0; i < 3; i++) {
var retVal = HandleRequestEngaged(
absTime, ds, targetVelocity, gradient, prohibitOverspeed, velocity, debug);
var retVal = HandleRequestEngaged(absTime, ds, targetVelocity, gradient, prohibitOverspeed,
velocity, debug);
if (retVal != null) {
return retVal;
}
......@@ -889,15 +888,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return response;
}
if (!(response is ResponseSuccess) && DataBus.ClutchInfo.ClutchClosed(absTime)) {
response = HandleRequestEngaged(
absTime, ds, targetVelocity, gradient, prohibitOverspeed, velocity, debug);
response = HandleRequestEngaged(absTime, ds, targetVelocity, gradient, prohibitOverspeed, velocity, debug);
}
return response;
}
private IResponse HandleRequestDisengaged(
Second absTime, Meter ds, Radian gradient, MeterPerSecond velocity,
private IResponse HandleRequestDisengaged(Second absTime, Meter ds, Radian gradient, MeterPerSecond velocity,
DebugData debug)
{
if (DataBus.VehicleInfo.VehicleSpeed.IsSmallerOrEqual(0.SI<MeterPerSecond>())) {
......@@ -914,18 +911,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
}
var response = Driver.DrivingActionRoll(absTime, ds, velocity, gradient);
debug.Add(new { action = "ClutchOpen -> Roll", response });
debug.Add(new { a = "[HRD-0] ClutchOpen -> Roll", response });
switch (response) {
case ResponseUnderload _ when DataBus.ClutchInfo.ClutchClosed(absTime):
response = HandleRequestEngaged(absTime, ds, velocity, gradient, false, velocity, debug);
break;
case ResponseUnderload _ when !DataBus.ClutchInfo.ClutchClosed(absTime):
response = Driver.DrivingActionBrake(absTime, ds, velocity, gradient, response);
debug.Add(new { action = "Roll:Underload -> Brake", response });
debug.Add(new { a = "[HRD-1] Roll:Underload -> Brake", response });
break;
case ResponseSpeedLimitExceeded _:
response = Driver.DrivingActionBrake(absTime, ds, velocity, gradient);
debug.Add(new { action = "Roll:SpeedLimitExceeded -> Brake", response });
debug.Add(new { a = "[HRD-2] Roll:SpeedLimitExceeded -> Brake", response });
break;
}
return response;
......@@ -936,8 +933,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
bool prohibitOverspeed, MeterPerSecond velocityWithOverspeed, DebugData debug)
{
// drive along
var first = FirstAccelerateOrCoast(
absTime, ds, targetVelocity, gradient, prohibitOverspeed, velocityWithOverspeed, debug);
var first = FirstAccelerateOrCoast(absTime, ds, targetVelocity, gradient, prohibitOverspeed, velocityWithOverspeed, debug);
var second = first;
switch (first) {
......@@ -945,11 +941,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
if (DataBus.GearboxInfo.GearboxType.AutomaticTransmission() && !DataBus.ClutchInfo.ClutchClosed(absTime)) {
//TODO mk20210616 the whole statement could be de-nested to switch-pattern matching (with "where") if this first "if" would not be here.
var debugResponse = Driver.DrivingActionRoll(absTime, ds, velocityWithOverspeed, gradient);
debug.Add(new { a = "[HRE-0] (Underload&Overspeed)->Roll", second });
}
if (DataBus.VehicleInfo.VehicleSpeed.IsGreater(0) && DriverStrategy.IsOverspeedAllowed(targetVelocity, prohibitOverspeed)) {
second = Driver.DrivingActionCoast(absTime, ds, velocityWithOverspeed, gradient);
debug.Add(new { action = "first:(Underload & Overspeed)-> Coast", second });
debug.Add(new { a = "[HRE-1] (Underload&Overspeed)->Coast", second });
second = HandleCoastAfterUnderloadWithOverspeed(absTime, ds, gradient, velocityWithOverspeed, debug, second);
} else {
// overrideAction: in case of hybrids with an AT gearbox after an underload we search for braking power because the torque converter
......@@ -967,7 +964,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
: (DrivingAction?)null;
second = Driver.DrivingActionBrake(absTime, ds, velocityWithOverspeed, gradient,
overrideAction: overrideAction);
debug.Add(new { action = "first:(Underload & !Overspeed) -> Brake", second });
debug.Add(new { a = "[HRE-2] (Underload&!Overspeed)->Brake", second });
}
break;
case ResponseEngineSpeedTooHigh _:
......@@ -975,7 +972,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
break;
case ResponseSpeedLimitExceeded _:
second = Driver.DrivingActionBrake(absTime, ds, velocityWithOverspeed, gradient);
debug.Add(new { action = "SpeedLimitExceeded -> Brake", second });
debug.Add(new { a = "[HRE-3] SpeedLimitExceeded->Brake", second });
break;
}
......@@ -988,36 +985,36 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
switch (second) {
case ResponseGearShift _:
third = Driver.DrivingActionRoll(absTime, ds, velocityWithOverspeed, gradient);
debug.Add(new { action = "second: GearShift -> Roll", third });
debug.Add(new { a = "[HRE-4] second: GearShift -> Roll", third });
switch (third) {
case ResponseUnderload _:
// overload may happen if driver limits acceleration when rolling downhill
// underload may happen if driver limits acceleration when rolling downhill
third = Driver.DrivingActionBrake(absTime, ds, velocityWithOverspeed, gradient);
debug.Add(new { action = "third:Underload -> Brake", third });
debug.Add(new { a = "[HRE-6] third:Underload -> Brake", third });
break;
case ResponseSpeedLimitExceeded _:
third = Driver.DrivingActionBrake(absTime, ds, velocityWithOverspeed, gradient);
debug.Add(new { action = "third:SpeedLimitExceeded -> Brake", third });
debug.Add(new { a = "[HRE-7] third:SpeedLimitExceeded -> Brake", third });
break;
}
break;
case ResponseOverload _ when DataBus.VehicleInfo.VehicleSpeed.IsGreater(0):
third = Driver.DrivingActionCoast(absTime, ds, velocityWithOverspeed, gradient);
debug.Add(new { action = "second:Overload -> Coast", third });
debug.Add(new { a = "[HRE-8] second:Overload -> Coast", third });
switch (third) {
case ResponseGearShift _:
third = Driver.DrivingActionCoast(absTime, ds, velocityWithOverspeed, gradient);
debug.Add(new { action = "third:GearShift -> try again Coast", third });
debug.Add(new { a = "[HRE-9] third:GearShift -> try again Coast", third });
break;
case ResponseSpeedLimitExceeded _:
if (DataBus.GearboxInfo.GearboxType.AutomaticTransmission() &&
!DataBus.GearboxInfo.Gear.IsLockedGear()) {
third = Driver.DrivingActionCoast(absTime, ds, velocityWithOverspeed + 1.KMPHtoMeterPerSecond(), gradient);
debug.Add(new { action = "third:Overload (AT, Converter gear) -> Coast", third });
debug.Add(new { a = "[HRE-10] third:Overload (AT, Converter gear) -> Coast", third });
} else {
third = Driver.DrivingActionBrake(absTime, ds, velocityWithOverspeed, gradient);
debug.Add(new { action = "third:SpeedLimitExceeded -> Brake", third });
debug.Add(new { a = "[HRE-11] third:SpeedLimitExceeded -> Brake", third });
}
break;
......@@ -1028,35 +1025,26 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return third;
}
private IResponse HandleCoastAfterUnderloadWithOverspeed(
Second absTime, Meter ds, Radian gradient,
private IResponse HandleCoastAfterUnderloadWithOverspeed(Second absTime, Meter ds, Radian gradient,
MeterPerSecond velocity, DebugData debug, IResponse second)
{
if (second is ResponseUnderload || second is ResponseSpeedLimitExceeded) {
second = Driver.DrivingActionBrake(absTime, ds, velocity, gradient);
debug.Add(
new {
action = "second:(Underload|SpeedLimitExceeded) -> Brake",
second
});
debug.Add(new { a = "[HCAUWO-0] second:(Underload|SpeedLimitExceeded) -> Brake", second });
}
if (second is ResponseEngineSpeedTooHigh) {
second = Driver.DrivingActionBrake(absTime, ds, velocity, gradient, second);
debug.Add(
new {
action = "second:(EngineSpeedTooHigh|SpeedLimitExceeded) -> Brake with reduced acceleration",
second
});
debug.Add(new { a = "[HCAUWO-1] second:(EngineSpeedTooHigh|SpeedLimitExceeded) -> Brake with reduced acceleration", second });
}
return second;
}
private IResponse FirstAccelerateOrCoast(
Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient,
private IResponse FirstAccelerateOrCoast(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient,
bool prohibitOverspeed, MeterPerSecond velocityWithOverspeed, DebugData debug)
{
if (DriverStrategy.pccState == PCCStates.UseCase1 || DriverStrategy.pccState == PCCStates.UseCase2) {
var response = Driver.DrivingActionCoast(absTime, ds, velocityWithOverspeed, gradient);
debug.Add(new { a = "[FAOC-0] Coast", response });
if (response is ResponseSuccess) {
return response;
}
......@@ -1068,27 +1056,27 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
//we are driving in overspeed (VehicleSpeed >= targetVelocity)
var response = Driver.DrivingActionCoast(absTime, ds, velocityWithOverspeed, gradient);
debug.Add(new { action = "Coast", response });
debug.Add(new { a = "[FAOC-1] Coast", response });
if (response is ResponseSuccess
&& response.Driver.Acceleration < 0 && response.Vehicle.VehicleSpeed <= targetVelocity) {
//do accelerate action if we would come below targetVelocity due to coasting
response = Driver.DrivingActionAccelerate(absTime, ds, targetVelocity, gradient);
debug.Add(new { action = "Accelerate(Success && Acc<0 && VehSpeed <= targetVelocity)", response });
debug.Add(new { a = "[FAOC-2] Accelerate(Success && Acc<0 && VehSpeed <= targetVelocity)", response });
}
if (response is ResponseOverload
&& DataBus.PowertrainInfo.HasCombustionEngine && !DataBus.EngineInfo.EngineOn) {
response = Driver.DrivingActionAccelerate(absTime, ds, targetVelocity, gradient);
debug.Add(new { action = "Accelerate(Overload && ICE off)", response });
debug.Add(new { a = "[FAOC-3] Accelerate(Overload && ICE off)", response });
}
if (response is ResponseOverload
&& !DataBus.PowertrainInfo.HasCombustionEngine) {
response = Driver.DrivingActionAccelerate(absTime, ds, targetVelocity, gradient);
debug.Add(new { action = "Accelerate(Overload && BEV)", response });
debug.Add(new { a = "[FAOC-4] Accelerate(Overload && BEV)", response });
}
if (response is ResponseOverload) {
response = Driver.DrivingActionAccelerate(absTime, ds, targetVelocity, gradient);
debug.Add(new { action = "Accelerate(Overload)", response });
debug.Add(new { a = "[FAOC-5] Accelerate(Overload)", response });
}
return response;
} else {
......@@ -1096,11 +1084,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
if (DataBus.GearboxInfo.GearboxType.AutomaticTransmission() && DataBus.GearboxInfo.DisengageGearbox) {
var response = Driver.DrivingActionCoast(absTime, ds, velocityWithOverspeed, gradient);
debug.Add(new { action = "Coast", response });
debug.Add(new { a = "[FAOC-6] Coast", response });
return response;
} else {
var response = Driver.DrivingActionAccelerate(absTime, ds, targetVelocity, gradient);
debug.Add(new { action = "Accelerate", response });
debug.Add(new { a = "[FAOC-7] Accelerate", response });
return response;
}
}
......@@ -1252,17 +1240,17 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
}
response = Driver.DrivingActionAccelerate(absTime, ds, 1.KMPHtoMeterPerSecond(), gradient);
debug.Add(new { a = "(1) Accelerate", response });
debug.Add(new { a = "[DB-] Accelerate", response });
if (response is ResponseUnderload) {
response = Driver.DrivingActionBrake(absTime, ds, 1.KMPHtoMeterPerSecond(), gradient, response,
overrideAction: DrivingAction.Accelerate);
debug.Add(new { a = "(2) Brake", response });
debug.Add(new { a = "[DB-2] Brake", response });
}
} else {
response = Driver.DrivingActionBrake(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed,
gradient, targetDistance: targetDistance);
debug.Add(new { a = "(3) Brake", response });
debug.Add(new { a = "[DB-3] Brake", response });
}
if ((DataBus.GearboxInfo.GearboxType.AutomaticTransmission() || DataBus.HybridControllerInfo != null)
......@@ -1271,7 +1259,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
DataBus.Brakes.BrakePower = 0.SI<Watt>();
response = Driver.DrivingActionBrake(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed,
gradient, targetDistance: targetDistance);
debug.Add(new { a = "(4) Brake", response });
debug.Add(new { a = "[DB-4] Brake", response });
}
if (response == null) {
......@@ -1284,10 +1272,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
if (!DataBus.ClutchInfo.ClutchClosed(absTime)) {
Log.Info("Brake -> Overload -> Clutch is open - Trying roll action");
response = Driver.DrivingActionRoll(absTime, ds, targetVelocity, gradient);
debug.Add(new { a = "(5) Roll", response });
debug.Add(new { a = "[DB-5] Roll", response });
if (response is ResponseSpeedLimitExceeded) {
response = Driver.DrivingActionBrake(absTime, ds, targetVelocity, gradient);
debug.Add(new { a = "(6) Brake", response });
debug.Add(new { a = "[DB-6] Brake", response });
}
} else {
Log.Info("Brake -> Overload -> Clutch is closed - Trying brake action again");
......@@ -1295,16 +1283,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
DataBus.HybridControllerCtl?.RepeatDrivingAction(absTime);
response = Driver.DrivingActionBrake(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed,
gradient, targetDistance: targetDistance);
debug.Add(new { a = "(7) Brake", response });
debug.Add(new { a = "[DB-7] Brake", response });
if (response is ResponseOverload) {
Log.Info("Brake -> Overload -> 2nd Brake -> Overload -> Trying accelerate action");
var gear = DataBus.GearboxInfo.Gear;
if (DataBus.GearboxInfo.GearEngaged(absTime)) {
response = Driver.DrivingActionAccelerate(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, gradient);
debug.Add(new { a = "(8) Accelerate", response });
debug.Add(new { a = "[DB-8] Accelerate", response });
} else {
response = Driver.DrivingActionRoll(absTime, ds, targetVelocity, gradient);
debug.Add(new { a = "(9) Roll", response });
debug.Add(new { a = "[DB-9] Roll", response });
}
switch (response) {
......@@ -1312,14 +1300,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
Log.Info("Brake -> Overload -> 2nd Brake -> Accelerate or Roll -> Got GearShift response, performing roll action");
response = Driver.DrivingActionRoll(absTime, ds,
DriverStrategy.BrakeTrigger.NextTargetSpeed, gradient);
debug.Add(new { a = "(12) Roll", response });
debug.Add(new { a = "[DB-12] Roll", response });
break;
case ResponseUnderload _:
if (gear.Gear != DataBus.GearboxInfo.Gear.Gear) {
// AT Gearbox switched gears, shift losses are no longer applied, try once more...
response = Driver.DrivingActionAccelerate(absTime, ds,
DriverStrategy.BrakeTrigger.NextTargetSpeed, gradient);
debug.Add(new { a = "(13 Accelerate", response });
debug.Add(new { a = "[DB-13] Accelerate", response });
}
break;
}
......@@ -1333,11 +1321,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
DataBus.Brakes.BrakePower = 0.SI<Watt>();
response = Driver.DrivingActionBrake(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed,
gradient, targetDistance: targetDistance);
debug.Add(new { a = "(14) Brake", response });
debug.Add(new { a = "[DB-14] Brake", response });
if (response is ResponseOverload) {
Log.Info("Brake -> Gearshift -> Overload -> trying roll action (no gear engaged)");
response = Driver.DrivingActionRoll(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, gradient);
debug.Add(new { a = "(15) Roll", response });
debug.Add(new { a = "[DB-15] Roll", response });
}
break;
}
......
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