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 3263c1b7 authored by Michael KRISPER's avatar Michael KRISPER
Browse files

fixed some errors in Response and time-Interval handling for MeasuredSpeed Driving Cycle

parent cd82d29d
Branches main
Tags milestones/3.2.0_RC
No related merge requests found
......@@ -112,6 +112,7 @@ namespace TUGraz.VectoCore.Models.Connector.Ports.Impl
/// </summary>
public class ResponseFailTimeInterval : AbstractResponse
{
public ResponseFailTimeInterval() {}
public Second DeltaT { get; set; }
}
......
......@@ -29,6 +29,7 @@
* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
*/
using System.Collections.Generic;
using TUGraz.VectoCore.Configuration;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Models.Connector.Ports;
......@@ -43,22 +44,23 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
protected override IResponse DoSimulationStep()
{
dt = Constants.SimulationSettings.TargetTimeInterval;
var debug = new List<dynamic>();
var loopCount = 0;
IResponse response;
do {
response = CyclePort.Request(AbsTime, dt);
debug.Add(response);
response.Switch().
Case<ResponseSuccess>().
Case<ResponseFailTimeInterval>(r => {
dt = r.DeltaT;
}).
Case<ResponseSuccess>(r => { dt = r.SimulationInterval; }).
Case<ResponseFailTimeInterval>(r => { dt = r.DeltaT; }).
Case<ResponseCycleFinished>(r => {
FinishedWithoutErrors = true;
Log.Info("========= Driving Cycle Finished");
}).
Default(r => {
throw new VectoException("TimeRun got an unexpected response: {0}", r);
});
Default(r => { throw new VectoException("TimeRun got an unexpected response: {0}", r); });
if (loopCount++ > Constants.SimulationSettings.MaximumIterationCountForSimulationStep) {
throw new VectoSimulationException("Maximum iteration count for a single simulation interval reached! Aborting!");
}
......
......@@ -30,6 +30,7 @@
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using NLog;
......@@ -92,6 +93,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
public void Run(BackgroundWorker worker = null, Action<double> reportProgressAction = null)
{
var debug = new List<dynamic>();
Log.Info("VectoJob started running.");
Initialize();
......@@ -99,6 +102,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
IResponse response;
do {
response = DoSimulationStep();
debug.Add(response);
if (response is ResponseSuccess) {
Container.CommitSimulationStep(AbsTime, dt);
AbsTime += dt;
......
......@@ -30,7 +30,6 @@
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using NLog;
......@@ -386,6 +385,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
Case<ResponseFailTimeInterval>(r =>
retVal = new ResponseDrivingCycleDistanceExceeded() {
Source = this,
// ReSharper disable once AccessToModifiedClosure
MaxDistance = DataBus.VehicleSpeed * r.DeltaT + operatingPoint.Acceleration / 2 * r.DeltaT * r.DeltaT
}).
Default(r => { throw new UnexpectedResponseException("DrivingAction Brake: first request.", r); });
......@@ -567,6 +567,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return NextComponent.Request(absTime, retVal.SimulationInterval, acc, gradient, true);
},
criterion: response => {
if (response is ResponseEngineSpeedTooLow) {
LogManager.EnableLogging();
Log.Debug("Got EngineSpeedTooLow during SearchOperatingPoint. Aborting!");
throw new VectoSimulationException("EngineSpeed too low during search.");
}
var r = (ResponseDryRun)response;
var d = actionRoll ? r.GearboxPowerRequest : (coasting ? r.DeltaDragLoad : r.DeltaFullLoad);
return d.IsEqual(0.SI<Watt>(), Constants.SimulationSettings.EnginePowerSearchTolerance);
......@@ -662,7 +668,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
Log.Error("{2}: vehicle speed is {0}, acceleration is {1}", currentSpeed.Value(), acceleration.Value(),
DataBus.Distance);
throw new VectoSimulationException(
"vehicle speed has to be > 0 if acceleration = 0! v: {0}, a: {1}, distance: ", currentSpeed.Value(),
"vehicle speed has to be > 0 if acceleration = 0! v: {0}, a: {1}, distance: {2}", currentSpeed.Value(),
acceleration.Value(), DataBus.Distance);
}
......@@ -710,9 +716,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public IResponse DrivingActionHalt(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient)
{
if (!targetVelocity.IsEqual(0) || !DataBus.VehicleSpeed.IsEqual(0, 1e-3)) {
throw new NotImplementedException(string.Format(
"TargetVelocity or VehicleVelocity is not zero! v: {0} target: {1}", DataBus.VehicleSpeed.Value(),
targetVelocity.Value()));
throw new VectoSimulationException("TargetVelocity or VehicleVelocity is not zero! v: {0} target: {1}",
DataBus.VehicleSpeed.Value(), targetVelocity.Value());
}
var retVal = NextComponent.Request(absTime, dt, 0.SI<MeterPerSquareSecond>(), gradient);
retVal.Switch().
......@@ -745,6 +750,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public class DriverState
{
// ReSharper disable once InconsistentNaming
public Second dt;
public MeterPerSquareSecond Acceleration;
public IResponse Response;
......
......@@ -342,6 +342,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public virtual IResponse Request(Second absTime, Second dt)
{
var debug = new List<dynamic>();
// cycle finished
if (RightSample.Current == null || LeftSample.Current == null) {
return new ResponseCycleFinished { AbsTime = absTime, Source = this };
......@@ -362,12 +364,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var acceleration = deltaV / deltaT;
var gradient = LeftSample.Current.RoadGradient;
var response = NextComponent.Request(absTime, dt, acceleration, gradient);
if (response is ResponseGearShift) {
IResponse response;
var responseCount = 0;
do {
response = NextComponent.Request(absTime, dt, acceleration, gradient);
}
debug.Add(response);
response.Switch()
.Case<ResponseGearShift>(() => response = NextComponent.Request(absTime, dt, acceleration, gradient))
.Case<ResponseUnderload>(r => {
DataBus.BrakePower = SearchAlgorithm.Search(DataBus.BrakePower, r.Delta, -r.Delta,
getYValue: result => ((ResponseDryRun)result).DeltaDragLoad,
......@@ -387,15 +390,17 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
criterion: y => ((ResponseDryRun)y).DeltaFullLoad.Abs() < Constants.SimulationSettings.EnginePowerSearchTolerance);
response = NextComponent.Request(absTime, dt, acceleration, gradient);
})
.Case<ResponseFailTimeInterval>(r => { dt = r.DeltaT; })
.Case<ResponseSuccess>(() => { })
.Default(
r => { throw new UnexpectedResponseException("MeasuredSpeedDrivingCycle received an unexpected response.", r); });
if (!(response is ResponseSuccess)) {
throw new UnexpectedResponseException("MeasuredSpeedDrivingCycle received an unexpected response.", response);
}
} while (!(response is ResponseSuccess || response is ResponseFailTimeInterval) && (++responseCount < 10));
AbsTime = absTime + dt;
response.SimulationInterval = dt;
response.Acceleration = acceleration;
debug.Add(response);
return response;
}
......@@ -465,7 +470,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
}
}
protected override void DoWriteModalResults(IModalDataContainer container) {}
protected override void DoWriteModalResults(IModalDataContainer container)
{
container[ModalResultField.dist] = DataBus.Distance;
}
public bool VehicleStopped
{
......
......@@ -66,7 +66,8 @@ namespace TUGraz.VectoCore.Tests.Integration
jobContainer.WaitFinished();
Assert.IsTrue(jobContainer.Runs.All(r => r.Success), string.Concat(jobContainer.Runs.Select(r => r.ExecException)));
Assert.IsTrue(jobContainer.Runs.All(r => r.Success),
string.Join("\n", jobContainer.Runs.Select(r => r.ExecException)));
Assert.IsTrue(File.Exists(@"TestData\Jobs\job-report.vsum"));
Assert.IsTrue(File.Exists(@"TestData\Jobs\job-report.pdf"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment