From 929366a277f8035d0996f8f986a4d5babf60c967 Mon Sep 17 00:00:00 2001
From: Stefanos Doumpoulakis <dubulak@gmail.com>
Date: Mon, 12 Sep 2022 18:19:14 +0300
Subject: [PATCH] implemented torque drift correction

---
 .../Reader/Impl/DeclarationVTPModeVectoRunDataFactory.cs  | 5 ++++-
 .../VectoCore/Models/Simulation/Data/VectoRunData.cs      | 4 ++++
 .../VectoCore/Models/SimulationComponent/Impl/VTPCycle.cs | 8 ++++++++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationVTPModeVectoRunDataFactory.cs b/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationVTPModeVectoRunDataFactory.cs
index e48d99ed43..9085820a83 100644
--- a/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationVTPModeVectoRunDataFactory.cs
+++ b/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationVTPModeVectoRunDataFactory.cs
@@ -219,8 +219,11 @@ namespace TUGraz.VectoCore.InputData.Reader.Impl
 			vtpRunData.VTPData = new VTPData() {
 				CorrectionFactor = mileageCorrection,
 			};
+
+			vtpRunData.TorqueDriftLeftWheel = JobInputData.TorqueDriftLeftWheel;
+			vtpRunData.TorqueDriftRightWheel = JobInputData.TorqueDriftRightWheel;
+
 			yield return vtpRunData;
-			
 		}
 
 		public IInputDataProvider DataProvider { get; }
diff --git a/VectoCore/VectoCore/Models/Simulation/Data/VectoRunData.cs b/VectoCore/VectoCore/Models/Simulation/Data/VectoRunData.cs
index a35fc933a3..7bfd6cd6cc 100644
--- a/VectoCore/VectoCore/Models/Simulation/Data/VectoRunData.cs
+++ b/VectoCore/VectoCore/Models/Simulation/Data/VectoRunData.cs
@@ -138,6 +138,10 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
 
 		public Watt ElectricAuxDemand { get; internal set; }
 
+		public NewtonMeter TorqueDriftLeftWheel { get; internal set; }
+
+		public NewtonMeter TorqueDriftRightWheel { get; internal set; }
+
 		public class AuxData
 		{
 			// ReSharper disable once InconsistentNaming
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/VTPCycle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/VTPCycle.cs
index ceaefb2c19..94f4e96f8c 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/VTPCycle.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/VTPCycle.cs
@@ -65,7 +65,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 
 		protected internal void PrepareCycleData()
 		{
+			Second timeDriftZero = Data.Entries.First().Time;
+			Second timeDriftCheck = Data.Entries.Last().Time;
+			
 			foreach (var entry in Data.Entries) {
+				var timeFactor = (entry.Time - timeDriftZero) / (timeDriftCheck - timeDriftZero);
+
+				entry.TorqueWheelLeft = entry.TorqueWheelLeft - (RunData.TorqueDriftLeftWheel * timeFactor);
+                entry.TorqueWheelRight = entry.TorqueWheelRight - (RunData.TorqueDriftRightWheel * timeFactor);
+
 				var wheelSpeed = (entry.WheelSpeedLeft + entry.WheelSpeedRight) / 2;
 				var wheelPower = entry.TorqueWheelLeft * entry.WheelSpeedLeft + entry.TorqueWheelRight * entry.WheelSpeedRight;
 				entry.PWheel = wheelPower;
-- 
GitLab