From 372fd5ef0f2bee10399396a43f1c20d02b9e18a9 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Wed, 21 Dec 2016 17:07:48 +0100
Subject: [PATCH] fix: computation of slope for changing engine speed during
 traction interruption

---
 .../SimulationComponent/Impl/CombustionEngine.cs   | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs
index ccd4adf437..002aa023c7 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs
@@ -444,7 +444,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 					var tStar = tStarPrev + PreviousState.dt;
 					dynFullPowerCalculated = stationaryFullLoadPower * (1 - Math.Exp((-tStar / pt1).Value()));
 					dynFullPowerCalculated = VectoMath.Max(PreviousState.EnginePower, dynFullPowerCalculated);
-				} catch (Exception ) {
+				} catch (Exception) {
 					Log.Error("failed to calculate dynamic full-load power - using stationary idle full-load. n: {0}", angularVelocity);
 				}
 			}
@@ -500,6 +500,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 
 			private Second _idleStart;
 			private Watt _lastEnginePower;
+			private PerSecond _engineTargetSpeed;
 
 			public ITnOutPort RequestPort { private get; set; }
 
@@ -539,11 +540,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 				if (!outTorque.IsEqual(0)) {
 					throw new VectoException("Torque has to be 0 for idle requests!");
 				}
-				var targetVelocity = _engine.PreviousState.EngineSpeed / _dataBus.GetGearData(_dataBus.Gear).Ratio *
+				if (_idleStart == null) {
+					_idleStart = absTime;
+					_engineTargetSpeed = _engine.PreviousState.EngineSpeed / _dataBus.GetGearData(_dataBus.Gear).Ratio *
 									_dataBus.GetGearData(_dataBus.NextGear.Gear).Ratio;
-				var velocitySlope = (targetVelocity - _engine.PreviousState.EngineSpeed) / _dataBus.TractionInterruption;
+				}
+
+				
+				var velocitySlope = (_engineTargetSpeed - _engine.PreviousState.EngineSpeed) / (_dataBus.TractionInterruption - (absTime - _idleStart));
 
-				var nextAngularSpeed = (velocitySlope * dt + _engine.PreviousState.EngineSpeed);
+				var nextAngularSpeed = (velocitySlope *  dt + _engine.PreviousState.EngineSpeed);
 				if (nextAngularSpeed < _engine.ModelData.IdleSpeed) {
 					nextAngularSpeed = _engine.ModelData.IdleSpeed;
 				}
-- 
GitLab