From ac3338c14b016466ef4535cc23edcd330f84818c Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Mon, 11 Oct 2021 15:34:22 +0200
Subject: [PATCH] refactoring wheels, brakes, vehicle, tc angledrive, axlegear
 response

---
 VectoCommon/VectoCommon/Models/IResponse.cs   | 64 +++++++++++++++++--
 .../Models/TorqueConverterOperatingPoint.cs   | 21 ++++++
 VectoCommon/VectoCommon/VectoCommon.csproj    |  1 +
 .../Models/Connector/Ports/Impl/Response.cs   | 40 +++++++-----
 .../Data/Gearbox/TorqueConverterData.cs       | 22 +------
 .../SimulationComponent/Impl/Angledrive.cs    |  4 +-
 .../SimulationComponent/Impl/AxleGear.cs      |  3 +-
 .../Models/SimulationComponent/Impl/Brakes.cs |  2 +-
 .../Models/SimulationComponent/Impl/Driver.cs |  2 +-
 .../Impl/TorqueConverter.cs                   | 16 +++--
 .../SimulationComponent/Impl/Vehicle.cs       |  1 +
 .../Models/SimulationComponent/Impl/Wheels.cs |  2 +-
 12 files changed, 126 insertions(+), 52 deletions(-)
 create mode 100644 VectoCommon/VectoCommon/Models/TorqueConverterOperatingPoint.cs

diff --git a/VectoCommon/VectoCommon/Models/IResponse.cs b/VectoCommon/VectoCommon/Models/IResponse.cs
index d77b29441b..d6f4c10092 100644
--- a/VectoCommon/VectoCommon/Models/IResponse.cs
+++ b/VectoCommon/VectoCommon/Models/IResponse.cs
@@ -40,16 +40,12 @@ namespace TUGraz.VectoCommon.Models
 	/// </summary>
 	public interface IResponse
 	{
+		object Source { get; }
+
 		Second AbsTime { get; set; }
 		Meter SimulationDistance { get; set; }
 		Second SimulationInterval { get; set; }
-		object Source { get; }
 
-		Watt AxlegearPowerRequest { get; set; }
-		Watt WheelsPowerRequest { get; set; }
-		Watt VehiclePowerRequest { get; set; }
-		Watt BrakePower { get; set; }
-		Watt AngledrivePowerRequest { get; set; }
 
 		DriverResponse Driver { get; }
 
@@ -59,6 +55,18 @@ namespace TUGraz.VectoCommon.Models
 
 		GearboxResponse Gearbox { get; }
 
+		TorqueConverterResponse TorqueConverter { get; }
+
+		AxlegearResponse Axlegear { get; }
+
+		AngledriveResponse Angledrive { get; }
+
+		WheelsResponse Wheels { get; }
+
+		VehicleResponse Vehicle { get; }
+
+		BrakesResponse Brakes { get; }
+
 	}
 
 	public abstract class AbstractComponentResponse
@@ -125,4 +133,48 @@ namespace TUGraz.VectoCommon.Models
 
 		public NewtonMeter OutputTorque { get; set; }
 	}
+
+	public class TorqueConverterResponse : AbstractPowertrainComponentResponse
+	{
+		public TorqueConverterOperatingPoint TorqueConverterOperatingPoint { get; set; }
+
+		public NewtonMeter TorqueConverterTorqueDemand { get; set; }
+
+	}
+
+	[DebuggerDisplay("P_out: {PowerRequest}; T_card: {CardanTorque}")]
+	public class AxlegearResponse : AbstractPowertrainComponentResponse
+	{
+		public NewtonMeter CardanTorque { get; set; }
+
+		public NewtonMeter OutputTorque { get; set; }
+
+		public PerSecond OutputSpeed { get; set; }
+	}
+
+	[DebuggerDisplay("P_out: {PowerRequest}")]
+	public class AngledriveResponse : AbstractPowertrainComponentResponse
+	{
+		public NewtonMeter OutputTorque { get; set; }
+
+		public PerSecond OutputSpeed { get; set; }
+
+	}
+
+	[DebuggerDisplay("P_out: {PowerRequest}")]
+	public class WheelsResponse : AbstractPowertrainComponentResponse { }
+
+	[DebuggerDisplay("v_veh: {VehicleSpeed}")]
+
+	public class VehicleResponse : AbstractComponentResponse
+	{
+		public MeterPerSecond VehicleSpeed { get; set; }
+	}
+
+	[DebuggerDisplay("P_brake: {BrakePower}")]
+
+	public class BrakesResponse : AbstractComponentResponse
+	{
+		public Watt BrakePower { get; set; }
+	}
 }
\ No newline at end of file
diff --git a/VectoCommon/VectoCommon/Models/TorqueConverterOperatingPoint.cs b/VectoCommon/VectoCommon/Models/TorqueConverterOperatingPoint.cs
new file mode 100644
index 0000000000..f728d8ed78
--- /dev/null
+++ b/VectoCommon/VectoCommon/Models/TorqueConverterOperatingPoint.cs
@@ -0,0 +1,21 @@
+using TUGraz.VectoCommon.Utils;
+
+namespace TUGraz.VectoCommon.Models {
+	public class TorqueConverterOperatingPoint
+	{
+		public PerSecond OutAngularVelocity;
+		public NewtonMeter OutTorque;
+
+		public PerSecond InAngularVelocity;
+		public NewtonMeter InTorque;
+
+		public double SpeedRatio;
+		public double TorqueRatio;
+		public bool Creeping;
+
+		public override string ToString()
+		{
+			return $"n_out: {OutAngularVelocity}, n_in: {InAngularVelocity}, tq_out: {OutTorque}, tq_in {InTorque}, nu: {SpeedRatio}, my: {TorqueRatio}";
+		}
+	}
+}
\ No newline at end of file
diff --git a/VectoCommon/VectoCommon/VectoCommon.csproj b/VectoCommon/VectoCommon/VectoCommon.csproj
index 99f42fb174..c1d43d6b64 100644
--- a/VectoCommon/VectoCommon/VectoCommon.csproj
+++ b/VectoCommon/VectoCommon/VectoCommon.csproj
@@ -83,6 +83,7 @@
     <Compile Include="Models\OperatingPoint.cs" />
     <Compile Include="Models\RetarderType.cs" />
     <Compile Include="Models\SimulationType.cs" />
+    <Compile Include="Models\TorqueConverterOperatingPoint.cs" />
     <Compile Include="Models\VehicleCategory.cs" />
     <Compile Include="Models\WHRType.cs" />
     <Compile Include="OutputData\IOutputFileWriter.cs" />
diff --git a/VectoCore/VectoCore/Models/Connector/Ports/Impl/Response.cs b/VectoCore/VectoCore/Models/Connector/Ports/Impl/Response.cs
index 9683b4bee7..4e28ba506d 100644
--- a/VectoCore/VectoCore/Models/Connector/Ports/Impl/Response.cs
+++ b/VectoCore/VectoCore/Models/Connector/Ports/Impl/Response.cs
@@ -49,16 +49,18 @@ namespace TUGraz.VectoCore.Models.Connector.Ports.Impl
             Engine = new EngineResponse();
             Clutch = new ClutchResponse();
             Gearbox = new GearboxResponse();
-			//Axlegear = new AxlegearResponse();
-			//Angledrive = new AngledriveResponse();
-			//Wheels = new WheelsResponse();
-			//Vehicle = new VehicleResponse();
-			//Brakes = new BrakesResponse();
-			//ElectricMotor = new ElectricMotorResponse();
-			////ElectricSystem = new
-			//TorqueConverter = new TorqueConverterResponse();
-			//HybridController = new HybridControllerResponse();
-		}
+            Axlegear = new AxlegearResponse();
+            Angledrive = new AngledriveResponse();
+            Wheels = new WheelsResponse();
+            Vehicle = new VehicleResponse();
+            Brakes = new BrakesResponse();
+            //ElectricMotor = new ElectricMotorResponse();
+            ////ElectricSystem = new
+            TorqueConverter = new TorqueConverterResponse();
+            //HybridController = new HybridControllerResponse();
+        }
+
+		
 
 
 		public object Source { get; }
@@ -66,11 +68,7 @@ namespace TUGraz.VectoCore.Models.Connector.Ports.Impl
 		public Second AbsTime { get; set; }
 		public Second SimulationInterval { get; set; }
 		public Meter SimulationDistance { get; set; }
