Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

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

code formatting

parent f6f509c8
No related branches found
No related tags found
No related merge requests found
...@@ -97,9 +97,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -97,9 +97,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
Log.Debug("Switching to DrivingMode BRAKE"); Log.Debug("Switching to DrivingMode BRAKE");
BrakeTrigger = NextDrivingAction; BrakeTrigger = NextDrivingAction;
//break; //break;
} else if ((currentDistance + ds).IsGreater(NextDrivingAction.ActionDistance)) { } else if ((currentDistance + ds).IsGreater(NextDrivingAction.ActionDistance)) {
Log.Debug("Current simulation interval exceeds next action distance at {0}. reducing maxDistance to {1}", Log.Debug(
"Current simulation interval exceeds next action distance at {0}. reducing maxDistance to {1}",
NextDrivingAction.ActionDistance, NextDrivingAction.ActionDistance - currentDistance); NextDrivingAction.ActionDistance, NextDrivingAction.ActionDistance - currentDistance);
return new ResponseDrivingCycleDistanceExceeded() { return new ResponseDrivingCycleDistanceExceeded() {
Source = this, Source = this,
...@@ -109,7 +111,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -109,7 +111,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
} }
} }
var retVal = DrivingModes[CurrentDrivingMode].Request(absTime, ds, VectoMath.Min(Driver.DataBus.MaxVehicleSpeed, targetVelocity), gradient); var retVal = DrivingModes[CurrentDrivingMode].Request(
absTime, ds, VectoMath.Min(Driver.DataBus.MaxVehicleSpeed, targetVelocity), gradient);
return retVal; return retVal;
} }
...@@ -118,7 +121,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -118,7 +121,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{ {
Driver.DriverBehavior = DrivingBehavior.Halted; Driver.DriverBehavior = DrivingBehavior.Halted;
CurrentDrivingMode = DrivingMode.DrivingModeDrive; CurrentDrivingMode = DrivingMode.DrivingModeDrive;
return Driver.DrivingActionHalt(absTime, dt, VectoMath.Min(Driver.DataBus.MaxVehicleSpeed, targetVelocity), gradient); return Driver.DrivingActionHalt(
absTime, dt, VectoMath.Min(Driver.DataBus.MaxVehicleSpeed, targetVelocity), gradient);
} }
private void UpdateDrivingAction(Meter currentDistance, Meter ds) private void UpdateDrivingAction(Meter currentDistance, Meter ds)
...@@ -164,6 +168,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -164,6 +168,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var brakingDistance = Driver.ComputeDecelerationDistance(NextDrivingAction.NextTargetSpeed) + BrakingSafetyMargin; var brakingDistance = Driver.ComputeDecelerationDistance(NextDrivingAction.NextTargetSpeed) + BrakingSafetyMargin;
switch (NextDrivingAction.Action) { switch (NextDrivingAction.Action) {
case DrivingBehavior.Coasting: case DrivingBehavior.Coasting:
//var coastingDistance = ComputeCoastingDistance(Driver.DataBus.VehicleSpeed, NextDrivingAction.NextTargetSpeed); //var coastingDistance = ComputeCoastingDistance(Driver.DataBus.VehicleSpeed, NextDrivingAction.NextTargetSpeed);
var coastingDistance = ComputeCoastingDistance(Driver.DataBus.VehicleSpeed, NextDrivingAction.CycleEntry); var coastingDistance = ComputeCoastingDistance(Driver.DataBus.VehicleSpeed, NextDrivingAction.CycleEntry);
NextDrivingAction.CoastingStartDistance = NextDrivingAction.TriggerDistance - coastingDistance; NextDrivingAction.CoastingStartDistance = NextDrivingAction.TriggerDistance - coastingDistance;
...@@ -173,8 +178,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -173,8 +178,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
NextDrivingAction.BrakingStartDistance = NextDrivingAction.TriggerDistance - brakingDistance; NextDrivingAction.BrakingStartDistance = NextDrivingAction.TriggerDistance - brakingDistance;
NextDrivingAction.CoastingStartDistance = double.MaxValue.SI<Meter>(); NextDrivingAction.CoastingStartDistance = double.MaxValue.SI<Meter>();
break; break;
default: default: throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException();
} }
} }
} }
...@@ -199,11 +203,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -199,11 +203,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
// acceleration is not relevant // acceleration is not relevant
continue; continue;
} }
nextActions.Add(GetDrivingBehaviorEntry(nextTargetSpeed, currentSpeed, entry)); nextActions.Add(GetDrivingBehaviorEntry(nextTargetSpeed, currentSpeed, entry));
} }
if (!nextActions.Any()) { if (!nextActions.Any()) {
return null; return null;
} }
var nextBrakingAction = nextActions.OrderBy(x => x.BrakingStartDistance).First(); var nextBrakingAction = nextActions.OrderBy(x => x.BrakingStartDistance).First();
var nextCoastingAction = nextActions.OrderBy(x => x.CoastingStartDistance).First(); var nextCoastingAction = nextActions.OrderBy(x => x.CoastingStartDistance).First();
...@@ -214,7 +221,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -214,7 +221,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
// MQ: 27.5.2016 remark: one could set the coasting distance to the closest coasting distance as found above to start coasting a little bit earlier. // MQ: 27.5.2016 remark: one could set the coasting distance to the closest coasting distance as found above to start coasting a little bit earlier.
} }
private DrivingBehaviorEntry GetDrivingBehaviorEntry(MeterPerSecond nextTargetSpeed, MeterPerSecond currentSpeed, private DrivingBehaviorEntry GetDrivingBehaviorEntry(
MeterPerSecond nextTargetSpeed, MeterPerSecond currentSpeed,
DrivingCycleData.DrivingCycleEntry entry) DrivingCycleData.DrivingCycleEntry entry)
{ {
var action = DrivingBehavior.Braking; var action = DrivingBehavior.Braking;
...@@ -249,7 +257,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -249,7 +257,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return nextEntry; return nextEntry;
} }
protected internal virtual Meter ComputeCoastingDistance(MeterPerSecond vehicleSpeed, protected internal virtual Meter ComputeCoastingDistance(
MeterPerSecond vehicleSpeed,
DrivingCycleData.DrivingCycleEntry actionEntry) DrivingCycleData.DrivingCycleEntry actionEntry)
{ {
var targetSpeed = OverspeedAllowed(actionEntry.VehicleTargetSpeed) var targetSpeed = OverspeedAllowed(actionEntry.VehicleTargetSpeed)
...@@ -270,7 +279,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -270,7 +279,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var airDragForce = Driver.DataBus.AirDragResistance(vehicleSpeed, targetSpeed); var airDragForce = Driver.DataBus.AirDragResistance(vehicleSpeed, targetSpeed);
var rollResistanceForce = Driver.DataBus.RollingResistance( var rollResistanceForce = Driver.DataBus.RollingResistance(
((targetAltitude - vehicleAltitude) / (actionEntry.Distance - Driver.DataBus.Distance)).Value().SI<Radian>()); ((targetAltitude - vehicleAltitude) / (actionEntry.Distance - Driver.DataBus.Distance))
.Value().SI<Radian>());
var engineDragLoss = Driver.DataBus.EngineDragPower(Driver.DataBus.EngineSpeed); var engineDragLoss = Driver.DataBus.EngineDragPower(Driver.DataBus.EngineSpeed);
var gearboxLoss = Driver.DataBus.GearboxLoss(); var gearboxLoss = Driver.DataBus.GearboxLoss();
var axleLoss = Driver.DataBus.AxlegearLoss(); var axleLoss = Driver.DataBus.AxlegearLoss();
...@@ -278,7 +288,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -278,7 +288,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var coastingResistanceForce = airDragForce + rollResistanceForce + var coastingResistanceForce = airDragForce + rollResistanceForce +
(gearboxLoss + axleLoss - engineDragLoss) / vehicleSpeed; (gearboxLoss + axleLoss - engineDragLoss) / vehicleSpeed;
var coastingDecisionFactor = Driver.DriverData.LookAheadCoasting.LookAheadDecisionFactor.Lookup(targetSpeed, var coastingDecisionFactor = Driver.DriverData.LookAheadCoasting.LookAheadDecisionFactor.Lookup(
targetSpeed,
vehicleSpeed - targetSpeed); vehicleSpeed - targetSpeed);
var coastingDistance = (energyDifference / (coastingDecisionFactor * coastingResistanceForce)).Cast<Meter>(); var coastingDistance = (energyDifference / (coastingDecisionFactor * coastingResistanceForce)).Cast<Meter>();
return coastingDistance; return coastingDistance;
...@@ -289,9 +300,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -289,9 +300,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
if (prohibitOverspeed) { if (prohibitOverspeed) {
return false; return false;
} }
return Driver.DriverData.OverSpeedEcoRoll.Mode == DriverMode.Overspeed return Driver.DriverData.OverSpeedEcoRoll.Mode == DriverMode.Overspeed
&& velocity > Driver.DriverData.OverSpeedEcoRoll.MinSpeed && velocity > Driver.DriverData.OverSpeedEcoRoll.MinSpeed
&& (velocity + Driver.DriverData.OverSpeedEcoRoll.OverSpeed) < (Driver.DataBus.MaxVehicleSpeed ?? 500.KMPHtoMeterPerSecond()); && (velocity + Driver.DriverData.OverSpeedEcoRoll.OverSpeed) <
(Driver.DataBus.MaxVehicleSpeed ?? 500.KMPHtoMeterPerSecond());
} }
} }
...@@ -356,13 +369,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -356,13 +369,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
if (ds.IsEqual(newds, 1e-3.SI<Meter>())) { if (ds.IsEqual(newds, 1e-3.SI<Meter>())) {
return response; return response;
} }
if (newds.IsSmallerOrEqual(0, 1e-3)) { if (newds.IsSmallerOrEqual(0, 1e-3)) {
newds = ds / 2.0; newds = ds / 2.0;
//DriverStrategy.CurrentDrivingMode = DefaultDriverStrategy.DrivingMode.DrivingModeBrake; //DriverStrategy.CurrentDrivingMode = DefaultDriverStrategy.DrivingMode.DrivingModeBrake;
//DriverStrategy.BrakeTrigger = DriverStrategy.NextDrivingAction; //DriverStrategy.BrakeTrigger = DriverStrategy.NextDrivingAction;
} }
var newOperatingPoint = VectoMath.ComputeTimeInterval(DataBus.VehicleSpeed, response.Acceleration, DataBus.Distance, var newOperatingPoint = VectoMath.ComputeTimeInterval(
DataBus.VehicleSpeed, response.Acceleration, DataBus.Distance,
newds); newds);
if (newOperatingPoint.SimulationInterval.IsSmaller(Constants.SimulationSettings.LowerBoundTimeInterval)) { if (newOperatingPoint.SimulationInterval.IsSmaller(Constants.SimulationSettings.LowerBoundTimeInterval)) {
// the next time interval will be too short, this may lead to issues with inertia etc. // the next time interval will be too short, this may lead to issues with inertia etc.
...@@ -370,7 +386,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -370,7 +386,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
response = DoHandleRequest(absTime, ds, Driver.DataBus.VehicleSpeed, gradient, true); response = DoHandleRequest(absTime, ds, Driver.DataBus.VehicleSpeed, gradient, true);
return response; return response;
} }
Log.Debug("Exceeding next ActionDistance at {0}. Reducing max Distance from {2} to {1}",
Log.Debug(
"Exceeding next ActionDistance at {0}. Reducing max Distance from {2} to {1}",
DriverStrategy.NextDrivingAction.ActionDistance, newds, ds); DriverStrategy.NextDrivingAction.ActionDistance, newds, ds);
return new ResponseDrivingCycleDistanceExceeded() { return new ResponseDrivingCycleDistanceExceeded() {
Source = this, Source = this,
...@@ -378,10 +396,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -378,10 +396,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
}; };
} }
protected abstract IResponse DoHandleRequest(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient, protected abstract IResponse DoHandleRequest(
Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient,
bool prohibitOverspeed = false); bool prohibitOverspeed = false);
protected abstract IResponse CheckRequestDoesNotExceedNextAction(Second absTime, Meter ds, protected abstract IResponse CheckRequestDoesNotExceedNextAction(
Second absTime, Meter ds,
MeterPerSecond targetVelocity, Radian gradient, IResponse response, out Meter newSimulationDistance); MeterPerSecond targetVelocity, Radian gradient, IResponse response, out Meter newSimulationDistance);
public abstract void ResetMode(); public abstract void ResetMode();
...@@ -391,7 +411,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -391,7 +411,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public class DriverModeDrive : AbstractDriverMode public class DriverModeDrive : AbstractDriverMode
{ {
protected override IResponse DoHandleRequest(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient, protected override IResponse DoHandleRequest(
Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient,
bool prohibitOverspeed = false) bool prohibitOverspeed = false)
{ {
var debug = new DebugData(); var debug = new DebugData();
...@@ -408,13 +429,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -408,13 +429,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return retVal; return retVal;
} }
} }
throw new VectoException("HandleRequestEngaged found no operating point."); throw new VectoException("HandleRequestEngaged found no operating point.");
} else { } else {
return HandleRequestDisengaged(absTime, ds, gradient, velocity, debug); return HandleRequestDisengaged(absTime, ds, gradient, velocity, debug);
} }
} }
private IResponse HandleRequestDisengaged(Second absTime, Meter ds, Radian gradient, MeterPerSecond velocity, private IResponse HandleRequestDisengaged(
Second absTime, Meter ds, Radian gradient, MeterPerSecond velocity,
DebugData debug) DebugData debug)
{ {
if (DataBus.VehicleSpeed.IsSmallerOrEqual(0.SI<MeterPerSecond>())) { if (DataBus.VehicleSpeed.IsSmallerOrEqual(0.SI<MeterPerSecond>())) {
...@@ -424,34 +447,38 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -424,34 +447,38 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
while (!DataBus.ClutchClosed(absTime + remainingShiftTime)) { while (!DataBus.ClutchClosed(absTime + remainingShiftTime)) {
remainingShiftTime += Constants.SimulationSettings.TargetTimeInterval; remainingShiftTime += Constants.SimulationSettings.TargetTimeInterval;
} }
return new ResponseFailTimeInterval { return new ResponseFailTimeInterval {
Source = this, Source = this,
DeltaT = remainingShiftTime, DeltaT = remainingShiftTime,
}; };
} }
var response = Driver.DrivingActionRoll(absTime, ds, velocity, gradient); var response = Driver.DrivingActionRoll(absTime, ds, velocity, gradient);
debug.Add(new { action = "ClutchOpen -> Roll", response }); debug.Add(new { action = "ClutchOpen -> Roll", response });
response.Switch(). response.Switch().Case<ResponseUnderload>(
Case<ResponseUnderload>(r => { r => {
response = Driver.DrivingActionBrake(absTime, ds, velocity, gradient, r); response = Driver.DrivingActionBrake(absTime, ds, velocity, gradient, r);
debug.Add(new { action = "Roll:Underload -> Brake", response }); debug.Add(new { action = "Roll:Underload -> Brake", response });
}) })
.Case<ResponseSpeedLimitExceeded>(() => { .Case<ResponseSpeedLimitExceeded>(
() => {
response = Driver.DrivingActionBrake(absTime, ds, velocity, gradient); response = Driver.DrivingActionBrake(absTime, ds, velocity, gradient);
debug.Add(new { action = "Roll:SpeedLimitExceeded -> Brake", response }); debug.Add(new { action = "Roll:SpeedLimitExceeded -> Brake", response });
}); });
return response; return response;
} }
private IResponse HandleRequestEngaged(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient, private IResponse HandleRequestEngaged(
Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient,
bool prohibitOverspeed, MeterPerSecond velocity, DebugData debug) bool prohibitOverspeed, MeterPerSecond velocity, DebugData debug)
{ {
// drive along // drive along
var first = FirstAccelerateOrCoast(absTime, ds, targetVelocity, gradient, prohibitOverspeed, velocity, debug); var first = FirstAccelerateOrCoast(absTime, ds, targetVelocity, gradient, prohibitOverspeed, velocity, debug);
var second = first; var second = first;
first.Switch(). first.Switch().Case<ResponseUnderload>(
Case<ResponseUnderload>(r => { r => {
if (DataBus.GearboxType.AutomaticTransmission() && !DataBus.ClutchClosed(absTime)) { if (DataBus.GearboxType.AutomaticTransmission() && !DataBus.ClutchClosed(absTime)) {
second = Driver.DrivingActionRoll(absTime, ds, velocity, gradient); second = Driver.DrivingActionRoll(absTime, ds, velocity, gradient);
} }
...@@ -463,32 +490,31 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -463,32 +490,31 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
second = Driver.DrivingActionBrake(absTime, ds, velocity, gradient); second = Driver.DrivingActionBrake(absTime, ds, velocity, gradient);
debug.Add(new { action = "first:(Underload & !Overspeed) -> Brake", second }); debug.Add(new { action = "first:(Underload & !Overspeed) -> Brake", second });
} }
}). }).Case<ResponseEngineSpeedTooHigh>(
Case<ResponseEngineSpeedTooHigh>(r => { r => { second = Driver.DrivingActionBrake(absTime, ds, targetVelocity, gradient, r); });
second = Driver.DrivingActionBrake(absTime, ds, targetVelocity, gradient, r);
});
if (second == null) { if (second == null) {
return null; return null;
} }
var third = second; var third = second;
second.Switch(). second.Switch().Case<ResponseGearShift>(
Case<ResponseGearShift>(r => { r => {
third = Driver.DrivingActionRoll(absTime, ds, velocity, gradient); third = Driver.DrivingActionRoll(absTime, ds, velocity, gradient);
debug.Add(new { action = "second: GearShift -> Roll", third }); debug.Add(new { action = "second: GearShift -> Roll", third });
third.Switch(). third.Switch().Case<ResponseUnderload>(
Case<ResponseUnderload>(() => { () => {
// overload may happen if driver limits acceleration when rolling downhill // overload may happen if driver limits acceleration when rolling downhill
third = Driver.DrivingActionBrake(absTime, ds, velocity, gradient); third = Driver.DrivingActionBrake(absTime, ds, velocity, gradient);
debug.Add(new { action = "third:Underload -> Brake", third }); debug.Add(new { action = "third:Underload -> Brake", third });
}). }).Case<ResponseSpeedLimitExceeded>(
Case<ResponseSpeedLimitExceeded>(() => { () => {
third = Driver.DrivingActionBrake(absTime, ds, velocity, gradient); third = Driver.DrivingActionBrake(absTime, ds, velocity, gradient);
debug.Add(new { action = "third:SpeedLimitExceeded -> Brake", third }); debug.Add(new { action = "third:SpeedLimitExceeded -> Brake", third });
}); });
}). }).Case<ResponseOverload>(
Case<ResponseOverload>(r => { r => {
third = Driver.DrivingActionCoast(absTime, ds, velocity, gradient); third = Driver.DrivingActionCoast(absTime, ds, velocity, gradient);
debug.Add(new { action = "second:Overload -> Coast", third }); debug.Add(new { action = "second:Overload -> Coast", third });
}); });
...@@ -496,19 +522,22 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -496,19 +522,22 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return third; 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) MeterPerSecond velocity, DebugData debug, IResponse second)
{ {
if (second is ResponseUnderload || second is ResponseSpeedLimitExceeded) { if (second is ResponseUnderload || second is ResponseSpeedLimitExceeded) {
second = Driver.DrivingActionBrake(absTime, ds, velocity, gradient); second = Driver.DrivingActionBrake(absTime, ds, velocity, gradient);
debug.Add(new { debug.Add(
new {
action = "second:(Underload|SpeedLimitExceeded) -> Brake", action = "second:(Underload|SpeedLimitExceeded) -> Brake",
second second
}); });
} }
if (second is ResponseEngineSpeedTooHigh) { if (second is ResponseEngineSpeedTooHigh) {
second = Driver.DrivingActionBrake(absTime, ds, velocity, gradient, second); second = Driver.DrivingActionBrake(absTime, ds, velocity, gradient, second);
debug.Add(new { debug.Add(
new {
action = "second:(EngineSpeedTooHigh|SpeedLimitExceeded) -> Brake with reduced acceleration", action = "second:(EngineSpeedTooHigh|SpeedLimitExceeded) -> Brake with reduced acceleration",
second second
}); });
...@@ -516,7 +545,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -516,7 +545,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return 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 velocity, DebugData debug) bool prohibitOverspeed, MeterPerSecond velocity, DebugData debug)
{ {
IResponse first; IResponse first;
...@@ -535,7 +565,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -535,7 +565,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return first; return first;
} }
protected override IResponse CheckRequestDoesNotExceedNextAction(Second absTime, Meter ds, protected override IResponse CheckRequestDoesNotExceedNextAction(
Second absTime, Meter ds,
MeterPerSecond targetVelocity, Radian gradient, IResponse response, out Meter newds) MeterPerSecond targetVelocity, Radian gradient, IResponse response, out Meter newds)
{ {
var nextAction = DriverStrategy.NextDrivingAction; var nextAction = DriverStrategy.NextDrivingAction;
...@@ -543,8 +574,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -543,8 +574,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
if (nextAction == null) { if (nextAction == null) {
return response; return response;
} }
var v2 = Driver.DataBus.VehicleSpeed + response.Acceleration * response.SimulationInterval; var v2 = Driver.DataBus.VehicleSpeed + response.Acceleration * response.SimulationInterval;
var newBrakingDistance = Driver.DriverData.AccelerationCurve.ComputeAccelerationDistance(v2, var newBrakingDistance = Driver.DriverData.AccelerationCurve.ComputeAccelerationDistance(
v2,
nextAction.NextTargetSpeed) + DefaultDriverStrategy.BrakingSafetyMargin; nextAction.NextTargetSpeed) + DefaultDriverStrategy.BrakingSafetyMargin;
switch (DriverStrategy.NextDrivingAction.Action) { switch (DriverStrategy.NextDrivingAction.Action) {
case DrivingBehavior.Coasting: case DrivingBehavior.Coasting:
...@@ -555,25 +588,29 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -555,25 +588,29 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
newActionDistance = newBrakingDistance; newActionDistance = newBrakingDistance;
safetyFactor = 0.5; safetyFactor = 0.5;
} }
// if the distance at the end of the simulation interval is smaller than the new ActionDistance // if the distance at the end of the simulation interval is smaller than the new ActionDistance
// we are safe - go ahead... // we are safe - go ahead...
if ((Driver.DataBus.Distance + ds).IsSmallerOrEqual(nextAction.TriggerDistance - newActionDistance, if ((Driver.DataBus.Distance + ds).IsSmallerOrEqual(
nextAction.TriggerDistance - newActionDistance,
Constants.SimulationSettings.DriverActionDistanceTolerance * safetyFactor) && Constants.SimulationSettings.DriverActionDistanceTolerance * safetyFactor) &&
(Driver.DataBus.Distance + ds).IsSmallerOrEqual(nextAction.TriggerDistance - newBrakingDistance)) { (Driver.DataBus.Distance + ds).IsSmallerOrEqual(nextAction.TriggerDistance - newBrakingDistance)) {
return response; return response;
} }
newds = ds / 2; //EstimateAccelerationDistanceBeforeBrake(response, nextAction) ?? ds; newds = ds / 2; //EstimateAccelerationDistanceBeforeBrake(response, nextAction) ?? ds;
break; break;
case DrivingBehavior.Braking: case DrivingBehavior.Braking:
if ((Driver.DataBus.Distance + ds).IsSmaller(nextAction.TriggerDistance - newBrakingDistance)) { if ((Driver.DataBus.Distance + ds).IsSmaller(nextAction.TriggerDistance - newBrakingDistance)) {
return response; return response;
} }
newds = nextAction.TriggerDistance - newBrakingDistance - Driver.DataBus.Distance - newds = nextAction.TriggerDistance - newBrakingDistance - Driver.DataBus.Distance -
Constants.SimulationSettings.DriverActionDistanceTolerance / 2; Constants.SimulationSettings.DriverActionDistanceTolerance / 2;
break; break;
default: default: return response;
return response;
} }
return response; return response;
} }
...@@ -593,7 +630,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -593,7 +630,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
protected BrakingPhase Phase; protected BrakingPhase Phase;
protected bool RetryDistanceExceeded; protected bool RetryDistanceExceeded;
protected override IResponse DoHandleRequest(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient, protected override IResponse DoHandleRequest(
Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient,
bool prohibitOverspeed = false) bool prohibitOverspeed = false)
{ {
if (DataBus.VehicleSpeed <= DriverStrategy.BrakeTrigger.NextTargetSpeed && !DataBus.VehicleStopped) { if (DataBus.VehicleSpeed <= DriverStrategy.BrakeTrigger.NextTargetSpeed && !DataBus.VehicleStopped) {
...@@ -608,6 +646,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -608,6 +646,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return retVal; return retVal;
} }
var currentDistance = DataBus.Distance; var currentDistance = DataBus.Distance;
var brakingDistance = Driver.ComputeDecelerationDistance(DriverStrategy.BrakeTrigger.NextTargetSpeed) + var brakingDistance = Driver.ComputeDecelerationDistance(DriverStrategy.BrakeTrigger.NextTargetSpeed) +
...@@ -619,6 +658,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -619,6 +658,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return resp; return resp;
} }
} }
switch (Phase) { switch (Phase) {
case BrakingPhase.Coast: case BrakingPhase.Coast:
for (var i = 1; i < 3; i++) { for (var i = 1; i < 3; i++) {
...@@ -630,20 +670,23 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -630,20 +670,23 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
throw new VectoException("No valid operating point found"); throw new VectoException("No valid operating point found");
case BrakingPhase.Brake: case BrakingPhase.Brake:
return DoBrake(absTime, ds, targetVelocity, gradient, brakingDistance, currentDistance); return DoBrake(absTime, ds, targetVelocity, gradient, brakingDistance, currentDistance);
default: default: throw new VectoException("Invalid Phase in DriverModeBrake");
throw new VectoException("Invalid Phase in DriverModeBrake");
} }
} }
private IResponse DoBrake(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient, private IResponse DoBrake(
Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient,
Meter brakingDistance, Meter currentDistance) Meter brakingDistance, Meter currentDistance)
{ {
IResponse response; IResponse response;
Log.Debug("Phase: BRAKE. breaking distance: {0} start braking @ {1}", brakingDistance, Log.Debug(
"Phase: BRAKE. breaking distance: {0} start braking @ {1}", brakingDistance,
DriverStrategy.BrakeTrigger.BrakingStartDistance); DriverStrategy.BrakeTrigger.BrakingStartDistance);
if (DriverStrategy.BrakeTrigger.BrakingStartDistance.IsSmaller(currentDistance, if (DriverStrategy.BrakeTrigger.BrakingStartDistance.IsSmaller(
currentDistance,
Constants.SimulationSettings.DriverActionDistanceTolerance / 2)) { Constants.SimulationSettings.DriverActionDistanceTolerance / 2)) {
Log.Info("Expected Braking Deceleration could not be reached! {0}", Log.Info(
"Expected Braking Deceleration could not be reached! {0}",
DriverStrategy.BrakeTrigger.BrakingStartDistance - currentDistance); DriverStrategy.BrakeTrigger.BrakingStartDistance - currentDistance);
} }
var targetDistance = DataBus.VehicleSpeed < Constants.SimulationSettings.MinVelocityForCoast var targetDistance = DataBus.VehicleSpeed < Constants.SimulationSettings.MinVelocityForCoast
...@@ -664,7 +707,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -664,7 +707,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
response = Driver.DrivingActionAccelerate(absTime, ds, 1.KMPHtoMeterPerSecond(), gradient); response = Driver.DrivingActionAccelerate(absTime, ds, 1.KMPHtoMeterPerSecond(), gradient);
if (response is ResponseUnderload) { if (response is ResponseUnderload) {
response = Driver.DrivingActionBrake(absTime, ds, 1.KMPHtoMeterPerSecond(), gradient, response, overrideAction: DrivingAction.Accelerate); response = Driver.DrivingActionBrake(
absTime, ds, 1.KMPHtoMeterPerSecond(), gradient, response, overrideAction: DrivingAction.Accelerate);
} }
} else { } else {
response = Driver.DrivingActionBrake( response = Driver.DrivingActionBrake(
...@@ -674,7 +718,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -674,7 +718,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
if (DataBus.GearboxType.AutomaticTransmission() && response == null) { if (DataBus.GearboxType.AutomaticTransmission() && response == null) {
for (var i = 0; i < 3 && response == null; i++) { for (var i = 0; i < 3 && response == null; i++) {
response = Driver.DrivingActionBrake(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, response = Driver.DrivingActionBrake(
absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed,
gradient, targetDistance: targetDistance); gradient, targetDistance: targetDistance);
} }
...@@ -682,8 +727,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -682,8 +727,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
throw new VectoException("No valid operating point found"); throw new VectoException("No valid operating point found");
} }
} }
response.Switch().
Case<ResponseOverload>(r => { response.Switch().Case<ResponseOverload>(
r => {
Log.Info( Log.Info(
"Brake -> Got OverloadResponse during brake action - desired deceleration could not be reached! response: {0}", "Brake -> Got OverloadResponse during brake action - desired deceleration could not be reached! response: {0}",
r); r);
...@@ -691,32 +737,35 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -691,32 +737,35 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
Log.Info("Brake -> Overload -> Clutch is open - Trying roll action"); Log.Info("Brake -> Overload -> Clutch is open - Trying roll action");
response = Driver.DrivingActionRoll(absTime, ds, targetVelocity, gradient); response = Driver.DrivingActionRoll(absTime, ds, targetVelocity, gradient);
response.Switch().Case<ResponseSpeedLimitExceeded>( response.Switch().Case<ResponseSpeedLimitExceeded>(
() => { () => { response = Driver.DrivingActionBrake(absTime, ds, targetVelocity, gradient); }
response = Driver.DrivingActionBrake(absTime, ds, targetVelocity, gradient);
}
); );
} else { } else {
Log.Info("Brake -> Overload -> Clutch is closed - Trying brake action again"); Log.Info("Brake -> Overload -> Clutch is closed - Trying brake action again");
DataBus.BrakePower = 0.SI<Watt>(); DataBus.BrakePower = 0.SI<Watt>();
response = Driver.DrivingActionBrake(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, gradient, response = Driver.DrivingActionBrake(
absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, gradient,
targetDistance: targetDistance); targetDistance: targetDistance);
response.Switch(). response.Switch().Case<ResponseOverload>(
Case<ResponseOverload>(r1 => { r1 => {
Log.Info("Brake -> Overload -> 2nd Brake -> Overload -> Trying accelerate action"); Log.Info("Brake -> Overload -> 2nd Brake -> Overload -> Trying accelerate action");
response = Driver.DrivingActionAccelerate(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, gradient); response = Driver.DrivingActionAccelerate(
absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, gradient);
response.Switch().Case<ResponseGearShift>( response.Switch().Case<ResponseGearShift>(
rs => { rs => {
Log.Info("Brake -> Overload -> 2nd Brake -> Accelerate -> Got GearShift response, performing roll action"); Log.Info(
"Brake -> Overload -> 2nd Brake -> Accelerate -> Got GearShift response, performing roll action");
response = Driver.DrivingActionRoll(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, gradient); response = Driver.DrivingActionRoll(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, gradient);
}); });
}); });
} }
}). }).Case<ResponseGearShift>(
Case<ResponseGearShift>(r => { r => {
Log.Info("Brake -> Got GearShift response, performing roll action + brakes"); Log.Info("Brake -> Got GearShift response, performing roll action + brakes");
//response = Driver.DrivingActionRoll(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, gradient); //response = Driver.DrivingActionRoll(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, gradient);
DataBus.BrakePower = 0.SI<Watt>(); DataBus.BrakePower = 0.SI<Watt>();
response = Driver.DrivingActionBrake(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, response = Driver.DrivingActionBrake(
absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed,
gradient, targetDistance: targetDistance); gradient, targetDistance: targetDistance);
response.Switch().Case<ResponseOverload>( response.Switch().Case<ResponseOverload>(
() => { () => {
...@@ -727,7 +776,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -727,7 +776,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return response; return response;
} }
private IResponse DoCoast(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient, private IResponse DoCoast(
Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient,
Meter currentDistance) Meter currentDistance)
{ {
IResponse response; IResponse response;
...@@ -735,40 +785,44 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -735,40 +785,44 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
response = DataBus.ClutchClosed(absTime) response = DataBus.ClutchClosed(absTime)
? Driver.DrivingActionCoast(absTime, ds, VectoMath.Max(targetVelocity, DataBus.VehicleSpeed), gradient) ? Driver.DrivingActionCoast(absTime, ds, VectoMath.Max(targetVelocity, DataBus.VehicleSpeed), gradient)
: Driver.DrivingActionRoll(absTime, ds, VectoMath.Max(targetVelocity, DataBus.VehicleSpeed), gradient); : Driver.DrivingActionRoll(absTime, ds, VectoMath.Max(targetVelocity, DataBus.VehicleSpeed), gradient);
response.Switch(). response.Switch().Case<ResponseUnderload>(
Case<ResponseUnderload>(r => { r => {
// coast would decelerate more than driver's max deceleration => issue brakes to decelerate with driver's max deceleration // coast would decelerate more than driver's max deceleration => issue brakes to decelerate with driver's max deceleration
response = Driver.DrivingActionBrake(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, response = Driver.DrivingActionBrake(
absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed,
gradient, r); gradient, r);
if ((DriverStrategy.BrakeTrigger.BrakingStartDistance - currentDistance).IsSmallerOrEqual( if ((DriverStrategy.BrakeTrigger.BrakingStartDistance - currentDistance).IsSmallerOrEqual(
Constants.SimulationSettings.DriverActionDistanceTolerance)) { Constants.SimulationSettings.DriverActionDistanceTolerance)) {
Phase = BrakingPhase.Brake; Phase = BrakingPhase.Brake;
} }
}). }).Case<ResponseOverload>(
Case<ResponseOverload>(r => { r => {
// limiting deceleration while coast may result in an overload => issue brakes to decelerate with driver's max deceleration // limiting deceleration while coast may result in an overload => issue brakes to decelerate with driver's max deceleration
response = DataBus.ClutchClosed(absTime) response = DataBus.ClutchClosed(absTime)
? Driver.DrivingActionAccelerate(absTime, ds, targetVelocity, gradient) ? Driver.DrivingActionAccelerate(absTime, ds, targetVelocity, gradient)
: Driver.DrivingActionRoll(absTime, ds, targetVelocity, gradient); : Driver.DrivingActionRoll(absTime, ds, targetVelocity, gradient);
//Phase = BrakingPhase.Brake; //Phase = BrakingPhase.Brake;
}). }).Case<ResponseDrivingCycleDistanceExceeded>(
Case<ResponseDrivingCycleDistanceExceeded>(r => { r => {
if (!ds.IsEqual(r.MaxDistance)) { if (!ds.IsEqual(r.MaxDistance)) {
// distance has been reduced due to vehicle stop in coast/roll action => use brake action to get exactly to the stop-distance // distance has been reduced due to vehicle stop in coast/roll action => use brake action to get exactly to the stop-distance
// TODO what if no gear is enaged (and we need driveline power to get to the stop-distance? // TODO what if no gear is enaged (and we need driveline power to get to the stop-distance?
response = Driver.DrivingActionBrake(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, gradient); response = Driver.DrivingActionBrake(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, gradient);
} }
}). }).Case<ResponseEngineSpeedTooHigh>(
Case<ResponseEngineSpeedTooHigh>(r => { r => { response = Driver.DrivingActionBrake(absTime, ds, targetVelocity, gradient, r); });
response = Driver.DrivingActionBrake(absTime, ds, targetVelocity, gradient, r); if (response == null) {
}); return response;
}
// handle the SpeedLimitExceeded Response and Gearshift Response separately in case it occurs in one of the requests in the second try // handle the SpeedLimitExceeded Response and Gearshift Response separately in case it occurs in one of the requests in the second try
response.Switch(). response.Switch().Case<ResponseGearShift>(
Case<ResponseGearShift>(r => { r => { response = Driver.DrivingActionRoll(absTime, ds, targetVelocity, gradient); })
response = Driver.DrivingActionRoll(absTime, ds, targetVelocity, gradient); .Case<ResponseSpeedLimitExceeded>(
}). () => {
Case<ResponseSpeedLimitExceeded>(() => { response = Driver.DrivingActionBrake(
response = Driver.DrivingActionBrake(absTime, ds, DataBus.VehicleSpeed, absTime, ds, DataBus.VehicleSpeed,
gradient); gradient);
if (response is ResponseOverload && !DataBus.ClutchClosed(absTime)) { if (response is ResponseOverload && !DataBus.ClutchClosed(absTime)) {
response = Driver.DrivingActionRoll(absTime, ds, DataBus.VehicleSpeed, gradient); response = Driver.DrivingActionRoll(absTime, ds, DataBus.VehicleSpeed, gradient);
...@@ -780,10 +834,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -780,10 +834,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
private IResponse CheckSwitchingToBraking(Meter ds, Meter currentDistance) private IResponse CheckSwitchingToBraking(Meter ds, Meter currentDistance)
{ {
var nextBrakeAction = DriverStrategy.GetNextDrivingAction(ds); var nextBrakeAction = DriverStrategy.GetNextDrivingAction(ds);
if (nextBrakeAction != null && !DriverStrategy.BrakeTrigger.TriggerDistance.IsEqual(nextBrakeAction.TriggerDistance) && if (nextBrakeAction != null &&
!DriverStrategy.BrakeTrigger.TriggerDistance.IsEqual(nextBrakeAction.TriggerDistance) &&
nextBrakeAction.BrakingStartDistance.IsSmaller(DriverStrategy.BrakeTrigger.BrakingStartDistance)) { nextBrakeAction.BrakingStartDistance.IsSmaller(DriverStrategy.BrakeTrigger.BrakingStartDistance)) {
DriverStrategy.BrakeTrigger = nextBrakeAction; DriverStrategy.BrakeTrigger = nextBrakeAction;
Log.Debug("setting brake trigger to new trigger: trigger distance: {0}, start braking @ {1}", Log.Debug(
"setting brake trigger to new trigger: trigger distance: {0}, start braking @ {1}",
nextBrakeAction.TriggerDistance, nextBrakeAction.BrakingStartDistance); nextBrakeAction.TriggerDistance, nextBrakeAction.BrakingStartDistance);
} }
...@@ -803,9 +859,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -803,9 +859,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
}; };
} }
} }
if (DataBus.VehicleSpeed < Constants.SimulationSettings.MinVelocityForCoast) { if (DataBus.VehicleSpeed < Constants.SimulationSettings.MinVelocityForCoast) {
Phase = BrakingPhase.Brake; Phase = BrakingPhase.Brake;
Log.Debug("Switching to BRAKE Phase. currentDistance: {0} v: {1}", currentDistance, Log.Debug(
"Switching to BRAKE Phase. currentDistance: {0} v: {1}", currentDistance,
DataBus.VehicleSpeed); DataBus.VehicleSpeed);
} }
return null; return null;
...@@ -814,30 +872,35 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -814,30 +872,35 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
private IResponse HandleTargetspeedReached(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient) private IResponse HandleTargetspeedReached(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient)
{ {
var response = TargetSpeedReachedDriveAlong(absTime, ds, targetVelocity, gradient); var response = TargetSpeedReachedDriveAlong(absTime, ds, targetVelocity, gradient);
//var i = 0; //var i = 0;
//do { //do {
response.Switch(). response.Switch().Case<ResponseGearShift>(
Case<ResponseGearShift>(() => { () => {
response = Driver.DrivingActionRoll(absTime, ds, targetVelocity, gradient); response = Driver.DrivingActionRoll(absTime, ds, targetVelocity, gradient);
response.Switch(). response.Switch().Case<ResponseUnderload>(
Case<ResponseUnderload>(r => { r => {
// under-load may happen if driver limits acceleration when rolling downhill // under-load may happen if driver limits acceleration when rolling downhill
response = Driver.DrivingActionBrake(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, response = Driver.DrivingActionBrake(
absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed,
gradient, r); gradient, r);
}). }).Case<ResponseSpeedLimitExceeded>(
Case<ResponseSpeedLimitExceeded>(() => { () => {
response = Driver.DrivingActionBrake(absTime, ds, DataBus.VehicleSpeed, response = Driver.DrivingActionBrake(
absTime, ds, DataBus.VehicleSpeed,
gradient); gradient);
}); });
}). }).Case<ResponseSpeedLimitExceeded>(
Case<ResponseSpeedLimitExceeded>(() => { () => {
response = Driver.DrivingActionBrake(absTime, ds, DataBus.VehicleSpeed, response = Driver.DrivingActionBrake(
absTime, ds, DataBus.VehicleSpeed,
gradient); gradient);
}). }).Case<ResponseUnderload>(
Case<ResponseUnderload>(r => { r => {
//response = Driver.DrivingActionBrake(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, //response = Driver.DrivingActionBrake(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed,
// gradient, r); // gradient, r);
response = Driver.DrivingActionBrake(absTime, ds, DataBus.VehicleSpeed + r.Acceleration * r.SimulationInterval, response = Driver.DrivingActionBrake(
absTime, ds, DataBus.VehicleSpeed + r.Acceleration * r.SimulationInterval,
gradient, r); gradient, r);
if (response != null) { if (response != null) {
response.Switch().Case<ResponseGearShift>( response.Switch().Case<ResponseGearShift>(
...@@ -867,11 +930,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -867,11 +930,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
}); });
} }
}); });
//} while (!(response is ResponseSuccess) && i++ < 3); //} while (!(response is ResponseSuccess) && i++ < 3);
return response; return response;
} }
private IResponse TargetSpeedReachedDriveAlong(Second absTime, Meter ds, MeterPerSecond targetVelocity, private IResponse TargetSpeedReachedDriveAlong(
Second absTime, Meter ds, MeterPerSecond targetVelocity,
Radian gradient) Radian gradient)
{ {
IResponse response; IResponse response;
...@@ -892,7 +957,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -892,7 +957,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return response; return response;
} }
protected override IResponse CheckRequestDoesNotExceedNextAction(Second absTime, Meter ds, protected override IResponse CheckRequestDoesNotExceedNextAction(
Second absTime, Meter ds,
MeterPerSecond targetVelocity, Radian gradient, IResponse response, out Meter newds) MeterPerSecond targetVelocity, Radian gradient, IResponse response, out Meter newds)
{ {
var nextAction = DriverStrategy.BrakeTrigger; var nextAction = DriverStrategy.BrakeTrigger;
...@@ -904,17 +970,19 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -904,17 +970,19 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
switch (nextAction.Action) { switch (nextAction.Action) {
case DrivingBehavior.Coasting: case DrivingBehavior.Coasting:
var v2 = Driver.DataBus.VehicleSpeed + response.Acceleration * response.SimulationInterval; var v2 = Driver.DataBus.VehicleSpeed + response.Acceleration * response.SimulationInterval;
var newBrakingDistance = Driver.DriverData.AccelerationCurve.ComputeAccelerationDistance(v2, var newBrakingDistance = Driver.DriverData.AccelerationCurve.ComputeAccelerationDistance(
v2,
nextAction.NextTargetSpeed); nextAction.NextTargetSpeed);
if ((Driver.DataBus.Distance + ds).IsSmaller(nextAction.TriggerDistance - newBrakingDistance)) { if ((Driver.DataBus.Distance + ds).IsSmaller(nextAction.TriggerDistance - newBrakingDistance)) {
return response; return response;
} }
newds = nextAction.TriggerDistance - newBrakingDistance - Driver.DataBus.Distance - newds = nextAction.TriggerDistance - newBrakingDistance - Driver.DataBus.Distance -
Constants.SimulationSettings.DriverActionDistanceTolerance / 2; Constants.SimulationSettings.DriverActionDistanceTolerance / 2;
break; break;
default: default: return response;
return response;
} }
return response; return response;
} }
...@@ -936,9 +1004,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -936,9 +1004,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public Meter ActionDistance public Meter ActionDistance
{ {
get get {
{ return VectoMath.Min(
return VectoMath.Min(CoastingStartDistance ?? double.MaxValue.SI<Meter>(), CoastingStartDistance ?? double.MaxValue.SI<Meter>(),
BrakingStartDistance ?? double.MaxValue.SI<Meter>()); BrakingStartDistance ?? double.MaxValue.SI<Meter>());
} }
} }
...@@ -962,7 +1030,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -962,7 +1030,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public override string ToString() public override string ToString()
{ {
return string.Format("action: {0} @ {1} / {2}. trigger: {3} targetSpeed: {4}", Action, CoastingStartDistance, return string.Format(
"action: {0} @ {1} / {2}. trigger: {3} targetSpeed: {4}", Action, CoastingStartDistance,
BrakingStartDistance, TriggerDistance, NextTargetSpeed); BrakingStartDistance, TriggerDistance, NextTargetSpeed);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment