From c14c542aa23e09bf003958d0ccc17b68b442213a Mon Sep 17 00:00:00 2001
From: Michael Krisper <michael.krisper@tugraz.at>
Date: Tue, 20 Dec 2016 15:50:03 +0100
Subject: [PATCH] ATShiftStrategy: Corrected error with checks for upshift in
 highest gear

---
 .../Impl/ATShiftStrategy.cs                   | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATShiftStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATShiftStrategy.cs
index 3b525c8781..99e66ba4c7 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATShiftStrategy.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATShiftStrategy.cs
@@ -155,8 +155,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			}
 			// Emergency Upshift: if higher than engine rated speed
 			if (inAngularVelocity.IsGreaterOrEqual(DataBus.EngineRatedSpeed)) {
-				// upshift is not possible
-				if (ModelData.Gears.ContainsKey(gear + 1)) {
+				// check if upshift is possible
+				if (!ModelData.Gears.ContainsKey(gear + 1)) {
 					return false;
 				}
 				Log.Debug("engine speed would be above rated speed - shift up");
@@ -207,12 +207,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 				var nextEnginePower = currentEnginePower / nextEngineSpeed;
 				var isAboveUpShift = IsAboveUpShiftCurve(gear, nextEnginePower, nextEngineSpeed, _gearbox.TorqueConverterLocked);
 
-				var reachableAcceleration = EstimateAccelerationForGear(nextGear, outAngularVelocity);
-				var minAcceleration = _gearbox.TorqueConverterLocked
-					? ModelData.UpshiftMinAcceleration
-					: ModelData.TorqueConverterData.CLUpshiftMinAcceleration;
-				minAcceleration = VectoMath.Min(minAcceleration, DataBus.DriverAcceleration);
-				var minAccelerationReachable = reachableAcceleration.IsGreaterOrEqual(minAcceleration);
+				var minAccelerationReachable = true;
+				if (!DataBus.VehicleSpeed.IsEqual(0)) {
+					var reachableAcceleration = EstimateAccelerationForGear(nextGear, outAngularVelocity);
+					var minAcceleration = _gearbox.TorqueConverterLocked
+						? ModelData.UpshiftMinAcceleration
+						: ModelData.TorqueConverterData.CLUpshiftMinAcceleration;
+					minAcceleration = VectoMath.Min(minAcceleration, DataBus.DriverAcceleration);
+					minAccelerationReachable = reachableAcceleration.IsGreaterOrEqual(minAcceleration);
+				}
 
 				if (isAboveUpShift && minAccelerationReachable) {
 					Upshift(absTime, gear);
-- 
GitLab