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 95c0a174 authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

add databus property to driver strategy for easier debugging (access databus in the same way)

parent 8f803c33
Branches
Tags
No related merge requests found
...@@ -130,16 +130,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -130,16 +130,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public IDriverActions Driver { get; set; } public IDriverActions Driver { get; set; }
protected IDataBus DataBus => Driver?.DataBus;
protected internal DrivingBehaviorEntry BrakeTrigger { get; set; } protected internal DrivingBehaviorEntry BrakeTrigger { get; set; }
public IResponse Request(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient) public IResponse Request(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient)
{ {
var retVal = DoHandleRequest(absTime, ds, targetVelocity, gradient); var retVal = DoHandleRequest(absTime, ds, targetVelocity, gradient);
if (retVal is ResponseSuccess) { if (retVal is ResponseSuccess) {
EcoRollState.PreviousBrakePower = Driver.DataBus.Brakes.BrakePower; EcoRollState.PreviousBrakePower = DataBus.Brakes.BrakePower;
if (retVal.Source is ICombustionEngine) { if (retVal.Source is ICombustionEngine) {
var success = retVal as ResponseSuccess; var success = retVal as ResponseSuccess;
var avgEngineSpeed = (success.Engine.EngineSpeed + Driver.DataBus.EngineInfo.EngineSpeed) / 2.0; var avgEngineSpeed = (success.Engine.EngineSpeed + DataBus.EngineInfo.EngineSpeed) / 2.0;
EcoRollState.AcceleratorPedalIdle = success.Engine.DragPower.IsEqual(success.Engine.TotalTorqueDemand * avgEngineSpeed, 10.SI<Watt>()); EcoRollState.AcceleratorPedalIdle = success.Engine.DragPower.IsEqual(success.Engine.TotalTorqueDemand * avgEngineSpeed, 10.SI<Watt>());
} else { } else {
EcoRollState.AcceleratorPedalIdle = false; EcoRollState.AcceleratorPedalIdle = false;
...@@ -158,8 +160,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -158,8 +160,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
} }
var retVal = Driver.DrivingActionHalt( var retVal = Driver.DrivingActionHalt(
absTime, dt, VectoMath.Min(Driver.DataBus.VehicleInfo.MaxVehicleSpeed, targetVelocity), gradient); absTime, dt, VectoMath.Min(DataBus.VehicleInfo.MaxVehicleSpeed, targetVelocity), gradient);
EcoRollState.PreviousBrakePower = Driver.DataBus.Brakes.BrakePower; EcoRollState.PreviousBrakePower = DataBus.Brakes.BrakePower;
return retVal; return retVal;
} }
...@@ -168,11 +170,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -168,11 +170,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
container.SetDataValue("EcoRollConditionsMet", EcoRollState.AllConditionsMet ? 1 : 0); container.SetDataValue("EcoRollConditionsMet", EcoRollState.AllConditionsMet ? 1 : 0);
if (PCCSegments.Count > 0) { if (PCCSegments.Count > 0) {
var val = 0; var val = 0;
if (Driver.DataBus.MileageCounter.Distance > PCCSegments.Current.EndDistance) { if (DataBus.MileageCounter.Distance > PCCSegments.Current.EndDistance) {
val = 0; val = 0;
} else if (Driver.DataBus.MileageCounter.Distance > PCCSegments.Current.DistanceAtLowestSpeed) { } else if (DataBus.MileageCounter.Distance > PCCSegments.Current.DistanceAtLowestSpeed) {
val = 5; val = 5;
} else if (Driver.DataBus.MileageCounter.Distance > PCCSegments.Current.StartDistance) { } else if (DataBus.MileageCounter.Distance > PCCSegments.Current.StartDistance) {
val = -5; val = -5;
} }
container.SetDataValue("PCCSegment", val); container.SetDataValue("PCCSegment", val);
...@@ -186,7 +188,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -186,7 +188,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public void CommitSimulationStep() public void CommitSimulationStep()
{ {
if (PCCSegments.Count > 0) { if (PCCSegments.Count > 0) {
if (Driver.DataBus.MileageCounter.Distance > PCCSegments.Current.EndDistance) { if (DataBus.MileageCounter.Distance > PCCSegments.Current.EndDistance) {
PCCSegments.MoveNext(); PCCSegments.MoveNext();
pccState = PCCStates.OutsideSegment; pccState = PCCStates.OutsideSegment;
} }
...@@ -211,8 +213,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -211,8 +213,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
if (EcoRollState.State != EcoRollStates.EcoRollOn && pccState != PCCStates.UseCase1 && if (EcoRollState.State != EcoRollStates.EcoRollOn && pccState != PCCStates.UseCase1 &&
pccState != PCCStates.UseCase2) { pccState != PCCStates.UseCase2) {
EngineOffTimestamp = null; EngineOffTimestamp = null;
if (Driver.DataBus.PowertrainInfo.HasCombustionEngine && !Driver.DataBus.PowertrainInfo.HasElectricMotor) { if (DataBus.PowertrainInfo.HasCombustionEngine && !DataBus.PowertrainInfo.HasElectricMotor) {
Driver.DataBus.EngineCtl.CombustionEngineOn = true; DataBus.EngineCtl.CombustionEngineOn = true;
} }
} }
//} //}
...@@ -222,7 +224,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -222,7 +224,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
if (nextAction != null && !BrakeTrigger.HasEqualTrigger(nextAction) && nextAction.ActionDistance.IsSmallerOrEqual(BrakeTrigger.ActionDistance)) { if (nextAction != null && !BrakeTrigger.HasEqualTrigger(nextAction) && nextAction.ActionDistance.IsSmallerOrEqual(BrakeTrigger.ActionDistance)) {
BrakeTrigger = nextAction; BrakeTrigger = nextAction;
} }
if (Driver.DataBus.MileageCounter.Distance.IsGreaterOrEqual(BrakeTrigger.TriggerDistance, 1e-3.SI<Meter>())) { if (DataBus.MileageCounter.Distance.IsGreaterOrEqual(BrakeTrigger.TriggerDistance, 1e-3.SI<Meter>())) {
CurrentDrivingMode = DrivingMode.DrivingModeDrive; CurrentDrivingMode = DrivingMode.DrivingModeDrive;
NextDrivingAction = null; NextDrivingAction = null;
DrivingModes[CurrentDrivingMode].ResetMode(); DrivingModes[CurrentDrivingMode].ResetMode();
...@@ -232,27 +234,27 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -232,27 +234,27 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
} }
if (CurrentDrivingMode == DrivingMode.DrivingModeDrive) { if (CurrentDrivingMode == DrivingMode.DrivingModeDrive) {
var currentDistance = Driver.DataBus.MileageCounter.Distance; var currentDistance = DataBus.MileageCounter.Distance;
//var coasting = LookAheadCoasting(ds); //var coasting = LookAheadCoasting(ds);
UpdateDrivingAction(currentDistance, ds); UpdateDrivingAction(currentDistance, ds);
if (NextDrivingAction != null) { if (NextDrivingAction != null) {
var remainingDistance = NextDrivingAction.ActionDistance - currentDistance; var remainingDistance = NextDrivingAction.ActionDistance - currentDistance;
var estimatedTimestep = remainingDistance / Driver.DataBus.VehicleInfo.VehicleSpeed; var estimatedTimestep = remainingDistance / DataBus.VehicleInfo.VehicleSpeed;
var atTriggerTistance = remainingDistance.IsEqual( var atTriggerTistance = remainingDistance.IsEqual(
0.SI<Meter>(), Constants.SimulationSettings.DriverActionDistanceTolerance); 0.SI<Meter>(), Constants.SimulationSettings.DriverActionDistanceTolerance);
var closeBeforeBraking = estimatedTimestep.IsSmaller(Constants.SimulationSettings.LowerBoundTimeInterval); var closeBeforeBraking = estimatedTimestep.IsSmaller(Constants.SimulationSettings.LowerBoundTimeInterval);
var brakingIntervalTooShort = NextDrivingAction.Action == DrivingBehavior.Braking && var brakingIntervalTooShort = NextDrivingAction.Action == DrivingBehavior.Braking &&
((NextDrivingAction.TriggerDistance - NextDrivingAction.ActionDistance) / Driver.DataBus.VehicleInfo.VehicleSpeed) ((NextDrivingAction.TriggerDistance - NextDrivingAction.ActionDistance) / DataBus.VehicleInfo.VehicleSpeed)
.IsSmaller( .IsSmaller(
Constants.SimulationSettings.LowerBoundTimeInterval / 20) && !Driver.DataBus.ClutchInfo.ClutchClosed(absTime); Constants.SimulationSettings.LowerBoundTimeInterval / 20) && !DataBus.ClutchInfo.ClutchClosed(absTime);
var brakingIntervalShort = NextDrivingAction.Action == DrivingBehavior.Braking && var brakingIntervalShort = NextDrivingAction.Action == DrivingBehavior.Braking &&
NextDrivingAction.ActionDistance.IsSmaller(currentDistance + ds) && NextDrivingAction.ActionDistance.IsSmaller(currentDistance + ds) &&
((NextDrivingAction.TriggerDistance - NextDrivingAction.ActionDistance) / Driver.DataBus.VehicleInfo.VehicleSpeed) ((NextDrivingAction.TriggerDistance - NextDrivingAction.ActionDistance) / DataBus.VehicleInfo.VehicleSpeed)
.IsSmaller( .IsSmaller(
Constants.SimulationSettings.LowerBoundTimeInterval / 2) && (Driver.DataBus.GearboxInfo.GearboxType.AutomaticTransmission() || !Driver.DataBus.ClutchInfo.ClutchClosed(absTime)); Constants.SimulationSettings.LowerBoundTimeInterval / 2) && (DataBus.GearboxInfo.GearboxType.AutomaticTransmission() || !DataBus.ClutchInfo.ClutchClosed(absTime));
if (brakingIntervalShort && remainingDistance.IsEqual(ds)) { if (brakingIntervalShort && remainingDistance.IsEqual(ds)) {
return new ResponseDrivingCycleDistanceExceeded(this) { return new ResponseDrivingCycleDistanceExceeded(this) {
MaxDistance = ds / 2 MaxDistance = ds / 2
...@@ -278,14 +280,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -278,14 +280,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
} }
var retVal = DrivingModes[CurrentDrivingMode].Request( var retVal = DrivingModes[CurrentDrivingMode].Request(
absTime, ds, VectoMath.Min(Driver.DataBus.VehicleInfo.MaxVehicleSpeed, targetVelocity), gradient); absTime, ds, VectoMath.Min(DataBus.VehicleInfo.MaxVehicleSpeed, targetVelocity), gradient);
return retVal; return retVal;
} }
private void HandlePCC(Second absTime, MeterPerSecond targetVelocity) private void HandlePCC(Second absTime, MeterPerSecond targetVelocity)
{ {
var dataBus = Driver.DataBus; var dataBus = DataBus;
var vehicleSpeed = dataBus.VehicleInfo.VehicleSpeed; var vehicleSpeed = dataBus.VehicleInfo.VehicleSpeed;
UpdatePCCState(targetVelocity); UpdatePCCState(targetVelocity);
...@@ -347,7 +349,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -347,7 +349,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
private void UpdatePCCState(MeterPerSecond targetVelocity) private void UpdatePCCState(MeterPerSecond targetVelocity)
{ {
// check if within PCC segment and update state ---------------------------- // check if within PCC segment and update state ----------------------------
var distance = Driver.DataBus.MileageCounter.Distance; var distance = DataBus.MileageCounter.Distance;
var withinPCCSegment = PCCSegments.Current != null var withinPCCSegment = PCCSegments.Current != null
&& PCCSegments.Current.StartDistance <= distance && PCCSegments.Current.StartDistance <= distance
&& distance <= PCCSegments.Current.EndDistance; && distance <= PCCSegments.Current.EndDistance;
...@@ -367,13 +369,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -367,13 +369,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var endEnergyUseCase1 = PCCSegments.Current.EnergyAtEnd; var endEnergyUseCase1 = PCCSegments.Current.EnergyAtEnd;
if ((distance + Driver.DriverData.PCC.PreviewDistanceUseCase1).IsSmallerOrEqual(endUseCase1)) { if ((distance + Driver.DriverData.PCC.PreviewDistanceUseCase1).IsSmallerOrEqual(endUseCase1)) {
endUseCase1 = distance + Driver.DriverData.PCC.PreviewDistanceUseCase1; endUseCase1 = distance + Driver.DriverData.PCC.PreviewDistanceUseCase1;
var endCycleEntry = Driver.DataBus.DrivingCycleInfo.CycleLookAhead(Driver.DriverData.PCC.PreviewDistanceUseCase1); var endCycleEntry = DataBus.DrivingCycleInfo.CycleLookAhead(Driver.DriverData.PCC.PreviewDistanceUseCase1);
endEnergyUseCase1 = CalculateEnergy(endCycleEntry.Altitude, endCycleEntry.VehicleTargetSpeed, Driver.DataBus.VehicleInfo.TotalMass); endEnergyUseCase1 = CalculateEnergy(endCycleEntry.Altitude, endCycleEntry.VehicleTargetSpeed, DataBus.VehicleInfo.TotalMass);
} }
var vehicleSpeed = Driver.DataBus.VehicleInfo.VehicleSpeed; var vehicleSpeed = DataBus.VehicleInfo.VehicleSpeed;
var coastingForce = CalculateCoastingForce(targetVelocity, vehicleSpeed, PCCSegments.Current.Altitude, endUseCase1); var coastingForce = CalculateCoastingForce(targetVelocity, vehicleSpeed, PCCSegments.Current.Altitude, endUseCase1);
var energyCoastingEndUseCase1 = (coastingForce * (endUseCase1 - distance)).Cast<Joule>(); var energyCoastingEndUseCase1 = (coastingForce * (endUseCase1 - distance)).Cast<Joule>();
var currentEnergy = CalculateEnergy(Driver.DataBus.DrivingCycleInfo.Altitude, vehicleSpeed, Driver.DataBus.VehicleInfo.TotalMass); var currentEnergy = CalculateEnergy(DataBus.DrivingCycleInfo.Altitude, vehicleSpeed, DataBus.VehicleInfo.TotalMass);
var energyCoastingLow = (coastingForce * (PCCSegments.Current.DistanceAtLowestSpeed - distance)).Cast<Joule>(); var energyCoastingLow = (coastingForce * (PCCSegments.Current.DistanceAtLowestSpeed - distance)).Cast<Joule>();
var beforeVLow = distance.IsSmaller(PCCSegments.Current.DistanceAtLowestSpeed); var beforeVLow = distance.IsSmaller(PCCSegments.Current.DistanceAtLowestSpeed);
...@@ -394,8 +396,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -394,8 +396,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var endEnergyUseCase2 = PCCSegments.Current.EnergyAtEnd; var endEnergyUseCase2 = PCCSegments.Current.EnergyAtEnd;
if ((distance + Driver.DriverData.PCC.PreviewDistanceUseCase2).IsSmallerOrEqual(endUseCase2)) { if ((distance + Driver.DriverData.PCC.PreviewDistanceUseCase2).IsSmallerOrEqual(endUseCase2)) {
endUseCase2 = distance + Driver.DriverData.PCC.PreviewDistanceUseCase2; endUseCase2 = distance + Driver.DriverData.PCC.PreviewDistanceUseCase2;
var endCycleEntry = Driver.DataBus.DrivingCycleInfo.CycleLookAhead(Driver.DriverData.PCC.PreviewDistanceUseCase2); var endCycleEntry = DataBus.DrivingCycleInfo.CycleLookAhead(Driver.DriverData.PCC.PreviewDistanceUseCase2);
endEnergyUseCase2 = CalculateEnergy(endCycleEntry.Altitude, endCycleEntry.VehicleTargetSpeed, Driver.DataBus.VehicleInfo.TotalMass); endEnergyUseCase2 = CalculateEnergy(endCycleEntry.Altitude, endCycleEntry.VehicleTargetSpeed, DataBus.VehicleInfo.TotalMass);
} }
var energyCoastingEndUseCase2 = coastingForce * (endUseCase2 - distance); var energyCoastingEndUseCase2 = coastingForce * (endUseCase2 - distance);
...@@ -414,26 +416,26 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -414,26 +416,26 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
private Newton CalculateCoastingForce(MeterPerSecond targetVelocity, MeterPerSecond vehicleSpeed, Meter targetAltitude, Meter targetDistance) private Newton CalculateCoastingForce(MeterPerSecond targetVelocity, MeterPerSecond vehicleSpeed, Meter targetAltitude, Meter targetDistance)
{ {
var dataBus = Driver.DataBus; var dataBus = DataBus;
var airDragForce = Driver.DataBus.VehicleInfo.AirDragResistance(vehicleSpeed, targetVelocity); var airDragForce = DataBus.VehicleInfo.AirDragResistance(vehicleSpeed, targetVelocity);
var rollResistanceForce = Driver.DataBus.VehicleInfo.RollingResistance(dataBus.DrivingCycleInfo.RoadGradient); var rollResistanceForce = DataBus.VehicleInfo.RollingResistance(dataBus.DrivingCycleInfo.RoadGradient);
//mk20211008 shouldn't we calculate it the same as in ComputeCoastingDistance? //mk20211008 shouldn't we calculate it the same as in ComputeCoastingDistance?
//var rollResistanceForce = Driver.DataBus.VehicleInfo.RollingResistance( //var rollResistanceForce = DataBus.VehicleInfo.RollingResistance(
// ((targetAltitude - Driver.DataBus.DrivingCycleInfo.Altitude) / (targetDistance - Driver.DataBus.MileageCounter.Distance)) // ((targetAltitude - DataBus.DrivingCycleInfo.Altitude) / (targetDistance - DataBus.MileageCounter.Distance))
// .Value().SI<Radian>()); // .Value().SI<Radian>());
var gearboxLoss = Driver.DataBus.GearboxInfo.GearboxLoss(); var gearboxLoss = DataBus.GearboxInfo.GearboxLoss();
var axleLoss = Driver.DataBus.AxlegearInfo.AxlegearLoss(); var axleLoss = DataBus.AxlegearInfo.AxlegearLoss();
var emDragLoss = CalculateElectricMotorDragLoss(); var emDragLoss = CalculateElectricMotorDragLoss();
var iceDragLoss = 0.SI<Watt>(); var iceDragLoss = 0.SI<Watt>();
if (dataBus.GearboxInfo.GearboxType.AutomaticTransmission()) { if (dataBus.GearboxInfo.GearboxType.AutomaticTransmission()) {
if (ADAS.EcoRoll == EcoRollType.None && ATEcoRollReleaseLockupClutch) { if (ADAS.EcoRoll == EcoRollType.None && ATEcoRollReleaseLockupClutch) {
iceDragLoss = Driver.DataBus.EngineInfo.EngineDragPower(Driver.DataBus.EngineInfo.EngineSpeed); iceDragLoss = DataBus.EngineInfo.EngineDragPower(DataBus.EngineInfo.EngineSpeed);
} }
} else { } else {
if (ADAS.EcoRoll == EcoRollType.None) { if (ADAS.EcoRoll == EcoRollType.None) {
iceDragLoss = Driver.DataBus.EngineInfo.EngineDragPower(Driver.DataBus.EngineInfo.EngineSpeed); iceDragLoss = DataBus.EngineInfo.EngineDragPower(DataBus.EngineInfo.EngineSpeed);
} }
} }
...@@ -447,7 +449,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -447,7 +449,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
private void HandleEcoRoll(Second absTime, MeterPerSecond targetVelocity) private void HandleEcoRoll(Second absTime, MeterPerSecond targetVelocity)
{ {
var dBus = Driver.DataBus; var dBus = DataBus;
var vehicleSpeedAboveLowerThreshold = dBus.VehicleInfo.VehicleSpeed >= Driver.DriverData.EcoRoll.MinSpeed; var vehicleSpeedAboveLowerThreshold = dBus.VehicleInfo.VehicleSpeed >= Driver.DriverData.EcoRoll.MinSpeed;
var slopeNegative = dBus.DrivingCycleInfo.RoadGradient.IsSmaller(0); var slopeNegative = dBus.DrivingCycleInfo.RoadGradient.IsSmaller(0);
// potential optimization... // potential optimization...
...@@ -524,7 +526,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -524,7 +526,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
private void HandleEngineStopStartDuringVehicleStop(Second absTime) private void HandleEngineStopStartDuringVehicleStop(Second absTime)
{ {
if (Driver.DataBus.DrivingCycleInfo.CycleData.LeftSample.PTOActive != PTOActivity.Inactive) { if (DataBus.DrivingCycleInfo.CycleData.LeftSample.PTOActive != PTOActivity.Inactive) {
// engine stop start is disabled for stops where the PTO is activated // engine stop start is disabled for stops where the PTO is activated
return; return;
} }
...@@ -537,12 +539,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -537,12 +539,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
Driver.DriverData.EngineStopStart.EngineOffStandStillActivationDelay)) { Driver.DriverData.EngineStopStart.EngineOffStandStillActivationDelay)) {
if (EngineOffTimestamp == null) { if (EngineOffTimestamp == null) {
EngineOffTimestamp = absTime; EngineOffTimestamp = absTime;
Driver.DataBus.EngineCtl.CombustionEngineOn = false; DataBus.EngineCtl.CombustionEngineOn = false;
} }
} }
if (EngineOffTimestamp != null && if (EngineOffTimestamp != null &&
(absTime - EngineOffTimestamp).IsGreaterOrEqual(Driver.DriverData.EngineStopStart.MaxEngineOffTimespan)) { (absTime - EngineOffTimestamp).IsGreaterOrEqual(Driver.DriverData.EngineStopStart.MaxEngineOffTimespan)) {
Driver.DataBus.EngineCtl.CombustionEngineOn = true; DataBus.EngineCtl.CombustionEngineOn = true;
} }
} }
...@@ -585,13 +587,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -585,13 +587,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
private void UpdateDistancesForCurrentNextAction() private void UpdateDistancesForCurrentNextAction()
{ {
if (Driver.DataBus.VehicleInfo.VehicleSpeed > NextDrivingAction.NextTargetSpeed) { if (DataBus.VehicleInfo.VehicleSpeed > NextDrivingAction.NextTargetSpeed) {
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(DataBus.VehicleSpeed, NextDrivingAction.NextTargetSpeed);
var coastingDistance = ComputeCoastingDistance(Driver.DataBus.VehicleInfo.VehicleSpeed, NextDrivingAction.CycleEntry); var coastingDistance = ComputeCoastingDistance(DataBus.VehicleInfo.VehicleSpeed, NextDrivingAction.CycleEntry);
NextDrivingAction.CoastingStartDistance = NextDrivingAction.TriggerDistance - coastingDistance; NextDrivingAction.CoastingStartDistance = NextDrivingAction.TriggerDistance - coastingDistance;
NextDrivingAction.BrakingStartDistance = NextDrivingAction.TriggerDistance - brakingDistance; NextDrivingAction.BrakingStartDistance = NextDrivingAction.TriggerDistance - brakingDistance;
break; break;
...@@ -613,20 +615,20 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -613,20 +615,20 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
protected internal MeterPerSecond GetOverspeed() protected internal MeterPerSecond GetOverspeed()
{ {
return ADAS.PredictiveCruiseControl == PredictiveCruiseControlType.Option_1_2_3 && Driver.DataBus.DrivingCycleInfo.CycleData.LeftSample.Highway return ADAS.PredictiveCruiseControl == PredictiveCruiseControlType.Option_1_2_3 && DataBus.DrivingCycleInfo.CycleData.LeftSample.Highway
? Driver.DriverData.PCC.OverspeedUseCase3 ? Driver.DriverData.PCC.OverspeedUseCase3
: Driver.DriverData.OverSpeed.OverSpeed; : Driver.DriverData.OverSpeed.OverSpeed;
} }
protected internal DrivingBehaviorEntry GetNextDrivingAction(Meter ds) protected internal DrivingBehaviorEntry GetNextDrivingAction(Meter ds)
{ {
var currentSpeed = Driver.DataBus.VehicleInfo.VehicleSpeed; var currentSpeed = DataBus.VehicleInfo.VehicleSpeed;
var lookaheadDistance = var lookaheadDistance =
(currentSpeed.Value() * 3.6 * Driver.DriverData.LookAheadCoasting.LookAheadDistanceFactor).SI<Meter>(); (currentSpeed.Value() * 3.6 * Driver.DriverData.LookAheadCoasting.LookAheadDistanceFactor).SI<Meter>();
var stopDistance = Driver.ComputeDecelerationDistance(0.SI<MeterPerSecond>()); var stopDistance = Driver.ComputeDecelerationDistance(0.SI<MeterPerSecond>());
lookaheadDistance = VectoMath.Max(2 * ds, lookaheadDistance, 1.2 * stopDistance + ds); lookaheadDistance = VectoMath.Max(2 * ds, lookaheadDistance, 1.2 * stopDistance + ds);
var lookaheadData = Driver.DataBus.DrivingCycleInfo.LookAhead(lookaheadDistance); var lookaheadData = DataBus.DrivingCycleInfo.LookAhead(lookaheadDistance);
Log.Debug("Lookahead distance: {0} @ current speed {1}", lookaheadDistance, currentSpeed); Log.Debug("Lookahead distance: {0} @ current speed {1}", lookaheadDistance, currentSpeed);
var nextActions = new List<DrivingBehaviorEntry>(); var nextActions = new List<DrivingBehaviorEntry>();
...@@ -700,9 +702,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -700,9 +702,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
targetSpeed += Driver.DriverData.OverSpeed.OverSpeed; targetSpeed += Driver.DriverData.OverSpeed.OverSpeed;
} }
var vehicleMass = Driver.DataBus.VehicleInfo.TotalMass + Driver.DataBus.WheelsInfo.ReducedMassWheels; var vehicleMass = DataBus.VehicleInfo.TotalMass + DataBus.WheelsInfo.ReducedMassWheels;
var targetAltitude = actionEntry.Altitude; var targetAltitude = actionEntry.Altitude;
var vehicleAltitude = Driver.DataBus.DrivingCycleInfo.Altitude; var vehicleAltitude = DataBus.DrivingCycleInfo.Altitude;
var kineticEnergyAtTarget = vehicleMass * Physics.GravityAccelleration * targetAltitude var kineticEnergyAtTarget = vehicleMass * Physics.GravityAccelleration * targetAltitude
+ vehicleMass * targetSpeed * targetSpeed / 2; + vehicleMass * targetSpeed * targetSpeed / 2;
...@@ -710,15 +712,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -710,15 +712,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
+ vehicleMass * vehicleSpeed * vehicleSpeed / 2; + vehicleMass * vehicleSpeed * vehicleSpeed / 2;
var energyDifference = currentKineticEnergy - kineticEnergyAtTarget; var energyDifference = currentKineticEnergy - kineticEnergyAtTarget;
var airDragForce = Driver.DataBus.VehicleInfo.AirDragResistance(vehicleSpeed, targetSpeed); var airDragForce = DataBus.VehicleInfo.AirDragResistance(vehicleSpeed, targetSpeed);
var rollingResistanceForce = Driver.DataBus.VehicleInfo.RollingResistance( var rollingResistanceForce = DataBus.VehicleInfo.RollingResistance(
((targetAltitude - vehicleAltitude) / (actionEntry.Distance - Driver.DataBus.MileageCounter.Distance)) ((targetAltitude - vehicleAltitude) / (actionEntry.Distance - DataBus.MileageCounter.Distance))
.Value().SI<Radian>()); .Value().SI<Radian>());
var gearboxLossPower = Driver.DataBus.GearboxInfo?.GearboxLoss() ?? 0.SI<Watt>(); var gearboxLossPower = DataBus.GearboxInfo?.GearboxLoss() ?? 0.SI<Watt>();
var axleLossPower = Driver.DataBus.AxlegearInfo?.AxlegearLoss() ?? 0.SI<Watt>(); var axleLossPower = DataBus.AxlegearInfo?.AxlegearLoss() ?? 0.SI<Watt>();
var emDragLossPower = CalculateElectricMotorDragLoss(); var emDragLossPower = CalculateElectricMotorDragLoss();
var iceDragLossPower = Driver.DataBus.EngineInfo?.EngineDragPower(Driver.DataBus.EngineInfo.EngineSpeed) ?? 0.SI<Watt>(); var iceDragLossPower = DataBus.EngineInfo?.EngineDragPower(DataBus.EngineInfo.EngineSpeed) ?? 0.SI<Watt>();
var totalComponentLossPowers = gearboxLossPower + axleLossPower + emDragLossPower - iceDragLossPower; var totalComponentLossPowers = gearboxLossPower + axleLossPower + emDragLossPower - iceDragLossPower;
var coastingResistanceForce = airDragForce + rollingResistanceForce + totalComponentLossPowers / vehicleSpeed; var coastingResistanceForce = airDragForce + rollingResistanceForce + totalComponentLossPowers / vehicleSpeed;
...@@ -732,7 +734,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -732,7 +734,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
private Watt CalculateElectricMotorDragLoss() private Watt CalculateElectricMotorDragLoss()
{ {
var sum = 0.SI<Watt>(); var sum = 0.SI<Watt>();
var db = Driver.DataBus; var db = DataBus;
foreach (var pos in db.PowertrainInfo.ElectricMotorPositions) foreach (var pos in db.PowertrainInfo.ElectricMotorPositions)
sum += db.ElectricMotorInfo(pos).DragPower( sum += db.ElectricMotorInfo(pos).DragPower(
db.BatteryInfo.InternalVoltage, db.BatteryInfo.InternalVoltage,
...@@ -744,7 +746,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -744,7 +746,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
!prohibitOverspeed !prohibitOverspeed
&& Driver.DriverData.OverSpeed.Enabled && Driver.DriverData.OverSpeed.Enabled
&& velocity > Driver.DriverData.OverSpeed.MinSpeed && velocity > Driver.DriverData.OverSpeed.MinSpeed
&& ApplyOverspeed(velocity) < (Driver.DataBus.VehicleInfo.MaxVehicleSpeed ?? 500.KMPHtoMeterPerSecond()); && ApplyOverspeed(velocity) < (DataBus.VehicleInfo.MaxVehicleSpeed ?? 500.KMPHtoMeterPerSecond());
} }
public struct EcoRoll public struct EcoRoll
...@@ -805,7 +807,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -805,7 +807,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
// if the speed at the end of the simulation interval is below the next target speed // if the speed at the end of the simulation interval is below the next target speed
// we are fine (no need to brake right now) // we are fine (no need to brake right now)
var v2 = Driver.DataBus.VehicleInfo.VehicleSpeed + response.Driver.Acceleration * response.SimulationInterval; var v2 = DataBus.VehicleInfo.VehicleSpeed + response.Driver.Acceleration * response.SimulationInterval;
if (v2 <= DriverStrategy.NextDrivingAction.NextTargetSpeed) { if (v2 <= DriverStrategy.NextDrivingAction.NextTargetSpeed) {
return response; return response;
} }
...@@ -829,7 +831,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -829,7 +831,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
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.
// instead of accelerating, drive at constant speed. // instead of accelerating, drive at constant speed.
response = DoHandleRequest(absTime, ds, Driver.DataBus.VehicleInfo.VehicleSpeed, gradient, true); response = DoHandleRequest(absTime, ds, DataBus.VehicleInfo.VehicleSpeed, gradient, true);
return response; return response;
} }
...@@ -1104,7 +1106,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -1104,7 +1106,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return response; return response;
} }
var v2 = Driver.DataBus.VehicleInfo.VehicleSpeed + response.Driver.Acceleration * response.SimulationInterval; var v2 = DataBus.VehicleInfo.VehicleSpeed + response.Driver.Acceleration * response.SimulationInterval;
var newBrakingDistance = Driver.DriverData.AccelerationCurve.ComputeDecelerationDistance(v2, var newBrakingDistance = Driver.DriverData.AccelerationCurve.ComputeDecelerationDistance(v2,
nextAction.NextTargetSpeed) + DefaultDriverStrategy.BrakingSafetyMargin; nextAction.NextTargetSpeed) + DefaultDriverStrategy.BrakingSafetyMargin;
switch (DriverStrategy.NextDrivingAction.Action) { switch (DriverStrategy.NextDrivingAction.Action) {
...@@ -1119,21 +1121,21 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -1119,21 +1121,21 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
// 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.MileageCounter.Distance + ds).IsSmallerOrEqual( if ((DataBus.MileageCounter.Distance + ds).IsSmallerOrEqual(
nextAction.TriggerDistance - newActionDistance, nextAction.TriggerDistance - newActionDistance,
Constants.SimulationSettings.DriverActionDistanceTolerance * safetyFactor) && Constants.SimulationSettings.DriverActionDistanceTolerance * safetyFactor) &&
(Driver.DataBus.MileageCounter.Distance + ds).IsSmallerOrEqual(nextAction.TriggerDistance - newBrakingDistance)) { (DataBus.MileageCounter.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.MileageCounter.Distance + ds).IsSmaller(nextAction.TriggerDistance - newBrakingDistance)) { if ((DataBus.MileageCounter.Distance + ds).IsSmaller(nextAction.TriggerDistance - newBrakingDistance)) {
return response; return response;
} }
newds = nextAction.TriggerDistance - newBrakingDistance - Driver.DataBus.MileageCounter.Distance - newds = nextAction.TriggerDistance - newBrakingDistance - DataBus.MileageCounter.Distance -
Constants.SimulationSettings.DriverActionDistanceTolerance / 2; Constants.SimulationSettings.DriverActionDistanceTolerance / 2;
break; break;
default: return response; default: return response;
...@@ -1510,15 +1512,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -1510,15 +1512,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
switch (nextAction.Action) { switch (nextAction.Action) {
case DrivingBehavior.Coasting: case DrivingBehavior.Coasting:
var v2 = Driver.DataBus.VehicleInfo.VehicleSpeed + response.Driver.Acceleration * response.SimulationInterval; var v2 = DataBus.VehicleInfo.VehicleSpeed + response.Driver.Acceleration * response.SimulationInterval;
var newBrakingDistance = Driver.DriverData.AccelerationCurve.ComputeDecelerationDistance( var newBrakingDistance = Driver.DriverData.AccelerationCurve.ComputeDecelerationDistance(
v2, v2,
nextAction.NextTargetSpeed); nextAction.NextTargetSpeed);
if ((Driver.DataBus.MileageCounter.Distance + ds).IsSmaller(nextAction.TriggerDistance - newBrakingDistance)) { if ((DataBus.MileageCounter.Distance + ds).IsSmaller(nextAction.TriggerDistance - newBrakingDistance)) {
return response; return response;
} }
newds = nextAction.TriggerDistance - newBrakingDistance - Driver.DataBus.MileageCounter.Distance - newds = nextAction.TriggerDistance - newBrakingDistance - DataBus.MileageCounter.Distance -
Constants.SimulationSettings.DriverActionDistanceTolerance / 2; Constants.SimulationSettings.DriverActionDistanceTolerance / 2;
break; break;
default: return response; default: return response;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment