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

refactoring code in hybrid strategy brake action: reduce complexity (invert if)

parent 35e4cc3e
No related branches found
No related tags found
No related merge requests found
......@@ -183,6 +183,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
TestPowertrain.HybridController.Initialize(Controller.PreviousState.OutTorque, Controller.PreviousState.OutAngularVelocity);
TestPowertrain.Brakes.BrakePower = DataBus.Brakes.BrakePower;
TestPowertrain.DCDCConverter?.UpdateFrom(DataBus.DCDCConverter);
if (nextGear.Engaged && !nextGear.Equals(TestPowertrain.Gearbox.Gear)) {
if (!AllowEmergencyShift && ModelData.GearboxData.Gears[nextGear.Gear].Ratio > ModelData.GearshiftParameters.RatioEarlyUpshiftFC) {
......@@ -863,21 +864,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
var vehiclespeedBelowThreshold = DataBus.VehicleInfo.VehicleSpeed.IsSmaller(disengageSpeedThreshold)
&& (DataBus.DriverInfo.NextBrakeTriggerSpeed?.IsEqual(0) ?? false);
if (ElectricMotorCanPropellDuringTractionInterruption || DataBus.GearboxInfo.GearEngaged(absTime)) {
if (vehiclespeedBelowThreshold && emPos.IsOneOf(PowertrainPosition.HybridP2, PowertrainPosition.HybridP1, PowertrainPosition.IHPC)) {
if (DataBus.GearboxInfo.GearboxType.AutomaticTransmission()) {
var firstgear = ResponseEmOff;
firstgear.Gear = GearList.First();
eval.Add(firstgear);
return;
} else {
if (!ElectricMotorCanPropellDuringTractionInterruption && !DataBus.GearboxInfo.GearEngaged(absTime)) {
var off = ResponseEmOff;
if (vehiclespeedBelowThreshold &&
(emPos == PowertrainPosition.HybridP2 || emPos == PowertrainPosition.HybridP1)) {
off.Setting.GearboxInNeutral = true;
} else {
off.Setting.GearboxInNeutral = PreviousState.Solution?.Setting.GearboxInNeutral ?? false;
}
eval.Add(off);
return;
}
}
GearshiftPosition nextGear;
if (!DataBus.GearboxInfo.GearEngaged(absTime)) {
......@@ -888,7 +886,41 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
nextGear = Controller.ShiftStrategy.NextGear;
}
if (vehiclespeedBelowThreshold && emPos.IsOneOf(PowertrainPosition.HybridP2,
PowertrainPosition.HybridP1, PowertrainPosition.IHPC)) {
if (DataBus.GearboxInfo.GearboxType.AutomaticTransmission()) {
var firstgear = ResponseEmOff;
firstgear.Gear = GearList.First();
eval.Add(firstgear);
return;
}
var testDisengage = new HybridStrategyResponse {
CombustionEngineOn = DataBus.EngineInfo.EngineOn, // AllowICEOff(absTime),
GearboxInNeutral = false,
NextGear = nextGear,
MechanicalAssistPower = ElectricMotorsOff
};
var testDisengageResponse = RequestDryRun(absTime, dt, outTorque, outAngularVelocity, nextGear,
testDisengage);
var off = ResponseEmOff;
if (testDisengageResponse.Clutch.PowerRequest.IsSmaller(0)) {
// only disengage if the torque at the clutch is negative - i.e. no propulsion needed
off.Setting.GearboxInNeutral = true;
}
eval.Add(off);
return;
}
if (!nextGear.IsLockedGear()) {
var off = ResponseEmOff;
var offResponse = RequestDryRun(absTime, dt, outTorque, outAngularVelocity, nextGear, off.Setting);
if (offResponse.Source is ATGearbox && offResponse is ResponseOverload && GearList.HasPredecessor(nextGear)) {
off.Gear = GearList.Predecessor(nextGear);
}
eval.Add(ResponseEmOff);
return;
}
......@@ -913,14 +945,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
var endSpeed = DataBus.VehicleInfo.VehicleSpeed +
DataBus.DriverInfo.DriverAcceleration * ModelData.GearboxData.TractionInterruption;
if (EngineSpeedTooLow(response)
&& (DataBus.GearboxInfo.GearboxType.ManualTransmission() || DataBus.GearboxInfo.GearboxType == GearboxType.IHPC)
&& (DataBus.GearboxInfo.GearboxType.ManualTransmission() ||
DataBus.GearboxInfo.GearboxType == GearboxType.IHPC)
&& endSpeed.IsSmallerOrEqual(disengageSpeedThreshold, 0.1.KMPHtoMeterPerSecond())) {
var responseEmOff = ResponseEmOff;
// if the engine speed is too low but the gear is engaged in this timestep, use the gear as calculated before.
// on re-engage the engine speed is checked and a lower gear is engaged. then the hybrid strategy is called again.
responseEmOff.Gear = (!PreviousState.GearboxEngaged && DataBus.GearboxInfo.GearEngaged(absTime)) ? currentGear : new GearshiftPosition(0);
responseEmOff.Gear = (!PreviousState.GearboxEngaged && DataBus.GearboxInfo.GearEngaged(absTime))
? currentGear
: new GearshiftPosition(0);
responseEmOff.Setting.GearboxEngaged = false;
responseEmOff.Setting.GearboxInNeutral = (!PreviousState.GearboxEngaged && DataBus.GearboxInfo.GearEngaged(absTime)) ? false : true;
responseEmOff.Setting.GearboxInNeutral =
(!PreviousState.GearboxEngaged && DataBus.GearboxInfo.GearEngaged(absTime)) ? false : true;
eval.Add(responseEmOff);
return;
}
......@@ -940,6 +976,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
eval.Add(downshift);
return;
}
do {
nextGear = GearList.Predecessor(nextGear);
response = RequestDryRun(absTime, dt, outTorque, outAngularVelocity, nextGear, tmp);
......@@ -957,7 +994,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
return;
}
if (DataBus.GearboxInfo.GearboxType.AutomaticTransmission() && response == null && nextGear.Equals(GearList.First())) {
if (DataBus.GearboxInfo.GearboxType.AutomaticTransmission() && response == null &&
nextGear.Equals(GearList.First())) {
var downshift = ResponseEmOff;
downshift.Gear = nextGear;
eval.Add(downshift);
......@@ -967,10 +1005,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
if (tmp.CombustionEngineOn) {
var firstEntry = new HybridResultEntry();
CalculateCosts(response, dt, firstEntry, AllowICEOff(absTime), dryRun);
var minimumShiftTimePassed = (DataBus.GearboxInfo.LastShift + ModelData.GearshiftParameters.TimeBetweenGearshifts).IsSmallerOrEqual(absTime);
var minimumShiftTimePassed =
(DataBus.GearboxInfo.LastShift + ModelData.GearshiftParameters.TimeBetweenGearshifts)
.IsSmallerOrEqual(absTime);
if (DataBus.GearboxInfo.GearEngaged(absTime) && !vehiclespeedBelowThreshold) {
var reEngaged = !PreviousState.GearboxEngaged && DataBus.GearboxInfo.GearEngaged(absTime);
if ((firstEntry.IgnoreReason.EngineSpeedBelowDownshift() && !firstEntry.IgnoreReason.EngineTorqueDemandTooHigh() ||
if ((firstEntry.IgnoreReason.EngineSpeedBelowDownshift() &&
!firstEntry.IgnoreReason.EngineTorqueDemandTooHigh() ||
firstEntry.IgnoreReason.EngineSpeedTooLow()) && !reEngaged) {
// ICE torque below FLD is OK as EM may regenerate and shift ICE operating point on drag line
// for negative torques the shift line is vertical anyway ;-)
......@@ -995,8 +1036,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
}
}
var deltaDragTqFirst = disengaged ?
(response as ResponseDryRun).Gearbox.InputTorque //.DeltaDragLoadTorque
var deltaDragTqFirst = disengaged
? (response as ResponseDryRun).Gearbox.InputTorque //.DeltaDragLoadTorque
: response.Engine.TotalTorqueDemand - response.Engine.DragTorque;
if (!response.Engine.EngineOn && DataBus.GearboxInfo.GearboxType.AutomaticTransmission()) {
......@@ -1010,13 +1051,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
eval.AddRange(FindSolution(absTime, dt, outTorque, outAngularVelocity, dryRun));
} else {
EvaluateConfigsForGear(
absTime, dt, outTorque, outAngularVelocity, nextGear, AllowICEOff(absTime), eval, emPos, dryRun);
absTime, dt, outTorque, outAngularVelocity, nextGear, AllowICEOff(absTime), eval, emPos,
dryRun);
}
} else if (DataBus.GearboxInfo.GearEngaged(absTime)) {
eval.AddRange(FindSolution(absTime, dt, outTorque, outAngularVelocity, dryRun));
} else {
eval.Add(ResponseEmOff);
}
return;
}
......@@ -1038,10 +1081,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
GearboxInNeutral = false,
NextGear = nextGear,
MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>> {
{ emPos, Tuple.Create(response.ElectricMotor.AngularVelocity, VectoMath.Max(response.ElectricMotor.MaxRecuperationTorque, 0.SI<NewtonMeter>())) }
{
emPos,
Tuple.Create(response.ElectricMotor.AngularVelocity,
VectoMath.Max(response.ElectricMotor.MaxRecuperationTorque, 0.SI<NewtonMeter>()))
}
}
};
var maxRecuperationResponse = RequestDryRun(absTime, dt, outTorque, outAngularVelocity, nextGear, maxRecuperation);
var maxRecuperationResponse =
RequestDryRun(absTime, dt, outTorque, outAngularVelocity, nextGear, maxRecuperation);
debug.Add("[AHS.HBA-2] DryRun maxRecuperationResponse", maxRecuperationResponse);
var deltaDragTqMaxRecuperation = disengaged
? (maxRecuperationResponse as ResponseDryRun).Gearbox.InputTorque //.DeltaDragLoadTorque
......@@ -1065,7 +1113,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
}
if (deltaDragTqMaxRecuperation.IsSmaller(0) &&
maxRecuperationResponse.ElectricSystem.RESSPowerDemand.IsBetween(maxRecuperationResponse.ElectricSystem.MaxPowerDrag, maxRecuperationResponse.ElectricSystem.MaxPowerDrive)) {
maxRecuperationResponse.ElectricSystem.RESSPowerDemand.IsBetween(
maxRecuperationResponse.ElectricSystem.MaxPowerDrag,
maxRecuperationResponse.ElectricSystem.MaxPowerDrive)) {
// even with full recuperation (and no braking) the operating point is below the drag curve (and the battery can handle it) - use full recuperation
eval.Add(
new HybridResultEntry {
......@@ -1075,8 +1125,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
CombustionEngineOn = DataBus.EngineInfo.EngineOn,
GearboxInNeutral = false,
NextGear = nextGear,
MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>> {
{ emPos, Tuple.Create(response.ElectricMotor.AngularVelocity, response.ElectricMotor.MaxRecuperationTorque) }
MechanicalAssistPower =
new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>> {
{
emPos,
Tuple.Create(response.ElectricMotor.AngularVelocity,
response.ElectricMotor.MaxRecuperationTorque)
}
}
}
});
......@@ -1087,7 +1142,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
var emRecuperationTq = SearchAlgorithm.Search(
maxRecuperationResponse.ElectricMotor.ElectricMotorPowerMech /
maxRecuperationResponse.ElectricMotor.AngularVelocity,
maxRecuperationResponse.Engine.TorqueOutDemand, maxRecuperationResponse.ElectricMotor.MaxRecuperationTorque * 0.1,
maxRecuperationResponse.Engine.TorqueOutDemand,
maxRecuperationResponse.ElectricMotor.MaxRecuperationTorque * 0.1,
getYValue: resp => {
var r = resp as IResponse;
var deltaDragLoad = disengaged
......@@ -1096,6 +1152,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
if (!r.Engine.EngineOn && isAPTWithTorqueConverter) {
deltaDragLoad = r.Gearbox.InputTorque;
}
return deltaDragLoad;
},
evaluateFunction: emTq => {
......@@ -1107,7 +1164,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
{ emPos, Tuple.Create(response.ElectricMotor.AngularVelocity, emTq) }
}
};
return RequestDryRun(absTime, dt, outTorque, outAngularVelocity, DataBus.GearboxInfo.GearEngaged(absTime) ? nextGear : new GearshiftPosition(0), cfg);
return RequestDryRun(absTime, dt, outTorque, outAngularVelocity,
DataBus.GearboxInfo.GearEngaged(absTime) ? nextGear : new GearshiftPosition(0), cfg);
},
criterion: resp => {
var r = resp as IResponse;
......@@ -1117,12 +1175,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
if (!r.Engine.EngineOn && isAPTWithTorqueConverter) {
deltaDragLoad = r.Gearbox.InputTorque;
}
return deltaDragLoad.Value();
},
searcher: this
);
if (emRecuperationTq.IsBetween(
response.ElectricMotor.MaxDriveTorque ?? 0.SI<NewtonMeter>(), response.ElectricMotor.MaxRecuperationTorque ?? 0.SI<NewtonMeter>())) {
response.ElectricMotor.MaxDriveTorque ?? 0.SI<NewtonMeter>(),
response.ElectricMotor.MaxRecuperationTorque ?? 0.SI<NewtonMeter>())) {
var entry = new HybridResultEntry {
ICEOff = !DataBus.EngineInfo.EngineOn,
Gear = nextGear,
......@@ -1141,7 +1201,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
} else {
// for the found operating point, although recuperating no electric energy is generated. leave EM off
var off = ResponseEmOff;
if (vehiclespeedBelowThreshold && (emPos == PowertrainPosition.HybridP2 || emPos == PowertrainPosition.HybridP1)) {
if (vehiclespeedBelowThreshold &&
(emPos == PowertrainPosition.HybridP2 || emPos == PowertrainPosition.HybridP1)) {
off.Setting.GearboxInNeutral = true;
} else {
off.Setting.GearboxInNeutral = PreviousState.Solution?.Setting.GearboxInNeutral ?? false;
......@@ -1163,8 +1224,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
CombustionEngineOn = DataBus.EngineInfo.EngineOn,
GearboxInNeutral = false,
NextGear = nextGear,
MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>> {
{ emPos, Tuple.Create(response.ElectricMotor.AngularVelocity, VectoMath.Min(maxbatDragTq, response.ElectricMotor.MaxRecuperationTorque)) }
MechanicalAssistPower =
new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>> {
{
emPos,
Tuple.Create(response.ElectricMotor.AngularVelocity,
VectoMath.Min(maxbatDragTq,
response.ElectricMotor.MaxRecuperationTorque))
}
}
}
});
......@@ -1172,16 +1239,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
eval.Add(ResponseEmOff);
}
}
} else {
var off = ResponseEmOff;
if (vehiclespeedBelowThreshold && (emPos == PowertrainPosition.HybridP2 || emPos == PowertrainPosition.HybridP1)) {
off.Setting.GearboxInNeutral = true;
} else {
off.Setting.GearboxInNeutral = PreviousState.Solution?.Setting.GearboxInNeutral ?? false;
}
eval.Add(off);
}
}
private bool EngineSpeedTooLow(IResponse firstResponse)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment