From b6ac248a4e67f63a33b3597aa030cb48548eda0a Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Wed, 30 Mar 2022 09:14:08 +0200
Subject: [PATCH] calculate disengage speed for at transmissions based on
 enginspeed/downshift speed in first locked gear

---
 .../DeclarationDataAdapterHeavyLorry.cs       | 14 ++++++++++++-
 .../EngineeringDataAdapter.cs                 | 12 +++++++++++
 .../SimulationComponent/Data/GearboxData.cs   | 20 +++++++++++++++++++
 .../Impl/ATShiftStrategy.cs                   |  2 +-
 .../Impl/BatteryElectricMotorController.cs    |  5 ++++-
 .../SimulationComponent/Impl/Gearbox.cs       |  2 +-
 .../Impl/PEVAMTShiftStrategy.cs               |  5 ++++-
 .../Strategies/HybridStrategy.cs              |  8 +++-----
 .../Strategies/SerialHybridStrategy.cs        |  2 +-
 9 files changed, 59 insertions(+), 11 deletions(-)

diff --git a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapterHeavyLorry.cs b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapterHeavyLorry.cs
index 75aaf38e7f..9c5ebee308 100644
--- a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapterHeavyLorry.cs
+++ b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapterHeavyLorry.cs
@@ -427,7 +427,19 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter
 				}
 			}
 
-			return retVal;
+            // update disengageWhenHaltingSpeed
+            if (retVal.Type.AutomaticTransmission()) {
+                var firstGear = retVal.GearList.First(x => x.IsLockedGear());
+				if (retVal.Gears[firstGear.Gear].ShiftPolygon.Downshift.Any()) {
+					var downshiftSpeedInc = retVal.Gears[firstGear.Gear].ShiftPolygon
+						.InterpolateDownshiftSpeed(0.SI<NewtonMeter>()) * 1.05;
+					var vehicleSpeedDisengage = downshiftSpeedInc / axlegearRatio / retVal.Gears[firstGear.Gear].Ratio *
+												dynamicTyreRadius;
+					retVal.DisengageWhenHaltingSpeed = vehicleSpeedDisengage;
+				}
+			}
+
+            return retVal;
 		}
 
 		protected virtual TorqueConverterData CreateTorqueConverterData(GearboxType gearboxType,
diff --git a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/EngineeringDataAdapter.cs b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/EngineeringDataAdapter.cs
index e7e13c95ba..72af4e3406 100644
--- a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/EngineeringDataAdapter.cs
+++ b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/EngineeringDataAdapter.cs
@@ -367,6 +367,18 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter
 					gearshiftData.CLUpshiftMinAcceleration, gearshiftData.CCUpshiftMinAcceleration);
 			}
 
+			// update disengageWhenHaltingSpeed
+			if (retVal.Type.AutomaticTransmission()) {
+				var firstGear = retVal.GearList.First(x => x.IsLockedGear());
+				if (retVal.Gears[firstGear.Gear].ShiftPolygon.Downshift.Any()) {
+					var downshiftSpeedInc = retVal.Gears[firstGear.Gear].ShiftPolygon
+						.InterpolateDownshiftSpeed(0.SI<NewtonMeter>()) * 1.05;
+					var vehicleSpeedDisengage = downshiftSpeedInc / axlegearRatio / retVal.Gears[firstGear.Gear].Ratio *
+												dynamicTyreRadius;
+					retVal.DisengageWhenHaltingSpeed = vehicleSpeedDisengage;
+				}
+			}
+
 			return retVal;
 		}
 
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Data/GearboxData.cs b/VectoCore/VectoCore/Models/SimulationComponent/Data/GearboxData.cs
index 8b6ea8c8f7..cba4e932cb 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Data/GearboxData.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Data/GearboxData.cs
@@ -39,6 +39,7 @@ using Newtonsoft.Json;
 using TUGraz.VectoCommon.InputData;
 using TUGraz.VectoCommon.Models;
 using TUGraz.VectoCommon.Utils;
+using TUGraz.VectoCore.Configuration;
 using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox;
 using TUGraz.VectoCore.Models.SimulationComponent.Impl;
 
