From 6b7dc0b15d01b73fc2ba17517ce1dd0763f62722 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Wed, 30 Mar 2022 09:01:41 +0200
Subject: [PATCH] set gearbox disengage speed for AT transmissions based on
 downshift line in first locked gear

---
 .../DataObjectAdapter/DeclarationDataAdapter.cs   | 12 ++++++++++++
 .../DataObjectAdapter/EngineeringDataAdapter.cs   | 12 ++++++++++++
 .../SimulationComponent/Data/GearboxData.cs       | 15 +++++++++++++++
 .../SimulationComponent/Impl/ATShiftStrategy.cs   |  2 +-
 .../Models/SimulationComponent/Impl/Gearbox.cs    |  2 +-
 5 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapter.cs b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapter.cs
index e89c136637..00d0635078 100644
--- a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapter.cs
+++ b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapter.cs
@@ -362,6 +362,18 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter
 				retVal.TorqueConverterData.CertificationNumber = torqueConverter.CertificationNumber;
 			}
 
+			// 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/InputData/Reader/DataObjectAdapter/EngineeringDataAdapter.cs b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/EngineeringDataAdapter.cs
index 6c827f53d6..a2c0839d04 100644
--- a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/EngineeringDataAdapter.cs
+++ b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/EngineeringDataAdapter.cs
@@ -333,6 +333,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 1927a02be3..eaaa887417 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Data/GearboxData.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Data/GearboxData.cs
@@ -38,6 +38,7 @@ using System.Runtime.Serialization;
 using Newtonsoft.Json;
 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,6 +53,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
 	public class GearboxData : SimulationComponentData
 	{
 		private GearList _gearlist;
+		private MeterPerSecond _disengageWhenHaltingSpeed;
 
 		public GearboxType Type { get; internal set; }
 
@@ -73,6 +75,19 @@ 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 3e73811c52..1ab62b193e 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATShiftStrategy.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATShiftStrategy.cs
@@ -157,7 +157,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/Gearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
index 28684b2176..c26d183e39 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
@@ -258,7 +258,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 											(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);
-- 
GitLab