From 454ab87fc8be6f8aab1fa35a18cd86197aa715c7 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Fri, 6 May 2016 10:47:37 +0200
Subject: [PATCH] gearbox: when halted: engage gear

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

diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
index 4e329695d5..26185cb3b2 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
@@ -138,7 +138,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			var dt = Constants.SimulationSettings.TargetTimeInterval;
 
 			// MK 2016-02-10: SI doesn't allow inifinity anymore -- therefore simply a very negative value is used.
-			_engageTime = -1e10.SI<Second>(); //double.NegativeInfinity.SI<Second>();
+			_engageTime = -double.MaxValue.SI<Second>(); //double.NegativeInfinity.SI<Second>();
 
 			if (Disengaged) {
 				Gear = _strategy.InitGear(absTime, dt, outTorque, outAngularVelocity);
@@ -326,7 +326,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 
 			if (dryRun) {
 				if ((DataBus.DriverBehavior == DrivingBehavior.Braking || DataBus.DriverBehavior == DrivingBehavior.Coasting) &&
-					inAngularVelocity < DataBus.EngineIdleSpeed && DataBus.VehicleSpeed < Constants.SimulationSettings.VehicleStopClutchDisengageSpeed) {
+					inAngularVelocity < DataBus.EngineIdleSpeed &&
+					DataBus.VehicleSpeed < Constants.SimulationSettings.VehicleStopClutchDisengageSpeed) {
 					Disengaged = true;
 					_engageTime = absTime + dt;
 					_strategy.Disengage(absTime, dt, outTorque, outAngularVelocity);
@@ -347,7 +348,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 				if (shiftRequired) {
 					_engageTime = absTime + ModelData.TractionInterruption;
 
-					Log.Debug("Gearbox is shifting. absTime: {0}, dt: {1}, interuptionTime: {2}, out: ({3}, {4}), in: ({5}, {6})", absTime,
+					Log.Debug("Gearbox is shifting. absTime: {0}, dt: {1}, interuptionTime: {2}, out: ({3}, {4}), in: ({5}, {6})",
+						absTime,
 						dt, _engageTime, outTorque, outAngularVelocity, inTorque, inAngularVelocity);
 
 					Disengaged = true;
@@ -427,7 +429,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 					}
 				}
 			}
-
+			if (DataBus.VehicleStopped) {
+				Disengaged = false;
+				_engageTime = -double.MaxValue.SI<Second>();
+			}
 			AdvanceState();
 		}
 
-- 
GitLab