-		public Watt AngledrivePowerRequest { get; set; }
-		public Watt AxlegearPowerRequest { get; set; }
-		public Watt WheelsPowerRequest { get; set; }
-		public Watt VehiclePowerRequest { get; set; }
-		public Watt BrakePower { get; set; }
+
 		public GearboxResponse Gearbox { get; }
 
 		public DriverResponse Driver { get; }
@@ -79,8 +77,18 @@ namespace TUGraz.VectoCore.Models.Connector.Ports.Impl
 
 		public ClutchResponse Clutch { get; }
 
-		public TorqueConverterOperatingPoint TorqueConverterOperatingPoint { get; set; }
+		public AxlegearResponse Axlegear { get; }
+
+		public AngledriveResponse Angledrive { get; }
 
+		public TorqueConverterResponse TorqueConverter { get; }
+
+		public WheelsResponse Wheels { get; }
+
+		public VehicleResponse Vehicle { get; }
+
+		public BrakesResponse Brakes { get; }
+		
 		public override string ToString()
 		{
 			var t = GetType();
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Data/Gearbox/TorqueConverterData.cs b/VectoCore/VectoCore/Models/SimulationComponent/Data/Gearbox/TorqueConverterData.cs
index c5a63ad3c5..98c357d2b4 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Data/Gearbox/TorqueConverterData.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Data/Gearbox/TorqueConverterData.cs
@@ -35,6 +35,7 @@ using System.ComponentModel.DataAnnotations;
 using System.Diagnostics;
 using System.Linq;
 using TUGraz.VectoCommon.Exceptions;
+using TUGraz.VectoCommon.Models;
 using TUGraz.VectoCommon.Utils;
 using TUGraz.VectoCore.Models.Declaration;
 
@@ -347,26 +348,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox
 
 
 	}
-
-	public class TorqueConverterOperatingPoint
-	{
-		public PerSecond OutAngularVelocity;
-		public NewtonMeter OutTorque;
-
-		public PerSecond InAngularVelocity;
-		public NewtonMeter InTorque;
-
-		public double SpeedRatio;
-		public double TorqueRatio;
-		public bool Creeping;
-
-		public override string ToString()
-		{
-			return string.Format("n_out: {0}, n_in: {1}, tq_out: {2}, tq_in {3}, nu: {4}, my: {5}", OutAngularVelocity,
-				InAngularVelocity, OutTorque, InTorque, SpeedRatio, TorqueRatio);
-		}
-	}
-
+	
 	[DebuggerDisplay("nu: {SpeedRatio}, mu: {TorqueRatio}, T_ref: {Torque}")]
 	public class TorqueConverterEntry
 	{
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Angledrive.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Angledrive.cs
index 21f21d0e3d..28ec760e1d 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Angledrive.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Angledrive.cs
@@ -46,7 +46,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			bool dryRun = false)
 		{
 			var retVal = base.Request(absTime, dt, outTorque, outAngularVelocity, dryRun);
-			retVal.AngledrivePowerRequest = outTorque * (PreviousState.OutAngularVelocity + CurrentState.OutAngularVelocity) / 2.0;
+			retVal.Angledrive.PowerRequest = outTorque * (PreviousState.OutAngularVelocity + CurrentState.OutAngularVelocity) / 2.0;
+			retVal.Angledrive.OutputTorque = outTorque;
+			retVal.Angledrive.OutputSpeed = outAngularVelocity;
 			return retVal;
 		}
 
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs
index 5cbc3220df..7188c675aa 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs
@@ -46,7 +46,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			bool dryRun = false)
 		{
 			var retVal = base.Request(absTime, dt, outTorque, outAngularVelocity, dryRun);
-			retVal.AxlegearPowerRequest = outTorque * (PreviousState.OutAngularVelocity + CurrentState.OutAngularVelocity) / 2.0;
+			retVal.Axlegear.PowerRequest = outTorque * (PreviousState.OutAngularVelocity + CurrentState.OutAngularVelocity) / 2.0;
+			retVal.Axlegear.CardanTorque = PreviousState.InTorque;
 			return retVal;
 		}
 
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs
index b91d9b2d8f..6933d79050 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs
@@ -77,7 +77,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			CurrentState.SetState(outTorque + brakeTorque, outAngularVelocity, outTorque, outAngularVelocity);
 
 			var retVal = NextComponent.Request(absTime, dt, outTorque + brakeTorque, outAngularVelocity, dryRun);
