Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit d0c1813c authored by Michael KRISPER's avatar Michael KRISPER
Browse files

bugfix: measured speed when halting and gear=0 but vehicle still has a remaining velocity.

parent 13b18ca1
No related branches found
No related tags found
No related merge requests found
......@@ -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,
......@@ -354,12 +352,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
}
var filtered = operatingPointList.Where(x =>
(x.InTorque * x.InAngularVelocity).IsSmallerOrEqual(DataBus.EngineStationaryFullPower(x.InAngularVelocity),
Constants.SimulationSettings.LineSearchTolerance.SI<Watt>()) &&
(x.InTorque * x.InAngularVelocity).IsGreaterOrEqual(DataBus.EngineDragPower(x.InAngularVelocity),
Constants.SimulationSettings.LineSearchTolerance.SI<Watt>())
).ToArray();
if (filtered.Count() == 1) {
(x.InTorque * x.InAngularVelocity).IsSmallerOrEqual(DataBus.EngineStationaryFullPower(x.InAngularVelocity),
Constants.SimulationSettings.LineSearchTolerance.SI<Watt>()) &&
(x.InTorque * x.InAngularVelocity).IsGreaterOrEqual(DataBus.EngineDragPower(x.InAngularVelocity),
Constants.SimulationSettings.LineSearchTolerance.SI<Watt>())
).ToArray();
if (filtered.Length == 1) {
return filtered.First();
}
return operatingPointList[0];
......@@ -448,12 +446,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
container[ModalResultField.TC_angularSpeedOut] = CurrentState.TorqueConverterOperatingPoint.OutAngularVelocity;
var avgOutVelocity = ((PreviousState.TorqueConverterOperatingPoint != null
? PreviousState.TorqueConverterOperatingPoint.OutAngularVelocity
: PreviousState.InAngularVelocity) +
? PreviousState.TorqueConverterOperatingPoint.OutAngularVelocity
: PreviousState.InAngularVelocity) +
CurrentState.TorqueConverterOperatingPoint.OutAngularVelocity) / 2.0;
var avgInVelocity = ((PreviousState.TorqueConverterOperatingPoint != null
? PreviousState.TorqueConverterOperatingPoint.InAngularVelocity
: PreviousState.InAngularVelocity) +
? PreviousState.TorqueConverterOperatingPoint.InAngularVelocity
: PreviousState.InAngularVelocity) +
CurrentState.TorqueConverterOperatingPoint.InAngularVelocity) / 2.0;
container[ModalResultField.P_TC_out] = CurrentState.OutTorque * avgOutVelocity;
container[ModalResultField.P_TC_loss] = CurrentState.InTorque * avgInVelocity -
......
......@@ -196,6 +196,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
debug.Add(response);
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.Acceleration = acceleration;
......
......@@ -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.
Finish editing this message first!
Please register or to comment