From 92f5d80caac8204b548c896b8832fd4531e6fc8e Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Mon, 29 Jan 2018 17:05:29 +0100
Subject: [PATCH] adding driver action information to databus; gearbox
 disengages on halt action;

---
 .../XMLDeclarationAuxiliaryDataProvider.cs    |  92 ++--
 .../Models/Simulation/DataBus/IDataBus.cs     |  36 +-
 .../Models/Simulation/DataBus/IDriverInfo.cs  |   4 +
 .../Simulation/Impl/VehicleContainer.cs       |   7 +-
 .../SimulationComponent/Impl/AxleGear.cs      |  68 +--
 .../Models/SimulationComponent/Impl/Driver.cs |  44 +-
 .../SimulationComponent/Impl/Gearbox.cs       |   8 +-
 .../Impl/MeasuredSpeedDrivingCycle.cs         |   5 +
 .../SimulationComponent/Impl/PWheelCycle.cs   |  69 +--
 .../Models/SimulationComponent/GearboxTest.cs |  13 +-
 VectoCore/VectoCoreTest/Utils/MockDriver.cs   |   5 +
 .../Utils/MockVehicleContainer.cs             | 402 +++++++++---------
 12 files changed, 389 insertions(+), 364 deletions(-)

diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/XMLDeclarationAuxiliaryDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/XMLDeclarationAuxiliaryDataProvider.cs
index bb1e8cc69f..fa7a277c72 100644
--- a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/XMLDeclarationAuxiliaryDataProvider.cs
+++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/XMLDeclarationAuxiliaryDataProvider.cs
@@ -29,50 +29,50 @@
 *   Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
 */
 