-			retVal.BrakePower = brakeTorque * avgAngularSpeed;
+			retVal.Brakes.BrakePower = brakeTorque * avgAngularSpeed;
 			return retVal;
 		}
 
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs
index ccfa9f667b..a4aa54ee4b 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs
@@ -556,7 +556,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 				operatingPoint.Acceleration, DataBus.BrakePower);
 			if (DataBus.BrakePower < 0) {
 				var overload = new ResponseOverload(this) {
-					BrakePower = DataBus.BrakePower,
+					Brakes = { BrakePower = DataBus.BrakePower, },
 					Driver = { Acceleration = operatingPoint.Acceleration }
 				};
 				DataBus.BrakePower = 0.SI<Watt>();
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/TorqueConverter.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/TorqueConverter.cs
index 24d54404c4..228c0f50b7 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/TorqueConverter.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/TorqueConverter.cs
@@ -106,7 +106,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			var inTorque = CalculateAverageInTorque(operatingPoint);
 
 			if (dryRun) {
-				return HandleDryRun(absTime, dt, outTorque, outAngularVelocity, inTorque, operatingPoint);
+				var retValD = HandleDryRun(absTime, dt, outTorque, outAngularVelocity, inTorque, operatingPoint);
+				retValD.TorqueConverter.TorqueConverterTorqueDemand = outTorque;
+				return retValD;
 			}
 
 			// normal request
@@ -117,9 +119,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 							(PreviousState.OutAngularVelocity + operatingPoint.OutAngularVelocity) / 2.0;
 				if (!delta.IsEqual(0, Constants.SimulationSettings.LineSearchTolerance)) {
 					return delta > 0
-						? new ResponseOverload(this) { Delta = delta, TorqueConverterOperatingPoint = operatingPoint }
+						? new ResponseOverload(this) { Delta = delta, TorqueConverter = { TorqueConverterOperatingPoint = operatingPoint }}
 						: (IResponse)
-						new ResponseUnderload(this) {Delta = delta, TorqueConverterOperatingPoint = operatingPoint };
+						new ResponseUnderload(this) {Delta = delta, TorqueConverter = { TorqueConverterOperatingPoint = operatingPoint } };
 				}
 			}
 
@@ -169,7 +171,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 				return new ResponseDryRun(this) {
 					DeltaFullLoad = delta,
 					DeltaDragLoad = delta,
-					TorqueConverterOperatingPoint = operatingPoint
+					TorqueConverter = { 
+						TorqueConverterOperatingPoint = operatingPoint
+					}
 				};
 			}
 
@@ -194,7 +198,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			return new ResponseDryRun(this) {
 				DeltaFullLoad = 10 * deltaMax,
 				DeltaDragLoad = 10 * deltaMin,
-				TorqueConverterOperatingPoint = DataBus.DriverInfo.DrivingAction == DrivingAction.Brake ? dryOperatingPointMin : dryOperatingPointMax
+				TorqueConverter = { 
+					TorqueConverterOperatingPoint = DataBus.DriverInfo.DrivingAction == DrivingAction.Brake ? dryOperatingPointMin : dryOperatingPointMax
+				}
 			};
 		}
 
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs
index b7d4981be1..21a13b180c 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs
@@ -134,6 +134,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 
 			var retval = NextComponent.Request(absTime, dt, CurrentState.VehicleTractionForce,
 				CurrentState.Velocity, dryRun);
+			retval.Vehicle.VehicleSpeed = CurrentState.Velocity;
 			return retval;
 		}
 
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Wheels.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Wheels.cs
index 0ad78d1245..a323a2ff86 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Wheels.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Wheels.cs
@@ -82,7 +82,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			var retVal = NextComponent.Request(absTime, dt, CurrentState.TorqueIn, CurrentState.AngularVelocity,
 				dryRun);
 
-			retVal.WheelsPowerRequest = CurrentState.TorqueIn * avgAngularSpeed;
+			retVal.Wheels.PowerRequest = CurrentState.TorqueIn * avgAngularSpeed;
 			return retVal;
 		}
 
-- 
GitLab