From 75d147df025d7595886c71972ebfe08637f6c29a Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Fri, 26 Feb 2016 15:46:14 +0100
Subject: [PATCH] increase loop threshold for extreme driving conditions

---
 VectoCore/Configuration/Constants.cs                         | 4 ++--
 .../Models/SimulationComponent/Impl/CombustionEngine.cs      | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/VectoCore/Configuration/Constants.cs b/VectoCore/Configuration/Constants.cs
index 3f2d5e841f..3c590a6278 100644
--- a/VectoCore/Configuration/Constants.cs
+++ b/VectoCore/Configuration/Constants.cs
@@ -23,7 +23,7 @@ namespace TUGraz.VectoCore.Configuration
 {
 	public static class Constants
 	{
-		public const double RPMToRad =  2 * Math.PI / 60;
+		public const double RPMToRad = 2 * Math.PI / 60;
 		public const double Kilo = 1000;
 		public const double MeterPerSecondToKMH = 3.6;
 		public const double SecondsPerHour = 3600;
@@ -88,7 +88,7 @@ namespace TUGraz.VectoCore.Configuration
 
 			//VectoMath.InclinationToAngle(0.25 / 100.0).Value();
 
-			public const int DriverSearchLoopThreshold = 100;
+			public const int DriverSearchLoopThreshold = 200;
 
 			public static readonly Watt EnginePowerSearchTolerance = 0.50.SI<Watt>(); // Watt
 
diff --git a/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs b/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs
index 371825a372..aead525b04 100644
--- a/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs
+++ b/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs
@@ -192,8 +192,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 				};
 			}
 
-			if (deltaFull.IsGreater(0.SI<NewtonMeter>()) &&
-				deltaDrag.IsSmaller(0.SI<NewtonMeter>())) {
+			if (
+				(deltaFull * avgEngineSpeed).IsGreater(0.SI<Watt>(), Constants.SimulationSettings.EnginePowerSearchTolerance) &&
+				(deltaDrag * avgEngineSpeed).IsSmaller(0.SI<Watt>(), Constants.SimulationSettings.EnginePowerSearchTolerance)) {
 				throw new VectoSimulationException(
 					"Unexpected condition: requested torque_out is above gearbox full-load and engine is below drag load! deltaFull: {0}, deltaDrag: {1}",
 					deltaFull, deltaDrag);
-- 
GitLab