-using System.Collections.Generic;
-using TUGraz.VectoCommon.InputData;
-using TUGraz.VectoCommon.Models;
-using TUGraz.VectoCommon.Resources;
-using TUGraz.VectoCommon.Utils;
-using TUGraz.VectoCore.InputData.Impl;
-
-namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration
-{
-	public class XMLDeclarationAuxiliaryDataProvider : AbstractDeclarationXMLComponentDataProvider,
-		IAuxiliariesDeclarationInputData
-	{
-		public XMLDeclarationAuxiliaryDataProvider(XMLDeclarationInputDataProvider xmlInputDataProvider) : base(xmlInputDataProvider)
-		{
-			XBasePath = Helper.Query(VehiclePath,
-				XMLNames.Vehicle_Components,
-				XMLNames.Component_Auxiliaries,
-				XMLNames.ComponentDataWrapper);
-		}
-
-
-		public IList<IAuxiliaryDeclarationInputData> Auxiliaries
-		{
-			get
-			{
-				var retVal = new List<IAuxiliaryDeclarationInputData>();
-				var auxiliaries = Navigator.Select(Helper.Query(XBasePath,
-					Helper.QueryConstraint("*",
-						Helper.NSPrefix(XMLNames.Auxiliaries_Auxiliary_Technology), null, "")),
-					Manager);
-
-				while (auxiliaries.MoveNext()) {
-					var techlistNodes = auxiliaries.Current.Select(Helper.NSPrefix(XMLNames.Auxiliaries_Auxiliary_Technology), Manager);
-					var technologyList = new List<string>();
-					while (techlistNodes.MoveNext()) {
-						technologyList.Add(techlistNodes.Current.Value);
-					}
-					retVal.Add(new AuxiliaryDataInputData {
-						Type = auxiliaries.Current.Name.ParseEnum<AuxiliaryType>(),
-						Technology = technologyList,
-					});
-				}
-				return retVal;
-			}
-		}
-	}
+using System.Collections.Generic;
+using TUGraz.VectoCommon.InputData;
+using TUGraz.VectoCommon.Models;
+using TUGraz.VectoCommon.Resources;
+using TUGraz.VectoCommon.Utils;
+using TUGraz.VectoCore.InputData.Impl;
+
+namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration
+{
+	public class XMLDeclarationAuxiliaryDataProvider : AbstractDeclarationXMLComponentDataProvider,
+		IAuxiliariesDeclarationInputData
+	{
+		public XMLDeclarationAuxiliaryDataProvider(XMLDeclarationInputDataProvider xmlInputDataProvider) : base(xmlInputDataProvider)
+		{
+			XBasePath = Helper.Query(VehiclePath,
+				XMLNames.Vehicle_Components,
+				XMLNames.Component_Auxiliaries,
+				XMLNames.ComponentDataWrapper);
+		}
+
+
+		public IList<IAuxiliaryDeclarationInputData> Auxiliaries
+		{
+			get
+			{
+				var retVal = new List<IAuxiliaryDeclarationInputData>();
+				var auxiliaries = Navigator.Select(Helper.Query(XBasePath,
+					Helper.QueryConstraint("*",
+						Helper.NSPrefix(XMLNames.Auxiliaries_Auxiliary_Technology), null, "")),
+					Manager);
+
+				while (auxiliaries.MoveNext()) {
+					var techlistNodes = auxiliaries.Current.Select(Helper.NSPrefix(XMLNames.Auxiliaries_Auxiliary_Technology), Manager);
+					var technologyList = new List<string>();
+					while (techlistNodes.MoveNext()) {
+						technologyList.Add(techlistNodes.Current.Value);
+					}
+					retVal.Add(new AuxiliaryDataInputData {
+						Type = auxiliaries.Current.Name.ParseEnum<AuxiliaryType>(),
+						Technology = technologyList,
+					});
+				}
+				return retVal;
+			}
+		}
+	}
 }
\ No newline at end of file
diff --git a/VectoCore/VectoCore/Models/Simulation/DataBus/IDataBus.cs b/VectoCore/VectoCore/Models/Simulation/DataBus/IDataBus.cs
index 292497a44e..c7414b8e7d 100644
--- a/VectoCore/VectoCore/Models/Simulation/DataBus/IDataBus.cs
+++ b/VectoCore/VectoCore/Models/Simulation/DataBus/IDataBus.cs
@@ -29,22 +29,22 @@
 *   Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
 */
 
-using TUGraz.VectoCommon.Models;
-using TUGraz.VectoCommon.Utils;
-using TUGraz.VectoCore.Models.SimulationComponent;
-
-namespace TUGraz.VectoCore.Models.Simulation.DataBus
-{
-	/// <summary>
-	/// Defines interfaces for all different cockpits to access shared data of the powertrain.
-	/// </summary>
-	public interface IDataBus : IGearboxInfo, IAxlegearInfo, IEngineInfo, IVehicleInfo, IMileageCounter, IClutchInfo,
-		IBrakes, IWheelsInfo, IDriverInfo, IDrivingCycleInfo
-	{
-		ExecutionMode ExecutionMode { get; }
-
-		FuelType FuelType { get; }
-
-		Second AbsTime { get; set; }
-	}
+using TUGraz.VectoCommon.Models;
+using TUGraz.VectoCommon.Utils;
+using TUGraz.VectoCore.Models.SimulationComponent;
+
+namespace TUGraz.VectoCore.Models.Simulation.DataBus
+{
+	/// <summary>
+	/// Defines interfaces for all different cockpits to access shared data of the powertrain.
+	/// </summary>
+	public interface IDataBus : IGearboxInfo, IAxlegearInfo, IEngineInfo, IVehicleInfo, IMileageCounter, IClutchInfo,
+		IBrakes, IWheelsInfo, IDriverInfo, IDrivingCycleInfo
+	{
+		ExecutionMode ExecutionMode { get; }
+
+		FuelType FuelType { get; }
+
+		Second AbsTime { get; set; }
+	}
 }
\ No newline at end of file
diff --git a/VectoCore/VectoCore/Models/Simulation/DataBus/IDriverInfo.cs b/VectoCore/VectoCore/Models/Simulation/DataBus/IDriverInfo.cs
index cef9d77aa1..3ae6ae60a3 100644
--- a/VectoCore/VectoCore/Models/Simulation/DataBus/IDriverInfo.cs
+++ b/VectoCore/VectoCore/Models/Simulation/DataBus/IDriverInfo.cs
@@ -30,6 +30,7 @@
 */
 
 using TUGraz.VectoCommon.Utils;
+using TUGraz.VectoCore.Models.SimulationComponent.Impl;
 
 namespace TUGraz.VectoCore.Models.Simulation.DataBus
 {
@@ -45,6 +46,9 @@ namespace TUGraz.VectoCore.Models.Simulation.DataBus
 	public interface IDriverInfo
 	{
 		DrivingBehavior DriverBehavior { get; }
+
+		DrivingAction DrivingAction { get; }
+
 		MeterPerSquareSecond DriverAcceleration { get; }
 	}
 }
\ No newline at end of file
diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs b/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs
index 84178bb810..57f4a2e5ea 100644
--- a/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs
+++ b/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs
@@ -299,7 +299,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
 					commitPriority = 6;
 				})
 				.If<PTOCycleController>(c => { commitPriority = 99; })
-                .If<VTPCycle>(_ => { commitPriority = 0; });
+				.If<VTPCycle>(_ => { commitPriority = 0; });
 
 			_components.Add(Tuple.Create(commitPriority, component));
 			_components = _components.OrderBy(x => x.Item1).Reverse().ToList();
@@ -395,6 +395,11 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
 			get { return Driver != null ? Driver.DriverBehavior : DrivingBehavior.Driving; }
 		}
 
