From 1dd6a4219f583db57e82e5bef7b97d982e8aece1 Mon Sep 17 00:00:00 2001
From: Michael Krisper <michael.krisper@tugraz.at>
Date: Wed, 13 Oct 2021 10:17:25 +0200
Subject: [PATCH] FirstAcceleratorOrCoast: Added additional condition: when in
 overspeed, to not accelerate until we would get lower than targetSpeed.

---
 .../Impl/DefaultDriverStrategy.cs                  | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs
index 620732d4d9..9c83ed0392 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs
@@ -1048,23 +1048,27 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			}
 
 			IResponse first;
-			if (DriverStrategy.IsOverspeedAllowed(targetVelocity, prohibitOverspeed) &&
-				DataBus.VehicleInfo.VehicleSpeed.IsGreaterOrEqual(targetVelocity)) {
+			var isOverspeedAllowed = DriverStrategy.IsOverspeedAllowed(targetVelocity, prohibitOverspeed);
+			var isDrivingWithOverspeed = DataBus.VehicleInfo.VehicleSpeed.IsGreaterOrEqual(targetVelocity);
+			if (isOverspeedAllowed && isDrivingWithOverspeed) {
+				//driving in overspeed (VehicleSpeed >= targetVelocity)
 				first = Driver.DrivingActionCoast(absTime, ds, velocityWithOverspeed, gradient);
 				debug.Add(new { action = "Coast", first });
-				if (first is ResponseSuccess && first.Driver.Acceleration < 0 && DataBus.VehicleInfo.VehicleSpeed.IsSmallerOrEqual(targetVelocity, 0.1.KMPHtoMeterPerSecond())) {
+				if (first is ResponseSuccess && first.Driver.Acceleration < 0 && first.Vehicle.VehicleSpeed <= targetVelocity) {
+					//do accelerate action if we would come below targetVelocity due to coasting
 					first = Driver.DrivingActionAccelerate(absTime, ds, targetVelocity, gradient);
 					debug.Add(new { action = "Coast:(Success & Acc<0) -> Accelerate", first });
 				}
-				if (DataBus.PowertrainInfo.HasCombustionEngine && !DataBus.EngineInfo.EngineOn && first is ResponseOverload) {
+				if (first is ResponseOverload && DataBus.PowertrainInfo.HasCombustionEngine && !DataBus.EngineInfo.EngineOn) {
 					first = Driver.DrivingActionAccelerate(absTime, ds, targetVelocity, gradient);
 					debug.Add(new { action = "Coast:(Overload & ICE off) -> Accelerate", first });
 				}
-				if (!DataBus.PowertrainInfo.HasCombustionEngine && first is ResponseOverload) {
+				if (first is ResponseOverload && !DataBus.PowertrainInfo.HasCombustionEngine) {
 					first = Driver.DrivingActionAccelerate(absTime, ds, targetVelocity, gradient);
 					debug.Add(new { action = "Coast:(Overload & BEV) -> Accelerate", first });
 				}
 			} else {
+				//not driving in overspeed (VehicleSpeed < targetVelocity)
 				if (DataBus.GearboxInfo.GearboxType.AutomaticTransmission() && DataBus.GearboxInfo.DisengageGearbox) {
 					first = Driver.DrivingActionCoast(absTime, ds, velocityWithOverspeed, gradient);
 				} else {
-- 
GitLab