diff --git a/VectoCore/Configuration/Constants.cs b/VectoCore/Configuration/Constants.cs index edaa862685ba7c8daaf0a2ac7f584230366eeb0c..bb6b936c92484f507d11530a7cdb29fd1d780e39 100644 --- a/VectoCore/Configuration/Constants.cs +++ b/VectoCore/Configuration/Constants.cs @@ -64,6 +64,8 @@ namespace TUGraz.VectoCore.Configuration public const double CluchNormSpeed = 0.03; + + public static readonly MeterPerSquareSecond MinimumAcceleration = 0.1.SI<MeterPerSquareSecond>(); } } } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/Data/Engine/EngineFullLoadCurve.cs b/VectoCore/Models/SimulationComponent/Data/Engine/EngineFullLoadCurve.cs index b729e81aa5a3d44e50c9659a64065b97fab2c645..c85463b8897be2f71c256adc9f292cf1c9ee88b6 100644 --- a/VectoCore/Models/SimulationComponent/Data/Engine/EngineFullLoadCurve.cs +++ b/VectoCore/Models/SimulationComponent/Data/Engine/EngineFullLoadCurve.cs @@ -51,7 +51,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine log.WarnFormat( "FullLoadCurve: Header Line is not valid. Expected: '{0}, {1}, {2}', Got: '{3}'. Falling back to column index.", Fields.EngineSpeed, Fields.TorqueFullLoad, Fields.TorqueDrag, - string.Join(", ", data.Columns.Cast<DataColumn>().Select(c => c.ColumnName).Reverse())); + string.Join(", ", data.Columns.Cast<DataColumn>().Select(c => c.ColumnName))); entriesFld = CreateFromColumnIndizes(data); } diff --git a/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs index ce74147eec98129fd57e25c304f2a1dd17379a9e..a252cd44214c18bf0f9d3f6e23b64b6127d6067d 100644 --- a/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs @@ -211,60 +211,60 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public class DrivingCycleEnumerator : IEnumerator<DrivingCycleData.DrivingCycleEntry> { - protected IEnumerator<DrivingCycleData.DrivingCycleEntry> LeftSampleIt; - protected IEnumerator<DrivingCycleData.DrivingCycleEntry> RightSampleIt; + //protected IEnumerator<DrivingCycleData.DrivingCycleEntry> LeftSampleIt; + //protected IEnumerator<DrivingCycleData.DrivingCycleEntry> RightSampleIt; - //protected uint currentCycleIndex; + protected int CurrentCycleIndex; + protected DrivingCycleData Data; public DrivingCycleEnumerator(DrivingCycleData data) { - LeftSampleIt = data.Entries.GetEnumerator(); - RightSampleIt = data.Entries.GetEnumerator(); - RightSampleIt.MoveNext(); - //currentCycleIndex = 0; + //LeftSampleIt = data.Entries.GetEnumerator(); + //RightSampleIt = data.Entries.GetEnumerator(); + //RightSampleIt.MoveNext(); + CurrentCycleIndex = 0; + Data = data; } public DrivingCycleData.DrivingCycleEntry Current { - get { return LeftSampleIt.Current; } + get { return LeftSample; } } public DrivingCycleData.DrivingCycleEntry Next { - get { return RightSampleIt.Current; } + get { return RightSample; } } public DrivingCycleData.DrivingCycleEntry LeftSample { - get { return LeftSampleIt.Current; } + get { return Data.Entries[CurrentCycleIndex]; } } public DrivingCycleData.DrivingCycleEntry RightSample { - get { return RightSampleIt.Current; } + get { return CurrentCycleIndex + 1 >= Data.Entries.Count ? null : Data.Entries[CurrentCycleIndex + 1]; } } - public void Dispose() - { - LeftSampleIt.Dispose(); - RightSampleIt.Dispose(); - } + public void Dispose() {} object System.Collections.IEnumerator.Current { - get { return LeftSampleIt.Current; } + get { return LeftSample; } } public bool MoveNext() { - return LeftSampleIt.MoveNext() && RightSampleIt.MoveNext(); + if (CurrentCycleIndex >= Data.Entries.Count - 1) { + return false; + } + CurrentCycleIndex++; + return true; } public void Reset() { - LeftSampleIt.Reset(); - RightSampleIt.Reset(); - RightSampleIt.MoveNext(); + CurrentCycleIndex = 0; } } diff --git a/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/Models/SimulationComponent/Impl/Driver.cs index 22f2380ad37e3c36d9a879224eb95a30433b33f9..2f6a8cc17642984f66191e63bfdf7b7d2ecdc907 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Driver.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Driver.cs @@ -148,6 +148,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } else { CurrentState.Acceleration += searchInterval; } + // check for minimum acceleration, add some safety margin due to search + if (CurrentState.Acceleration < Constants.SimulationSettings.MinimumAcceleration / 5.0 && + searchInterval < Constants.SimulationSettings.MinimumAcceleration.Value() / 20.0) { + throw new VectoSimulationException("Could not achieve minimum acceleration"); + } searchInterval /= 2.0; ComputeTimeInterval(CurrentState.Acceleration, ref computedDs, out CurrentState.dt); response = Next.Request(absTime, CurrentState.dt, CurrentState.Acceleration, gradient, true); diff --git a/VectoCoreTest/Models/SimulationComponent/DriverTest.cs b/VectoCoreTest/Models/SimulationComponent/DriverTest.cs index 516626e27366fafb275c9b11fbf1571f16590091..b631ec5fdc391ce2d4fde0f25e08de022dccfd71 100644 --- a/VectoCoreTest/Models/SimulationComponent/DriverTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/DriverTest.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCore.Configuration; +using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.FileIO.Reader; using TUGraz.VectoCore.FileIO.Reader.Impl; using TUGraz.VectoCore.Models.Connector.Ports; @@ -122,7 +123,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent vehicleContainer.CommitSimulationStep(absTime, response.SimulationInterval); absTime += response.SimulationInterval; - Assert.AreEqual(0.900, modalWriter.GetValues<SI>(ModalResultField.acc).Last().Value(), Tolerance); + Assert.AreEqual(0.908, modalWriter.GetValues<SI>(ModalResultField.acc).Last().Value(), Tolerance); response = driverPort.Request(absTime, 1.SI<Meter>(), 10.SI<MeterPerSecond>(), 0.SI<Radian>()); @@ -131,14 +132,18 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent vehicleContainer.CommitSimulationStep(absTime, response.SimulationInterval); absTime += response.SimulationInterval; - Assert.AreEqual(0.7990, modalWriter.GetValues<SI>(ModalResultField.acc).Last().Value(), Tolerance); + Assert.AreEqual(0.7973, modalWriter.GetValues<SI>(ModalResultField.acc).Last().Value(), Tolerance); - /// change vehicle weight + // change vehicle weight, cannot reach minimum acceleration... vehicleData.Loading = 70000.SI<Kilogram>(); - response = driverPort.Request(absTime, 1.SI<Meter>(), 10.SI<MeterPerSecond>(), 0.05.SI<Radian>()); - - Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); + try { + response = driverPort.Request(absTime, 1.SI<Meter>(), 10.SI<MeterPerSecond>(), 0.05.SI<Radian>()); + Assert.Fail(); + } catch (VectoSimulationException e) { + Assert.AreEqual("Could not achieve minimum acceleration", e.Message); + } + //Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); } [TestMethod]