From aeb6d82b1a821c8a5d65eccb05c4e50f8ffb203e Mon Sep 17 00:00:00 2001
From: Michael Krisper <michael.krisper@tugraz.at>
Date: Thu, 14 Apr 2022 18:09:13 +0200
Subject: [PATCH] HybridStrategy: FindBestGearForBraking: added check if
 targetSpeed is actually 0 when checking for DisengageWhenHaltingSpeed.
 Otherwise braking below 10 km/h caused problems, because gearbox disengaged.

---
 .../SimulationComponent/Strategies/HybridStrategy.cs      | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs
index fc578cd31a..f005d2593d 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs
@@ -1051,7 +1051,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
 
 			if (ElectricMotorCanPropellDuringTractionInterruption || DataBus.GearboxInfo.GearEngaged(absTime)) {
 
-				if (vehiclespeedBelowThreshold && (emPos == PowertrainPosition.HybridP2 || emPos == PowertrainPosition.HybridP1)) {
+				if (vehiclespeedBelowThreshold && emPos.IsOneOf(PowertrainPosition.HybridP2, PowertrainPosition.HybridP1)) {
 					if (DataBus.GearboxInfo.GearboxType.AutomaticTransmission()) {
 						var firstgear = ResponseEmOff;
 						firstgear.Gear = GearList.First();
@@ -1152,7 +1152,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
 							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 ;-)
-							var best = FindBestGearForBraking(nextGear, firstResponse);
+							var best = FindBestGearForBraking(nextGear, firstResponse, DataBus.DrivingCycleInfo.TargetSpeed);
 							if (!best.Equals(currentGear)) {
 								// downshift required!
 								var downshift = ResponseEmOff;
@@ -1360,11 +1360,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
 			return firstResponse.Clutch.OutputSpeed.IsSmaller(ModelData.EngineData.IdleSpeed); //  firstResponse.Gearbox.InputSpeed.IsSmaller(ModelData.EngineData.IdleSpeed));
 		}
 
-		private GearshiftPosition FindBestGearForBraking(GearshiftPosition nextGear, IResponse firstResponse)
+		private GearshiftPosition FindBestGearForBraking(GearshiftPosition nextGear, IResponse firstResponse, MeterPerSecond targetSpeed)
 		{
 			var endSpeed = DataBus.VehicleInfo.VehicleSpeed +
 							DataBus.DriverInfo.DriverAcceleration * ModelData.GearboxData.TractionInterruption;
-			if (DataBus.GearboxInfo.GearboxType.ManualTransmission() &&
+			if (DataBus.GearboxInfo.GearboxType.ManualTransmission() && targetSpeed.IsEqual(0) &&
 				endSpeed.IsSmallerOrEqual(ModelData.GearboxData.DisengageWhenHaltingSpeed, 0.1.KMPHtoMeterPerSecond())) {
 				return new GearshiftPosition(0);
 			}
-- 
GitLab