From 0887d100968d462b9ee38bb55d0941d4a785b8a8 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Sat, 29 Dec 2018 14:27:44 +0100
Subject: [PATCH] gearbox: fix for using correct gear in case of transition
 from disengaged to engaged

---
 .../VectoCore/Models/SimulationComponent/Impl/Gearbox.cs | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
index 384dd74c1c..3b20d66b9a 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
@@ -181,6 +181,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 				_engageTime = absTime + dt;
 			}
 
+			if (ClutchClosed(absTime) && Disengaged && !outAngularVelocity.IsEqual(0)) {
+				ReEngageGear(absTime, dt, outTorque, outAngularVelocity);
+				Log.Debug("Gearbox engaged gear {0}", Gear);
+			}
+
 			var gear = Disengaged ? NextGear.Gear : Gear;
 			var avgOutAngularVelocity = (PreviousState.OutAngularVelocity + outAngularVelocity) / 2.0;
 			var inTorqueLossResult = ModelData.Gears[gear].LossMap.GetTorqueLoss(avgOutAngularVelocity, outTorque);
@@ -319,10 +324,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			//{
 			//	Gear = _strategy.InitGear(absTime, dt, outTorque, outAngularVelocity);
 			//}
-			if (Disengaged && !outAngularVelocity.IsEqual(0)) {
-				ReEngageGear(absTime, dt, outTorque, outAngularVelocity);
-				Log.Debug("Gearbox engaged gear {0}", Gear);
-			}
 
 			var inAngularVelocity = outAngularVelocity * ModelData.Gears[Gear].Ratio;
 
-- 
GitLab