+		public DrivingAction DrivingAction
+		{
+			get { return Driver.DrivingAction; }
+		}
+
 		public MeterPerSquareSecond DriverAcceleration
 		{
 			get { return Driver != null ? Driver.DriverAcceleration : 0.SI<MeterPerSquareSecond>(); }
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs
index 013be9c16d..c4c0e09f98 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs
@@ -29,38 +29,38 @@
 *   Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
 */
 
-using TUGraz.VectoCommon.Models;
-using TUGraz.VectoCommon.Utils;
-using TUGraz.VectoCore.Models.Simulation;
-using TUGraz.VectoCore.Models.Simulation.Data;
-using TUGraz.VectoCore.Models.SimulationComponent.Data;
-using TUGraz.VectoCore.OutputData;
-
-namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
-{
-	public class AxleGear : TransmissionComponent, IAxlegear
-	{
-		public AxleGear(IVehicleContainer container, AxleGearData modelData) : base(container, modelData.AxleGear) {}
-
-		public override IResponse Request(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity,
-			bool dryRun = false)
-		{
-			var retVal = base.Request(absTime, dt, outTorque, outAngularVelocity, dryRun);
-			retVal.AxlegearPowerRequest = outTorque * (PreviousState.OutAngularVelocity + CurrentState.OutAngularVelocity) / 2.0;
-			return retVal;
-		}
-
-		protected override void DoWriteModalResults(IModalDataContainer container)
-		{
-			var avgAngularVelocity = (PreviousState.InAngularVelocity + CurrentState.InAngularVelocity) / 2.0;
-			container[ModalResultField.P_axle_loss] = (CurrentState.InTorque - CurrentState.OutTorque / ModelData.Ratio) *
-													avgAngularVelocity;
-			container[ModalResultField.P_axle_in] = CurrentState.InTorque * avgAngularVelocity;
-		}
-
-		public Watt AxlegearLoss()
-		{
-			return PreviousState.TorqueLossResult.Value * PreviousState.InAngularVelocity;
-		}
-	}
+using TUGraz.VectoCommon.Models;
+using TUGraz.VectoCommon.Utils;
+using TUGraz.VectoCore.Models.Simulation;
+using TUGraz.VectoCore.Models.Simulation.Data;
+using TUGraz.VectoCore.Models.SimulationComponent.Data;
+using TUGraz.VectoCore.OutputData;
+
+namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
+{
+	public class AxleGear : TransmissionComponent, IAxlegear
+	{
+		public AxleGear(IVehicleContainer container, AxleGearData modelData) : base(container, modelData.AxleGear) {}
+
+		public override IResponse Request(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity,
+			bool dryRun = false)
+		{
+			var retVal = base.Request(absTime, dt, outTorque, outAngularVelocity, dryRun);
+			retVal.AxlegearPowerRequest = outTorque * (PreviousState.OutAngularVelocity + CurrentState.OutAngularVelocity) / 2.0;
+			return retVal;
+		}
+
+		protected override void DoWriteModalResults(IModalDataContainer container)
+		{
+			var avgAngularVelocity = (PreviousState.InAngularVelocity + CurrentState.InAngularVelocity) / 2.0;
+			container[ModalResultField.P_axle_loss] = (CurrentState.InTorque - CurrentState.OutTorque / ModelData.Ratio) *
+													avgAngularVelocity;
+			container[ModalResultField.P_axle_in] = CurrentState.InTorque * avgAngularVelocity;
+		}
+
+		public Watt AxlegearLoss()
+		{
+			return PreviousState.TorqueLossResult.Value * PreviousState.InAngularVelocity;
+		}
+	}
 }
\ No newline at end of file
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs
index c9c7b0cbf4..892a126ddb 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs
@@ -45,6 +45,14 @@ using DriverData = TUGraz.VectoCore.Models.SimulationComponent.Data.DriverData;
 
 namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 {
+	public enum DrivingAction
+	{
+		Halt = 0,
+		Roll = 2,
+		Coast = 4,
+		Accelerate = 6,
+		Brake = -5,
+	}
 	public class Driver :
 		StatefulProviderComponent<Driver.DriverState, IDrivingCycleOutPort, IDriverDemandInPort, IDriverDemandOutPort>,
 		IDriver, IDrivingCycleOutPort, IDriverDemandInPort, IDriverActions, IDriverInfo
@@ -52,7 +60,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 		public DriverData DriverData { get; protected set; }
 
 		protected readonly IDriverStrategy DriverStrategy;
-		public string CurrentAction = "";
+		
+		public DrivingAction DrivingAction { get; private set; }
 
 		public Driver(IVehicleContainer container, DriverData driverData, IDriverStrategy strategy) : base(container)
 		{
@@ -132,7 +141,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			Radian gradient,
 			IResponse previousResponse = null)
 		{
-			CurrentAction = "ACCELERATE";
+			DrivingAction = DrivingAction.Accelerate;
 			IterationStatistics.Increment(this, "Accelerate");
 			Log.Debug("DrivingAction Accelerate");
 			var operatingPoint = ComputeAcceleration(ds, targetVelocity);
@@ -186,7 +195,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 						"No operating point found! Vehicle stopped! trying HALT action");
 					DataBus.BrakePower = 1.SI<Watt>();
 					retVal = DrivingActionHalt(absTime, operatingPoint.SimulationInterval, 0.SI<MeterPerSecond>(), gradient);
-
+					
 					retVal.SimulationDistance = 0.SI<Meter>();
 					retVal.Acceleration = 0.SI<MeterPerSquareSecond>();
 					retVal.SimulationInterval = operatingPoint.SimulationInterval;
@@ -300,7 +309,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 		/// <returns></returns>
 		public IResponse DrivingActionCoast(Second absTime, Meter ds, MeterPerSecond maxVelocity, Radian gradient)
 		{
-			CurrentAction = "COAST";
+			DrivingAction = DrivingAction.Coast;
 			IterationStatistics.Increment(this, "Coast");
 			Log.Debug("DrivingAction Coast");
 
@@ -317,7 +326,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 		/// <returns></returns>
 		public IResponse DrivingActionRoll(Second absTime, Meter ds, MeterPerSecond maxVelocity, Radian gradient)
 		{
-			CurrentAction = "ROLL";
+			DrivingAction = DrivingAction.Roll;
 			IterationStatistics.Increment(this, "Roll");
 
 			Log.Debug("DrivingAction Roll");
@@ -436,7 +445,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 		public IResponse DrivingActionBrake(Second absTime, Meter ds, MeterPerSecond nextTargetSpeed, Radian gradient,
 			IResponse previousResponse = null, Meter targetDistance = null)
 		{
-			CurrentAction = "BRAKE";
+			DrivingAction = DrivingAction.Brake;
 			IterationStatistics.Increment(this, "Brake");
 			Log.Debug("DrivingAction Brake");
 
@@ -916,7 +925,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 		/// <returns></returns>
 		public IResponse DrivingActionHalt(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient)
 		{
-			CurrentAction = "HALT";
+			DrivingAction = DrivingAction.Halt;
 			if (!targetVelocity.IsEqual(0) || !DataBus.VehicleStopped) {
 				Log.Error("TargetVelocity ({0}) and VehicleVelocity ({1}) must be zero when vehicle is halting!",
 					targetVelocity,
@@ -943,27 +952,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 		protected override void DoWriteModalResults(IModalDataContainer container)
 		{
 			container[ModalResultField.acc] = CurrentState.Acceleration;
-			container.SetDataValue("DriverAction", ActionToNumber(CurrentAction));
-		}
-
-		private int ActionToNumber(string currentAction)
-		{
-			switch (currentAction.ToUpper()) {
-				case "HALT":
-					return 0;
-				case "ROLL":
-					return 2;
-				case "COAST":
-					return 4;
-				case "ACCELERATE":
-					return 6;
-				case "BRAKE":
-					return -5;
-				default:
-					return -10;
-			}
+			container.SetDataValue("DriverAction", (int)DrivingAction);
 		}
 
+		
 		protected override void DoCommitSimulationStep()
 		{
 			if (!(CurrentState.Response is ResponseSuccess)) {
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
index 565fabc1c8..477ec7b5cd 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
@@ -178,8 +178,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 				_engageTime = absTime + dt;
 			}
 
-			if (DataBus.DriverBehavior == DrivingBehavior.Braking && (DataBus.BrakePower.IsGreater(0) || outTorque < 0) &&
-				DataBus.VehicleSpeed.IsSmaller(Constants.SimulationSettings.ClutchDisengageWhenHaltingSpeed)) {
+			var halted = DataBus.DrivingAction == DrivingAction.Halt;
+			var driverDeceleratingNegTorque = DataBus.DriverBehavior == DrivingBehavior.Braking &&
+											(DataBus.BrakePower.IsGreater(0) || outTorque < 0);
+			var vehiclespeedBelowThreshold =
+				DataBus.VehicleSpeed.IsSmaller(Constants.SimulationSettings.ClutchDisengageWhenHaltingSpeed);
+			if (halted || (driverDeceleratingNegTorque && vehiclespeedBelowThreshold)) {
 				_engageTime = VectoMath.Max(_engageTime, absTime + dt);
 
 				return RequestGearDisengaged(absTime, dt, outTorque, outAngularVelocity, dryRun);
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/MeasuredSpeedDrivingCycle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/MeasuredSpeedDrivingCycle.cs
index 5e156498f1..488de7cd83 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/MeasuredSpeedDrivingCycle.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/MeasuredSpeedDrivingCycle.cs
@@ -389,6 +389,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 
 		public DrivingBehavior DriverBehavior { get; internal set; }
 
+		public DrivingAction DrivingAction
+		{
+			get { return DrivingAction.Accelerate; }
+		}
+
 		public MeterPerSquareSecond DriverAcceleration { get; protected set; }
 
 		public Meter Distance
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PWheelCycle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PWheelCycle.cs
index 4711b22174..1f7ed4d545 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PWheelCycle.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PWheelCycle.cs
@@ -47,38 +47,38 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 	public class PWheelCycle : PowertrainDrivingCycle, IDriverInfo, IVehicleInfo
 	{
 		protected bool FirstRun = true;
-        protected readonly VectoRunData RunData;
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="PWheelCycle"/> class.
-        /// </summary>
-        /// <param name="container">The container.</param>
-        /// <param name="cycle">The cycle.</param>
-        public PWheelCycle(IVehicleContainer container, IDrivingCycleData cycle) : base(container, cycle)
-        {
-            RunData = container.RunData;
-        }
-
-        protected virtual void InitializeCycleData()
-        {
-            FirstRun = false;
-            var gearRatios = RunData.GearboxData.Gears.ToDictionary(g => g.Key, g => g.Value.Ratio);
-            // just to ensure that null-gear has ratio 1
-            gearRatios[0] = 1;
-            var axleRatio = RunData.AxleGearData.AxleGear.Ratio;
-
-            foreach (var entry in Data.Entries) {
-                entry.WheelAngularVelocity = entry.AngularVelocity / (axleRatio * gearRatios[entry.Gear]);
-                entry.Torque = entry.PWheel / entry.WheelAngularVelocity;
-            }
-        }
-
-        public override IResponse Initialize()
-		{
-            if (FirstRun) {
-                InitializeCycleData();
-               
-            }
+		protected readonly VectoRunData RunData;
+
+		/// <summary>
+		/// Initializes a new instance of the <see cref="PWheelCycle"/> class.
+		/// </summary>
+		/// <param name="container">The container.</param>
+		/// <param name="cycle">The cycle.</param>
+		public PWheelCycle(IVehicleContainer container, IDrivingCycleData cycle) : base(container, cycle)
+		{
+			RunData = container.RunData;
+		}
+
+		protected virtual void InitializeCycleData()
+		{
+			FirstRun = false;
+			var gearRatios = RunData.GearboxData.Gears.ToDictionary(g => g.Key, g => g.Value.Ratio);
+			// just to ensure that null-gear has ratio 1
+			gearRatios[0] = 1;
+			var axleRatio = RunData.AxleGearData.AxleGear.Ratio;
+
+			foreach (var entry in Data.Entries) {
+				entry.WheelAngularVelocity = entry.AngularVelocity / (axleRatio * gearRatios[entry.Gear]);
+				entry.Torque = entry.PWheel / entry.WheelAngularVelocity;
+			}
+		}
+
+		public override IResponse Initialize()
+		{
+			if (FirstRun) {
+				InitializeCycleData();
+			   
+			}
 			var first = Data.Entries[0];
 			AbsTime = first.Time;
 			var response = NextComponent.Initialize(first.Torque, first.WheelAngularVelocity);
@@ -165,6 +165,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			get { return DrivingBehavior.Driving; }
 		}
 
+		public DrivingAction DrivingAction
+		{
+			get { return DrivingAction.Accelerate; }
+		}
+
 		public MeterPerSquareSecond DriverAcceleration
 		{
 			get { return 0.SI<MeterPerSquareSecond>(); }
diff --git a/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs b/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs
index 0d6304bc71..6a8fff1be3 100644
--- a/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs
+++ b/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs
@@ -82,13 +82,13 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent
 
 		public const string AngledriveLossMap = @"TestData\Components\AngleGear.vtlm";
 
-        [OneTimeSetUp]
-        public void RunBeforeAnyTests()
-        {
-            Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory);
-        }
+		[OneTimeSetUp]
+		public void RunBeforeAnyTests()
+		{
+			Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory);
+		}
 
-        private static GearboxData CreateGearboxData()
+		private static GearboxData CreateGearboxData()
 		{
 			var ratios = new[] { 6.38, 4.63, 3.44, 2.59, 1.86, 1.35, 1, 0.76 };
 
@@ -548,6 +548,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent
 			var container = new MockVehicleContainer() {
 				VehicleSpeed = 10.SI<MeterPerSecond>(),
 				DriverBehavior = DrivingBehavior.Driving,
+				DrivingAction = DrivingAction.Accelerate,
 				Altitude = 0.SI<Meter>(),
 				VehicleMass = 10000.SI<Kilogram>(),
 				ReducedMassWheels = 100.SI<Kilogram>(),
diff --git a/VectoCore/VectoCoreTest/Utils/MockDriver.cs b/VectoCore/VectoCoreTest/Utils/MockDriver.cs
index b561c9ea53..3999f369b2 100644
--- a/VectoCore/VectoCoreTest/Utils/MockDriver.cs
+++ b/VectoCore/VectoCoreTest/Utils/MockDriver.cs
@@ -36,6 +36,7 @@ using TUGraz.VectoCore.Models.Connector.Ports.Impl;
 using TUGraz.VectoCore.Models.Simulation;
 using TUGraz.VectoCore.Models.Simulation.DataBus;
 using TUGraz.VectoCore.Models.SimulationComponent;
+using TUGraz.VectoCore.Models.SimulationComponent.Impl;
 using TUGraz.VectoCore.OutputData;
 
 namespace TUGraz.VectoCore.Tests.Utils
@@ -49,6 +50,7 @@ namespace TUGraz.VectoCore.Tests.Utils
 		public MockDriver(IVehicleContainer container) : base(container)
 		{
 			DriverBehavior = DrivingBehavior.Accelerating;
+			DrivingAction = DrivingAction.Accelerate;
 		}
 
 		protected override void DoWriteModalResults(IModalDataContainer container) {}
@@ -117,6 +119,9 @@ namespace TUGraz.VectoCore.Tests.Utils
 		public bool VehicleStopped { get; set; }
 
 		public DrivingBehavior DriverBehavior { get; set; }
+
+		public DrivingAction DrivingAction { get; set; }
+
 		public MeterPerSquareSecond DriverAcceleration { get; set; }
 	}
 }
\ No newline at end of file
diff --git a/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs b/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs
index 3cd6443191..df365a62f5 100644
--- a/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs
+++ b/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs
@@ -29,203 +29,207 @@
 *   Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
 */
 
-using System;
-using System.Collections.Generic;
-using TUGraz.VectoCommon.Exceptions;
-using TUGraz.VectoCommon.Models;
-using TUGraz.VectoCommon.Utils;
-using TUGraz.VectoCore.Models.Connector.Ports;
-using TUGraz.VectoCore.Models.Declaration;
-using TUGraz.VectoCore.Models.Simulation;
-using TUGraz.VectoCore.Models.Simulation.Data;
-using TUGraz.VectoCore.Models.Simulation.DataBus;
-using TUGraz.VectoCore.Models.Simulation.Impl;
-using TUGraz.VectoCore.Models.SimulationComponent;
-using TUGraz.VectoCore.Models.SimulationComponent.Data;
-using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox;
-using TUGraz.VectoCore.OutputData;
-
-namespace TUGraz.VectoCore.Tests.Utils
-{
-	public class MockVehicleContainer : IVehicleContainer
-	{
-		// only CycleData Lookup is set / accessed...
-
-		public List<VectoSimulationComponent> Components = new List<VectoSimulationComponent>();
-		private Watt _axlegearLoss = 0.SI<Watt>();
-		private bool _clutchClosed = true;
-
-		public IEngineInfo Engine { get; set; }
-
-		public GearboxType GearboxType { get; set; }
-
-		public uint Gear { get; set; }
-		public GearInfo NextGear { get; private set; }
-
-		public Second TractionInterruption
-		{
-			get { return 1.SI<Second>(); }
-		}
-
-		public uint NumGears { get; set; }
-
-		public MeterPerSecond StartSpeed { get; set; }
-		public MeterPerSquareSecond StartAcceleration { get; set; }
-		public NewtonMeter GearMaxTorque { get; set; }
-
-		public FuelType FuelType
-		{
-			get { return FuelType.DieselCI; }
-		}
-
-		public Second AbsTime { get; set; }
-
-		public Watt GearboxLoss()
-		{
-			throw new System.NotImplementedException();
-		}
-
-		public Second LastShift { get; private set; }
-
-		public GearData GetGearData(uint gear)
-		{
-			throw new System.NotImplementedException();
-		}
-
-		public PerSecond EngineSpeed { get; set; }
-		public NewtonMeter EngineTorque { get; set; }
-
-		public Watt EngineStationaryFullPower(PerSecond angularSpeed)
-		{
-			return Engine.EngineStationaryFullPower(angularSpeed);
-		}
-
-		public Watt EngineDragPower(PerSecond angularSpeed)
-		{
-			return Engine.EngineStationaryFullPower(angularSpeed);
-		}
-
-		public PerSecond EngineIdleSpeed
-		{
-			get { return Engine.EngineIdleSpeed; }
-		}
-
-		public PerSecond EngineRatedSpeed
-		{
-			get { return Engine.EngineRatedSpeed; }
-		}
-
-		public PerSecond EngineN95hSpeed
-		{
-			get { return Engine.EngineN95hSpeed; }
-		}
-
-		public PerSecond EngineN80hSpeed
-		{
-			get { return Engine.EngineN80hSpeed; }
-		}
-
-		public MeterPerSecond VehicleSpeed { get; set; }
-		public Kilogram VehicleMass { get; set; }
-		public Kilogram VehicleLoading { get; set; }
-		public Kilogram TotalMass { get; set; }
-		public CubicMeter CargoVolume { get; set; }
-
-		public Newton AirDragResistance(MeterPerSecond previousVelocity, MeterPerSecond nextVelocity)
-		{
-			return 0.SI<Newton>();
-		}
-
-		public Newton RollingResistance(Radian gradient)
-		{
-			return 0.SI<Newton>();
-		}
-
-		public Newton SlopeResistance(Radian gradient)
-		{
-			return 0.SI<Newton>();
-		}
-
-		public Meter Distance { get; set; }
-
-		public bool SetClutchClosed
-		{
-			set { _clutchClosed = value; }
-		}
-
-		public bool ClutchClosed(Second absTime)
-		{
-			return _clutchClosed;
-		}
-
-		public Watt BrakePower { get; set; }
-		public Meter CycleStartDistance { get; set; }
-
-		public IReadOnlyList<DrivingCycleData.DrivingCycleEntry> LookAhead(Meter lookaheadDistance)
-		{
-			throw new System.NotImplementedException();
-		}
-
-		public IReadOnlyList<DrivingCycleData.DrivingCycleEntry> LookAhead(Second time)
-		{
-			throw new System.NotImplementedException();
-		}
-
-		public bool VehicleStopped { get; set; }
-
-		public DrivingBehavior DriverBehavior { get; set; }
-		public MeterPerSquareSecond DriverAcceleration { get; set; }
-
-		public CycleData CycleData { get; set; }
-
-		public DrivingCycleData.DrivingCycleEntry CycleLookAhead(Meter distance)
-		{
-			return new DrivingCycleData.DrivingCycleEntry() {
-				RoadGradient = 0.SI<Radian>(),
-				Altitude = 0.SI<Meter>()
-			};
-		}
-
-		public Meter Altitude { get; set; }
-		public ExecutionMode ExecutionMode { get; set; }
-		public IModalDataContainer ModalData { get; set; }
-		public VectoRunData RunData { get; set; }
-
-		public ISimulationOutPort GetCycleOutPort()
-		{
-			throw new System.NotImplementedException();
-		}
-
-		public VectoRun.Status RunStatus { get; set; }
-
-		public bool PTOActive { get; private set; }
-
-		public void AddComponent(VectoSimulationComponent component)
-		{
-			Components.Add(component);
-		}
-
-		public void CommitSimulationStep(Second time, Second simulationInterval)
-		{
-			foreach (var entry in Components) {
-				entry.CommitSimulationStep(ModalData);
-			}
-		}
-
-		public void FinishSimulation() {}
-
-		public void FinishSimulationRun(Exception e) {}
-
-		public Watt SetAxlegearLoss
-		{
-			set { _axlegearLoss = value; }
-		}
-
-		public Watt AxlegearLoss()
-		{
-			return _axlegearLoss;
-		}
-
-		public Kilogram ReducedMassWheels { get; set; }
-	}
+using System;
+using System.Collections.Generic;
+using TUGraz.VectoCommon.Exceptions;
+using TUGraz.VectoCommon.Models;
+using TUGraz.VectoCommon.Utils;
+using TUGraz.VectoCore.Models.Connector.Ports;
+using TUGraz.VectoCore.Models.Declaration;
+using TUGraz.VectoCore.Models.Simulation;
+using TUGraz.VectoCore.Models.Simulation.Data;
+using TUGraz.VectoCore.Models.Simulation.DataBus;
+using TUGraz.VectoCore.Models.Simulation.Impl;
+using TUGraz.VectoCore.Models.SimulationComponent;
+using TUGraz.VectoCore.Models.SimulationComponent.Data;
+using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox;
+using TUGraz.VectoCore.Models.SimulationComponent.Impl;
+using TUGraz.VectoCore.OutputData;
+
+namespace TUGraz.VectoCore.Tests.Utils
+{
+	public class MockVehicleContainer : IVehicleContainer
+	{
+		// only CycleData Lookup is set / accessed...
+
+		public List<VectoSimulationComponent> Components = new List<VectoSimulationComponent>();
+		private Watt _axlegearLoss = 0.SI<Watt>();
+		private bool _clutchClosed = true;
+
+		public IEngineInfo Engine { get; set; }
+
+		public GearboxType GearboxType { get; set; }
+
+		public uint Gear { get; set; }
+		public GearInfo NextGear { get; private set; }
+
+		public Second TractionInterruption
+		{
+			get { return 1.SI<Second>(); }
+		}
+
+		public uint NumGears { get; set; }
+
+		public MeterPerSecond StartSpeed { get; set; }
+		public MeterPerSquareSecond StartAcceleration { get; set; }
+		public NewtonMeter GearMaxTorque { get; set; }
+
+		public FuelType FuelType
+		{
+			get { return FuelType.DieselCI; }
+		}
+
+		public Second AbsTime { get; set; }
+
+		public Watt GearboxLoss()
+		{
+			throw new System.NotImplementedException();
+		}
+
+		public Second LastShift { get; private set; }
+
+		public GearData GetGearData(uint gear)
+		{
+			throw new System.NotImplementedException();
+		}
+
+		public PerSecond EngineSpeed { get; set; }
+		public NewtonMeter EngineTorque { get; set; }
+
+		public Watt EngineStationaryFullPower(PerSecond angularSpeed)
+		{
+			return Engine.EngineStationaryFullPower(angularSpeed);
+		}
+
+		public Watt EngineDragPower(PerSecond angularSpeed)
+		{
+			return Engine.EngineStationaryFullPower(angularSpeed);
+		}
+
+		public PerSecond EngineIdleSpeed
+		{
+			get { return Engine.EngineIdleSpeed; }
+		}
+
+		public PerSecond EngineRatedSpeed
+		{
+			get { return Engine.EngineRatedSpeed; }
+		}
+
+		public PerSecond EngineN95hSpeed
+		{
+			get { return Engine.EngineN95hSpeed; }
+		}
+
+		public PerSecond EngineN80hSpeed
+		{
+			get { return Engine.EngineN80hSpeed; }
+		}
+
+		public MeterPerSecond VehicleSpeed { get; set; }
+		public Kilogram VehicleMass { get; set; }
+		public Kilogram VehicleLoading { get; set; }
+		public Kilogram TotalMass { get; set; }
+		public CubicMeter CargoVolume { get; set; }
+
+		public Newton AirDragResistance(MeterPerSecond previousVelocity, MeterPerSecond nextVelocity)
+		{
+			return 0.SI<Newton>();
+		}
+
+		public Newton RollingResistance(Radian gradient)
+		{
+			return 0.SI<Newton>();
+		}
+
+		public Newton SlopeResistance(Radian gradient)
+		{
+			return 0.SI<Newton>();
+		}
+
+		public Meter Distance { get; set; }
+
+		public bool SetClutchClosed
+		{
+			set { _clutchClosed = value; }
+		}
+
+		public bool ClutchClosed(Second absTime)
+		{
+			return _clutchClosed;
+		}
+
+		public Watt BrakePower { get; set; }
+		public Meter CycleStartDistance { get; set; }
+
+		public IReadOnlyList<DrivingCycleData.DrivingCycleEntry> LookAhead(Meter lookaheadDistance)
+		{
+			throw new System.NotImplementedException();
+		}
+
+		public IReadOnlyList<DrivingCycleData.DrivingCycleEntry> LookAhead(Second time)
+		{
+			throw new System.NotImplementedException();
+		}
+
+		public bool VehicleStopped { get; set; }
+
+		public DrivingBehavior DriverBehavior { get; set; }
+
+		public DrivingAction DrivingAction { get; set; }
+
+		public MeterPerSquareSecond DriverAcceleration { get; set; }
+
+		public CycleData CycleData { get; set; }
+
+		public DrivingCycleData.DrivingCycleEntry CycleLookAhead(Meter distance)
+		{
+			return new DrivingCycleData.DrivingCycleEntry() {
+				RoadGradient = 0.SI<Radian>(),
+				Altitude = 0.SI<Meter>()
+			};
+		}
+
+		public Meter Altitude { get; set; }
+		public ExecutionMode ExecutionMode { get; set; }
+		public IModalDataContainer ModalData { get; set; }
+		public VectoRunData RunData { get; set; }
+
+		public ISimulationOutPort GetCycleOutPort()
+		{
+			throw new System.NotImplementedException();
+		}
+
+		public VectoRun.Status RunStatus { get; set; }
+
+		public bool PTOActive { get; private set; }
+
+		public void AddComponent(VectoSimulationComponent component)
+		{
+			Components.Add(component);
+		}
+
+		public void CommitSimulationStep(Second time, Second simulationInterval)
+		{
+			foreach (var entry in Components) {
+				entry.CommitSimulationStep(ModalData);
+			}
+		}
+
+		public void FinishSimulation() {}
+
+		public void FinishSimulationRun(Exception e) {}
+
+		public Watt SetAxlegearLoss
+		{
+			set { _axlegearLoss = value; }
+		}
+
+		public Watt AxlegearLoss()
+		{
+			return _axlegearLoss;
+		}
+
+		public Kilogram ReducedMassWheels { get; set; }
+	}
 }
\ No newline at end of file
-- 
GitLab