@@ -52,11 +53,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
 	[DebuggerDisplay("GearboxData({Type}, #Gears: {Gears.Count}, ...)")]
 	public class GearboxData : SimulationComponentData
 	{
+		public GearboxData() {}
+
 		public GearboxType Type { get; internal set; }
 
 		[Required, ValidateObject] public Dictionary<uint, GearData> Gears = new Dictionary<uint, GearData>();
 		
 		private GearList _gearlist;
+		private MeterPerSecond _disengageWhenHaltingSpeed;
 
 		public TorqueConverterData TorqueConverterData { get; internal set; } 
 
@@ -83,6 +87,22 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
 		[JsonIgnore]
 		public GearList GearList => _gearlist ?? (_gearlist = CreateGearList());
 
+		public MeterPerSecond DisengageWhenHaltingSpeed
+		{
+			get
+			{
+				return _disengageWhenHaltingSpeed != null
+					? _disengageWhenHaltingSpeed
+					: (Type.AutomaticTransmission()
+						? Constants.SimulationSettings.ATGearboxDisengageWhenHaltingSpeed
+						: Constants.SimulationSettings.ClutchDisengageWhenHaltingSpeed);
+			}
+			internal set
+			{
+				_disengageWhenHaltingSpeed = value;
+			}
+		}
+
 		private GearList CreateGearList()
 		{
 			var gearList = new List<GearshiftPosition>();
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATShiftStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATShiftStrategy.cs
index 84fda24b28..d1af4f8622 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATShiftStrategy.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATShiftStrategy.cs
@@ -150,7 +150,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			var braking = DataBus.DriverInfo.DriverBehavior == DrivingBehavior.Braking;
 			var torqueNegative = outTorque.IsSmaller(0);
 			var slowerThanDisengageSpeed =
-				DataBus.VehicleInfo.VehicleSpeed.IsSmaller(Constants.SimulationSettings.ATGearboxDisengageWhenHaltingSpeed);
+				DataBus.VehicleInfo.VehicleSpeed.IsSmaller(GearboxModelData.DisengageWhenHaltingSpeed);
 			var disengageBeforeHalting = braking && torqueNegative && slowerThanDisengageSpeed;
 
 			// 2) L -> 0: disengage if inAngularVelocity == 0
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BatteryElectricMotorController.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BatteryElectricMotorController.cs
index 351066623b..0b76e0af92 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BatteryElectricMotorController.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BatteryElectricMotorController.cs
@@ -14,11 +14,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl {
 		private ElectricSystem ElectricSystem;
 		protected ElectricMotorData ElectricMotorData;
 
+		protected readonly GearboxData GearboxModelData;
+
 		public BatteryElectricMotorController(VehicleContainer container, ElectricSystem es)
 		{
 			DataBus = container;
 			ElectricMotorData = container.RunData.ElectricMachinesData.FirstOrDefault()?.Item2;
 			ElectricSystem = es;
+			GearboxModelData = container.RunData.GearboxData;
 		}
 
 		#region Implementation of IElectricMotorControl
@@ -41,7 +44,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl {
                 return null;
             }
 
-            if (DataBus.VehicleInfo.VehicleSpeed.IsSmallerOrEqual(Constants.SimulationSettings.ClutchDisengageWhenHaltingSpeed) && outTorque.IsSmaller(0)) {
+            if (DataBus.VehicleInfo.VehicleSpeed.IsSmallerOrEqual(GearboxModelData.DisengageWhenHaltingSpeed) && outTorque.IsSmaller(0)) {
                 return null;
             }
 
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
index c2061789a9..b2eedc4832 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
@@ -271,7 +271,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 											(ICEAvailable && inAngularVelocity.IsSmaller(DataBus.EngineInfo.EngineIdleSpeed))) &&
 											(DataBus.Brakes.BrakePower.IsGreater(0) || inTorque.IsSmaller(0));
 			var vehicleSpeedBelowThreshold =
-				DataBus.VehicleInfo.VehicleSpeed.IsSmaller(Constants.SimulationSettings.ClutchDisengageWhenHaltingSpeed);
+				DataBus.VehicleInfo.VehicleSpeed.IsSmaller(ModelData.DisengageWhenHaltingSpeed);
 			if (halted || (driverDeceleratingNegTorque && vehicleSpeedBelowThreshold)) {
 				EngageTime = VectoMath.Max(EngageTime, absTime + dt);
 				_strategy?.Disengage(absTime, dt, outTorque, outAngularVelocity);
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PEVAMTShiftStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PEVAMTShiftStrategy.cs
index f15e669cb1..c91954c602 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PEVAMTShiftStrategy.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PEVAMTShiftStrategy.cs
@@ -817,11 +817,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			protected IDataBus DataBus;
 			protected ElectricMotorData ElectricMotorData;
 
+			protected readonly GearboxData GearboxModelData;
+
 			public PEVInitControl(IVehicleContainer dataBus)
 			{
 				DataBus = dataBus;
 				ElectricMotorData = dataBus.RunData.ElectricMachinesData
 					.First(x => x.Item1 == PowertrainPosition.BatteryElectricE2).Item2;
+				GearboxModelData = dataBus.RunData.GearboxData;
 			}
 
 			#region Implementation of IElectricMotorControl
@@ -843,7 +846,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 					return null;
 				}
 
-				if (DataBus.VehicleInfo.VehicleSpeed.IsSmallerOrEqual(Constants.SimulationSettings.ClutchDisengageWhenHaltingSpeed) && outTorque.IsSmaller(0)) {
+				if (DataBus.VehicleInfo.VehicleSpeed.IsSmallerOrEqual(GearboxModelData.DisengageWhenHaltingSpeed) && outTorque.IsSmaller(0)) {
 					return null;
 				}
 
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs
index 7dc2a9aad7..e86d8f72c2 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs
@@ -1016,9 +1016,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
 			}
 
 			var emPos = ModelData.ElectricMachinesData.First().Item1;
-			var disengageSpeedThreshold = DataBus.GearboxInfo.GearboxType.AutomaticTransmission()
-				? Constants.SimulationSettings.ATGearboxDisengageWhenHaltingSpeed
-				: Constants.SimulationSettings.ClutchDisengageWhenHaltingSpeed;
+			var disengageSpeedThreshold = ModelData.GearboxData.DisengageWhenHaltingSpeed;
 			var vehiclespeedBelowThreshold = DataBus.VehicleInfo.VehicleSpeed.IsSmaller(disengageSpeedThreshold);
 
 			if (ElectricMotorCanPropellDuringTractionInterruption || DataBus.GearboxInfo.GearEngaged(absTime)) {
@@ -1069,7 +1067,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
 				var endSpeed = DataBus.VehicleInfo.VehicleSpeed +
 								DataBus.DriverInfo.DriverAcceleration * ModelData.GearboxData.TractionInterruption;
 				if (engineSpeedTooLow && DataBus.GearboxInfo.GearboxType.ManualTransmission() &&
-					endSpeed.IsSmallerOrEqual(Constants.SimulationSettings.ClutchDisengageWhenHaltingSpeed, 0.1.KMPHtoMeterPerSecond())) {
+					endSpeed.IsSmallerOrEqual(ModelData.GearboxData.DisengageWhenHaltingSpeed, 0.1.KMPHtoMeterPerSecond())) {
 					var response = ResponseEmOff;
 					response.Gear = new GearshiftPosition(0);
 					response.Setting.GearboxEngaged = false;
@@ -1337,7 +1335,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
 			var endSpeed = DataBus.VehicleInfo.VehicleSpeed +
 							DataBus.DriverInfo.DriverAcceleration * ModelData.GearboxData.TractionInterruption;
 			if (DataBus.GearboxInfo.GearboxType.ManualTransmission() &&
-				endSpeed.IsSmallerOrEqual(Constants.SimulationSettings.ClutchDisengageWhenHaltingSpeed, 0.1.KMPHtoMeterPerSecond())) {
+				endSpeed.IsSmallerOrEqual(ModelData.GearboxData.DisengageWhenHaltingSpeed, 0.1.KMPHtoMeterPerSecond())) {
 				return new GearshiftPosition(0);
 			}
 
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/SerialHybridStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/SerialHybridStrategy.cs
index f64706e76e..58dd9512f7 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/SerialHybridStrategy.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/SerialHybridStrategy.cs
@@ -494,7 +494,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
 				return null;
 			}
 
-			if (DataBus.VehicleInfo.VehicleSpeed.IsSmallerOrEqual(Constants.SimulationSettings.ClutchDisengageWhenHaltingSpeed) && emOutTorque.IsSmaller(0)) {
+			if (DataBus.VehicleInfo.VehicleSpeed.IsSmallerOrEqual(ModelData.GearboxData.DisengageWhenHaltingSpeed) && emOutTorque.IsSmaller(0)) {
 				return null;
 			}
 
-- 
GitLab