From 9c1082a9078f4d826564f4cd27445d02cf634056 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Tue, 20 Oct 2015 13:41:09 +0200
Subject: [PATCH] set vehicle speed to zero if below certain threshold

---
 .../Impl/DefaultDriverStrategy.cs             | 28 +++++++------------
 .../SimulationComponent/Impl/Vehicle.cs       |  3 ++
 2 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs b/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs
index e16b637a9f..20e33b17a8 100644
--- a/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs
+++ b/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs
@@ -78,6 +78,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			return retVal;
 		}
 
+		public IResponse Request(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient)
+		{
+			DriverBehavior = DrivingBehavior.Halted;
+			return Driver.DrivingActionHalt(absTime, dt, targetVelocity, gradient);
+		}
+
+
+		public DrivingBehavior DriverBehavior { get; internal set; }
+
+
 		private void UpdateDrivingAction(Meter currentDistance)
 		{
 			var nextAction = GetNextDrivingAction(currentDistance);
@@ -126,15 +136,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 		}
 
 
-		public IResponse Request(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient)
-		{
-			DriverBehavior = DrivingBehavior.Halted;
-			return Driver.DrivingActionHalt(absTime, dt, targetVelocity, gradient);
-		}
-
-
-		public DrivingBehavior DriverBehavior { get; internal set; }
-
 		protected DrivingBehaviorEntry GetNextDrivingAction(Meter minDistance)
 		{
 			var currentSpeed = Driver.DataBus.VehicleSpeed;
@@ -152,7 +153,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 					? entry.VehicleTargetSpeed + Driver.DriverData.OverSpeedEcoRoll.OverSpeed
 					: entry.VehicleTargetSpeed;
 				if (nextTargetSpeed < currentSpeed) {
-					// TODO @@@quam  currentSpeed ? targetSpeed? nextTargetSpeed?
 					if (!Driver.DriverData.LookAheadCoasting.Enabled ||
 						currentSpeed < Driver.DriverData.LookAheadCoasting.MinSpeed) {
 						var brakingDistance = Driver.ComputeDecelerationDistance(nextTargetSpeed);
@@ -178,14 +178,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 							});
 					}
 				}
-				//if (nextTargetSpeed > currentSpeed) {
-				//	nextActions.Add(new DrivingBehaviorEntry {
-				//		Action = DefaultDriverStrategy.DrivingBehavior.Accelerating,
-				//		NextTargetSpeed = entry.VehicleTargetSpeed,
-				//		TriggerDistance = entry.Distance,
-				//		ActionDistance = entry.Distance
-				//	});
-				//}
 			}
 
 			return nextActions.Count == 0 ? null : nextActions.OrderBy(x => x.ActionDistance).First();
diff --git a/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs b/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs
index 1472ab8943..a5ac4cdc56 100644
--- a/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs
+++ b/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs
@@ -125,6 +125,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			_currentState.dt = dt;
 			_currentState.Acceleration = acceleration;
 			_currentState.Velocity = _previousState.Velocity + acceleration * dt;
+			if (_currentState.Velocity.IsEqual(0, 1e-4)) {
+				_currentState.Velocity = 0.SI<MeterPerSecond>();
+			}
 			_currentState.Distance = _previousState.Distance + dt * (_previousState.Velocity + _currentState.Velocity) / 2;
 
 			_currentState.DriverAcceleration = DriverAcceleration(acceleration);
-- 
GitLab