From 9a5b571ae73abab12e29b8e7f80722a6c4f2fead Mon Sep 17 00:00:00 2001
From: Michael Krisper <michael.krisper@tugraz.at>
Date: Tue, 20 Oct 2015 14:51:20 +0200
Subject: [PATCH] vehicle speed halt tolerance check only in vehicle

---
 VectoCore/Configuration/Constants.cs                 | 2 +-
 VectoCore/Models/Simulation/Impl/DistanceRun.cs      | 2 +-
 VectoCore/Models/SimulationComponent/Impl/Driver.cs  | 6 +++---
 VectoCore/Models/SimulationComponent/Impl/Vehicle.cs | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/VectoCore/Configuration/Constants.cs b/VectoCore/Configuration/Constants.cs
index b155f6611a..a5bc06b9ce 100644
--- a/VectoCore/Configuration/Constants.cs
+++ b/VectoCore/Configuration/Constants.cs
@@ -72,7 +72,7 @@ namespace TUGraz.VectoCore.Configuration
 
 			public static Meter DriverActionDistanceTolerance = 0.25.SI<Meter>();
 
-			public static double VehicleSpeedTolerance = 1e-3;
+			public static MeterPerSecond VehicleSpeedHaltTolerance = 1e-3.SI<MeterPerSecond>();
 
 			/// <summary>
 			/// The initial search interval for the operating point search in the driver.
diff --git a/VectoCore/Models/Simulation/Impl/DistanceRun.cs b/VectoCore/Models/Simulation/Impl/DistanceRun.cs
index fb6c29fd07..a4b7695ac4 100644
--- a/VectoCore/Models/Simulation/Impl/DistanceRun.cs
+++ b/VectoCore/Models/Simulation/Impl/DistanceRun.cs
@@ -17,7 +17,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
 		protected override IResponse DoSimulationStep()
 		{
 			// estimate distance to be traveled within the next TargetTimeInterval
-			var ds = Container.VehicleSpeed.IsEqual(0, Constants.SimulationSettings.VehicleSpeedTolerance)
+			var ds = Container.VehicleSpeed.IsEqual(0)
 				? Constants.SimulationSettings.DriveOffDistance
 				: Constants.SimulationSettings.TargetTimeInterval * Container.VehicleSpeed;
 
diff --git a/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/Models/SimulationComponent/Impl/Driver.cs
index eb8118aa52..102e9166a5 100644
--- a/VectoCore/Models/SimulationComponent/Impl/Driver.cs
+++ b/VectoCore/Models/SimulationComponent/Impl/Driver.cs
@@ -492,7 +492,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			// braking power is in the range of the exceeding delta. set searching range to 2/3 so that 
 			// the target point is approximately in the center of the second interval
 			var searchInterval = origDelta.Abs() * 2 / 3;
-			
+
 			debug.Add(new { brakePower = 0.SI<Watt>(), searchInterval, delta = origDelta, operatingPoint });
 
 			var brakePower = searchInterval * -origDelta.Sign();
@@ -776,10 +776,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 		/// <returns></returns>
 		public IResponse DrivingActionHalt(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient)
 		{
-			if (!targetVelocity.IsEqual(0) || !DataBus.VehicleSpeed.IsEqual(0, 1e-3)) {
+			if (!targetVelocity.IsEqual(0) || !DataBus.VehicleSpeed.IsEqual(0)) {
 				throw new NotImplementedException("TargetVelocity or VehicleVelocity is not zero!");
 			}
-			DataBus.BreakPower = Double.PositiveInfinity.SI<Watt>();
+			DataBus.BreakPower = double.PositiveInfinity.SI<Watt>();
 			var retVal = NextComponent.Request(absTime, dt, 0.SI<MeterPerSquareSecond>(), gradient);
 			retVal.Switch().
 				Case<ResponseGearShift>(r => {
diff --git a/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs b/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs
index a5ac4cdc56..9d097f103a 100644
--- a/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs
+++ b/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs
@@ -125,7 +125,7 @@ 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)) {
+			if (_currentState.Velocity.IsEqual(0.SI<MeterPerSecond>(), Constants.SimulationSettings.VehicleSpeedHaltTolerance)) {
 				_currentState.Velocity = 0.SI<MeterPerSecond>();
 			}
 			_currentState.Distance = _previousState.Distance + dt * (_previousState.Velocity + _currentState.Velocity) / 2;
-- 
GitLab