From 345b86aecb6ac698b79a9c7aad466d0367091f61 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Mon, 26 Jun 2017 15:54:07 +0200
Subject: [PATCH] don't limit engine speed when disengaged, more info in
 response too high

---
 .../SimulationComponent/Impl/CombustionEngine.cs  | 15 +++++++++------
 .../Impl/EngineOnlyCombustionEngine.cs            |  2 +-
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs
index 61febfe04e..6ba0325173 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs
@@ -181,9 +181,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 
 			var avgEngineSpeed = (PreviousState.EngineSpeed + angularVelocity) / 2.0;
 
-			var engineSpeedLimit = GetEngineSpeedLimit();
+			var engineSpeedLimit = GetEngineSpeedLimit(absTime);
 			if (!dryRun && avgEngineSpeed.IsGreater(engineSpeedLimit, Constants.SimulationSettings.LineSearchTolerance)) {
-				return new ResponseEngineSpeedTooHigh() { DeltaEngineSpeed = avgEngineSpeed - engineSpeedLimit };
+				return new ResponseEngineSpeedTooHigh() {
+					DeltaEngineSpeed = avgEngineSpeed - engineSpeedLimit,
+					Source = this,
+					EngineSpeed = angularVelocity
+				};
 			}
 
 			var fullDragTorque = ModelData.FullLoadCurves[DataBus.Gear].DragLoadStationaryTorque(avgEngineSpeed);
@@ -293,12 +297,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			};
 		}
 
-		protected virtual PerSecond GetEngineSpeedLimit()
+		protected virtual PerSecond GetEngineSpeedLimit(Second absTime)
 		{
-			return DataBus.Gear == 0
+			return DataBus.Gear == 0 || !DataBus.ClutchClosed(absTime)
 				? ModelData.FullLoadCurves[0].N95hSpeed
-				: VectoMath.Min(DataBus.GetGearData(DataBus.Gear).MaxSpeed,
-					ModelData.FullLoadCurves[0].N95hSpeed);
+				: VectoMath.Min(DataBus.GetGearData(DataBus.Gear).MaxSpeed, ModelData.FullLoadCurves[0].N95hSpeed);
 		}
 
 		public IResponse Initialize(NewtonMeter outTorque, PerSecond outAngularVelocity)
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/EngineOnlyCombustionEngine.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/EngineOnlyCombustionEngine.cs
index 9837ac690f..e577fef15f 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/EngineOnlyCombustionEngine.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/EngineOnlyCombustionEngine.cs
@@ -110,7 +110,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			return requestedEngineTorque;
 		}
 
-		protected override PerSecond GetEngineSpeedLimit()
+		protected override PerSecond GetEngineSpeedLimit(Second absTime)
 		{
 			return ModelData.FullLoadCurves[0].N95hSpeed;
 		}
-- 
GitLab