Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 2a12f9c7 authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

Merge pull request #284 in VECTO/vecto-sim from...

Merge pull request #284 in VECTO/vecto-sim from ~EMKRISPMI/vecto-sim:bugfix/measured-speed-distance-wrong to master

* commit '94e2a410':
  bugfix: measured speed when halting and gear=0 but vehicle still has a remaining velocity.
  bugfix: measured speed distance wrong
parents 0c331c0c 94e2a410
No related branches found
No related tags found
No related merge requests found
......@@ -67,7 +67,7 @@ namespace TUGraz.VectoCore.Models.Declaration
public static VehicleClass Parse(string text)
{
return text.Replace(Prefix, "").ParseEnum<VehicleClass>();
return (Prefix + text).ParseEnum<VehicleClass>();
}
public static string GetClassNumber(this VehicleClass hdvClass)
......
......@@ -281,7 +281,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
}
/// <summary>
/// Handles Requests when no gear is engaged
/// Handles Requests when no gear is disengaged
/// </summary>
/// <param name="absTime"></param>
/// <param name="dt"></param>
......@@ -303,8 +303,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
};
}
if ((outTorque * avgOutAngularVelocity).IsGreater(0.SI<Watt>(),
Constants.SimulationSettings.LineSearchTolerance)) {
if ((outTorque * avgOutAngularVelocity).IsGreater(0.SI<Watt>(), Constants.SimulationSettings.LineSearchTolerance) &&
!outAngularVelocity.IsEqual(0)) {
return new ResponseOverload {
Source = this,
Delta = outTorque * avgOutAngularVelocity,
......@@ -312,8 +312,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
};
}
if ((outTorque * avgOutAngularVelocity).IsSmaller(0.SI<Watt>(),
Constants.SimulationSettings.LineSearchTolerance)) {
if ((outTorque * avgOutAngularVelocity).IsSmaller(0.SI<Watt>(), Constants.SimulationSettings.LineSearchTolerance)) {
return new ResponseUnderload {
Source = this,
Delta = outTorque * avgOutAngularVelocity,
......@@ -321,13 +320,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
};
}
CurrentState.SetState(0.SI<NewtonMeter>(), 0.RPMtoRad(), outTorque, outAngularVelocity);
CurrentState.SetState(0.SI<NewtonMeter>(), 0.SI<PerSecond>(), outTorque, outAngularVelocity);
CurrentState.Gear = Gear;
var disengagedResponse = NextComponent.Request(absTime, dt, 0.SI<NewtonMeter>(), DataBus.EngineIdleSpeed);
disengagedResponse.GearboxPowerRequest = outTorque * avgOutAngularVelocity;
return disengagedResponse;
//todo mk-2016-08-17: minus inTorqueLoss?? Why not plus?
}
private TorqueConverterOperatingPoint FindOperatingPoint(NewtonMeter outTorque,
......@@ -359,7 +357,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
(x.InTorque * x.InAngularVelocity).IsGreaterOrEqual(DataBus.EngineDragPower(x.InAngularVelocity),
Constants.SimulationSettings.LineSearchTolerance.SI<Watt>())
).ToArray();
if (filtered.Count() == 1) {
if (filtered.Length == 1) {
return filtered.First();
}
return operatingPointList[0];
......
......@@ -31,17 +31,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
return new DrivingCycleState {
Distance = Distance,
VehicleSpeed = VehicleSpeed,
};
}
public Meter Distance;
public MeterPerSecond VehicleSpeed;
public Meter SimulationDistance;
public MeterPerSquareSecond Acceleration;
}
protected DrivingCycleData Data;
protected readonly DrivingCycleData Data;
private bool _isInitializing;
protected IEnumerator<DrivingCycleData.DrivingCycleEntry> RightSample { get; set; }
protected IEnumerator<DrivingCycleData.DrivingCycleEntry> LeftSample { get; set; }
......@@ -64,10 +62,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
RightSample.MoveNext();
RightSample.MoveNext();
var first = LeftSample.Current;
PreviousState = new DrivingCycleState {
Distance = 0.SI<Meter>(),
VehicleSpeed = first.VehicleTargetSpeed,
};
CurrentState = PreviousState.Clone();
}
......@@ -118,6 +114,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
// calc acceleration from speed diff vehicle to cycle
var deltaV = RightSample.Current.VehicleTargetSpeed - DataBus.VehicleSpeed;
var deltaT = RightSample.Current.Time - LeftSample.Current.Time;
if (DataBus.VehicleSpeed.IsSmaller(0)) {
throw new VectoSimulationException("vehicle velocity is smaller than zero");
}
if (deltaT.IsSmaller(0)) {
throw new VectoSimulationException("deltaT is smaller than zero");
}
var acceleration = deltaV / deltaT;
var gradient = LeftSample.Current.RoadGradient;
DriverAcceleration = acceleration;
......@@ -190,9 +195,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
response.Acceleration = acceleration;
debug.Add(response);
CurrentState.SimulationDistance = acceleration / 2 * dt * dt + PreviousState.VehicleSpeed * dt;
CurrentState.SimulationDistance = acceleration / 2 * dt * dt + DataBus.VehicleSpeed * dt;
if (CurrentState.SimulationDistance.IsSmaller(0))
throw new VectoSimulationException(
"MeasuredSpeed: Simulation Distance must not be negative. Driving Backward is not allowed.");
CurrentState.Distance = CurrentState.SimulationDistance + PreviousState.Distance;
CurrentState.VehicleSpeed = acceleration * dt + PreviousState.VehicleSpeed;
CurrentState.Acceleration = acceleration;
return response;
......
......@@ -104,7 +104,7 @@ namespace TUGraz.VectoCore.Tests.Integration.EngineOnlyCycle
}
modData.Finish(VectoRun.Status.Success);
ResultFileHelper.TestModFile(modalResultFile, modFile + Constants.FileExtensions.ModDataFile, testVelocity: false);
ResultFileHelper.TestModFile(modalResultFile, modFile + Constants.FileExtensions.ModDataFile);
}
[TestCase]
......
......@@ -109,7 +109,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation
var testColumns = new[] { "P_aux_FAN", "P_aux_STP", "P_aux_AC", "P_aux_ES", "P_aux_PS", "P_aux" };
ResultFileHelper.TestModFile(@"TestData\Results\EngineOnlyCycles\AuxWriteModFileSumFile.vmod",
@"AuxWriteModFileSumFile.vmod", testColumns, testVelocity: false);
@"AuxWriteModFileSumFile.vmod", testColumns);
ResultFileHelper.TestSumFile(@"TestData\Results\EngineOnlyCycles\AuxWriteModFileSumFile.vsum",
@"AuxWriteModFileSumFile.vsum");
}
......
......@@ -166,7 +166,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation
ResultFileHelper.TestSumFile(@"TestData\Pwheel\Results\Pwheel.vsum", @"TestData\Pwheel\Pwheel.vsum");
ResultFileHelper.TestModFile(@"TestData\Pwheel\Results\Pwheel_Gear2_pt1_rep1_actual.vmod",
@"TestData\Pwheel\Pwheel_Gear2_pt1_rep1_actual.vmod", testVelocity: false);
@"TestData\Pwheel\Pwheel_Gear2_pt1_rep1_actual.vmod");
}
/// <summary>
......@@ -194,7 +194,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation
ResultFileHelper.TestSumFile(@"TestData\Pwheel\Results\Pwheel_ultimate.vsum", @"TestData\Pwheel\Pwheel_ultimate.vsum");
ResultFileHelper.TestModFile(@"TestData\Pwheel\Results\Pwheel_ultimate_RD_#1_Pwheel_AuxStd.vmod",
@"TestData\Pwheel\Pwheel_ultimate_RD_#1_Pwheel_AuxStd.vmod", testVelocity: false);
@"TestData\Pwheel\Pwheel_ultimate_RD_#1_Pwheel_AuxStd.vmod");
}
}
}
\ No newline at end of file
......@@ -69,7 +69,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation
Assert.IsTrue(job.FinishedWithoutErrors);
ResultFileHelper.TestModFile(expected, actual, testVelocity: false);
ResultFileHelper.TestModFile(expected, actual);
}
[TestMethod]
......@@ -89,7 +89,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation
Assert.IsTrue(r.Run.FinishedWithoutErrors, string.Format("{0}", r.ExecException));
}
ResultFileHelper.TestModFile(expected, actual, testVelocity: false);
ResultFileHelper.TestModFile(expected, actual);
}
public IVectoRun CreateRun(string resultFileName)
......@@ -136,7 +136,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation
@"TestData\Jobs\24t Coach EngineOnly_Engine Only1.vmod",
@"TestData\Jobs\24t Coach EngineOnly_Engine Only2.vmod",
@"TestData\Jobs\24t Coach EngineOnly_Engine Only3.vmod"
}, testVelocity: false)
})
;
}
}
......
......@@ -43,13 +43,13 @@ namespace TUGraz.VectoCore.Tests.Utils
public static class ResultFileHelper
{
public static void TestModFile(string expectedFile, string actualFile, string[] testColumns = null,
bool testRowCount = true, bool testVelocity = true)
bool testRowCount = true)
{
TestModFiles(new[] { expectedFile }, new[] { actualFile }, testColumns, testRowCount, testVelocity);
TestModFiles(new[] { expectedFile }, new[] { actualFile }, testColumns, testRowCount);
}
public static void TestModFiles(IEnumerable<string> expectedFiles, IEnumerable<string> actualFiles,
string[] testColumns = null, bool testRowcount = true, bool testVelocity = true)
string[] testColumns = null, bool testRowcount = true)
{
var resultFiles = expectedFiles.ZipAll(actualFiles, (expectedFile, actualFile) => new { expectedFile, actualFile });
foreach (var result in resultFiles) {
......@@ -59,17 +59,31 @@ namespace TUGraz.VectoCore.Tests.Utils
var expected = VectoCSVFile.Read(result.expectedFile);
var actual = VectoCSVFile.Read(result.actualFile);
if (testVelocity) {
Assert.IsTrue(
actual.Rows.Cast<DataRow>()
if (actual.Columns.Contains(ModalResultField.v_act.GetShortCaption()) &&
!double.IsNaN(actual.Rows[0].Field<string>(ModalResultField.v_act.GetShortCaption()).ToDouble(double.NaN))) {
// test v_act >= 0
Assert.IsTrue(actual.Rows.Cast<DataRow>()
.All(r => r.ParseDouble(ModalResultField.v_act.GetShortCaption()).IsGreaterOrEqual(0)),
"v_act must not be negative.");
Assert.IsTrue(
actual.Rows.Cast<DataRow>()
// test v_targ >= 0
Assert.IsTrue(actual.Rows.Cast<DataRow>()
.All(r => r.ParseDouble(ModalResultField.v_targ.GetShortCaption()).IsGreaterOrEqual(0)),
"v_targ must not be negative.");
}
if (actual.Columns.Contains(ModalResultField.dist.GetShortCaption()) &&
!double.IsNaN(actual.Rows[0].Field<string>(ModalResultField.dist.GetShortCaption()).ToDouble(double.NaN))) {
// test distance monotonous increasing
var distPrev = actual.Rows[0].ParseDouble(ModalResultField.dist.GetShortCaption());
for (var i = 1; i < actual.Rows.Count; i++) {
var dist = actual.Rows[i].ParseDouble(ModalResultField.dist.GetShortCaption());
Assert.IsTrue(distPrev.IsSmallerOrEqual(dist), "distance must not decrease.");
distPrev = dist;
}
}
if (testRowcount) {
Assert.AreEqual(expected.Rows.Count, actual.Rows.Count,
string.Format("Moddata: Row count differs.\nExpected {0} Rows in {1}\nGot {2} Rows in {3}", expected.Rows.Count,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment