From 24768e2de034be5215d299e4dbf12dcef1ddda03 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <quaritsch@ivt.tugraz.at>
Date: Wed, 14 Dec 2022 12:22:42 +0100
Subject: [PATCH] Bugfix: avoiding short simulation interval. in case the
 vehicle speed is already below the target speed of the current  'next driving
 action' and the trigger distance is reached, assume the current 'next driving
 action' as completed and switch to the next one.

---
 .../SimulationComponent/Impl/DefaultDriverStrategy.cs    | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs
index a4e3d8fe2b..5bc6399a05 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs
@@ -558,12 +558,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 				// update action distance for current 'next action'
 				UpdateDistancesForCurrentNextAction();
 
-				SetNextDrivingAction(currentDistance, nextAction);
+				SetNextDrivingAction(currentDistance, nextAction, ds);
 			}
 			Log.Debug("Next Driving Action: {0}", NextDrivingAction);
 		}
 
-		private void SetNextDrivingAction(Meter currentDistance, DrivingBehaviorEntry nextAction)
+		private void SetNextDrivingAction(Meter currentDistance, DrivingBehaviorEntry nextAction, Meter ds)
 		{
 			if (nextAction != null) {
 				if (nextAction.HasEqualTrigger(NextDrivingAction)) {
@@ -577,6 +577,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 					if (nextAction.ActionDistance < NextDrivingAction.ActionDistance) {
 						NextDrivingAction = nextAction;
 					}
+					
+					if ((currentDistance + ds).IsEqual(NextDrivingAction.TriggerDistance) && Driver.DataBus.VehicleInfo.VehicleSpeed < NextDrivingAction.NextTargetSpeed) {
+						// the currently active NextDrivingAction already reached the target speed - ignore it.
+						NextDrivingAction = nextAction;
+					}
 				}
 			} else {
 				NextDrivingAction = null;
-- 
GitLab